diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-09 16:27:55 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-01-09 17:48:04 +0000 |
| commit | b438bd66d6f95113d52f25c25bfef0e963c8ce8d (patch) | |
| tree | affa3733771acfc752397dc89a1c6e712d4d622c /dashboard/app/api_test.go | |
| parent | 83b32fe8f20dc1e910866fa110b0d872df283f03 (diff) | |
dashboard: introduce an emergency stop mode
Add an emergency stop button that can be used by any admin. After it's
clicked two times, syzbot stops all reporting and recoding of new bugs.
It's assumed that the stop mode is revoked by manually deleting an entry
from the database.
Diffstat (limited to 'dashboard/app/api_test.go')
| -rw-r--r-- | dashboard/app/api_test.go | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/dashboard/app/api_test.go b/dashboard/app/api_test.go index 8d63ce7a7..4a872231e 100644 --- a/dashboard/app/api_test.go +++ b/dashboard/app/api_test.go @@ -5,6 +5,9 @@ package main import ( "testing" + "time" + + "github.com/google/syzkaller/dashboard/dashapi" ) func TestClientSecretOK(t *testing.T) { @@ -63,3 +66,139 @@ func TestClientNamespaceOK(t *testing.T) { 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("test@requester.com"), + EmailOptCC([]string{"somebody@else.com", "test@syzkaller.com"})) + 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) +} |
