feat(cypress): ensure csrftoken cookie is set without timeout

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/1795>
environments/review-docs-merge-hoc7bt/deployments/18064
Kasper Seweryn 2023-06-20 11:15:32 +02:00
rodzic caa6a26c77
commit 588f79a45b
2 zmienionych plików z 9 dodań i 9 usunięć

Wyświetl plik

@ -2,7 +2,7 @@ declare module 'cypress' {
global {
namespace Cypress {
interface Chainable {
login(): Chainable<JQuery<HTMLElement>>
login(): void
}
}
}

Wyświetl plik

@ -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: {