From 02a2ba2966613de55c837fe709ee34f1ff5be606 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 17 Jan 2018 11:51:41 +0100 Subject: dashboard/app: add job user blacklist --- dashboard/app/app_test.go | 3 +++ dashboard/app/config.go | 7 +++++++ dashboard/app/jobs.go | 6 ++++++ dashboard/app/jobs_test.go | 8 +++++++- dashboard/app/util_test.go | 10 +++++++--- 5 files changed, 30 insertions(+), 4 deletions(-) (limited to 'dashboard') diff --git a/dashboard/app/app_test.go b/dashboard/app/app_test.go index cf9347516..9507a5209 100644 --- a/dashboard/app/app_test.go +++ b/dashboard/app/app_test.go @@ -19,6 +19,9 @@ var config = GlobalConfig{ Clients: map[string]string{ "reporting": "reportingkeyreportingkeyreportingkey", }, + EmailBlacklist: []string{ + "\"Bar\" ", + }, Namespaces: map[string]*Config{ "test1": &Config{ Key: "test1keytest1keytest1key", diff --git a/dashboard/app/config.go b/dashboard/app/config.go index 0d6234f35..cb1759d4c 100644 --- a/dashboard/app/config.go +++ b/dashboard/app/config.go @@ -8,6 +8,8 @@ import ( "fmt" "regexp" "time" + + "github.com/google/syzkaller/pkg/email" ) // There are multiple configurable aspects of the app (namespaces, reporting, API clients, etc). @@ -18,6 +20,8 @@ type GlobalConfig struct { AuthDomain string // Global API clients that work across namespaces (e.g. external reporting). Clients map[string]string + // List of emails blacklisted from issuing test requests. + EmailBlacklist []string // Per-namespace config. // Namespaces are a mechanism to separate groups of different kernels. // E.g. Debian 4.4 kernels and Ubuntu 4.9 kernels. @@ -101,6 +105,9 @@ func init() { if len(config.Namespaces) == 0 { panic("no namespaces found") } + for i := range config.EmailBlacklist { + config.EmailBlacklist[i] = email.CanonicalEmail(config.EmailBlacklist[i]) + } namespaces := make(map[string]bool) clientNames := make(map[string]bool) checkClients(clientNames, config.Clients) diff --git a/dashboard/app/jobs.go b/dashboard/app/jobs.go index 52e7a4b5e..ff5f127cb 100644 --- a/dashboard/app/jobs.go +++ b/dashboard/app/jobs.go @@ -23,6 +23,12 @@ import ( func handleTestRequest(c context.Context, bugID, user, extID, patch, repo, branch string) string { log.Infof(c, "test request: bug=%q user=%q extID=%q patch=%v, repo=%q branch=%q", bugID, user, extID, len(patch), repo, branch) + for _, blacklisted := range config.EmailBlacklist { + if user == blacklisted { + log.Warningf(c, "test request from blacklisted user: %v", user) + return "" + } + } reply, err := addTestJob(c, bugID, user, extID, patch, repo, branch) if err != nil { log.Errorf(c, "test request failed: %v", err) diff --git a/dashboard/app/jobs_test.go b/dashboard/app/jobs_test.go index f1eacc408..77eb594e4 100644 --- a/dashboard/app/jobs_test.go +++ b/dashboard/app/jobs_test.go @@ -70,11 +70,17 @@ func TestJob(t *testing.T) { c.expectEQ(len(c.emailSink), 1) c.expectEQ(strings.Contains((<-c.emailSink).Body, "I don't see any patch attached to the request"), true) + c.incomingEmailFrom("\"foo\" ", sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch) + c.expectOK(c.GET("/email_poll")) + c.expectEQ(len(c.emailSink), 0) + pollResp := new(dashapi.JobPollResp) + c.expectOK(c.API(client2, key2, "job_poll", &dashapi.JobPollReq{[]string{build.Manager}}, pollResp)) + c.expectEQ(pollResp.ID, "") + c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch) c.expectOK(c.GET("/email_poll")) c.expectEQ(len(c.emailSink), 0) - pollResp := new(dashapi.JobPollResp) c.expectOK(c.API(client2, key2, "job_poll", &dashapi.JobPollReq{[]string{"foobar"}}, pollResp)) c.expectEQ(pollResp.ID, "") c.expectOK(c.API(client2, key2, "job_poll", &dashapi.JobPollReq{[]string{build.Manager}}, pollResp)) diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go index c9b8f8688..0df38a002 100644 --- a/dashboard/app/util_test.go +++ b/dashboard/app/util_test.go @@ -179,17 +179,21 @@ func (c *Ctx) httpRequest(method, url, body string) error { } func (c *Ctx) incomingEmail(to, body string) { - email := fmt.Sprintf(`Sender: foo@bar.com + c.incomingEmailFrom("default@sender.com", to, body) +} + +func (c *Ctx) incomingEmailFrom(from, to, body string) { + email := fmt.Sprintf(`Sender: %v Date: Tue, 15 Aug 2017 14:59:00 -0700 Message-ID: <1234> Subject: crash1 -From: default@sender.com +From: %v Cc: test@syzkaller.com, bugs@syzkaller.com To: %v Content-Type: text/plain %v -`, to, body) +`, from, from, to, body) c.expectOK(c.POST("/_ah/mail/", email)) } -- cgit mrf-deployment