-
Notifications
You must be signed in to change notification settings - Fork 459
OCPBUGS-99757: Include extra scopes in OIDC token cache key #2323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 1 commit into
openshift:main
from
michaelryanmcneill:OCPBUGS-99757
Jul 28, 2026
+153
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package tokencache | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestComputeFilename(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| k1 Key | ||
| k2 Key | ||
| wantEqual bool | ||
| }{ | ||
| { | ||
| name: "same keys without scopes produce same filename", | ||
| k1: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client"}, | ||
| k2: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client"}, | ||
| wantEqual: true, | ||
| }, | ||
| { | ||
| name: "identical sorted scopes produce same filename", | ||
| k1: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client", ExtraScopes: []string{"email", "profile"}}, | ||
| k2: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client", ExtraScopes: []string{"email", "profile"}}, | ||
| wantEqual: true, | ||
| }, | ||
| { | ||
| name: "presence of scopes changes filename", | ||
| k1: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client"}, | ||
| k2: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client", ExtraScopes: []string{"email", "profile"}}, | ||
| wantEqual: false, | ||
| }, | ||
| { | ||
| name: "differently ordered scopes produce same filename", | ||
| k1: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client", ExtraScopes: []string{"email", "profile"}}, | ||
| k2: Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client", ExtraScopes: []string{"profile", "email"}}, | ||
| wantEqual: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| f1, err := computeFilename(tt.k1) | ||
| if err != nil { | ||
| t.Fatalf("computeFilename(k1) error: %v", err) | ||
| } | ||
| f2, err := computeFilename(tt.k2) | ||
| if err != nil { | ||
| t.Fatalf("computeFilename(k2) error: %v", err) | ||
| } | ||
|
|
||
| if tt.wantEqual && f1 != f2 { | ||
| t.Errorf("expected same filename, got %s and %s", f1, f2) | ||
| } | ||
| if !tt.wantEqual && f1 == f2 { | ||
| t.Errorf("expected different filenames, got %s for both", f1) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSaveAndFindByKey(t *testing.T) { | ||
| dir := t.TempDir() | ||
| repo := &Repository{} | ||
|
|
||
| key := Key{ | ||
| IssuerURL: "https://issuer.example.com", | ||
| ClientID: "my-client", | ||
| ExtraScopes: []string{"email", "profile"}, | ||
| } | ||
| want := Set{ | ||
| IDToken: "test-id-token", | ||
| RefreshToken: "test-refresh-token", | ||
| } | ||
|
|
||
| if err := repo.Save(dir, key, want); err != nil { | ||
| t.Fatalf("Save() error: %v", err) | ||
| } | ||
|
|
||
| got, err := repo.FindByKey(dir, key) | ||
| if err != nil { | ||
| t.Fatalf("FindByKey() error: %v", err) | ||
| } | ||
|
|
||
| if diff := cmp.Diff(&want, got); diff != "" { | ||
| t.Errorf("FindByKey() mismatch (-want +got):\n%s", diff) | ||
| } | ||
| } | ||
|
|
||
| func TestFindByKey_DifferentScopesMiss(t *testing.T) { | ||
| dir := t.TempDir() | ||
| repo := &Repository{} | ||
|
|
||
| key := Key{ | ||
| IssuerURL: "https://issuer.example.com", | ||
| ClientID: "my-client", | ||
| ExtraScopes: []string{"email"}, | ||
| } | ||
| if err := repo.Save(dir, key, Set{IDToken: "token1", RefreshToken: "refresh1"}); err != nil { | ||
| t.Fatalf("Save() error: %v", err) | ||
| } | ||
|
|
||
| differentKey := Key{ | ||
| IssuerURL: "https://issuer.example.com", | ||
| ClientID: "my-client", | ||
| ExtraScopes: []string{"email", "profile"}, | ||
| } | ||
| _, err := repo.FindByKey(dir, differentKey) | ||
| if err == nil { | ||
| t.Fatal("expected FindByKey to fail for a key with different scopes, but it succeeded") | ||
| } | ||
| if !os.IsNotExist(err) { | ||
| t.Errorf("expected file-not-found error, got: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestSave_FilePermissions(t *testing.T) { | ||
| dir := t.TempDir() | ||
| repo := &Repository{} | ||
|
|
||
| key := Key{IssuerURL: "https://issuer.example.com", ClientID: "my-client"} | ||
| if err := repo.Save(dir, key, Set{IDToken: "tok"}); err != nil { | ||
| t.Fatalf("Save() error: %v", err) | ||
| } | ||
|
|
||
| filename, err := computeFilename(key) | ||
| if err != nil { | ||
| t.Fatalf("computeFilename() error: %v", err) | ||
| } | ||
| info, err := os.Stat(filepath.Join(dir, filename)) | ||
| if err != nil { | ||
| t.Fatalf("Stat() error: %v", err) | ||
| } | ||
| if perm := info.Mode().Perm(); perm != 0600 { | ||
| t.Errorf("expected file permission 0600, got %o", perm) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.