Skip to content
Closed
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
3 changes: 3 additions & 0 deletions app/auth/plugins/azure_oidc/outgoing.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func parseExpiry(expiresOn string, expiresIn json.Number) time.Time {
if ts, err := strconv.ParseInt(expiresOn, 10, 64); err == nil && ts > 0 {
return time.Unix(ts, 0)
}
if t, err := time.Parse("01/02/2006 15:04:05 -07:00", expiresOn); err == nil {
return t
}
}
if expiresIn != "" {
if secs, err := expiresIn.Int64(); err == nil && secs > 0 {
Expand Down
34 changes: 34 additions & 0 deletions app/auth/plugins/azure_oidc/outgoing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ func TestAzureOIDCUsesExpiresOn(t *testing.T) {
}
}

func TestAzureOIDCParsesDateFormattedExpiresOn(t *testing.T) {
resetCache()

future := time.Now().Add(45 * time.Minute).UTC()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"access_token":"tok","expires_on":"%s"}`, future.Format("01/02/2006 15:04:05 -07:00"))
}))
defer ts.Close()

oldHost := MetadataHost
MetadataHost = ts.URL
defer func() { MetadataHost = oldHost }()

oldClient := HTTPClient
HTTPClient = ts.Client()
defer func() { HTTPClient = oldClient }()

p := AzureOIDC{}
cfg, err := p.ParseParams(map[string]interface{}{"resource": "api://res"})
if err != nil {
t.Fatal(err)
}

r := &http.Request{Header: http.Header{}}
if err := p.AddAuth(context.Background(), r, cfg); err != nil {
t.Fatal(err)
}

_, exp := getCachedToken("api://res|")
if time.Until(exp) < 40*time.Minute {
t.Fatalf("expected parsed expiry around 45m, got %s", exp)
}
}

func TestAzureOIDCParamLists(t *testing.T) {
p := AzureOIDC{}
if got := p.RequiredParams(); len(got) != 1 || got[0] != "resource" {
Expand Down
Loading