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

Devex update cognito identity provider #10080

Merged
merged 5 commits into from
Jun 28, 2023
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
25 changes: 24 additions & 1 deletion cypress-smoketests.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import { defineConfig } from 'cypress';

import {
confirmUser,
getRestApi,
getUserToken,
} from './cypress/cypress-smoketests/support/login';

const { CYPRESS_SMOKETESTS_LOCAL } = process.env;

import {
getRestApi as getRestApiLocal,
getUserToken as getUserTokenLocal,
} from './cypress/cypress-smoketests/support/pages/local-login';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
chromeWebSecurity: false,
defaultCommandTimeout: 60000,
e2e: {
setupNodeEvents(on) {
on('task', {
confirmUser({ email }) {
return confirmUser({ email });
},
getRestApi() {
return CYPRESS_SMOKETESTS_LOCAL ? getRestApiLocal() : getRestApi();
},
getUserToken({ email, password }) {
return CYPRESS_SMOKETESTS_LOCAL
? getUserTokenLocal(email)
: getUserToken(email, password);
},
log(message) {
console.log(message);

return null;
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faker } from '@faker-js/faker';

export const fillInCreateCaseFromPaperForm = testData => {
export const fillInCreateCaseFromPaperForm = (testData?: any) => {
const petitionerName = `${faker.person.firstName()} ${faker.person.lastName()}`;
cy.get('#party-type').select('Petitioner');
cy.get('#name').type(petitionerName);
Expand Down
51 changes: 25 additions & 26 deletions cypress/cypress-readonly/support/pages/login.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CognitoIdentityProvider } from '@aws-sdk/client-cognito-identity-provider';
import AWS from 'aws-sdk';

const awsRegion = 'us-east-1';
Expand All @@ -10,48 +11,46 @@ AWS.config.region = awsRegion;

const ENV = Cypress.env('ENV');

const cognito = new AWS.CognitoIdentityServiceProvider({
const cognito = new CognitoIdentityProvider({
region: 'us-east-1',
});

const getClientId = async userPoolId => {
const results = await cognito
.listUserPoolClients({
MaxResults: 60,
UserPoolId: userPoolId,
})
.promise();
const results = await cognito.listUserPoolClients({
MaxResults: 60,
UserPoolId: userPoolId,
});
if (!results.UserPoolClients) {
throw new Error(`No client found for ${userPoolId}`);
}
const clientId = results.UserPoolClients[0].ClientId;
return clientId;
};

const getUserPoolId = async () => {
const results = await cognito
.listUserPools({
MaxResults: 50,
})
.promise();
const userPoolId = results.UserPools.find(
pool => pool.Name === `efcms-${ENV}`,
).Id;
const { UserPools } = await cognito.listUserPools({
MaxResults: 50,
});
if (!UserPools) {
throw new Error('no user pools found on cognito');
}
const userPoolId = UserPools.find(pool => pool.Name === `efcms-${ENV}`)?.Id;
return userPoolId;
};

export const getUserToken = async (username, password) => {
const userPoolId = await getUserPoolId();
const clientId = await getClientId(userPoolId);

return cognito
.adminInitiateAuth({
AuthFlow: 'ADMIN_NO_SRP_AUTH',
AuthParameters: {
PASSWORD: password,
USERNAME: username,
},
ClientId: clientId,
UserPoolId: userPoolId,
})
.promise();
return cognito.adminInitiateAuth({
AuthFlow: 'ADMIN_NO_SRP_AUTH',
AuthParameters: {
PASSWORD: password,
USERNAME: username,
},
ClientId: clientId,
UserPoolId: userPoolId,
});
};

export const login = token => {
Expand Down
42 changes: 22 additions & 20 deletions cypress/cypress-smoketests/integration/case-creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');
let token = null;
let testData = { createdPaperDocketNumber: '' };

const { closeScannerSetupDialog, getUserToken, login } =
getEnvironmentSpecificFunctions();
const { closeScannerSetupDialog, login } = getEnvironmentSpecificFunctions();

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -76,12 +76,13 @@ describe('Petitioner', () => {
});

describe('Private practitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -116,12 +117,13 @@ describe('Private practitioner', () => {
});

describe('Petitions clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
15 changes: 8 additions & 7 deletions cypress/cypress-smoketests/integration/change-address.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import {
updateAddress1,
} from '../support/pages/my-account';

const { getUserToken, login } = getEnvironmentSpecificFunctions();
const { login } = getEnvironmentSpecificFunctions();

const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

describe('Private practitioner', () => {
let token = null;

before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('logs in', () => {
Expand Down
42 changes: 22 additions & 20 deletions cypress/cypress-smoketests/integration/court-issued-documents.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ const testData = {};

const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

const { closeScannerSetupDialog, getUserToken, login } =
getEnvironmentSpecificFunctions();
const { closeScannerSetupDialog, login } = getEnvironmentSpecificFunctions();

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -89,12 +89,13 @@ describe('Petitioner', () => {
});

describe('Petitions clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand All @@ -117,12 +118,13 @@ describe('Petitions clerk', () => {
});

describe('Docket Clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
43 changes: 24 additions & 19 deletions cypress/cypress-smoketests/integration/create-trial-session.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,42 @@ const testData = {
preferredTrialCity: 'Mobile, Alabama',
trialSessionIds: [],
};
const { login } = getEnvironmentSpecificFunctions();

let firstDocketNumber;
let secondDocketNumber;
const caseTestData = { docketNumbers: [] };

describe('Petitions Clerk', () => {
const { getUserToken, login } = getEnvironmentSpecificFunctions();

before(async () => {
let result = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
petitionsClerkToken = result.AuthenticationResult.IdToken;
result = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
docketClerkToken = result.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
petitionsClerkToken = result.AuthenticationResult.IdToken;
});
});

before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
docketClerkToken = result.AuthenticationResult.IdToken;
});
});

describe('Petitioner creates cases', () => {
let petitionerToken;

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
petitionerToken = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
Loading