Skip to content

Commit

Permalink
Merge pull request #914 from this-Aditya/fix/e2e
Browse files Browse the repository at this point in the history
Setting credentials dynamically and preserving session info
  • Loading branch information
mpgxvii authored Aug 6, 2024
2 parents c8d756a + 03c1ea3 commit 7e780dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
6 changes: 5 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"fixturesFolder": false,
"baseUrl": "http://localhost:8081",
"experimentalSessionAndOrigin": true,
"chromeWebSecurity": false
"chromeWebSecurity": false,
"env": {
"username": "[email protected]",
"secret": "secret123"
}
}
2 changes: 1 addition & 1 deletion src/test/javascript/e2e/cypress/integration/util/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function login() {
cy.login('[email protected]', 'secret123');
cy.login(Cypress.env('username'), Cypress.env('secret'));
cy.wait(2000);
cy.visit('managementportal/');
}
35 changes: 14 additions & 21 deletions src/test/javascript/e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,21 @@ Cypress.Commands.add('getCSRFToken', () => {
});

Cypress.Commands.add('login', (identifier, password) => {
cy.initiateLoginFlow().then(({flow, csrfToken}) => {
cy.request({
method: 'POST',
url: IDENTITY_SERVER + `/self-service/login?flow=${flow}`,
body: {
identifier: identifier,
password: password,
csrf_token: csrfToken,
method: 'password'
},
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
const cookies = response.headers['set-cookie'] || [];
cookies.forEach((cookie) => {
const [cookieName, cookieValue] = cookie.split(';')[0].split('=');
cy.setCookie(cookieName, cookieValue);
Cypress.Cookies.defaults({
preserve: [cookieName, cookieValue] // Ensure relevant cookies are preserved
cy.session([identifier, password], () => {
cy.initiateLoginFlow().then(({flow, csrfToken}) => {
cy.request({
method: 'POST',
url: IDENTITY_SERVER + `/self-service/login?flow=${flow}`,
body: {
identifier: identifier,
password: password,
csrf_token: csrfToken,
method: 'password'
},
headers: {
'Content-Type': 'application/json'
}
});
});
});
});
});

0 comments on commit 7e780dc

Please sign in to comment.