Repository navigation
Support long login sessions within Windows credential limits #277
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
Open
kosesena
wants to merge
1
commit into
AssemblyAI:main
Choose a base branch
from
kosesena:codex/windows-long-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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,81 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import keyring | ||
| import keyring.errors | ||
| import pytest | ||
|
|
||
| from aai_cli.core import keyring_store | ||
|
|
||
|
|
||
| def test_large_session_fits_windows_credential_limit(monkeypatch): | ||
| original = keyring.set_password | ||
|
|
||
| def limited(service: str, username: str, password: str) -> None: | ||
| if len(password.encode("utf-16-le")) > 2560: | ||
| raise ValueError("CredWrite: credential exceeds Windows limit") | ||
| original(service, username, password) | ||
|
|
||
| monkeypatch.setattr(keyring, "set_password", limited) | ||
| secret = "fake-session-😀" * 400 | ||
| keyring_store.set_secret("session:default", secret) | ||
| assert keyring_store.get_secret("session:default") == secret | ||
| keyring_store.delete_secret("session:default") | ||
| assert keyring_store.get_secret("session:default") is None | ||
|
|
||
|
|
||
| def test_failed_large_write_preserves_old_secret(monkeypatch): | ||
| keyring_store.set_secret("session:default", "old") | ||
| original = keyring.set_password | ||
| calls = 0 | ||
|
|
||
| def fail_second(service: str, username: str, password: str) -> None: | ||
| nonlocal calls | ||
| calls += 1 | ||
| if calls == 2: | ||
| raise keyring.errors.PasswordSetError("locked") | ||
| original(service, username, password) | ||
|
|
||
| monkeypatch.setattr(keyring, "set_password", fail_second) | ||
| with pytest.raises(keyring_store.CLIError): | ||
| keyring_store.set_secret("session:default", "x" * 4000) | ||
| assert keyring_store.get_secret("session:default") == "old" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("replacement", ["small", "y" * 5000]) | ||
| def test_overwrite_removes_old_chunks(replacement): | ||
| keyring_store.set_secret("session:default", "x" * 4000) | ||
| raw = keyring.get_password(keyring_store.KEYRING_SERVICE, "session:default") | ||
| old_names = keyring_store._chunk_names(raw) | ||
| assert old_names | ||
| keyring_store.set_secret("session:default", replacement) | ||
| assert keyring_store.get_secret("session:default") == replacement | ||
| assert all(keyring.get_password(keyring_store._CHUNK_SERVICE, n) is None for n in old_names) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("corrupt", [None, "!invalid-base64!", "/w=="]) | ||
| def test_missing_or_corrupt_chunk_is_not_a_session(corrupt): | ||
| keyring_store.set_secret("session:default", "x" * 4000) | ||
| raw = keyring.get_password(keyring_store.KEYRING_SERVICE, "session:default") | ||
| name = keyring_store._chunk_names(raw)[0] | ||
| if corrupt is None: | ||
| keyring.delete_password(keyring_store._CHUNK_SERVICE, name) | ||
| else: | ||
| keyring.set_password(keyring_store._CHUNK_SERVICE, name, corrupt) | ||
| assert keyring_store.get_secret("session:default") is None | ||
|
|
||
|
|
||
| def test_restore_and_delete_large_secret(): | ||
| secret = "z" * 4000 | ||
| keyring_store.restore_secret("session:default", secret) | ||
| assert keyring_store.get_secret("session:default") == secret | ||
| raw = keyring.get_password(keyring_store.KEYRING_SERVICE, "session:default") | ||
| names = keyring_store._chunk_names(raw) | ||
| keyring_store.restore_secret("session:default", None) | ||
| assert keyring_store.get_secret("session:default") is None | ||
| assert all(keyring.get_password(keyring_store._CHUNK_SERVICE, n) is None for n in names) | ||
|
|
||
|
|
||
| def test_manifest_shaped_secret_round_trips(): | ||
| secret = "assemblyai-chunks-v1:" + "a" * 32 + ":1" | ||
| keyring_store.set_secret("default", secret) | ||
| assert keyring_store.get_secret("default") == secret | ||
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.
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.
Exposed secret in tests/test_keyring_large.py - low severity
Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
Reply
@AikidoSec ignore: [REASON]to ignore this issue.More Info
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.
This is a synthetic test fixture, not a credential. The value is constructed locally as
"assemblyai-chunks-v1:" + "a" * 32 + ":1"; it is not issued by any service and grants no access. The test intentionally uses a string matching the versioned chunk-manifest format to verify that a secret with that shape can still be stored and read back unchanged. Changing it to a non-matching placeholder would remove that regression coverage.