Files
zitadel/e2e/cypress/e2e/permissions/permissions.cy.ts

283 lines
10 KiB
TypeScript
Raw Normal View History

import { ensureProjectGrantExists } from 'support/api/grants';
import {
ensureHumanIsOrgMember,
ensureHumanIsNotOrgMember,
ensureHumanIsNotProjectMember,
ensureHumanIsProjectMember,
} from 'support/api/members';
import { ensureOrgExists } from 'support/api/orgs';
import { ensureDomainPolicy } from 'support/api/policies';
import { ensureHumanUserExists, ensureUserDoesntExist } from 'support/api/users';
import { Context } from 'support/commands';
import { ensureProjectExists, ensureProjectResourceDoesntExist, Roles } from '../../support/api/projects';
describe('permissions', () => {
beforeEach(() => {
cy.context()
.as('ctx')
.then((ctx) => {
ensureDomainPolicy(ctx.api, false, true, false);
});
});
describe('management', () => {
const testManagerUsername = 'e2ehumanmanager';
function testAuthorizations(
roles: string[],
beforeCreate: (ctx: Context) => void,
beforeMutate: (ctx: Context) => void,
navigate: () => void,
) {
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
ensureUserDoesntExist(ctx.api, testManagerUsername);
ensureHumanUserExists(ctx.api, testManagerUsername);
});
});
describe('create authorization', () => {
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
beforeCreate(ctx);
navigate();
});
});
it('should add a manager', () => {
cy.get('[data-e2e="add-member-button"]').click();
2024-08-22 09:48:36 +02:00
cy.get('[data-e2e="add-member-input"]').should('be.enabled').type(testManagerUsername);
cy.get('[data-e2e="user-option"]').first().click();
cy.contains('[data-e2e="role-checkbox"]', roles[0]).click();
cy.get('[data-e2e="confirm-add-member-button"]').click();
cy.shouldConfirmSuccess();
cy.contains('[data-e2e="member-avatar"]', 'ee');
});
});
describe('mutate authorization', () => {
const rowSelector = `tr:contains(${testManagerUsername})`;
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
beforeMutate(ctx);
navigate();
cy.contains('[data-e2e="member-avatar"]', 'ee').click();
cy.get(rowSelector).as('managerRow');
});
});
it('should remove a manager', () => {
cy.get('@managerRow').find('[data-e2e="remove-member-button"]').click({ force: true });
cy.get('[data-e2e="confirm-dialog-button"]').click();
cy.shouldConfirmSuccess();
cy.shouldNotExist({
selector: rowSelector,
timeout: { ms: 2000, errMessage: 'timed out before manager disappeared from the table' },
});
});
it('should remove a managers authorization', () => {
cy.get('@managerRow').find('[data-e2e="role"]').should('have.length', roles.length);
cy.get('@managerRow')
.contains('[data-e2e="role"]', roles[0])
.find('[data-e2e="remove-role-button"]')
.click({ force: true }); // TODO: Is this a bug?
cy.get('[data-e2e="confirm-dialog-button"]').click();
cy.shouldConfirmSuccess();
cy.get('@managerRow')
.find('[data-e2e="remove-role-button"]')
.should('have.length', roles.length - 1);
});
});
}
ci(e2e): Run Tests in Pipelines (#3903) * cy10 changes * test: setup local e2e env * test(e2e): migrate e2e setup * add more config * make e2e setup work * align variables * fix config * skip mfa * set user register to false * read ids from database if not provided * don't read ids withing env file * fix escaping in id queries * fix project root * export projectRoot path * export projectRoot * add e2e-setup.sh * specify GOOS and GOARCH for dockerfile compatible binary * add org default redirect uri * correctly initialize org policy * await ids * fix awaiting ids * fix cypress configuration * fix some tests * initial compose setup * fix working directory * fix references * make tests less flaky * run go tests * compose works until e2e-setup incl * pass created e2e sa key * make cypress run * derive e2e orgs domain from baseurl * use host from baseurl for setup ctx * move defaults.yaml back to cmd pkg * just create org owner * Don't render element if no roles are passed * use map instead of switchMap * fix e2e tests * added testdata for e3e * zipped dump * removed dumpDir * cypress workflow with compose * quote name * cleanup vars * eliminate need for e2e setup * compose has no builds anymore * use compose run and zitadel nw * test e2e on pr (#4114) * test e2e on pr * install goreleaser * install npm dev dependencies * run cypress wf * dynamic release version * skip flaky user tests * skip flaky permissions test * cache docker layers in pipeline * Update .github/workflows/cypress.yml Co-authored-by: Florian Forster <florian@caos.ch> * align goreleaser version * get rid of install.sh * remove cypress-terminal-report * Revert "remove cypress-terminal-report" This reverts commit 254b5a1f87be71c64c1289b12fc1bf23a401ea64. * just one npm e2e:build command * cache npm dependencies * install node modules using docker * dedicated e2e context * fix syntax * don't copy node modules from goreleaser * add npm-copy target * add tsconfig.json * remove docker caching * deleted unneeded shellscript * naming and cleanup Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Christian Jakob <christian@caos.ch> * cleanup Co-authored-by: Elio Bischof <eliobischof@gmail.com> Co-authored-by: Christian Jakob <christian@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch>
2022-08-05 20:00:46 +02:00
describe('organizations', () => {
const roles = [
{ internal: 'ORG_OWNER', display: 'Org Owner' },
{ internal: 'ORG_OWNER_VIEWER', display: 'Org Owner Viewer' },
];
testAuthorizations(
roles.map((role) => role.display),
function (ctx: Context) {
ensureHumanIsNotOrgMember(ctx.api, testManagerUsername);
},
function (ctx: Context) {
ensureHumanIsNotOrgMember(ctx.api, testManagerUsername);
ensureHumanIsOrgMember(
ctx.api,
testManagerUsername,
roles.map((role) => role.internal),
);
},
() => {
cy.visit('/orgs');
cy.contains('tr', Cypress.env('ORGANIZATION')).click();
},
);
});
describe('projects', () => {
describe('owned projects', () => {
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
ensureProjectExists(ctx.api, 'e2eprojectpermission').as('projectId');
});
});
const visitOwnedProject = () => {
cy.get<number>('@projectId').then((projectId) => {
cy.visit(`/projects/${projectId}`);
});
};
describe('authorizations', () => {
const roles = [
{ internal: 'PROJECT_OWNER_GLOBAL', display: 'Project Owner Global' },
{ internal: 'PROJECT_OWNER_VIEWER_GLOBAL', display: 'Project Owner Viewer Global' },
];
testAuthorizations(
roles.map((role) => role.display),
function (ctx) {
cy.get<string>('@projectId').then((projectId) => {
ensureHumanIsNotProjectMember(ctx.api, projectId, testManagerUsername);
});
},
function (ctx) {
cy.get<string>('@projectId').then((projectId) => {
ensureHumanIsNotProjectMember(ctx.api, projectId, testManagerUsername);
ensureHumanIsProjectMember(
ctx.api,
projectId,
testManagerUsername,
roles.map((role) => role.internal),
);
});
},
visitOwnedProject,
);
});
ci(e2e): Run Tests in Pipelines (#3903) * cy10 changes * test: setup local e2e env * test(e2e): migrate e2e setup * add more config * make e2e setup work * align variables * fix config * skip mfa * set user register to false * read ids from database if not provided * don't read ids withing env file * fix escaping in id queries * fix project root * export projectRoot path * export projectRoot * add e2e-setup.sh * specify GOOS and GOARCH for dockerfile compatible binary * add org default redirect uri * correctly initialize org policy * await ids * fix awaiting ids * fix cypress configuration * fix some tests * initial compose setup * fix working directory * fix references * make tests less flaky * run go tests * compose works until e2e-setup incl * pass created e2e sa key * make cypress run * derive e2e orgs domain from baseurl * use host from baseurl for setup ctx * move defaults.yaml back to cmd pkg * just create org owner * Don't render element if no roles are passed * use map instead of switchMap * fix e2e tests * added testdata for e3e * zipped dump * removed dumpDir * cypress workflow with compose * quote name * cleanup vars * eliminate need for e2e setup * compose has no builds anymore * use compose run and zitadel nw * test e2e on pr (#4114) * test e2e on pr * install goreleaser * install npm dev dependencies * run cypress wf * dynamic release version * skip flaky user tests * skip flaky permissions test * cache docker layers in pipeline * Update .github/workflows/cypress.yml Co-authored-by: Florian Forster <florian@caos.ch> * align goreleaser version * get rid of install.sh * remove cypress-terminal-report * Revert "remove cypress-terminal-report" This reverts commit 254b5a1f87be71c64c1289b12fc1bf23a401ea64. * just one npm e2e:build command * cache npm dependencies * install node modules using docker * dedicated e2e context * fix syntax * don't copy node modules from goreleaser * add npm-copy target * add tsconfig.json * remove docker caching * deleted unneeded shellscript * naming and cleanup Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Christian Jakob <christian@caos.ch> * cleanup Co-authored-by: Elio Bischof <eliobischof@gmail.com> Co-authored-by: Christian Jakob <christian@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch>
2022-08-05 20:00:46 +02:00
describe('roles', () => {
const testRoleName = 'e2eroleundertestname';
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
cy.get<string>('@projectId').then((projectId) => {
ensureProjectResourceDoesntExist(ctx.api, projectId, Roles, testRoleName);
visitOwnedProject();
});
});
});
it('should add a role', () => {
cy.get('[data-e2e="sidenav-element-roles"]').click();
cy.get('[data-e2e="add-new-role"]').click();
2024-08-22 09:48:36 +02:00
cy.get('[formcontrolname="key"]').should('be.enabled').type(testRoleName);
cy.get('[formcontrolname="displayName"]').should('be.enabled').type('e2eroleundertestdisplay');
cy.get('[formcontrolname="group"]').should('be.enabled').type('e2eroleundertestgroup');
cy.get('[data-e2e="save-button"]').click();
cy.shouldConfirmSuccess();
cy.contains('tr', testRoleName);
});
it('should remove a role');
});
});
describe('granted projects', () => {
beforeEach(() => {
cy.get<Context>('@ctx').then((ctx) => {
ensureOrgExists(ctx, 'e2eforeignorg').then((foreignOrgId) => {
ensureProjectExists(ctx.api, 'e2eprojectgrants', foreignOrgId)
.as('foreignProjectId')
.then((foreignProjectId) => {
ensureProjectGrantExists(ctx, foreignOrgId, foreignProjectId).as('grantId');
});
});
});
});
function visitGrantedProject() {
cy.get<string>('@foreignProjectId').then((foreignProjectId) => {
cy.get<string>('@grantId').then((grantId) => {
cy.visit(`/granted-projects/${foreignProjectId}/grant/${grantId}`);
});
});
}
describe('authorizations', () => {
const roles = [
{ internal: 'PROJECT_GRANT_OWNER', display: 'Project Grant Owner' },
{ internal: 'PROJECT_GRANT_OWNER_VIEWER', display: 'Project Grant Owner Viewer' },
];
testAuthorizations(
roles.map((role) => role.display),
function (ctx: Context) {
cy.get<string>('@foreignProjectId').then((foreignProjectId) => {
cy.get<string>('@grantId').then((grantId) => {
ensureHumanIsNotProjectMember(ctx.api, foreignProjectId, testManagerUsername, grantId);
});
});
},
function (ctx: Context) {
cy.get<string>('@foreignProjectId').then((foreignProjectId) => {
cy.get<string>('@grantId').then((grantId) => {
ensureHumanIsNotProjectMember(ctx.api, foreignProjectId, testManagerUsername, grantId);
ensureHumanIsProjectMember(
ctx.api,
foreignProjectId,
testManagerUsername,
roles.map((role) => role.internal),
grantId,
);
});
});
},
visitGrantedProject,
);
});
});
});
});
});
describe('validations', () => {
describe('owned projects', () => {
describe('no ownership', () => {
it('a user without project global ownership can ...');
it('a user without project global ownership can not ...');
});
describe('project owner viewer global', () => {
it('a project owner viewer global additionally can ...');
it('a project owner viewer global still can not ...');
});
describe('project owner global', () => {
it('a project owner global additionally can ...');
it('a project owner global still can not ...');
});
});
ci(e2e): Run Tests in Pipelines (#3903) * cy10 changes * test: setup local e2e env * test(e2e): migrate e2e setup * add more config * make e2e setup work * align variables * fix config * skip mfa * set user register to false * read ids from database if not provided * don't read ids withing env file * fix escaping in id queries * fix project root * export projectRoot path * export projectRoot * add e2e-setup.sh * specify GOOS and GOARCH for dockerfile compatible binary * add org default redirect uri * correctly initialize org policy * await ids * fix awaiting ids * fix cypress configuration * fix some tests * initial compose setup * fix working directory * fix references * make tests less flaky * run go tests * compose works until e2e-setup incl * pass created e2e sa key * make cypress run * derive e2e orgs domain from baseurl * use host from baseurl for setup ctx * move defaults.yaml back to cmd pkg * just create org owner * Don't render element if no roles are passed * use map instead of switchMap * fix e2e tests * added testdata for e3e * zipped dump * removed dumpDir * cypress workflow with compose * quote name * cleanup vars * eliminate need for e2e setup * compose has no builds anymore * use compose run and zitadel nw * test e2e on pr (#4114) * test e2e on pr * install goreleaser * install npm dev dependencies * run cypress wf * dynamic release version * skip flaky user tests * skip flaky permissions test * cache docker layers in pipeline * Update .github/workflows/cypress.yml Co-authored-by: Florian Forster <florian@caos.ch> * align goreleaser version * get rid of install.sh * remove cypress-terminal-report * Revert "remove cypress-terminal-report" This reverts commit 254b5a1f87be71c64c1289b12fc1bf23a401ea64. * just one npm e2e:build command * cache npm dependencies * install node modules using docker * dedicated e2e context * fix syntax * don't copy node modules from goreleaser * add npm-copy target * add tsconfig.json * remove docker caching * deleted unneeded shellscript * naming and cleanup Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Christian Jakob <christian@caos.ch> * cleanup Co-authored-by: Elio Bischof <eliobischof@gmail.com> Co-authored-by: Christian Jakob <christian@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch>
2022-08-05 20:00:46 +02:00
describe('granted projects', () => {
describe('no ownership', () => {
it('a user without project grant ownership can ...');
it('a user without project grant ownership can not ...');
});
describe('project grant owner viewer', () => {
it('a project grant owner viewer additionally can ...');
it('a project grant owner viewer still can not ...');
});
describe('project grant owner', () => {
it('a project grant owner additionally can ...');
it('a project grant owner still can not ...');
});
});
describe('organization', () => {
describe('org owner', () => {
it('a project owner global can ...');
it('a project owner global can not ...');
});
});
});