Skip to content

Fix flaky TestJWTManager#6478

Merged
qwerty287 merged 2 commits into
woodpecker-ci:mainfrom
6543-forks:fix-flaky_TestJWTManager/tampered_token_is_rejected
Apr 22, 2026
Merged

Fix flaky TestJWTManager#6478
qwerty287 merged 2 commits into
woodpecker-ci:mainfrom
6543-forks:fix-flaky_TestJWTManager/tampered_token_is_rejected

Conversation

@6543

@6543 6543 commented Apr 21, 2026

Copy link
Copy Markdown
Member

The test verified that a tampered JWT is rejected, but it was flipping the last base64url character of the signature instead of flipping an actual byte.

This was unreliable: the final character of a 32-byte HMAC-SHA256 signature only carries 4 meaningful bits. Go's base64 decoder silently ignores the other 2, so roughly 1 in 16 tokens decoded to the same bytes after the swap — meaning the "tampered" token passed verification and the test flaked.

Fix: decode the signature to raw bytes, XOR the first byte, then re-encode. This guarantees the signature bytes are actually different, making the test deterministic.

example: https://ci.woodpecker-ci.org/repos/3780/pipeline/33691/33

@6543 6543 added the tests related to tests or other things CI check before merge label Apr 21, 2026
@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.29%. Comparing base (f1bf85f) to head (7cc30ec).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6478      +/-   ##
==========================================
+ Coverage   41.25%   41.29%   +0.04%     
==========================================
  Files         431      431              
  Lines       28815    28815              
==========================================
+ Hits        11887    11899      +12     
+ Misses      15861    15850      -11     
+ Partials     1067     1066       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@6543 6543 changed the title Fix flaky TestJWTManager test Fix flaky TestJWTManager Apr 21, 2026
@qwerty287 qwerty287 merged commit 91c1b1c into woodpecker-ci:main Apr 22, 2026
9 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Apr 22, 2026
1 task
@6543 6543 deleted the fix-flaky_TestJWTManager/tampered_token_is_rejected branch April 22, 2026 19:05
@woodpecker-bot woodpecker-bot mentioned this pull request Apr 27, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests related to tests or other things CI check before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants