Skip to content

[TESTING] Add integration test for expired JWT token rejection - #195

Merged
chizzy192 merged 4 commits into
StellarState:devfrom
MissBlue00:feature/issue-170-expired-jwt-test
Jul 30, 2026
Merged

[TESTING] Add integration test for expired JWT token rejection#195
chizzy192 merged 4 commits into
StellarState:devfrom
MissBlue00:feature/issue-170-expired-jwt-test

Conversation

@MissBlue00

Copy link
Copy Markdown
Contributor

Closes #170

Summary

Adds integration test in tests/integration/auth-jwt-validation.test.ts that verifies expired JWT tokens are rejected with 401 Unauthorized.

Implementation Details

  • Generates expired JWT token using jwt.sign(payload, secret, { expiresIn: "-5m" })
  • Tests GET /api/v1/invoices with expired token returns 401
  • Also validates that valid tokens still work and missing tokens are rejected
  • Follows existing test patterns from tests/invoice.routes.test.ts

Testing

All 46 integration tests pass.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@MissBlue00 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192

Copy link
Copy Markdown
Contributor

Hi @MissBlue00! 👋

Conflict Summary & Action Required:
Your PR has 1 merge conflict against dev in tests/integration/auth-jwt-validation.test.ts because tests/integration/auth-jwt-validation.test.ts was also added on dev.

Rebase Steps:

git fetch origin dev
git checkout feature/issue-170-expired-jwt-test
git rebase origin/dev
# Reconcile tests/integration/auth-jwt-validation.test.ts by appending your describe block:
git add tests/integration/auth-jwt-validation.test.ts
git rebase --continue
npm test
git push --force-with-lease origin feature/issue-170-expired-jwt-test

Once clean, we will review and merge into dev. Thanks! 🚀

@chizzy192

Copy link
Copy Markdown
Contributor

Hi @MissBlue00! 👋

Here is a detailed breakdown of the conflict in your PR and the exact code changes needed to resolve it:

📌 File in Conflict

  • File Path: tests/integration/auth-jwt-validation.test.ts

🔍 Root Cause & Conflict Details

Both dev and your branch created tests/integration/auth-jwt-validation.test.ts.

  • On dev, the file initializes Express app routing, DATABASE_URL, and JWT secret handling.
  • On your branch, you created a separate Express app setup to test expired token handling with:
    const expiredToken = jwt.sign(
      { sub: sellerId, stellarAddress: "GTEST123" },
      "test-secret",
      { expiresIn: "-5m" }
    );

🛠️ Step-by-Step Resolution

  1. Rebase your branch onto the latest dev:
    git fetch origin dev
    git checkout feature/issue-170-expired-jwt-test
    git rebase origin/dev
  2. Open tests/integration/auth-jwt-validation.test.ts and append your expired token test case directly inside the existing describe("Auth JWT validation...", ...) block, reusing the existing test App instance:
    it("should reject requests with an expired JWT token (401)", async () => {
      const expiredToken = jwt.sign(
        { sub: sellerId, stellarAddress: "GTEST123" },
        process.env.JWT_SECRET || "test-secret",
        { expiresIn: "-5m" }
      );
    
      const res = await request(app)
        .get("/api/protected-endpoint")
        .set("Authorization", `Bearer ${expiredToken}`);
    
      expect(res.status).toBe(401);
      expect(res.body.error).toMatch(/expired/i);
    });
  3. Finalize rebase and push:
    git add tests/integration/auth-jwt-validation.test.ts
    git rebase --continue
    npm test
    git push --force-with-lease origin feature/issue-170-expired-jwt-test

Thanks! 🚀

Combine expired JWT token rejection test with upstream dev
version. Keeps upstream's createTestApp() infrastructure while
adding expired token, valid token, and missing token test cases.

Closes StellarState#170
@MissBlue00

Copy link
Copy Markdown
Contributor Author

@chizzy192 the conflict has been resolved

@chizzy192
chizzy192 merged commit 7f7fd2f into StellarState:dev Jul 30, 2026
2 of 3 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.

[TESTING] Add integration test for expired JWT token rejection

3 participants