Skip to content

Commit 3b244b7

Browse files
committed
test: add CSRF token Cypress command
1 parent ddff723 commit 3b244b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cypress/support/commands.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ Cypress.Commands.add('login', (username, password) => {
3939
cy.url().should('include', '/dashboard/repo');
4040
});
4141
});
42+
43+
Cypress.Commands.add('getCSRFToken', () => {
44+
return cy.request('GET', 'http://localhost:8080/api/v1/repo').then((res) => {
45+
const cookies = res.headers['set-cookie'];
46+
const csrfCookie = cookies.find(c => c.startsWith('csrf='));
47+
const token = decodeURIComponent(csrfCookie.split('=')[1].split(';')[0]);
48+
return cy.wrap(token);
49+
});
50+
});

0 commit comments

Comments
 (0)