Skip to content

Commit

Permalink
migrate e2e test for adding group permission (#3683)
Browse files Browse the repository at this point in the history
* migrate e2e test for adding group permission

Signed-off-by: gitdallas <[email protected]>

* fix the test to use the typeahead properly

Signed-off-by: gitdallas <[email protected]>

* update process so this works in headless better

Signed-off-by: gitdallas <[email protected]>

* change cypress test tags

Signed-off-by: gitdallas <[email protected]>

---------

Signed-off-by: gitdallas <[email protected]>
  • Loading branch information
gitdallas authored Feb 5, 2025
1 parent 2760f93 commit 8450988
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
19 changes: 19 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ class PermissionTable extends Contextual<HTMLElement> {
.click();
}

addGroupName(name: string) {
const userNameCell = permissions.getGroupTable().find().find('[data-label="Username"]');
userNameCell.findByRole('button', { name: 'Typeahead menu toggle' }).should('exist').click();
userNameCell.children().first().type(`${name}`);
//have to do this at top level `cy` because it goes to top of dom
cy.findByRole('option', { name: `Select "${name}"` }).click();
}

selectAdminOption() {
permissions
.getGroupTable()
.find()
.find('[data-label="Permission"]')
.children()
.first()
.findSelectOption('Admin Edit the project and manage user access')
.click();
}

findSaveNewButton() {
return this.find().findByTestId(['save-new-button']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { projectDetails, projectListPage } from '~/__tests__/cypress/cypress/pag
import { permissions } from '~/__tests__/cypress/cypress/pages/permissions';
import {
HTPASSWD_CLUSTER_ADMIN_USER,
LDAP_CONTRIBUTOR_GROUP,
LDAP_CONTRIBUTOR_USER,
} from '~/__tests__/cypress/cypress/utils/e2eUsers';
import { loadDSPFixture } from '~/__tests__/cypress/cypress/utils/dataLoader';
import { createCleanProject } from '~/__tests__/cypress/cypress/utils/projectChecker';
import { deleteOpenShiftProject } from '~/__tests__/cypress/cypress/utils/oc_commands/project';

describe('Verify that users can provide admin project permissions to non-admin users', () => {
describe('Verify that users can provide admin project permissions to non-admin users/groups', () => {
let testData: DataScienceProjectData;
let projectName: string;

Expand Down Expand Up @@ -39,7 +40,9 @@ describe('Verify that users can provide admin project permissions to non-admin u

it(
'Verify that user can be added as an Admin for a Project',
{ tags: ['@Smoke', '@SmokeSet1', '@ODS-2194', '@ODS-2201', '@Dashboard'] },
{
tags: ['@Smoke', '@SmokeSet1', '@ODS-2194', '@ODS-2201', '@ODS-2208', '@Dashboard'],
},
() => {
// Authentication and navigation
cy.step('Log into the application');
Expand Down Expand Up @@ -71,9 +74,41 @@ describe('Verify that users can provide admin project permissions to non-admin u
cy.contains(LDAP_CONTRIBUTOR_USER.USERNAME).should('exist');
},
);
it(
'Verify user can assign access permissions to user group',
{
tags: ['@Smoke', '@SmokeSet1', '@ODS-2194', '@ODS-2201', '@ODS-2208', '@Dashboard'],
},
() => {
// Authentication and navigation
cy.step('Log into the application');
cy.visitWithLogin('/', HTPASSWD_CLUSTER_ADMIN_USER);

// Project navigation, add group and provide admin permissions
cy.step(
`Navigate to the Project list tab and search for ${testData.projectPermissionResourceName}`,
);
projectListPage.navigate();
projectListPage.filterProjectByName(testData.projectPermissionResourceName);
projectListPage.findProjectLink(testData.projectPermissionResourceName).click();
projectDetails.findSectionTab('permissions').click();

cy.step('Assign admin group Project Permissions');
permissions.findAddGroupButton().click();
permissions.getGroupTable().addGroupName(LDAP_CONTRIBUTOR_GROUP.USERNAME);
permissions.getGroupTable().selectAdminOption();
cy.step(
`Save the group and validate that ${LDAP_CONTRIBUTOR_GROUP.USERNAME} has been saved with admin permissions`,
);
permissions.getGroupTable().findSaveNewButton().should('exist').and('be.visible').click();
cy.contains(LDAP_CONTRIBUTOR_GROUP.USERNAME).should('exist');
},
);
it(
'Verify that user can access the created project with Admin rights',
{ tags: ['@Smoke', '@SmokeSet1', '@ODS-2194', '@ODS-2201', '@Dashboard'] },
{
tags: ['@Smoke', '@SmokeSet1', '@ODS-2194', '@ODS-2201', '@ODS-2208', '@Dashboard'],
},
() => {
// Authentication and navigation
cy.step(`Log into the application with ${LDAP_CONTRIBUTOR_USER.USERNAME}`);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/__tests__/cypress/cypress/utils/e2eUsers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { UserAuthConfig } from '~/__tests__/cypress/cypress/types';

export const LDAP_CONTRIBUTOR_USER: UserAuthConfig = Cypress.env('LDAP_CONTRIBUTOR_USER');
export const LDAP_CONTRIBUTOR_GROUP: UserAuthConfig = Cypress.env('LDAP_CONTRIBUTOR_GROUP');
export const HTPASSWD_CLUSTER_ADMIN_USER: UserAuthConfig = Cypress.env(
'HTPASSWD_CLUSTER_ADMIN_USER',
);
7 changes: 7 additions & 0 deletions frontend/src/__tests__/cypress/cypress/utils/testConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const LDAP_CONTRIBUTOR_USER: UserAuthConfig = testConfig?.TEST_USER_3 ?? {
PASSWORD: env.TEST_USER_3_PASSWORD || '',
};

const LDAP_CONTRIBUTOR_GROUP: UserAuthConfig = testConfig?.TEST_USER_3 ?? {
AUTH_TYPE: env.TEST_USER_3_AUTH_TYPE || '',
USERNAME: `${env.TEST_USER_3_USERNAME ?? ''}-group`,
PASSWORD: env.TEST_USER_3_PASSWORD || '',
};

const HTPASSWD_CLUSTER_ADMIN_USER: UserAuthConfig = testConfig?.OCP_ADMIN_USER ?? {
AUTH_TYPE: env.ADMIN_USER_AUTH_TYPE || '',
USERNAME: env.ADMIN_USER_USERNAME || '',
Expand Down Expand Up @@ -73,6 +79,7 @@ const PIP_TRUSTED_HOST = testConfig?.PIP_TRUSTED_HOST;
// spread the cypressEnv variables into the cypress config
export const cypressEnv = {
LDAP_CONTRIBUTOR_USER,
LDAP_CONTRIBUTOR_GROUP,
HTPASSWD_CLUSTER_ADMIN_USER,
AWS_PIPELINES,
TEST_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const RoleBindingPermissionsNameInput: React.FC<RoleBindingPermissionsNameInputP
}
return (
<TypeaheadSelect
dataTestId={`role-binding-name-select ${value}`}
isScrollable
selectOptions={selectOptions}
selected={value}
Expand Down

0 comments on commit 8450988

Please sign in to comment.