Commit dc979c1d authored by Moto Ishizawa's avatar Moto Ishizawa

server: use time.Time instead of int64 for token expiration time

parent 25e4228e
......@@ -283,7 +283,7 @@ func TestServerCodeTokenCrossClient(t *testing.T) {
t.Fatalf("case %d: unexpected error: %v", i, err)
}
jwt, token, expiresIn, err := f.srv.CodeToken(f.clientCreds[tt.clientID], key)
jwt, token, expiresAt, err := f.srv.CodeToken(f.clientCreds[tt.clientID], key)
if err != nil {
t.Fatalf("case %d: unexpected error: %v", i, err)
}
......@@ -293,7 +293,7 @@ func TestServerCodeTokenCrossClient(t *testing.T) {
if token != tt.refreshToken {
t.Errorf("case %d: expect refresh token %q, got %q", i, tt.refreshToken, token)
}
if expiresIn == 0 {
if expiresAt.IsZero() {
t.Errorf("case %d: expect non-zero expiration time", i)
}
......
......@@ -491,7 +491,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
var jwt *jose.JWT
var refreshToken string
var expiresIn int64
var expiresAt time.Time
grantType := r.PostForm.Get("grant_type")
switch grantType {
......@@ -502,14 +502,14 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
writeTokenError(w, oauth2.NewError(oauth2.ErrorInvalidRequest), state)
return
}
jwt, refreshToken, expiresIn, err = srv.CodeToken(creds, code)
jwt, refreshToken, expiresAt, err = srv.CodeToken(creds, code)
if err != nil {
log.Errorf("couldn't exchange code for token: %v", err)
writeTokenError(w, err, state)
return
}
case oauth2.GrantTypeClientCreds:
jwt, expiresIn, err = srv.ClientCredsToken(creds)
jwt, expiresAt, err = srv.ClientCredsToken(creds)
if err != nil {
log.Errorf("couldn't creds for token: %v", err)
writeTokenError(w, err, state)
......@@ -522,7 +522,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
writeTokenError(w, oauth2.NewError(oauth2.ErrorInvalidRequest), state)
return
}
jwt, refreshToken, expiresIn, err = srv.RefreshToken(creds, strings.Split(scopes, " "), token)
jwt, refreshToken, expiresAt, err = srv.RefreshToken(creds, strings.Split(scopes, " "), token)
if err != nil {
writeTokenError(w, err, state)
return
......@@ -538,7 +538,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
IDToken: jwt.Encode(),
TokenType: "bearer",
RefreshToken: refreshToken,
ExpiresIn: expiresIn,
ExpiresIn: int64(expiresAt.Sub(time.Now()).Seconds()),
}
b, err := json.Marshal(t)
......
This diff is collapsed.
......@@ -443,7 +443,7 @@ func TestServerCodeToken(t *testing.T) {
t.Fatalf("case %d: unexpected error: %v", i, err)
}
jwt, token, expiresIn, err := f.srv.CodeToken(oidc.ClientCredentials{
jwt, token, expiresAt, err := f.srv.CodeToken(oidc.ClientCredentials{
ID: testClientID,
Secret: clientTestSecret}, key)
if err != nil {
......@@ -455,7 +455,7 @@ func TestServerCodeToken(t *testing.T) {
if token != tt.refreshToken {
t.Fatalf("case %d: expect refresh token %q, got %q", i, tt.refreshToken, token)
}
if expiresIn == 0 {
if expiresAt.IsZero() {
t.Fatalf("case %d: expect non-zero expiration time", i)
}
}
......@@ -478,7 +478,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
jwt, token, expiresIn, err := f.srv.CodeToken(testClientCredentials, "foo")
jwt, token, expiresAt, err := f.srv.CodeToken(testClientCredentials, "foo")
if err == nil {
t.Fatalf("Expected non-nil error")
}
......@@ -488,7 +488,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
if token != "" {
t.Fatalf("Expected empty refresh token")
}
if expiresIn != 0 {
if !expiresAt.IsZero() {
t.Fatalf("Expected zero expiration time")
}
}
......@@ -586,7 +586,7 @@ func TestServerTokenFail(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
jwt, token, expiresIn, err := f.srv.CodeToken(tt.argCC, tt.argKey)
jwt, token, expiresAt, err := f.srv.CodeToken(tt.argCC, tt.argKey)
if token != tt.refreshToken {
fmt.Printf("case %d: expect refresh token %q, got %q\n", i, tt.refreshToken, token)
t.Fatalf("case %d: expect refresh token %q, got %q", i, tt.refreshToken, token)
......@@ -601,8 +601,8 @@ func TestServerTokenFail(t *testing.T) {
if err != nil && jwt != nil {
t.Errorf("case %d: got non-nil JWT %v", i, jwt)
}
if err == nil && expiresIn == 0 {
t.Errorf("case %d: got zero expiration time %v", i, expiresIn)
if err == nil && expiresAt.IsZero() {
t.Errorf("case %d: got zero expiration time %v", i, expiresAt)
}
}
}
......@@ -885,7 +885,7 @@ func TestServerRefreshToken(t *testing.T) {
t.Errorf("Case %d: want=%v, got=%v", i, tt.expectedRefreshToken, refreshToken)
}
if err == nil && expiresIn == 0 {
if err == nil && expiresIn.IsZero() {
t.Errorf("case %d: got zero expiration time %v", i, expiresIn)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment