Skip to content

Commit 8227340

Browse files
ScruffyProdigycodyoss
authored andcommitted
fix: missing expiration_time field isn't a problem for executables
Change-Id: Ib19e3d9dcd8a4c41afebf2a1fb97429617eef86b GitHub-Last-Rev: 96eb234 GitHub-Pull-Request: #576 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/418434 Reviewed-by: Leo Siracusa <leosiracusa@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cody Oss <codyoss@google.com>
1 parent 128564f commit 8227340

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

‎google/internal/externalaccount/executablecredsource.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ type executableResponse struct {
178178
Message string `json:"message,omitempty"`
179179
}
180180

181-
func parseSubjectTokenFromSource(response []byte, source string, now int64) (string, error) {
181+
func (cs executableCredentialSource) parseSubjectTokenFromSource(response []byte, source string, now int64) (string, error) {
182182
var result executableResponse
183183
if err := json.Unmarshal(response, &result); err != nil {
184184
return "", jsonParsingError(source, string(response))
@@ -203,15 +203,15 @@ func parseSubjectTokenFromSource(response []byte, source string, now int64) (str
203203
return "", unsupportedVersionError(source, result.Version)
204204
}
205205

206-
if result.ExpirationTime == 0 {
206+
if result.ExpirationTime == 0 && cs.OutputFile != "" {
207207
return "", missingFieldError(source, "expiration_time")
208208
}
209209

210210
if result.TokenType == "" {
211211
return "", missingFieldError(source, "token_type")
212212
}
213213

214-
if result.ExpirationTime < now {
214+
if result.ExpirationTime != 0 && result.ExpirationTime < now {
215215
return "", tokenExpiredError()
216216
}
217217

@@ -259,7 +259,7 @@ func (cs executableCredentialSource) getTokenFromOutputFile() (token string, err
259259
return "", nil
260260
}
261261

262-
token, err = parseSubjectTokenFromSource(data, outputFileSource, cs.env.now().Unix())
262+
token, err = cs.parseSubjectTokenFromSource(data, outputFileSource, cs.env.now().Unix())
263263
if err != nil {
264264
if _, ok := err.(nonCacheableError); ok {
265265
// If the cached token is expired we need a new token,
@@ -304,5 +304,5 @@ func (cs executableCredentialSource) getTokenFromExecutableCommand() (string, er
304304
if err != nil {
305305
return "", err
306306
}
307-
return parseSubjectTokenFromSource(output, executableSource, cs.env.now().Unix())
307+
return cs.parseSubjectTokenFromSource(output, executableSource, cs.env.now().Unix())
308308
}

‎google/internal/externalaccount/executablecredsource_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,6 @@ var failureTests = []struct {
388388
expectedErr: missingFieldError(executableSource, "token_type"),
389389
},
390390

391-
{
392-
name: "Missing Expiration",
393-
testEnvironment: testEnvironment{
394-
envVars: executablesAllowed,
395-
jsonResponse: &executableResponse{
396-
Success: Bool(true),
397-
Version: 1,
398-
TokenType: "urn:ietf:params:oauth:token-type:jwt",
399-
},
400-
},
401-
expectedErr: missingFieldError(executableSource, "expiration_time"),
402-
},
403-
404391
{
405392
name: "Token Expired",
406393
testEnvironment: testEnvironment{
@@ -564,6 +551,19 @@ var successTests = []struct {
564551
},
565552
},
566553
},
554+
555+
{
556+
name: "Missing Expiration",
557+
testEnvironment: testEnvironment{
558+
envVars: executablesAllowed,
559+
jsonResponse: &executableResponse{
560+
Success: Bool(true),
561+
Version: 1,
562+
TokenType: "urn:ietf:params:oauth:token-type:jwt",
563+
IdToken: "tokentokentoken",
564+
},
565+
},
566+
},
567567
}
568568

569569
func TestRetrieveExecutableSubjectTokenSuccesses(t *testing.T) {

0 commit comments

Comments
 (0)