mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
test(e2e): test authorizations (#4342)
* add specs that cover the b2b demo * update cypress * test handling manager roles * use shared mocha contexts * use beforeEach instead of before * improve readability * improve application test * remove static waits * remove old awaitDesired * test owned project authorizations * simplify ensure.ts * test granted projects authz * disable prevSubject for shouldNotExist * await non-existence, then expect no error * update dependencies * fix tests from scratch * fix settings tests from scratch * Apply suggestions from code review Co-authored-by: Max Peintner <max@caos.ch> * Implement code review suggestions * use spread operator * settings properties must match * add check settings object * revert spread operator Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
@@ -1,26 +1,80 @@
|
||||
/*
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
*/
|
||||
/**
|
||||
* Custom command that authenticates a user.
|
||||
*
|
||||
* @example cy.consolelogin('hodor', 'hodor1234')
|
||||
*/
|
||||
/* consolelogin(username: string, password: string): void
|
||||
}
|
||||
import 'cypress-wait-until';
|
||||
//
|
||||
//namespace Cypress {
|
||||
// interface Chainable {
|
||||
// /**
|
||||
// * Custom command that authenticates a user.
|
||||
// *
|
||||
// * @example cy.consolelogin('hodor', 'hodor1234')
|
||||
// */
|
||||
// consolelogin(username: string, password: string): void
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//Cypress.Commands.add('consolelogin', { prevSubject: false }, (username: string, password: string) => {
|
||||
//
|
||||
// window.sessionStorage.removeItem("zitadel:access_token")
|
||||
// cy.visit(Cypress.config('baseUrl')/ui/console).then(() => {
|
||||
// // fill the fields and push button
|
||||
// cy.get('#loginName').type(username, { log: false })
|
||||
// cy.get('#submit-button').click()
|
||||
// cy.get('#password').type(password, { log: false })
|
||||
// cy.get('#submit-button').click()
|
||||
// cy.location('pathname', {timeout: 5 * 1000}).should('eq', '/');
|
||||
// })
|
||||
//})
|
||||
//
|
||||
|
||||
interface ShouldNotExistOptions {
|
||||
selector?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
Cypress.Commands.add('consolelogin', { prevSubject: false }, (username: string, password: string) => {
|
||||
declare global {
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
/**
|
||||
* Custom command that asserts on clipboard text.
|
||||
*
|
||||
* @example cy.clipboardMatches('hodor', 'hodor1234')
|
||||
*/
|
||||
clipboardMatches(pattern: RegExp | string): Cypress.Chainable<null>;
|
||||
|
||||
window.sessionStorage.removeItem("zitadel:access_token")
|
||||
cy.visit(Cypress.config('baseUrl')/ui/console).then(() => {
|
||||
// fill the fields and push button
|
||||
cy.get('#loginName').type(username, { log: false })
|
||||
cy.get('#submit-button').click()
|
||||
cy.get('#password').type(password, { log: false })
|
||||
cy.get('#submit-button').click()
|
||||
cy.location('pathname', {timeout: 5 * 1000}).should('eq', '/');
|
||||
})
|
||||
})
|
||||
*/
|
||||
/**
|
||||
* Custom command that waits until the selector finds zero elements.
|
||||
*/
|
||||
shouldNotExist(options?: ShouldNotExistOptions): Cypress.Chainable<null>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cypress.Commands.add('clipboardMatches', { prevSubject: false }, (pattern: RegExp | string) => {
|
||||
/* doesn't work reliably
|
||||
return cy.window()
|
||||
.then(win => {
|
||||
win.focus()
|
||||
return cy.waitUntil(() => win.navigator.clipboard.readText()
|
||||
.then(clipboadText => {
|
||||
win.focus()
|
||||
const matches = typeof pattern === "string"
|
||||
? clipboadText.includes(pattern)
|
||||
: pattern.test(clipboadText)
|
||||
if (!matches) {
|
||||
cy.log(`text in clipboard ${clipboadText} doesn't match the pattern ${pattern}, yet`)
|
||||
}
|
||||
return matches
|
||||
})
|
||||
)
|
||||
})
|
||||
.then(() => null)
|
||||
*/
|
||||
});
|
||||
|
||||
Cypress.Commands.add('shouldNotExist', { prevSubject: false }, (options?: ShouldNotExistOptions) => {
|
||||
return cy.waitUntil(
|
||||
() => {
|
||||
return Cypress.$(options?.selector).length === 0;
|
||||
},
|
||||
{ timeout: typeof options?.timeout === 'number' ? options.timeout : 500 },
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user