From b438bd66d6f95113d52f25c25bfef0e963c8ce8d Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 9 Jan 2024 16:27:55 +0100 Subject: 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. --- dashboard/app/api_test.go | 139 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) (limited to 'dashboard/app/api_test.go') 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) +} -- cgit mrf-deployment