Skip to content

Commit e7efdb4

Browse files
committed
Treat both implicit or explicit 0 value as invalid behavior unless backend team giving a spec
1 parent 00978f1 commit e7efdb4

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

google/internal/externalaccount/basecredentials.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,10 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
247247
// The RFC8693 doesn't define the explicit 0 of "expires_in" field behavior.
248248
// In practice a lot of sts request is using 0 means "never expire" for an sts token.
249249
// So the logic here shall use a max unix time value.
250-
if stsResp.ExpiresIn < 0 {
250+
if stsResp.ExpiresIn <= 0 {
251251
return nil, fmt.Errorf("oauth2/google: got invalid expiry from security token service")
252-
} else if stsResp.ExpiresIn > 0 {
253-
accessToken.Expiry = now().Add(time.Duration(stsResp.ExpiresIn) * time.Second)
254-
} else {
255-
accessToken.Expiry = maxUnixTime
256252
}
253+
accessToken.Expiry = now().Add(time.Duration(stsResp.ExpiresIn) * time.Second)
257254

258255
if stsResp.RefreshToken != "" {
259256
accessToken.RefreshToken = stsResp.RefreshToken

google/internal/externalaccount/basecredentials_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,15 @@ func TestToken(t *testing.T) {
151151
},
152152
},
153153
{
154-
name: "happy case, non expire token",
154+
name: "no expiry time on token",
155155
responseBody: MockSTSResponse{
156156
AccessToken: correctAT,
157157
IssuedTokenType: "urn:ietf:params:oauth:token-type:access_token",
158158
TokenType: "Bearer",
159-
ExpiresIn: 0,
160159
Scope: "https://www.googleapis.com/auth/cloud-platform",
161160
},
162-
expectToken: &oauth2.Token{
163-
AccessToken: correctAT,
164-
TokenType: "Bearer",
165-
Expiry: maxUnixTime,
166-
},
161+
expectToken: nil,
162+
expectErrorMsg: "oauth2/google: got invalid expiry from security token service",
167163
},
168164
{
169165
name: "negative expiry time",

0 commit comments

Comments
 (0)