Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vapid.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func getVAPIDAuthorizationHeader(

token := jwt.NewWithClaims(jwt.SigningMethodES256, jwt.MapClaims{
"aud": subURL.Scheme + "://" + subURL.Host,
"exp": time.Now().Add(time.Hour * 12).Unix(),
"exp": expiration.Unix(),
"sub": subscriber,
})

Expand Down
14 changes: 13 additions & 1 deletion vapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ func TestVAPID(t *testing.T) {
t.Fatal(err)
}

// Unusual expiration to check that the expiration value is used
expiration := time.Now().Add(time.Hour * 11).Add(23 * time.Minute)

// Get authentication header
vapidAuthHeader, err := getVAPIDAuthorizationHeader(
s.Endpoint,
sub,
vapidPublicKey,
vapidPrivateKey,
time.Now().Add(time.Hour*12),
expiration,
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -65,6 +68,15 @@ func TestVAPID(t *testing.T) {
if claims["aud"] == "" {
t.Fatal("Audience should not be empty")
}

expectedExp := float64(expiration.Unix())
if expectedExp != claims["exp"] {
t.Fatalf(
"Incorrect exp, expected=%v, got=%v",
expectedExp,
claims["exp"],
)
}
} else {
t.Fatal(err)
}
Expand Down