Skip to content
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

chore(deps-dev): bump jsonwebtoken from 8.5.1 to 9.0.0 in /compose/neurosynth-frontend #396

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ describe(PAGE_NAME, () => {
});

it('should load', () => {
cy.intercept('GET', `**/api/projects*`).as('realProjectsRequest');
cy.intercept('GET', `**/api/studies/mock-study-id*`, { fixture: 'study' }).as(
'studyFixture'
);
cy.login('mocked').visit(PATH).wait('@studyFixture');
cy.login('mocked').wait('@realProjectsRequest').visit(PATH).wait('@studyFixture');
});

// it('should redirect if the user is not authenticated', () => {
Expand Down
13 changes: 5 additions & 8 deletions compose/neurosynth-frontend/cypress/e2e/pages/StudyPage.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ describe(PAGE_NAME, () => {
it('should load successfully', () => {
cy.intercept('GET', `**/api/projects*`).as('realProjectsRequest');
cy.intercept('GET', `**/api/studies/**`).as('realStudyFixture');
cy.login('real')
.wait('@realProjectsRequest')
.visit('/studies')
.wait('@realStudyFixture')
.get('tr')
.eq(2)
.click()
.wait('@realStudyFixture');
cy.login('real').wait('@realProjectsRequest').visit('/studies').wait('@realStudyFixture');
// .get('tr')
// .eq(2)
// .click()
// .wait('@realStudyFixture');
});

// describe('Cloning', () => {
Expand Down
101 changes: 56 additions & 45 deletions compose/neurosynth-frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jwt from 'jsonwebtoken';
import * as jose from 'jose';

/// <reference types="cypress" />
// ***********************************************
Expand Down Expand Up @@ -38,16 +38,57 @@ import jwt from 'jsonwebtoken';
// }
// }

const constructMockAuthJWT = (jwtPayload = {}): string => {
return jwt.sign(
{
...jwtPayload,
const constructMockAuthJWT = async (jwtPayload = {}): Promise<string> => {
const jwt = await new jose.SignJWT({ ...jwtPayload })
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('2h')
.sign(new TextEncoder().encode('SECRET'));
return jwt;
};

const createMockRequest = async (
audience: string,
client_id: string,
domain: string,
extraClaims = {}
) => {
const access_token = await constructMockAuthJWT({
iss: 'https://dev-mui7zm42.us.auth0.com/',
sub: 'auth0|62e0e6c9dd47048572613b4d',
aud: ['https://dev-mui7zm42.us.auth0.com/userinfo', audience],
iat: 1659719697,
exp: 1659806097,
azp: 'EmcOFhu0XAINM4EyslaKpZ3u09QlBvef',
scope: 'openid profile email',
});

const id_token = await constructMockAuthJWT({
'https://neurosynth-compose/loginsCount': 871,
nickname: 'test-user',
name: '[email protected]',
picture:
'https://s.gravatar.com/avatar/3a6e372ed11e9bc975215430fe82c28f?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fte.png',
updated_at: '2022-08-02T18:50:33.106Z',
email: '[email protected]',
email_verified: false,
iss: `https://${domain}/`,
sub: 'auth0|62e0e6c9dd47048572613b4d',
aud: client_id,
iat: Math.floor(Date.now() / 1000 + 86400),
exp: Math.floor(Date.now() / 1000 + 86400),
...extraClaims,
});

return {
body: {
access_token: access_token,
expires_in: 86400,
id_token: id_token,
scope: 'openid profile email read:current_user update:current_user_metadata delete:current_user_metadata create:current_user_metadata create:current_user_device_credentials delete:current_user_device_credentials update:current_user_identities',
token_type: 'Bearer',
},
'SECRET',
{
keyid: 'yGR0k3tMAFj3UszOgaA6N',
}
);
};
};

Cypress.Commands.add('login', (loginMode = 'mocked', extraClaims = {}) => {
Expand All @@ -63,38 +104,7 @@ Cypress.Commands.add('login', (loginMode = 'mocked', extraClaims = {}) => {
*/
if (loginMode === 'mocked') {
cy.stub(cy, 'request').callsFake(() =>
cy.wrap({
body: {
access_token: constructMockAuthJWT({
iss: 'https://dev-mui7zm42.us.auth0.com/',
sub: 'auth0|62e0e6c9dd47048572613b4d',
aud: ['https://dev-mui7zm42.us.auth0.com/userinfo', audience],
iat: 1659719697,
exp: 1659806097,
azp: 'EmcOFhu0XAINM4EyslaKpZ3u09QlBvef',
scope: 'openid profile email',
}),
expires_in: 86400,
id_token: constructMockAuthJWT({
'https://neurosynth-compose/loginsCount': 871,
nickname: 'test-user',
name: '[email protected]',
picture:
'https://s.gravatar.com/avatar/3a6e372ed11e9bc975215430fe82c28f?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fte.png',
updated_at: '2022-08-02T18:50:33.106Z',
email: '[email protected]',
email_verified: false,
iss: `https://${domain}/`,
sub: 'auth0|62e0e6c9dd47048572613b4d',
aud: client_id,
iat: Math.floor(Date.now() / 1000 + 86400),
exp: Math.floor(Date.now() / 1000 + 86400),
...extraClaims,
}),
scope: 'openid profile email read:current_user update:current_user_metadata delete:current_user_metadata create:current_user_metadata create:current_user_device_credentials delete:current_user_device_credentials update:current_user_identities',
token_type: 'Bearer',
},
})
cy.wrap(createMockRequest(audience, client_id, domain, extraClaims))
);
}

Expand All @@ -117,7 +127,8 @@ Cypress.Commands.add('login', (loginMode = 'mocked', extraClaims = {}) => {
},
}).then(({ body }) => {
const { access_token, expires_in, id_token } = body;
const jwtObject = jwt.decode(id_token, { complete: true }) as jwt.Jwt;
console.log({ access_token, id_token });
const jwtObject = jose.decodeJwt(id_token);
const [header, payload, signature] = id_token.split('.');

// localstorage object that is used by auth0.
Expand All @@ -129,7 +140,7 @@ Cypress.Commands.add('login', (loginMode = 'mocked', extraClaims = {}) => {
client_id,
decodedToken: {
claims: {
...(jwtObject.payload as jwt.JwtPayload),
...jwtObject,
__raw: id_token,
},
encoded: {
Expand All @@ -138,7 +149,7 @@ Cypress.Commands.add('login', (loginMode = 'mocked', extraClaims = {}) => {
signature,
},
header: jwtObject.header,
user: jwtObject.payload as jwt.JwtPayload,
user: jwtObject.sub,
},
expires_in,
id_token,
Expand Down
Loading