diff options
| author | Greg Steuck <greg@nest.cx> | 2021-07-04 06:35:26 -0700 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-07-14 07:16:41 +0200 |
| commit | 8a2d0342e072b3bdbc232f5158f421a3b96cc2a0 (patch) | |
| tree | 6d9ed57fb4a006e351934c6fc7179b54c158f428 /dashboard/app/auth_test.go | |
| parent | 116439eed7dad478f73e1fb883285609926eafc9 (diff) | |
dashboard/app: parse JWT into a separate JSON struct
Between JSON type choices and Go struct embedding syntax noise,
relying on field duplication seems the least ugly option.
Diffstat (limited to 'dashboard/app/auth_test.go')
| -rw-r--r-- | dashboard/app/auth_test.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/dashboard/app/auth_test.go b/dashboard/app/auth_test.go index 6b68f61a1..02d7ad9fc 100644 --- a/dashboard/app/auth_test.go +++ b/dashboard/app/auth_test.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "github.com/google/syzkaller/dashboard/dashapi" "net/http" "net/http/httptest" @@ -10,13 +11,13 @@ import ( "time" ) -func dayFromNow() float64 { - return float64(time.Now().AddDate(0, 0, 1).Unix()) -} - func reponseFor(t *testing.T, claims jwtClaims) (*httptest.Server, authEndpoint) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - bytes, err := json.Marshal(claims) + bytes, err := json.Marshal(jwtClaimsParse{ + Subject: claims.Subject, + Audience: claims.Audience, + Expiration: fmt.Sprint(claims.Expiration.Unix()), + }) if err != nil { t.Fatalf("Marshal %v", err) } @@ -30,8 +31,8 @@ func TestBearerValid(t *testing.T) { magic := "ValidSubj" ts, dut := reponseFor(t, jwtClaims{ Subject: magic, - Expiration: dayFromNow(), Audience: dashapi.DashboardAudience, + Expiration: time.Now().AddDate(0, 0, 1), }) defer ts.Close() @@ -47,7 +48,7 @@ func TestBearerValid(t *testing.T) { func TestBearerWrongAudience(t *testing.T) { ts, dut := reponseFor(t, jwtClaims{ Subject: "irrelevant", - Expiration: dayFromNow(), + Expiration: time.Now().AddDate(0, 0, 1), Audience: "junk", }) defer ts.Close() @@ -61,7 +62,7 @@ func TestBearerWrongAudience(t *testing.T) { func TestBearerExpired(t *testing.T) { ts, dut := reponseFor(t, jwtClaims{ Subject: "irrelevant", - Expiration: -1234, + Expiration: time.Now().AddDate(0, 0, -1), Audience: dashapi.DashboardAudience, }) defer ts.Close() |
