Skip to content

Commit

Permalink
[RFR] Adapted RBAC tests to changes in 7.0.0 (#792)
Browse files Browse the repository at this point in the history
* Adapted RBAC tests to changes in 7.0.0

Signed-off-by: Igor Braginsky <[email protected]>

* More fixes

Signed-off-by: Igor Braginsky <[email protected]>

* Updated 'doesExistButton' according to Alex's idea, using ternar operator

Signed-off-by: Igor Braginsky <[email protected]>

---------

Signed-off-by: Igor Braginsky <[email protected]>
  • Loading branch information
ibragins authored Nov 7, 2023
1 parent 74617d9 commit e9e9a03
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
click,
clickByText,
clickTab,
clickWithin,
doesExistSelector,
doesExistText,
inputText,
Expand Down Expand Up @@ -454,7 +455,7 @@ export class Analysis extends Application {
cy.get(".pf-v5-c-page__main-section")
.eq(1)
.within(() => {
click(kebabTopMenuButton);
clickWithin(kebabTopMenuButton, button);
});
doesExistText("Import", rbacRules["Action menu"]["Import"]);
doesExistText("Manage imports", rbacRules["Action menu"]["Manage imports"]);
Expand Down
15 changes: 7 additions & 8 deletions cypress/e2e/models/migration/applicationinventory/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
doesExistText,
clickTab,
clickItemInKebabMenu,
doesExistButton,
} from "../../../../utils/utils";
import { applicationData, RbacValidationRules } from "../../../types/types";
import { kebabButton, rightSideMenu, sourceDropdown } from "../../../views/analysis.view";
Expand Down Expand Up @@ -343,14 +344,16 @@ export class Application {
cy.contains("h2", "No tags available", { timeout: 2 * SEC });
}

static validateAssessButton(rbacRules: RbacValidationRules) {
public validateAssessButton(rbacRules: RbacValidationRules) {
Application.open();
doesExistSelector(assessAppButton, rbacRules["Assess"]);
performRowActionByIcon(this.name, kebabMenu);
doesExistButton(assessAppButton, rbacRules["Assess"]);
}

static validateReviewButton(rbacRules: RbacValidationRules) {
public validateReviewButton(rbacRules: RbacValidationRules) {
Application.open();
doesExistSelector(reviewAppButton, rbacRules["Review"]);
performRowActionByIcon(this.name, kebabMenu);
doesExistButton(reviewAppButton, rbacRules["Review"]);
}

static validateCreateAppButton(rbacRules: RbacValidationRules) {
Expand Down Expand Up @@ -398,10 +401,6 @@ export class Application {
"Discard assessment/review",
rbacRules["assessment applicable options"]["Discard assessment"]
);
doesExistText(
"Copy assessment",
rbacRules["assessment applicable options"]["Copy assessment"]
);
doesExistText(
"Manage dependencies",
rbacRules["assessment applicable options"]["Manage dependencies"]
Expand Down
19 changes: 4 additions & 15 deletions cypress/e2e/tests/rbac/architect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,26 @@ limitations under the License.
import { User } from "../../models/keycloak/users/user";
import { getRandomCredentialsData, getRandomUserData } from "../../../utils/data_utils";
import { UserArchitect } from "../../models/keycloak/users/userArchitect";
import { deleteByList, getRandomApplicationData, login, logout } from "../../../utils/utils";
import { getRandomApplicationData, login, logout } from "../../../utils/utils";
import { Analysis } from "../../models/migration/applicationinventory/analysis";
import { CredentialsSourceControlUsername } from "../../models/administration/credentials/credentialsSourceControlUsername";
import { CredentialType } from "../../types/constants";
import { Application } from "../../models/migration/applicationinventory/application";
import { Stakeholders } from "../../models/migration/controls/stakeholders";
import { Assessment } from "../../models/migration/applicationinventory/assessment";
import * as data from "../../../utils/data_utils";

describe(["@tier2", "@rhsso"], "Architect RBAC operations", function () {
let userArchitect = new UserArchitect(getRandomUserData());
const application = new Assessment(getRandomApplicationData());
let stakeholdersList: Array<Stakeholders> = [];
let stakeholderNameList: Array<string> = [];

let appCredentials = new CredentialsSourceControlUsername(
getRandomCredentialsData(CredentialType.sourceControl)
);

before("Creating RBAC users, adding roles for them", function () {
login();
// Navigate to stakeholders control tab and create new stakeholder
const stakeholder = new Stakeholders(data.getEmail(), data.getFullName());
stakeholder.create();
stakeholdersList.push(stakeholder);
stakeholderNameList.push(stakeholder.name);

appCredentials.create();
application.create();
application.perform_assessment("low", stakeholderNameList);
application.perform_review("low");
logout();
User.loginKeycloakAdmin();
userArchitect.create();
Expand All @@ -69,12 +59,12 @@ describe(["@tier2", "@rhsso"], "Architect RBAC operations", function () {

it("Architect, validate assess application button", function () {
//Architect is allowed to create applications
Application.validateAssessButton(this.rbacRules);
application.validateAssessButton(this.rbacRules);
});

it("Architect, validate review application button", function () {
//Architect is allowed to review applications
Application.validateReviewButton(this.rbacRules);
application.validateReviewButton(this.rbacRules);
});

it("Architect, validate presence of import and manage imports", function () {
Expand Down Expand Up @@ -104,7 +94,6 @@ describe(["@tier2", "@rhsso"], "Architect RBAC operations", function () {
login();
appCredentials.delete();
application.delete();
deleteByList(stakeholdersList);
logout();
User.loginKeycloakAdmin();
userArchitect.delete();
Expand Down
19 changes: 4 additions & 15 deletions cypress/e2e/tests/rbac/migrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ limitations under the License.
import { User } from "../../models/keycloak/users/user";
import { getRandomCredentialsData, getRandomUserData } from "../../../utils/data_utils";
import { UserMigrator } from "../../models/keycloak/users/userMigrator";
import { deleteByList, getRandomApplicationData, login, logout } from "../../../utils/utils";
import { getRandomApplicationData, login, logout } from "../../../utils/utils";
import { Analysis } from "../../models/migration/applicationinventory/analysis";
import { CredentialsSourceControlUsername } from "../../models/administration/credentials/credentialsSourceControlUsername";
import { CredentialType } from "../../types/constants";
import { Application } from "../../models/migration/applicationinventory/application";
import { Assessment } from "../../models/migration/applicationinventory/assessment";
import { Stakeholders } from "../../models/migration/controls/stakeholders";
import * as data from "../../../utils/data_utils";

describe(["@tier2", "@rhsso"], "Migrator RBAC operations", () => {
let userMigrator = new UserMigrator(getRandomUserData());
const application = new Assessment(getRandomApplicationData());
let stakeholdersList: Array<Stakeholders> = [];
let stakeholderNameList: Array<string> = [];

let appCredentials = new CredentialsSourceControlUsername(
getRandomCredentialsData(CredentialType.sourceControl)
Expand All @@ -40,15 +36,9 @@ describe(["@tier2", "@rhsso"], "Migrator RBAC operations", () => {
before("Creating RBAC users, adding roles for them", () => {
//Need to log in as admin and create simple app with known name to use it for tests
login();
// Navigate to stakeholders control tab and create new stakeholder
const stakeholder = new Stakeholders(data.getEmail(), data.getFullName());
stakeholder.create();
stakeholdersList.push(stakeholder);
stakeholderNameList.push(stakeholder.name);

appCredentials.create();
application.create();
application.perform_assessment("low", stakeholderNameList);
application.perform_review("low");
logout();
//Logging in as keycloak admin to create migrator user and test it
User.loginKeycloakAdmin();
Expand All @@ -71,12 +61,12 @@ describe(["@tier2", "@rhsso"], "Migrator RBAC operations", () => {

it("Migrator, validate assess application button", function () {
//Migrator is not allowed to create applications
Application.validateAssessButton(this.rbacRules);
application.validateAssessButton(this.rbacRules);
});

it("Migrator, validate review application button", function () {
//Migrator is not allowed to review applications
Application.validateReviewButton(this.rbacRules);
application.validateReviewButton(this.rbacRules);
});

it("Migrator, validate presence of import and manage imports", function () {
Expand Down Expand Up @@ -105,7 +95,6 @@ describe(["@tier2", "@rhsso"], "Migrator RBAC operations", () => {
login();
appCredentials.delete();
application.delete();
deleteByList(stakeholdersList);
logout();
User.loginKeycloakAdmin();
userMigrator.delete();
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/types/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const suggestedAdoptionPlan = "Suggested adoption plan";
export const assessmentQuestionnaires = "Assessment questionnaires";

export const createAppButton = "#create-application";
export const assessAppButton = "#assess-application";
export const reviewAppButton = "#review-application";
export const assessAppButton = "Assess";
export const reviewAppButton = "Review";
export const analyzeAppButton = "#analyze-application";
export const duplicateMigrationWaveError =
"Danger alert:The migration wave could not be created due to a conflict with an existing wave. Make sure the name and start/end dates are unique and try again.";
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/views/analysis.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export const analysisDetails = "Analysis details";
export const analysisDetailsEditor = ".monaco-editor";
export const rightSideMenu = "#page-drawer-content";
export const enableAutomatedTagging = "input[name=autoTaggingEnabled]";
export const kebabTopMenuButton = 'button[aria-label="Actions"]';
export const kebabTopMenuButton = "#toolbar-kebab";
export const kebabButton = 'button[aria-label="Kebab toggle"]';
16 changes: 6 additions & 10 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,19 +1617,15 @@ export function writeGpgKey(git_key): void {
}

export function doesExistSelector(selector: string, isAccessible: boolean): void {
if (isAccessible) {
cy.get(selector).should("exist");
} else {
cy.get(selector).should("not.exist");
}
cy.get(selector).should(isAccessible ? "exist" : "not.exist");
}

export function doesExistText(str: string, toBePresent: boolean): void {
if (toBePresent) {
cy.contains(str, { timeout: 120 * SEC }).should("exist");
} else {
cy.contains(str, { timeout: 120 * SEC }).should("not.exist");
}
cy.contains(str).should(toBePresent ? "exist" : "not.exist");
}

export function doesExistButton(str: string, toBePresent: boolean): void {
cy.contains(button, str).should(toBePresent ? "exist" : "not.exist");
}

export function enableSwitch(selector: string): void {
Expand Down

0 comments on commit e9e9a03

Please sign in to comment.