Skip to content

feat(backend): add unit tests for auth middleware and endpoints #369#409

Merged
ogazboiz merged 8 commits into
LabsCrypt:mainfrom
sweetesty:fix/auth-tests-369
Apr 29, 2026
Merged

feat(backend): add unit tests for auth middleware and endpoints #369#409
ogazboiz merged 8 commits into
LabsCrypt:mainfrom
sweetesty:fix/auth-tests-369

Conversation

@sweetesty

Copy link
Copy Markdown
Contributor

📌 Pull Request

🔗 Related Issue
Closes #369

📝 Description

  • Adds comprehensive unit tests for the auth middleware and challenge/verify endpoints to catch authentication bugs before they silently expose stream data or lock out legitimate users
  • Necessary because backend/src/middleware/auth.ts and the POST /v1/auth/challenge and POST /v1/auth/verify endpoints had zero test coverage

🚀 Changes Made

  • Testing — created backend/tests/auth.test.ts:
    • test_challenge_returns_nonce_for_valid_stellar_address
    • test_verify_valid_signature_returns_jwt
    • test_verify_expired_nonce_returns_401
    • test_verify_invalid_signature_returns_401
    • test_verify_wrong_address_returns_401
    • test_auth_middleware_accepts_valid_jwt
    • test_auth_middleware_rejects_expired_jwt
    • test_auth_middleware_rejects_missing_header
    • test_sse_subscribe_without_token_returns_401
    • All 9 tests use mocked Stellar signature verification — no real Stellar RPC required
    • Suite is fully compatible with CI

🧪 Testing & Validation

  • Tested locally
  • No runtime errors
  • Existing features work as expected
  • Edge cases handled (expired nonces, invalid signatures, wrong addresses, missing auth headers, expired JWTs)
  • All 9 tests passing ✅

⚠️ Breaking Changes

  • No breaking changes

📋 Contributor Checklist (MANDATORY)

💡 Notes for Reviewer

  • Key areas to review: mock setup for Stellar signature verification, nonce expiry simulation, JWT validation edge cases
  • Known limitations: None — all cases covered with mocks, no external RPC dependency

@ogazboiz ogazboiz merged commit 3b6500b into LabsCrypt:main Apr 29, 2026
7 of 9 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.

Write unit tests for auth middleware and challenge/verify endpoints

2 participants