aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dashboard/app/access_test.go33
-rw-r--r--dashboard/app/app_test.go1
-rw-r--r--dashboard/app/util_test.go14
3 files changed, 25 insertions, 23 deletions
diff --git a/dashboard/app/access_test.go b/dashboard/app/access_test.go
index 315ee341f..c2a3191c4 100644
--- a/dashboard/app/access_test.go
+++ b/dashboard/app/access_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"github.com/google/syzkaller/dashboard/dashapi"
+ "github.com/stretchr/testify/assert"
"google.golang.org/appengine/v2/user"
)
@@ -44,9 +45,6 @@ func TestAccessConfig(t *testing.T) {
// TestAccess checks that all UIs respect access levels.
// nolint: funlen, goconst
func TestAccess(t *testing.T) {
- if testing.Short() {
- t.Skip()
- }
c := NewCtx(t)
defer c.Close()
@@ -379,7 +377,7 @@ func TestAccess(t *testing.T) {
// checkReferences checks that page contents do not contain
// references to entities that must not be visible.
- checkReferences := func(url string, requestLevel AccessLevel, reply []byte) {
+ checkReferences := func(t *testing.T, url string, requestLevel AccessLevel, reply []byte) {
for _, ent := range entities {
if requestLevel >= ent.level || ent.ref == "" {
continue
@@ -392,22 +390,22 @@ func TestAccess(t *testing.T) {
}
// checkPage checks that the page at url is accessible/not accessible as required.
- checkPage := func(requestLevel, pageLevel AccessLevel, url string) []byte {
+ checkPage := func(t *testing.T, requestLevel, pageLevel AccessLevel, url string) []byte {
reply, err := c.AuthGET(requestLevel, url)
if requestLevel >= pageLevel {
- c.expectOK(err)
+ assert.NoError(t, err)
} else if requestLevel == AccessPublic {
loginURL, err1 := user.LoginURL(c.ctx, url)
if err1 != nil {
t.Fatal(err1)
}
- c.expectNE(err, nil)
+ assert.NotNil(t, err)
var httpErr *HTTPError
- c.expectTrue(errors.As(err, &httpErr))
- c.expectEQ(httpErr.Code, http.StatusTemporaryRedirect)
- c.expectEQ(httpErr.Headers["Location"], []string{loginURL})
+ assert.True(t, errors.As(err, &httpErr))
+ assert.Equal(t, httpErr.Code, http.StatusTemporaryRedirect)
+ assert.Equal(t, httpErr.Headers["Location"], []string{loginURL})
} else {
- c.expectForbidden(err)
+ expectFailureStatus(t, err, http.StatusForbidden)
}
return reply
}
@@ -415,12 +413,19 @@ func TestAccess(t *testing.T) {
// Finally, request all entities at all access levels and
// check that we see only what we need to see.
for requestLevel := AccessPublic; requestLevel < AccessAdmin; requestLevel++ {
- for _, ent := range entities {
+ for i, ent := range entities {
if ent.url == "" {
continue
}
- reply := checkPage(requestLevel, ent.level, ent.url)
- checkReferences(ent.url, requestLevel, reply)
+ if testing.Short() && (requestLevel != AccessPublic || ent.level == AccessPublic) {
+ // In the short mode, only test that there's no public access to non-public URLs.
+ continue
+ }
+ ent := ent
+ t.Run(fmt.Sprintf("level%d_%d", requestLevel, i), func(t *testing.T) {
+ reply := checkPage(t, requestLevel, ent.level, ent.url)
+ checkReferences(t, ent.url, requestLevel, reply)
+ })
}
}
}
diff --git a/dashboard/app/app_test.go b/dashboard/app/app_test.go
index 99da350aa..8a82d78d0 100644
--- a/dashboard/app/app_test.go
+++ b/dashboard/app/app_test.go
@@ -693,6 +693,7 @@ func testCrashWithRepro(build *dashapi.Build, id int) *dashapi.Crash {
crash.ReproOpts = []byte(fmt.Sprintf("repro opts %v", id))
crash.ReproSyz = []byte(fmt.Sprintf("syncfs(%v)", id))
crash.ReproC = []byte(fmt.Sprintf("int main() { return %v; }", id))
+ crash.ReproLog = []byte(fmt.Sprintf("repro log %d", id))
return crash
}
diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go
index c2f64ff67..f30581095 100644
--- a/dashboard/app/util_test.go
+++ b/dashboard/app/util_test.go
@@ -107,23 +107,19 @@ func (c *Ctx) expectFail(msg string, err error) {
}
}
-func (c *Ctx) expectFailureStatus(err error, code int) {
- c.t.Helper()
+func expectFailureStatus(t *testing.T, err error, code int) {
+ t.Helper()
if err == nil {
- c.t.Fatalf("expected to fail as %d, but it does not", code)
+ t.Fatalf("expected to fail as %d, but it does not", code)
}
var httpErr *HTTPError
if !errors.As(err, &httpErr) || httpErr.Code != code {
- c.t.Fatalf("expected to fail as %d, but it failed as %v", code, err)
+ t.Fatalf("expected to fail as %d, but it failed as %v", code, err)
}
}
-func (c *Ctx) expectForbidden(err error) {
- c.expectFailureStatus(err, http.StatusForbidden)
-}
-
func (c *Ctx) expectBadReqest(err error) {
- c.expectFailureStatus(err, http.StatusBadRequest)
+ expectFailureStatus(c.t, err, http.StatusBadRequest)
}
func (c *Ctx) expectEQ(got, want interface{}) {