Repository navigation
Add a test pinning the OS keyring secret size cap behind #7707 #7727
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //go:build darwin || windows | ||
|
|
||
| package storage | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
| "uuid" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/zalando/go-keyring" | ||
| "golang.org/x/oauth2" | ||
| ) | ||
|
|
||
| // issue7707AccessTokenBytes is the size of the U2M access tokens reported in | ||
| // https://github.com/databricks/cli/issues/7707. Tokens of 800-950 bytes from | ||
| // the same account store fine. | ||
| const issue7707AccessTokenBytes = 3250 | ||
|
|
||
| // The OS backends behind zalando/go-keyring cap the secret size and return | ||
| // ErrSetDataTooBig before touching the keyring, so this test does not need an | ||
| // unlocked keychain or Credential Manager: | ||
| // - macOS: the base64-encoded `security -i add-generic-password` line must be | ||
| // at most 4096 bytes (https://github.com/zalando/go-keyring/blob/v0.2.8/keyring_darwin.go), | ||
| // which leaves ~3000 bytes for the JSON envelope. | ||
| // - Windows: the credential blob must be at most 2560 bytes | ||
| // (https://github.com/zalando/go-keyring/blob/v0.2.8/keyring_windows.go). | ||
| // | ||
| // Linux Secret Service has no such cap, hence the build constraint. This test | ||
| // pins the current behavior so a fix for #7707 has to flip it on purpose. | ||
|
Comment on lines
+30
to
+31
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Only fixes that change what |
||
| func TestKeyringStore_Put_RealBackendRejectsLargeToken(t *testing.T) { | ||
| store := NewKeyringStore() | ||
| account := keyringProbeAccountPrefix + uuid.New().String() | ||
| t.Cleanup(func() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] |
||
| // Nothing is written when Put fails as expected; this only matters if | ||
| // the limit disappears and the token lands in the real keyring. | ||
| _ = store.Delete(account) | ||
| }) | ||
|
|
||
| // The access token alone already exceeds both caps once base64-encoded, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] go-keyring base64-encodes the secret only on macOS. |
||
| // so the exact refresh token size is irrelevant. | ||
|
Comment on lines
+41
to
+42
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] go-keyring does not base64-encode on Windows. The 2560-byte cap applies to the raw JSON envelope, so access tokens from about 2.4 KB already fail there. Reword to something like "The access token alone exceeds both caps", and consider noting the lower Windows threshold. |
||
| tok := &oauth2.Token{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] |
||
| AccessToken: strings.Repeat("a", issue7707AccessTokenBytes), | ||
| TokenType: "Bearer", | ||
| RefreshToken: strings.Repeat("r", 64), | ||
| Expiry: time.Now().Add(time.Hour), | ||
| } | ||
|
|
||
| err := store.Put(account, Entry{Token: tok}) | ||
| require.ErrorIs(t, err, keyring.ErrSetDataTooBig) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
.agents/rules/comments.mdasks for Go doc comments that start with the function name, but this one starts with "The OS backends behind zalando/go-keyring...". Start it withTestKeyringStore_Put_RealBackendRejectsLargeToken ....