Skip to content

FIX use 32-byte test JWT key to silence PyJWT InsecureKeyLengthWarning#1804

Merged
romanlutz merged 2 commits into
microsoft:mainfrom
immu4989:fix/jwt-test-key-length
May 27, 2026
Merged

FIX use 32-byte test JWT key to silence PyJWT InsecureKeyLengthWarning#1804
romanlutz merged 2 commits into
microsoft:mainfrom
immu4989:fix/jwt-test-key-length

Conversation

@immu4989
Copy link
Copy Markdown
Contributor

@immu4989 immu4989 commented May 25, 2026

Fixes #1803.

tests/unit/auth/test_manual_copilot_authenticator.py signs test JWTs with key="secret" (6 bytes), which trips PyJWT's InsecureKeyLengthWarning because HMAC-SHA256 requires a key of at least 32 bytes per RFC 7518 §3.2. The unit suite emits 12 of these warnings per run.

Fix

Move the test key to a module-level constant set to a 32-byte string, with a brief comment noting (a) the RFC requirement and (b) that ManualCopilotAuthenticator decodes with verify_signature=False (pyrit/auth/copilot_authenticator.py:259), so the key value is purely formal.

No functional change.

Verification

# Pre-fix:
pytest tests/unit/auth/test_manual_copilot_authenticator.py 2>&1 | grep -c InsecureKeyLength
-> 12

# Post-fix:
pytest tests/unit/auth/test_manual_copilot_authenticator.py 2>&1 | grep -c InsecureKeyLength
-> 0

# Tests still pass:
pytest tests/unit/auth/test_manual_copilot_authenticator.py
-> 13 passed in 0.02s

immu4989 and others added 2 commits May 25, 2026 15:46
tests/unit/auth/test_manual_copilot_authenticator.py used a 6-byte key ("secret") to sign test JWTs with HS256. PyJWT emits InsecureKeyLengthWarning because HMAC-SHA256 requires a key >=32 bytes per RFC 7518 section 3.2. The full unit suite emits 12 of these warnings per run.

ManualCopilotAuthenticator decodes tokens with verify_signature=False (pyrit/auth/copilot_authenticator.py:259), so the test key value is purely formal -- any well-formed key works. Switch to a module-level 32-byte constant with a brief explanatory comment.

No functional change; warnings drop from 12 to 0 for this test module.
@romanlutz romanlutz enabled auto-merge May 26, 2026 23:29
@romanlutz romanlutz added this pull request to the merge queue May 26, 2026
Merged via the queue into microsoft:main with commit af46830 May 27, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG test JWTs in test_manual_copilot_authenticator use 6-byte HMAC key, emitting 12 InsecureKeyLengthWarning per suite run

2 participants