From 960bb91de37d686d234aaca2f1b645d46ddc2481 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Wed, 20 Jul 2022 19:04:37 +0200 Subject: [PATCH] fix cypress configuration --- cmd/e2e-setup/config.go | 12 ++----- cmd/e2e-setup/defaults.yaml | 4 +-- console/cypress.sh | 2 +- .../e2e/applications/applications.cy.ts | 4 +-- console/cypress/e2e/humans/humans.cy.ts | 8 ++--- console/cypress/e2e/machines/machines.cy.ts | 2 +- .../cypress/e2e/permissions/permissions.cy.ts | 22 ++++++------- console/cypress/e2e/projects/projects.cy.ts | 6 ++-- .../cypress/e2e/settings/login-policy.cy.ts | 2 +- .../e2e/settings/password-complexity.cy.ts | 2 +- .../e2e/settings/private-labeling.cy.ts | 2 +- console/cypress/support/api/apiauth.ts | 10 +++--- console/cypress/support/commands.ts | 4 +-- console/cypress/support/login/users.ts | 32 ++++++++++--------- console/package.json | 4 +-- e2e/local.env | 5 +-- 16 files changed, 56 insertions(+), 65 deletions(-) diff --git a/cmd/e2e-setup/config.go b/cmd/e2e-setup/config.go index 0649b0046a..084ef83fee 100644 --- a/cmd/e2e-setup/config.go +++ b/cmd/e2e-setup/config.go @@ -48,9 +48,7 @@ type E2EConfig struct { MachineKeyPath string InstanceID string ZitadelProjectResourceID string - APIURL string - IssuerURL string - Audience string + BaseURL string OrgOwnerPassword string OrgOwnerViewerPassword string OrgProjectCreatorPassword string @@ -65,12 +63,8 @@ func (e E2EConfig) Validate() (err error) { if e.MachineKeyPath == "" { return errors.New("field MachineKeyPath is empty") } - - if e.APIURL == "" { - return errors.New("field APIURL is empty") - } - if e.IssuerURL == "" { - return errors.New("field IssuerURL is empty") + if e.BaseURL == "" { + return errors.New("field BaseURL is empty") } if e.OrgOwnerPassword == "" { return errors.New("field OrgOwnerPassword is empty") diff --git a/cmd/e2e-setup/defaults.yaml b/cmd/e2e-setup/defaults.yaml index d7c6a37eb3..2455a233ec 100644 --- a/cmd/e2e-setup/defaults.yaml +++ b/cmd/e2e-setup/defaults.yaml @@ -3,9 +3,7 @@ E2E: ZitadelProjectResourceID: "" Org: "e2e-tests" MachineKeyPath: ".keys/e2e.json" - APIURL: "http://localhost:8080" - IssuerURL: "http://localhost:8080/oauth/v2" - Audience: "http://localhost:8080" + BaseURL: "http://localhost:8080" OrgOwnerPassword: "Password1!" OrgOwnerViewerPassword: "Password1!" OrgProjectCreatorPassword: "Password1!" diff --git a/console/cypress.sh b/console/cypress.sh index 5f0f5e5781..ac7046a935 100755 --- a/console/cypress.sh +++ b/console/cypress.sh @@ -17,5 +17,5 @@ fi $NPX cypress $ACTION \ --port "${E2E_CYPRESSPORT}" \ - --env org="${ZITADEL_E2E_ORG}",org_owner_password="${ZITADEL_E2E_ORGOWNERPW}",org_owner_viewer_password="${ZITADEL_E2E_ORGOWNERVIEWERPW}",org_project_creator_password="${ZITADEL_E2E_ORGPROJECTCREATORPW}",login_policy_user_password="${ZITADEL_E2E_LOGINPOLICYUSERPW}",password_complexity_user_password="${ZITADEL_E2E_PASSWORDCOMPLEXITYUSERPW}",consoleUrl="${ZITADEL_E2E_CONSOLEURL}",apiUrl="${ZITADEL_E2E_APIURL}",accountsUrl="${ZITADEL_E2E_ACCOUNTSURL}",issuerUrl="${ZITADEL_E2E_ISSUERURL}",serviceAccountKeyPath="${ZITADEL_E2E_MACHINEKEYPATH}",otherZitadelIdpInstance="${ZITADEL_E2E_OTHERZITADELIDPINSTANCE}",zitadelProjectResourceId="${ZITADEL_E2E_ZITADELPROJECTRESOURCEID}" \ + --env org="${ZITADEL_E2E_ORG}",org_owner_password="${ZITADEL_E2E_ORGOWNERPW}",org_owner_viewer_password="${ZITADEL_E2E_ORGOWNERVIEWERPW}",org_project_creator_password="${ZITADEL_E2E_ORGPROJECTCREATORPW}",login_policy_user_password="${ZITADEL_E2E_LOGINPOLICYUSERPW}",password_complexity_user_password="${ZITADEL_E2E_PASSWORDCOMPLEXITYUSERPW}",baseUrl="${ZITADEL_E2E_BASEURL}",serviceAccountKeyPath="${ZITADEL_E2E_MACHINEKEYPATH}",otherZitadelIdpInstance="${ZITADEL_E2E_OTHERZITADELIDPINSTANCE}",zitadelProjectResourceId="${ZITADEL_E2E_ZITADELPROJECTRESOURCEID}" \ "$@" diff --git a/console/cypress/e2e/applications/applications.cy.ts b/console/cypress/e2e/applications/applications.cy.ts index 4b0313bf68..4c926e464e 100644 --- a/console/cypress/e2e/applications/applications.cy.ts +++ b/console/cypress/e2e/applications/applications.cy.ts @@ -16,7 +16,7 @@ describe('applications', () => { apiAuth().then(api => { ensureProjectExists(api, testProjectName).then(projectID => { ensureProjectResourceDoesntExist(api, projectID, Apps, testAppName).then(() => { - cy.visit(`${Cypress.env('consoleUrl')}/projects/${projectID}`) + cy.visit(`${Cypress.env('baseUrl')}/ui/console/projects/${projectID}`) }) }) }) @@ -46,5 +46,5 @@ describe('applications', () => { //TODO: check client ID/Secret }) }) - }) + }) }) \ No newline at end of file diff --git a/console/cypress/e2e/humans/humans.cy.ts b/console/cypress/e2e/humans/humans.cy.ts index 28a7ba2e14..aedd0fcc96 100644 --- a/console/cypress/e2e/humans/humans.cy.ts +++ b/console/cypress/e2e/humans/humans.cy.ts @@ -3,7 +3,7 @@ import { ensureHumanUserExists, ensureUserDoesntExist } from '../../support/api/ import { login, User, username } from '../../support/login/users'; describe('humans', () => { - const humansPath = `${Cypress.env('consoleUrl')}/users?type=human`; + const humansPath = `${Cypress.env('baseUrl')}/ui/console/users?type=human`; const testHumanUserNameAdd = 'e2ehumanusernameadd'; const testHumanUserNameRemove = 'e2ehumanusernameremove'; @@ -64,18 +64,18 @@ describe('humans', () => { describe("users", ()=> { before(()=> { - cy.consolelogin(Cypress.env('username'), Cypress.env('password'), Cypress.env('consoleUrl')) + cy.consolelogin(Cypress.env('username'), Cypress.env('password'), `Cypress.env('baseUrl')/ui/console`) }) it('should show personal information', () => { cy.log(`USER: show personal information`); - //click on user information + //click on user information cy.get('a[href*="users/me"').eq(0).click() cy.url().should('contain', '/users/me') }) it('should show users', () => { - cy.visit(Cypress.env('consoleUrl') + '/users/list/humans') + cy.visit(Cypress.env('baseUrl')/ui/console + '/users/list/humans') cy.url().should('contain', 'users/list/humans') }) }) diff --git a/console/cypress/e2e/machines/machines.cy.ts b/console/cypress/e2e/machines/machines.cy.ts index 38c0f770fd..7fac07522c 100644 --- a/console/cypress/e2e/machines/machines.cy.ts +++ b/console/cypress/e2e/machines/machines.cy.ts @@ -3,7 +3,7 @@ import { ensureMachineUserExists, ensureUserDoesntExist } from '../../support/ap import { login, User, username } from '../../support/login/users'; describe('machines', () => { - const machinesPath = `${Cypress.env('consoleUrl')}/users?type=machine`; + const machinesPath = `${Cypress.env('baseUrl')}/ui/console/users?type=machine`; const testMachineUserNameAdd = 'e2emachineusernameadd'; const testMachineUserNameRemove = 'e2emachineusernameremove'; diff --git a/console/cypress/e2e/permissions/permissions.cy.ts b/console/cypress/e2e/permissions/permissions.cy.ts index 49b19741a1..59e85c7107 100644 --- a/console/cypress/e2e/permissions/permissions.cy.ts +++ b/console/cypress/e2e/permissions/permissions.cy.ts @@ -24,7 +24,7 @@ describe('permissions', () => { api = apiCalls ensureProjectExists(apiCalls, testProjectName).then(projId => { projectId = projId - cy.visit(`${Cypress.env('consoleUrl')}/projects/${projId}`) + cy.visit(`${Cypress.env('baseUrl')}/ui/console/projects/${projId}`) }) }) }) @@ -54,19 +54,19 @@ describe('permissions', () => { describe('permissions', () => { before(()=> { -// cy.consolelogin(Cypress.env('username'), Cypress.env('password'), Cypress.env('consoleUrl')) +// cy.consolelogin(Cypress.env('username'), Cypress.env('password'), Cypress.env('baseUrl')/ui/console) }) it('should show projects ', () => { - cy.visit(Cypress.env('consoleUrl') + '/projects') + cy.visit(Cypress.env('baseUrl')/ui/console + '/projects') cy.url().should('contain', '/projects') }) it('should add a role', () => { - cy.visit(Cypress.env('consoleUrl') + '/org').then(() => { + cy.visit(Cypress.env('baseUrl')/ui/console + '/org').then(() => { cy.url().should('contain', '/org'); }) - cy.visit(Cypress.env('consoleUrl') + '/projects').then(() => { + cy.visit(Cypress.env('baseUrl')/ui/console + '/projects').then(() => { cy.url().should('contain', '/projects'); cy.get('.card').should('contain.text', "newProjectToTest") }) @@ -77,8 +77,8 @@ describe('permissions', () => { cy.log(url.split('/')[4]) projectID = url.split('/')[4] }); - - cy.then(() => cy.visit(Cypress.env('consoleUrl') + '/projects/' + projectID +'/roles/create')) + + cy.then(() => cy.visit(Cypress.env('baseUrl')/ui/console + '/projects/' + projectID +'/roles/create')) cy.get('[formcontrolname^=key]').type("newdemorole") cy.get('[formcontrolname^=displayName]').type("newdemodisplayname") cy.get('[formcontrolname^=group]').type("newdemogroupname") @@ -88,10 +88,10 @@ describe('permissions', () => { }) it('should add a grant', () => { - cy.visit(Cypress.env('consoleUrl') + '/org').then(() => { + cy.visit(Cypress.env('baseUrl')/ui/console + '/org').then(() => { cy.url().should('contain', '/org'); }) - cy.visit(Cypress.env('consoleUrl') + '/projects').then(() => { + cy.visit(Cypress.env('baseUrl')/ui/console + '/projects').then(() => { cy.url().should('contain', '/projects'); cy.get('.card').should('contain.text', "newProjectToTest") }) @@ -102,8 +102,8 @@ describe('permissions', () => { cy.log(url.split('/')[4]) projectID = url.split('/')[4] }); - - cy.then(() => cy.visit(Cypress.env('consoleUrl') + '/grant-create/project/' + projectID )) + + cy.then(() => cy.visit(Cypress.env('baseUrl')/ui/console + '/grant-create/project/' + projectID )) cy.get('input').type("demo") cy.get('[role^=listbox]').filter(`:contains("${Cypress.env("fullUserName")}")`).should('be.visible').click() cy.wait(5000) diff --git a/console/cypress/e2e/projects/projects.cy.ts b/console/cypress/e2e/projects/projects.cy.ts index 0a1c10283c..3d684cc88e 100644 --- a/console/cypress/e2e/projects/projects.cy.ts +++ b/console/cypress/e2e/projects/projects.cy.ts @@ -18,7 +18,7 @@ describe('projects', () => { apiAuth().then((api) => { ensureProjectDoesntExist(api, testProjectNameCreate); }); - cy.visit(`${Cypress.env('consoleUrl')}/projects`); + cy.visit(`${Cypress.env('baseUrl')}/ui/console/projects`); }); it('should add a project', () => { @@ -37,7 +37,7 @@ describe('projects', () => { apiAuth().then((api) => { ensureProjectExists(api, testProjectNameDeleteList); }); - cy.visit(`${Cypress.env('consoleUrl')}/projects`); + cy.visit(`${Cypress.env('baseUrl')}/ui/console/projects`); }); it('removes the project', () => { @@ -58,7 +58,7 @@ describe('projects', () => { apiAuth().then((api) => { ensureProjectExists(api, testProjectNameDeleteGrid); }); - cy.visit(`${Cypress.env('consoleUrl')}/projects`); + cy.visit(`${Cypress.env('baseUrl')}/ui/console/projects`); }); it('removes the project', () => { diff --git a/console/cypress/e2e/settings/login-policy.cy.ts b/console/cypress/e2e/settings/login-policy.cy.ts index e0e81694f8..fe210a0ef9 100644 --- a/console/cypress/e2e/settings/login-policy.cy.ts +++ b/console/cypress/e2e/settings/login-policy.cy.ts @@ -4,7 +4,7 @@ import { login, User } from "../../support/login/users"; describe("login policy", ()=> { - const orgPath = `${Cypress.env('consoleUrl')}/org` + const orgPath = `${Cypress.env('baseUrl')}/ui/console/org` ;[User.OrgOwner].forEach(user => { diff --git a/console/cypress/e2e/settings/password-complexity.cy.ts b/console/cypress/e2e/settings/password-complexity.cy.ts index 05e2698b98..f6664870db 100644 --- a/console/cypress/e2e/settings/password-complexity.cy.ts +++ b/console/cypress/e2e/settings/password-complexity.cy.ts @@ -2,7 +2,7 @@ import { login, User } from "../../support/login/users"; describe("password complexity", ()=> { - const orgPath = `${Cypress.env('consoleUrl')}/org` + const orgPath = `${Cypress.env('baseUrl')}/ui/console/org` const testProjectName = 'e2eproject' ;[User.OrgOwner].forEach(user => { diff --git a/console/cypress/e2e/settings/private-labeling.cy.ts b/console/cypress/e2e/settings/private-labeling.cy.ts index 2c2ca4032e..93aa0b58c4 100644 --- a/console/cypress/e2e/settings/private-labeling.cy.ts +++ b/console/cypress/e2e/settings/private-labeling.cy.ts @@ -3,7 +3,7 @@ import { Policy, resetPolicy } from '../../support/api/policies'; import { login, User } from '../../support/login/users'; describe('private labeling', () => { - const orgPath = `${Cypress.env('consoleUrl')}/org`; + const orgPath = `${Cypress.env('baseUrl')}/ui/console/org`; [User.OrgOwner].forEach((user) => { describe(`as user "${user}"`, () => { diff --git a/console/cypress/support/api/apiauth.ts b/console/cypress/support/api/apiauth.ts index 7a51846a86..67ec4cc256 100644 --- a/console/cypress/support/api/apiauth.ts +++ b/console/cypress/support/api/apiauth.ts @@ -6,8 +6,8 @@ export interface apiCallProperties { } export function apiAuth(): Cypress.Chainable { - const apiUrl = Cypress.env('apiUrl') - const issuerUrl = Cypress.env('issuerUrl') + const baseUrl = Cypress.env('baseUrl') + const issuerUrl = `${baseUrl}/oauth/v2` const zitadelProjectResourceID = (Cypress.env('zitadelProjectResourceId')).replace('bignumber-', '') const key = Cypress.env("parsedServiceAccountKey") @@ -18,7 +18,7 @@ export function apiAuth(): Cypress.Chainable { const bearerToken = sign({ iss: key.userId, sub: key.userId, - aud: `${issuerUrl}`, + aud: `${baseUrl}`, iat: iat, exp: exp }, key.key, { @@ -30,7 +30,7 @@ export function apiAuth(): Cypress.Chainable { return cy.request({ method: 'POST', - url: `${apiUrl}/oauth/v2/token`, + url: `${issuerUrl}/token`, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -43,7 +43,7 @@ export function apiAuth(): Cypress.Chainable { return { authHeader: `Bearer ${token}`, - mgntBaseURL: `${apiUrl}/management/v1/`, + mgntBaseURL: `${baseUrl}/management/v1/`, } }) } \ No newline at end of file diff --git a/console/cypress/support/commands.ts b/console/cypress/support/commands.ts index 20af219d25..cb8662e5f0 100644 --- a/console/cypress/support/commands.ts +++ b/console/cypress/support/commands.ts @@ -7,14 +7,14 @@ namespace Cypress { * * @example cy.consolelogin('hodor', 'hodor1234') */ -/* consolelogin(username: string, password: string): void +/* 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.env('consoleUrl')).then(() => { + cy.visit(Cypress.env('baseUrl')/ui/console).then(() => { // fill the fields and push button cy.get('#loginName').type(username, { log: false }) cy.get('#submit-button').click() diff --git a/console/cypress/support/login/users.ts b/console/cypress/support/login/users.ts index 3d33750ebf..430d03e6bf 100644 --- a/console/cypress/support/login/users.ts +++ b/console/cypress/support/login/users.ts @@ -4,7 +4,7 @@ export enum User { OrgProjectCreator = 'org_project_creator', LoginPolicyUser = 'login_policy_user', PasswordComplexityUser = 'password_complexity_user', - IAMAdminUser = 'zitadel-admin', +// IAMAdminUser = 'zitadel-admin', } export function login( @@ -17,8 +17,10 @@ export function login( ): void { let creds = credentials(user, pw); - const accountsUrl: string = Cypress.env('accountsUrl'); - const consoleUrl: string = Cypress.env('consoleUrl'); + const baseUrl: string = Cypress.env('baseUrl'); + const consoleUrl: string = `${baseUrl}/ui/console`; + const loginUrl: string = `${baseUrl}/ui/login`; + const issuerUrl: string = `${baseUrl}/oauth/v2`; const otherZitadelIdpInstance: boolean = Cypress.env('otherZitadelIdpInstance'); cy.session( @@ -30,7 +32,7 @@ export function login( cy.intercept( { method: 'GET', - url: `${accountsUrl}/login*`, + url: `${loginUrl}*`, times: 1, }, (req) => { @@ -44,7 +46,7 @@ export function login( cy.intercept( { method: 'POST', - url: `${accountsUrl}/loginname*`, + url: `${loginUrl}/loginname*`, times: 1, }, (req) => { @@ -58,7 +60,7 @@ export function login( cy.intercept( { method: 'POST', - url: `${accountsUrl}/password*`, + url: `${loginUrl}/password*`, times: 1, }, (req) => { @@ -72,7 +74,7 @@ export function login( cy.intercept( { method: 'GET', - url: `${accountsUrl}/success*`, + url: `${loginUrl}/success*`, times: 1, }, (req) => { @@ -86,7 +88,7 @@ export function login( cy.intercept( { method: 'GET', - url: `${accountsUrl}/oauth/v2/authorize/callback*`, + url: `${issuerUrl}/authorize/callback*`, times: 1, }, (req) => { @@ -100,7 +102,7 @@ export function login( cy.intercept( { method: 'GET', - url: `${accountsUrl}/oauth/v2/authorize*`, + url: `${issuerUrl}/authorize*`, times: 1, }, (req) => { @@ -111,7 +113,7 @@ export function login( ); } - cy.visit(`${consoleUrl}/loginname`, { retryOnNetworkFailure: true }); + cy.visit(`${loginUrl}`, { retryOnNetworkFailure: true }); otherZitadelIdpInstance && cy.wait('@login'); onUsernameScreen ? onUsernameScreen() : null; @@ -127,7 +129,7 @@ export function login( otherZitadelIdpInstance && cy.wait('@callback'); - cy.location('pathname', { timeout: 5 * 1000 }).should('eq', '/'); + cy.location('pathname', { timeout: 5 * 1000 }).should('eq', '/ui/console/'); }, { validate: () => { @@ -141,14 +143,14 @@ export function login( ); } -export function username(withoutDomain: string, project?: string): string { - return `${withoutDomain}@${project ? `${project}.` : ''}${host(Cypress.env('apiUrl')).replace('api.', '')}`; +export function username(withoutDomain: string, org?: string): string { + return `${withoutDomain}@${org}.${host(Cypress.env('baseUrl'))}`; } function credentials(user: User, pw?: string) { - const isAdmin = user == User.IAMAdminUser; +// const isAdmin = user == User.IAMAdminUser; return { - username: username(isAdmin ? user : `${user}_user_name`, isAdmin ? 'caos-ag' : Cypress.env('org')), + username: username(`${user}_user_name`, Cypress.env('org')), password: pw ? pw : Cypress.env(`${user}_password`), }; } diff --git a/console/package.json b/console/package.json index 2db0c1dc52..c67950e0cf 100644 --- a/console/package.json +++ b/console/package.json @@ -7,8 +7,8 @@ "build": "ng build", "prodbuild": "ng build --configuration production --base-href=/ui/console/", "lint": "ng lint && stylelint './src/**/*.scss' --syntax scss", - "e2e": "./cypress.sh run e2e.env", - "e2e:open": "./cypress.sh open e2e.env" + "e2e": "./cypress.sh run ../e2e/local.env", + "e2e:open": "./cypress.sh open ../e2e/local.env" }, "private": true, "dependencies": { diff --git a/e2e/local.env b/e2e/local.env index 87f28aee79..6f29bbab52 100644 --- a/e2e/local.env +++ b/e2e/local.env @@ -6,10 +6,7 @@ ZITADEL_E2E_ORGPROJECTCREATORPW=Password1! ZITADEL_E2E_PASSWORDCOMPLEXITYUSERPW=Password1! ZITADEL_E2E_LOGINPOLICYUSERPW=Password1! ZITADEL_E2E_MACHINEKEYPATH="${projectRoot}/.keys/e2e.json" -ZITADEL_E2E_CONSOLEURL="http://localhost:8080/ui/console/" -ZITADEL_E2E_APIURL="http://localhost:8080" -ZITADEL_E2E_ACCOUNTSURL="http://localhost:8080" -ZITADEL_E2E_ISSUERURL="http://localhost:8080/oauth/v2" +ZITADEL_E2E_BASEURL="http://localhost:8080" ZITADEL_E2E_OTHERZITADELIDPINSTANCE=false ZITADEL_E2E_ZITADELPROJECTRESOURCEID="bignumber-$(echo -n $(${projectRoot}/e2e/docker-compose.sh exec --no-TTY db cockroach sql --database zitadel --insecure --execute "select aggregate_id from eventstore.events where event_type = 'project.added' and event_data = '{\"name\": \"ZITADEL\"}';" --format tsv) | cut -d " " -f 2)" ZITADEL_E2E_INSTANCEID="$(echo -n $(${projectRoot}/e2e/docker-compose.sh exec --no-TTY db cockroach sql --database zitadel --insecure --execute "select aggregate_id from eventstore.events where event_type = 'instance.added' and event_data = '{\"name\": \"Localhost\"}';" --format tsv) | cut -d " " -f 2)"