Fixed UI Tests (#3471)

Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2024-11-11 18:49:47 -06:00
committed by GitHub
parent 2ca484c691
commit 97ef82f831
13 changed files with 23 additions and 398 deletions

View File

@@ -1,68 +0,0 @@
// This file is part of MinIO Console Server
// Copyright (c) 2022 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import * as roles from "../utils/roles";
import * as elements from "../utils/elements";
import { monitoringElement, traceElement } from "../utils/elements-menu";
import { Selector } from "testcafe";
export const traceStartButton = Selector('[data-test-id="trace-start-button"]');
export const traceStopButton = Selector('[data-test-id="trace-stop-button"]');
fixture("For user with Trace permissions")
.page("http://localhost:9090")
.beforeEach(async (t) => {
await t.useRole(roles.trace);
});
test("Monitoring sidebar item exists", async (t) => {
await t.expect(monitoringElement.exists).ok();
});
test("Trace link exists in Monitoring menu", async (t) => {
await t
.expect(monitoringElement.exists)
.ok()
.click(monitoringElement)
.expect(traceElement.exists)
.ok();
});
test("Trace page can be opened", async (t) => {
await t.navigateTo("http://localhost:9090/tools/trace");
});
test("Start button can be clicked", async (t) => {
await t
.navigateTo("http://localhost:9090/tools/trace")
.click(traceStartButton);
});
test("Stop button appears after Start button has been clicked", async (t) => {
const stopButtonExists = traceStopButton.exists;
await t
.navigateTo("http://localhost:9090/tools/trace")
.click(traceStartButton)
.expect(stopButtonExists)
.ok();
});
test("Stop button can be clicked after Start button has been clicked", async (t) => {
await t
.navigateTo("http://localhost:9090/tools/trace")
.click(traceStartButton)
.click(traceStopButton);
});

View File

@@ -1,154 +0,0 @@
// This file is part of MinIO Console Server
// Copyright (c) 2022 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { Role, Selector } from "testcafe";
import { readFileSync } from "fs";
import { IAM_PAGES } from "../../src/common/SecureComponent/permissions";
import { inspectElement, monitoringElement } from "../utils/elements-menu";
const data = readFileSync(__dirname + "/../constants/timestamp.txt", "utf-8");
const $TIMESTAMP = data.trim();
let testDomainUrl = "http://localhost:9090";
let insAllowedAccKey = `inspect-allowed-${$TIMESTAMP}`;
let insAllowedSeckey = "insallowed1234";
let insNotAllowedAccKey = `inspect-not-allowed-${$TIMESTAMP}`;
let insNotAllowedSeckey = "insnotallowed1234";
/* Begin Local Testing config block */
// For local Testing Create users and assign policies then update here.
// Command to invoke the test locally: testcafe chrome tests/permissions/inspect.ts
/*
testDomainUrl = "http://localhost:5005";
insAllowedAccKey = `all-actions`;
insAllowedSeckey = "minio123";
insNotAllowedAccKey = `deny-admin`;
insNotAllowedSeckey = "minio123";
*/
/* End Local Testing config block */
const loginUrl = `${testDomainUrl}/login`;
const inspectScreenUrl = `${testDomainUrl}${IAM_PAGES.SUPPORT_INSPECT}`;
const loginSubmitBtn = Selector("button").withAttribute("id", "do-login");
export const inspectEl = Selector(".MuiPaper-root")
.find("ul")
.child("#inspect");
export const inspect_volume_input = Selector("#inspect_volume");
export const inspect_path_input = Selector("#inspect_path");
export const inspect_volume_input_err =
Selector("#inspect_volume").sibling("div.errorText");
export const inspect_path_input_err =
Selector("#inspect_path").sibling("div.errorText");
export const inspect_encrypt_input = Selector("#inspect_encrypt");
export const inspect_form_clear_btn = Selector(
'[data-test-id="inspect-clear-button"]',
);
export const inspect_form_submit_btn = Selector(
'[data-test-id="inspect-submit-button"]',
);
/** Begin Allowed Policy Test **/
export const inspectAllowedRole = Role(
loginUrl,
async (t) => {
await t
.typeText("#accessKey", insAllowedAccKey)
.typeText("#secretKey", insAllowedSeckey)
.click(loginSubmitBtn);
},
{ preserveUrl: true },
);
fixture("For user with Inspect permissions")
.page(testDomainUrl)
.beforeEach(async (t) => {
await t.useRole(inspectAllowedRole);
});
test("Inspect page can be opened", async (t) => {
await t.navigateTo(inspectScreenUrl);
});
test("Inspect link exists in Menu list", async (t) => {
await t.useRole(inspectAllowedRole).expect(inspectElement.exists).ok();
});
test("Form Input states verification", async (t) => {
const volumeValue = "test";
const pathValue = "test.txt/xl.meta";
await t.navigateTo(inspectScreenUrl);
//Initial state verification
await t.expect(inspect_volume_input.value).eql("");
await t.expect(inspect_path_input.value).eql("");
await t.expect(inspect_form_submit_btn.hasAttribute("disabled")).ok();
await t.expect(inspect_encrypt_input.hasAttribute("checked")).ok();
await t
.expect(inspect_volume_input_err.innerText)
.eql("This field is required");
await t
.expect(inspect_path_input_err.innerText)
.eql("This field is required");
});
/** End Allowed Policy Test **/
/** Begin Not Allowed Policy Test **/
export const inspectNotAllowedRole = Role(
loginUrl,
async (t) => {
await t
.typeText("#accessKey", insNotAllowedAccKey)
.typeText("#secretKey", insNotAllowedSeckey)
.click(loginSubmitBtn);
},
{ preserveUrl: true },
);
fixture("For user with Denied Inspect permissions")
.page(testDomainUrl)
.beforeEach(async (t) => {
await t.useRole(inspectNotAllowedRole);
});
test("Inspect page can NOT be opened", async (t) => {
try {
await t.navigateTo(inspectScreenUrl);
} catch (e) {
await t.expect(e).ok();
}
});
test("Inspect link should NOT exists in Menu list", async (t) => {
await t
.expect(monitoringElement.exists)
.ok()
.click(monitoringElement)
.expect(inspectEl.exists)
.notOk(
"Inspect Link should not exist in the menu list as per inspect not allowed policy",
);
});
/** End Not Allowed Policy Test **/

View File

@@ -24,7 +24,7 @@ import {
testBucketBrowseButtonFor,
} from "../utils/functions";
import { Selector } from "testcafe";
import { deniedError, file } from "../permissions-6/resourceTesting";
import { deniedError, file } from "../permissions-4/resourceTesting";
fixture("Rewind Testing").page("http://localhost:9090");

View File

@@ -33,28 +33,6 @@ export const getSubmenuBlock = (item) => {
//----------------------------------------------------
export const logoutItem = getMenuElement("sign-out");
//----------------------------------------------------
// Specific sidebar elements
//----------------------------------------------------
export const monitoringElement = getMenuElement("tools");
export const monitoringChildren = getSubmenuBlock("tools");
export const dashboardElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorMetrics");
export const logsElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorLogs");
export const traceElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorTrace");
export const drivesElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorDrives");
export const watchElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorWatch");
export const bucketsElement = getMenuElement("buckets");
export const serviceAcctsElement = getMenuElement("nav-accesskeys");
@@ -78,3 +56,25 @@ export const notificationEndpointsElement = getMenuElement("lambda");
export const inspectElement = getMenuElement("inspectObjects");
export const licenseElement = getMenuElement("license");
//----------------------------------------------------
// Specific sidebar elements
//----------------------------------------------------
export const monitoringElement = getMenuElement("tools");
export const monitoringChildren = getSubmenuBlock("tools");
export const dashboardElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorMetrics");
export const logsElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorLogs");
export const traceElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorTrace");
export const drivesElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorDrives");
export const watchElement = monitoringChildren
.find("button")
.withAttribute("id", "monitorWatch");