forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
204 lines (167 loc) · 4.66 KB
/
api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"testing"
"time"
"github.com/google/syzkaller/dashboard/dashapi"
)
func TestClientSecretOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "secr1t",
},
}, "user", "secr1t", "")
if err != nil || got != "" {
t.Errorf("unexpected error %v %v", got, err)
}
}
func TestClientOauthOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "OauthSubject:public",
},
}, "user", "", "OauthSubject:public")
if err != nil || got != "" {
t.Errorf("unexpected error %v %v", got, err)
}
}
func TestClientSecretFail(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "secr1t",
},
}, "user", "wrong", "")
if err != ErrAccess || got != "" {
t.Errorf("unexpected error %v %v", got, err)
}
}
func TestClientSecretMissing(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{},
}, "user", "ignored", "")
if err != ErrAccess || got != "" {
t.Errorf("unexpected error %v %v", got, err)
}
}
func TestClientNamespaceOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Namespaces: map[string]*Config{
"ns1": {
Clients: map[string]string{
"user": "secr1t",
},
},
},
}, "user", "secr1t", "")
if err != nil || got != "ns1" {
t.Errorf("unexpected error %v %v", got, err)
}
}
func TestEmergentlyStoppedEmail(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.publicClient
build := testBuild(1)
client.UploadBuild(build)
crash := testCrash(build, 1)
client.ReportCrash(crash)
c.advanceTime(time.Hour)
_, err := c.AuthGET(AccessAdmin, "/admin?action=emergency_stop")
c.expectOK(err)
// There should be no email.
c.advanceTime(time.Hour)
c.expectNoEmail()
}
func TestEmergentlyStoppedReproEmail(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.publicClient
build := testBuild(1)
client.UploadBuild(build)
crash := testCrash(build, 1)
client.ReportCrash(crash)
c.pollEmailBug()
crash2 := testCrash(build, 1)
crash2.ReproOpts = []byte("repro opts")
crash2.ReproSyz = []byte("getpid()")
client.ReportCrash(crash2)
c.advanceTime(time.Hour)
_, err := c.AuthGET(AccessAdmin, "/admin?action=emergency_stop")
c.expectOK(err)
// There should be no email.
c.advanceTime(time.Hour)
c.expectNoEmail()
}
func TestEmergentlyStoppedExternalReport(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.client
build := testBuild(1)
client.UploadBuild(build)
crash := testCrash(build, 1)
client.ReportCrash(crash)
c.advanceTime(time.Hour)
_, err := c.AuthGET(AccessAdmin, "/admin?action=emergency_stop")
c.expectOK(err)
// There should be no email.
c.advanceTime(time.Hour)
client.pollBugs(0)
}
func TestEmergentlyStoppedEmailJob(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.publicClient
build := testBuild(1)
client.UploadBuild(build)
crash := testCrash(build, 1)
crash.ReproOpts = []byte("repro opts")
crash.ReproSyz = []byte("getpid()")
client.ReportCrash(crash)
sender := c.pollEmailBug().Sender
c.incomingEmail(sender, "#syz upstream\n")
sender = c.pollEmailBug().Sender
// Send a patch testing request.
c.advanceTime(time.Hour)
c.incomingEmail(sender, syzTestGitBranchSamplePatch,
EmailOptMessageID(1), EmailOptFrom("[email protected]"),
EmailOptCC([]string{"[email protected]", "[email protected]"}))
c.expectNoEmail()
// Emulate a finished job.
pollResp := client.pollJobs(build.Manager)
c.expectEQ(pollResp.Type, dashapi.JobTestPatch)
c.advanceTime(time.Hour)
jobDoneReq := &dashapi.JobDoneReq{
ID: pollResp.ID,
Build: *build,
CrashTitle: "test crash title",
CrashLog: []byte("test crash log"),
CrashReport: []byte("test crash report"),
}
client.JobDone(jobDoneReq)
// Now we emergently stop syzbot.
c.advanceTime(time.Hour)
_, err := c.AuthGET(AccessAdmin, "/admin?action=emergency_stop")
c.expectOK(err)
// There should be no email.
c.advanceTime(time.Hour)
c.expectNoEmail()
}
func TestEmergentlyStoppedCrashReport(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.publicClient
build := testBuild(1)
client.UploadBuild(build)
// Now we emergently stop syzbot.
c.advanceTime(time.Hour)
_, err := c.AuthGET(AccessAdmin, "/admin?action=emergency_stop")
c.expectOK(err)
crash := testCrash(build, 1)
crash.ReproOpts = []byte("repro opts")
crash.ReproSyz = []byte("getpid()")
client.ReportCrash(crash)
listResp, err := client.BugList()
c.expectOK(err)
c.expectEQ(len(listResp.List), 0)
}