-
Notifications
You must be signed in to change notification settings - Fork 3
Fix return type annotation in loadJWTKeys helper #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
10
commits into
master
Choose a base branch
from
copilot/add-jwt-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4dce85
Initial plan
Copilot e120d51
Add JWT authentication tests
Copilot 8e0d675
Add JWT testing documentation
Copilot eb612ae
Address code review feedback - improve JWT tests and fix terminology
Copilot f5c4b24
Implement JWT test fixtures infrastructure
Copilot 3b5e52a
Add developer documentation and example .env for JWT testing
Copilot b83d58f
Add implementation summary documentation
Copilot a8ad57e
Fix TypeScript compilation error in jwt-helper.ts
Copilot 81f3a39
Enhance JWT testing infrastructure by implementing Cypress Node tasks…
jrhoads d55f2fb
Refactor getAuthToken function to improve error handling and type saf…
jrhoads File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Example environment configuration for local JWT testing | ||
| # Copy this file to .env and uncomment the JWT public key to enable JWT authentication tests | ||
|
|
||
| # JWT Test Public Key - Use this for local testing with generated test tokens | ||
| # This key matches the private key in cypress/fixtures/jwt-keys.json | ||
| # WARNING: This is a TEST KEY ONLY - DO NOT use in production! | ||
| #NEXT_PUBLIC_JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY----- | ||
| #MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj760PNWDk5AWonv/G63Q | ||
| #08b1XAqUdCVttXLxr6AEXcJeYWXwDPRZAGKBpMTVcu0SIl7I958ebVx2A1I4dNAZ | ||
| #6xCku2bgOzoOiFJqNF1EzaxhHbk2gBQt6q92X5RaPFZh3UUkmvISACoiDH+Mja2W | ||
| #kW3o8o4iRWaRUvo0sRpbv+O7PSx+3FBABGZSSz1wV7rz7YMjDUjHCF2gsS3XKeA3 | ||
| #ZzmwYlLmpxM1kD6h/XloO9OHgH2h2IlOyhm7VkhRYYc1auj5zJYKzKkWfCvbozF+ | ||
| #rufZNFqMGjlUzmH5KYr4CcnuzYFTN0RxUJrCs1UDh/KbI2wZx3ZXXt4zp4QQNAO0 | ||
| #RQIDAQAB | ||
| #-----END PUBLIC KEY-----" | ||
|
|
||
| # Other environment variables (see .env.example for complete list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| /// <reference types="cypress" /> | ||
|
|
||
| import { setAuthenticatedSession } from '../support/jwt-helper' | ||
|
|
||
| describe('JWT Authentication', () => { | ||
| beforeEach(() => { | ||
| cy.setCookie('_consent', 'true') | ||
| }) | ||
|
|
||
| describe('Unauthenticated User', () => { | ||
| it('should show sign in link when not authenticated', () => { | ||
| cy.visit('/') | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should not show user menu when not authenticated', () => { | ||
| cy.visit('/') | ||
| cy.get('#sign-in').should('not.exist') | ||
| }) | ||
| }) | ||
|
|
||
| describe('Authenticated User (with valid JWT)', () => { | ||
| beforeEach(() => { | ||
| // Set up authenticated session with valid JWT token using test fixtures | ||
| // This will work if NEXT_PUBLIC_JWT_PUBLIC_KEY is set to the test public key | ||
| setAuthenticatedSession({ uid: 'test-user-123', name: 'Test User' }) | ||
| }) | ||
|
|
||
| it('should display user name when authenticated with valid JWT', () => { | ||
| // Skip if JWT public key is not configured for tests | ||
| if (!Cypress.env('jwtPublicKey') && !Cypress.env('NEXT_PUBLIC_JWT_PUBLIC_KEY')) { | ||
| cy.log('Skipping: NEXT_PUBLIC_JWT_PUBLIC_KEY not configured for tests') | ||
| return | ||
| } | ||
|
|
||
| cy.visit('/') | ||
| cy.get('#sign-in', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should show user dropdown menu when authenticated with valid JWT', () => { | ||
| // Skip if JWT public key is not configured for tests | ||
| if (!Cypress.env('jwtPublicKey') && !Cypress.env('NEXT_PUBLIC_JWT_PUBLIC_KEY')) { | ||
| cy.log('Skipping: NEXT_PUBLIC_JWT_PUBLIC_KEY not configured for tests') | ||
| return | ||
| } | ||
|
|
||
| cy.visit('/') | ||
| cy.get('#sign-in', { timeout: 30000 }).click() | ||
| cy.get('[data-cy=settings]').should('be.visible') | ||
| }) | ||
| }) | ||
|
|
||
| describe('Invalid JWT Token', () => { | ||
| it('should handle invalid token gracefully', () => { | ||
| // Set an invalid JWT token | ||
| const invalidCookie = JSON.stringify({ | ||
| authenticated: { | ||
| access_token: 'invalid.jwt.token' | ||
| } | ||
| }) | ||
| cy.setCookie('_datacite', invalidCookie) | ||
|
|
||
| cy.visit('/') | ||
| // Should behave like unauthenticated user | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should handle malformed cookie gracefully', () => { | ||
| // Set a malformed cookie | ||
| cy.setCookie('_datacite', 'not-valid-json') | ||
|
|
||
| cy.visit('/') | ||
| // Should behave like unauthenticated user | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should handle missing access_token in cookie', () => { | ||
| // Set a cookie without access_token | ||
| const incompleteCookie = JSON.stringify({ | ||
| authenticated: {} | ||
| }) | ||
| cy.setCookie('_datacite', incompleteCookie) | ||
|
|
||
| cy.visit('/') | ||
| // Should behave like unauthenticated user | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
| }) | ||
|
|
||
| describe('JWT Verification Error Handling', () => { | ||
| it('should not crash the app with expired token', () => { | ||
| // Set an expired JWT token (this will be caught by JWT verification) | ||
| const expiredCookie = JSON.stringify({ | ||
| authenticated: { | ||
| access_token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJ0ZXN0LXVzZXIiLCJuYW1lIjoiVGVzdCBVc2VyIiwiZXhwIjoxfQ.invalid' | ||
| } | ||
| }) | ||
| cy.setCookie('_datacite', expiredCookie) | ||
|
|
||
| cy.visit('/') | ||
| // App should still load | ||
| cy.get('body').should('be.visible') | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should not crash the app with corrupted token', () => { | ||
| // Set a corrupted JWT token | ||
| const corruptedCookie = JSON.stringify({ | ||
| authenticated: { | ||
| access_token: 'corrupted-token-that-is-not-valid' | ||
| } | ||
| }) | ||
| cy.setCookie('_datacite', corruptedCookie) | ||
|
|
||
| cy.visit('/') | ||
| // App should still load | ||
| cy.get('body').should('be.visible') | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
| }) | ||
|
|
||
| describe('Session Persistence', () => { | ||
| it('should maintain session across page navigations', () => { | ||
| // Set a cookie (even though token verification may fail without proper JWT setup) | ||
| const testCookie = JSON.stringify({ | ||
| authenticated: { | ||
| access_token: 'test.token.value' | ||
| } | ||
| }) | ||
| cy.setCookie('_datacite', testCookie) | ||
|
|
||
| cy.visit('/') | ||
| // Cookie should be present on first page | ||
| cy.getCookie('_datacite').should('exist') | ||
|
|
||
| // Navigate to different pages | ||
| cy.visit('/about') | ||
| cy.get('body').should('be.visible') | ||
|
|
||
| // Cookie should still be present after navigation | ||
| cy.getCookie('_datacite').should('exist') | ||
|
|
||
| // Authentication state should remain consistent (signed out in this case) | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('should handle session when NEXT_PUBLIC_JWT_PUBLIC_KEY is not configured', () => { | ||
| // This test verifies that when NEXT_PUBLIC_JWT_PUBLIC_KEY env var is not set, | ||
| // the app doesn't crash but handles it gracefully | ||
| const testCookie = JSON.stringify({ | ||
| authenticated: { | ||
| access_token: 'test.token.value' | ||
| } | ||
| }) | ||
| cy.setCookie('_datacite', testCookie) | ||
|
|
||
| cy.visit('/') | ||
| // App should still be functional | ||
| cy.get('body').should('be.visible') | ||
| // Should show sign in link since JWT verification fails without the key | ||
| cy.get('a[href*="sign_in"]', { timeout: 30000 }).should('be.visible') | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| export {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: datacite/akita
Length of output: 228
🏁 Script executed:
Repository: datacite/akita
Length of output: 1848
🏁 Script executed:
Repository: datacite/akita
Length of output: 1724
🏁 Script executed:
Repository: datacite/akita
Length of output: 1719
Gate JWT test enablement on
NEXT_PUBLIC_JWT_PUBLIC_KEYinstead of local fixture (prevents test mismatch with unconfigurated app).The fixture (
cypress/fixtures/jwt-keys.json) is unconditionally loaded if it exists, which always setsconfig.env.jwtPublicKey. Tests skip only when bothCypress.env('jwtPublicKey')ANDCypress.env('NEXT_PUBLIC_JWT_PUBLIC_KEY')are absent—so with the fixture present, the skip condition never triggers even when the app isn't configured with JWT. This causes tests to run with a test key while the app may be using a different or missing key, creating false positives.Instead, check
process.env.NEXT_PUBLIC_JWT_PUBLIC_KEYand set the Cypress env only when that variable is present, or expose an explicitjwtPublicKeyConfiguredflag to indicate whether JWT is ready for testing.Suggested adjustment (illustrative)
Also applies to: 31-36
🤖 Prompt for AI Agents