From e35775c857c95b93610a85418a0dc8a5da08af1f Mon Sep 17 00:00:00 2001 From: "Cleopatra Enjeck M." Date: Thu, 2 Jan 2025 16:59:09 +0100 Subject: [PATCH] ci: Hotfix to make login work as long as we are on older cypress version Signed-off-by: Cleopatra Enjeck M. --- cypress/support/commands.js | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index eb67e7048..2e2121b4e 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -28,13 +28,54 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) import { addCommands } from '@nextcloud/cypress' +import { emit } from '@nextcloud/event-bus' require('cypress-downloadfile/lib/downloadFileCommand') const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '') Cypress.env('baseUrl', url) +const silent = { log: false } addCommands() +// Copy of the new login command as long as we are blocked to upgrade @nextcloud/cypress by cypress crashes +const login = function(user) { + cy.session(user, function() { + cy.request('/csrftoken').then(({ body }) => { + const requestToken = body.token + cy.request({ + method: 'POST', + url: '/login', + body: { + user: user.userId, + password: user.password, + requesttoken: requestToken, + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + // Add the Origin header so that the request is not blocked by the browser. + Origin: (Cypress.config('baseUrl') ?? '').replace('index.php/', ''), + }, + followRedirect: false, + }) + }) + }, { + validate() { + cy.request('/apps/files').its('status').should('eq', 200) + }, + }) +} + +// Prepare the csrf-token for axios +Cypress.Commands.overwrite('login', (_login, user) => { + cy.window(silent).then((win) => { + win.location.href = 'about:blank' + }) + login(user) + cy.request('/csrftoken', silent) + .then(({ body }) => emit('csrf-token-update', body)) + cy.wrap(user, silent).as('currentUser') +}) + Cypress.Commands.add('createTable', (title) => { cy.get('.icon-loading').should('not.exist') cy.get('[data-cy="navigationCreateTableIcon"]').click({ force: true })