Skip to content

Conversation

Copy link

Copilot AI commented Jan 18, 2026

Summary

Two token verification tests were failing intermittently (~4% of runs) because they modified the last character of JWT tokens. Due to Base64 URL-safe encoding with 43-character signatures, the last character only contributes 2 bits to the decoded value. Characters 'U' and 'X' share the same high-order 4 bits (010100 vs 010111), so modifying 'U'→'X' produces an identical decoded signature, correctly passing verification.

Changes:

  • Modified tests to change middle characters instead of trailing characters, ensuring decoded values always differ
  • Added constants MIN_TOKEN_LENGTH_FOR_MODIFICATION and MIN_SIGNATURE_LENGTH_FOR_MODIFICATION
  • Added explanatory comments about the Base64 padding edge case

Example of the issue:

# Base64 decode shows why 'U' and 'X' are equivalent:
sig = "NSTtSO04ZCh7kcmvXDxjm5vuLW_6a8GBDXKWtm_H0UU"
sig_modified = "NSTtSO04ZCh7kcmvXDxjm5vuLW_6a8GBDXKWtm_H0UX"
# Both decode to: 3524ed48ed3864287b91c9af5c3c639b9bee2d6ffa6bc1810d7296b66fc7d145

Related Issues / Discussions

Issue describes the intermittent test failures with full error logs.

QA Instructions

Run the affected tests multiple times to verify deterministic behavior:

for i in {1..20}; do python -m pytest tests/app/services/auth/test_token_service.py::TestTokenVerification::test_verify_token_with_modified_payload tests/app/services/auth/test_token_service.py::TestTokenSecurity::test_token_signature_verification -q; done

All runs should pass. Previously, approximately 4% would fail.

Merge Plan

N/A - Test-only changes, no production code affected.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)
Original prompt

This section details on the original issue you should resolve

<issue_title>[bug]: Token service test failures</issue_title>
<issue_description>### Is there an existing issue for this problem?

  • I have searched the existing issues

Install method

Invoke's Launcher

Operating system

Linux

GPU vendor

Nvidia (CUDA)

GPU model

No response

GPU VRAM

No response

Version number

lstein-master HEAD

Browser

No response

System Information

No response

What happened

Two unit tests in tests/app/services/auth/test_token_service.py are intermittently failing:

  1. test_verify_token_with_modified_payload()
  2. test_token_signature_verification()

Here is the short test summary info. The full error log is attached.

=========================== short test summary info ============================
206
FAILED tests/app/services/auth/test_token_service.py::TestTokenVerification::test_verify_token_with_modified_payload - AssertionError: assert TokenData(user_id='user123', email='test@example.com', is_admin=False) is None
207
FAILED tests/app/services/auth/test_token_service.py::TestTokenSecurity::test_token_signature_verification - AssertionError: assert TokenData(user_id='user123', email='test@example.com', is_admin=False) is None
208
 +  where TokenData(user_id='user123', email='test@example.com', is_admin=False) = verify_token('***')
209
= 2 failed, 783 passed, 102 skipped, 4 deselected, 8 warnings in 206.16s (0:03:26) =
210
Error: Process completed with exit code 1.

test.txt

What you expected to happen

I expect the auth unit tests to succeed.

How to reproduce the problem

No response

Additional context

No response

Discord username

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 18, 2026 03:30
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix token service test failures in auth module Fix intermittent token service test failures caused by Base64 padding Jan 18, 2026
Copilot AI requested a review from lstein January 18, 2026 03:37
@lstein lstein marked this pull request as ready for review January 18, 2026 03:39
@lstein lstein merged commit cdd593f into lstein-master Jan 18, 2026
13 checks passed
@lstein lstein deleted the copilot/fix-token-service-tests branch January 18, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Token service test failures

2 participants