feat(cypress): ensure csrftoken cookie is set without timeout
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/1795>
This commit is contained in:
parent
caa6a26c77
commit
588f79a45b
|
@ -2,7 +2,7 @@ declare module 'cypress' {
|
|||
global {
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
login(): Chainable<JQuery<HTMLElement>>
|
||||
login(): void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
// Currently we cannot login purely programmatically, so we need to use the
|
||||
// graphical login until the vue3 branch is merged
|
||||
Cypress.Commands.add('login', () => {
|
||||
cy.fixture('testuser.json').then((user) => {
|
||||
const username = user.username
|
||||
const password = user.password
|
||||
cy.visit('/login')
|
||||
cy.wait(1000)
|
||||
cy.getCookie('csrftoken').then(($cookie) => {
|
||||
const csrfToken = $cookie?.value
|
||||
cy.fixture('testuser.json').then(({ username, password }) => {
|
||||
// We need to request a page that sets the csrf cookie
|
||||
cy.request('/api/v1/instance/nodeinfo/2.0/')
|
||||
|
||||
// Then we can login
|
||||
cy.visit('/login')
|
||||
|
||||
cy.getCookie('csrftoken').then(($cookie) => {
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: '/api/v1/users/login',
|
||||
form: true,
|
||||
headers: {
|
||||
'X-CSRFTOKEN': csrfToken,
|
||||
'X-CSRFTOKEN': $cookie?.value,
|
||||
Referer: Cypress.config().baseUrl + '/login'
|
||||
},
|
||||
body: {
|
||||
|
|
Loading…
Reference in New Issue