From f92f3e33820f88f3d23520eae6470d5eb82b994c Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:39:42 -0800 Subject: [PATCH] Testcafe: Add tenant without audit log (#1644) --- .github/workflows/jobs.yaml | 92 ++++++++++++------- portal-ui/check-warnings.sh | 2 +- .../FormSwitchWrapper/FormSwitchWrapper.tsx | 1 + .../InputBoxWrapper/InputBoxWrapper.tsx | 3 + .../Common/GenericWizard/GenericWizard.tsx | 4 +- .../Common/ModalWrapper/ConfirmDialog.tsx | 2 + .../AddTenant/Steps/ConfigLogSearch.tsx | 4 +- .../Steps/TenantResources/NameTenantMain.tsx | 1 + .../Tenants/ListTenants/TenantListItem.tsx | 2 +- portal-ui/src/screens/LoginPage/LoginPage.tsx | 4 + portal-ui/tests/operator/list-tenants.ts | 41 --------- portal-ui/tests/operator/tenants.ts | 61 ++++++++++++ portal-ui/tests/permissions/inspect.ts | 12 ++- 13 files changed, 144 insertions(+), 85 deletions(-) delete mode 100644 portal-ui/tests/operator/list-tenants.ts create mode 100644 portal-ui/tests/operator/tenants.ts diff --git a/.github/workflows/jobs.yaml b/.github/workflows/jobs.yaml index 0be847190..aa020ab26 100644 --- a/.github/workflows/jobs.yaml +++ b/.github/workflows/jobs.yaml @@ -20,8 +20,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -63,6 +63,7 @@ jobs: repository: minio/operator path: operator - uses: actions/cache@v2 + name: Go Mod Cache with: path: | ~/.cache/go-build @@ -77,25 +78,35 @@ jobs: - uses: actions/cache@v2 id: yarn-cache + name: Yarn Cache with: path: | ${{ steps.yarn-cache-dir-path.outputs.dir }} ./portal-ui/node_modules/ - ./portal-ui/build/ key: ${{ runner.os }}-yarn-${{ hashFiles('./portal-ui/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - - name: Install Dependencies - if: steps.yarn-cache.outputs.cache-hit != 'true' - working-directory: ./ - run: make assets + - uses: actions/cache@v2 + id: assets-cache + name: Assets Cache + with: + path: | + ./portal-ui/build/ + key: ${{ runner.os }}-assets-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-assets- + - name: Install Dependencies + working-directory: ./portal-ui + continue-on-error: false + run: | + yarn install - name: Check for Warnings in build output working-directory: ./portal-ui continue-on-error: false run: | - chmod +x check-warnings.sh && ./check-warnings.sh + ./check-warnings.sh compile-job: name: Compiles on Go ${{ matrix.go-version }} and ${{ matrix.os }} @@ -106,8 +117,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -134,8 +145,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -162,8 +173,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -190,8 +201,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -218,8 +229,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -246,8 +257,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -274,8 +285,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -302,8 +313,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.17.x] - os: [ubuntu-latest] + go-version: [ 1.17.x ] + os: [ ubuntu-latest ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} uses: actions/setup-go@v2 @@ -331,7 +342,7 @@ jobs: strategy: matrix: - go-version: [1.17.x] + go-version: [ 1.17.x ] steps: - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} @@ -416,6 +427,7 @@ jobs: repository: minio/operator path: operator - uses: actions/cache@v2 + name: Go Mod Cache with: path: | ~/.cache/go-build @@ -430,19 +442,24 @@ jobs: - uses: actions/cache@v2 id: yarn-cache + name: Yarn Cache with: path: | ${{ steps.yarn-cache-dir-path.outputs.dir }} ./portal-ui/node_modules/ - ./portal-ui/build/ key: ${{ runner.os }}-yarn-${{ hashFiles('./portal-ui/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - - name: Install Dependencies - if: steps.yarn-cache.outputs.cache-hit != 'true' - working-directory: ./ - run: make assets + - uses: actions/cache@v2 + id: assets-cache + name: Assets Cache + with: + path: | + ./portal-ui/build/ + key: ${{ runner.os }}-assets-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-assets- - name: Build Console on ${{ matrix.os }} env: @@ -484,6 +501,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - uses: actions/cache@v2 + name: Go Mod Cache with: path: | ~/.cache/go-build @@ -498,6 +516,7 @@ jobs: - uses: actions/cache@v2 id: yarn-cache + name: Yarn Cache with: path: | ${{ steps.yarn-cache-dir-path.outputs.dir }} @@ -507,10 +526,15 @@ jobs: restore-keys: | ${{ runner.os }}-yarn- - - name: Install Dependencies - if: steps.yarn-cache.outputs.cache-hit != 'true' - working-directory: ./ - run: make assets + - uses: actions/cache@v2 + id: assets-cache + name: Assets Cache + with: + path: | + ./portal-ui/build/ + key: ${{ runner.os }}-assets-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-assets- - name: Build Console on ${{ matrix.os }} env: diff --git a/portal-ui/check-warnings.sh b/portal-ui/check-warnings.sh index 6369d8217..750bdedde 100755 --- a/portal-ui/check-warnings.sh +++ b/portal-ui/check-warnings.sh @@ -11,7 +11,7 @@ die() { try() { "$@" &> yarn.log || die "cannot $*"; } rm yarn.log -try yarn build +try make build-static if cat yarn.log | grep "Compiled with warnings"; then echo "There are warnings in the code" diff --git a/portal-ui/src/screens/Console/Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper.tsx b/portal-ui/src/screens/Console/Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper.tsx index 1837fe279..eb362ab2b 100644 --- a/portal-ui/src/screens/Console/Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper.tsx +++ b/portal-ui/src/screens/Console/Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper.tsx @@ -153,6 +153,7 @@ const FormSwitchWrapper = ({ disableFocusRipple disableTouchRipple value={value} + id={id} /> {!switchOnly && ( void; overlayObject?: any; @@ -125,6 +126,7 @@ const InputBoxWrapper = ({ placeholder = "", min, max, + overlayId, overlayIcon = null, overlayObject = null, extraInputProps = {}, @@ -215,6 +217,7 @@ const InputBoxWrapper = ({ } : () => null } + id={overlayId} size={"small"} disableFocusRipple={false} disableRipple={false} diff --git a/portal-ui/src/screens/Console/Common/GenericWizard/GenericWizard.tsx b/portal-ui/src/screens/Console/Common/GenericWizard/GenericWizard.tsx index 705e32f64..6c061068c 100644 --- a/portal-ui/src/screens/Console/Common/GenericWizard/GenericWizard.tsx +++ b/portal-ui/src/screens/Console/Common/GenericWizard/GenericWizard.tsx @@ -165,7 +165,9 @@ const GenericWizard = ({ {wizardSteps.map((step, index) => { return ( pageChange(index)} diff --git a/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx b/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx index e2a6ebdc3..e0e7b5dc7 100644 --- a/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx +++ b/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx @@ -95,6 +95,7 @@ const ConfirmDialog = ({ {...cancelButtonProps} variant="outlined" color="primary" + id={"confirm-cancel"} > {cancelText} @@ -110,6 +111,7 @@ const ConfirmDialog = ({ loadingPosition="start" startIcon={} autoFocus + id={"confirm-ok"} {...confirmButtonProps} > {confirmText} diff --git a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/ConfigLogSearch.tsx b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/ConfigLogSearch.tsx index 2ae9de589..121dc9c47 100644 --- a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/ConfigLogSearch.tsx +++ b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/ConfigLogSearch.tsx @@ -260,8 +260,8 @@ const ConfigLogSearch = ({ { const targetD = e.target; diff --git a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx index d93d6b8cd..fd9a00ebb 100644 --- a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx +++ b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx @@ -321,6 +321,7 @@ const NameTenantMain = ({ label="Namespace" value={namespace} error={validationErrors["namespace"] || ""} + overlayId={"add-namespace"} overlayIcon={showCreateButton ? : null} overlayAction={addNamespace} required diff --git a/portal-ui/src/screens/Console/Tenants/ListTenants/TenantListItem.tsx b/portal-ui/src/screens/Console/Tenants/ListTenants/TenantListItem.tsx index 3a7e00f53..cc78a9cc6 100644 --- a/portal-ui/src/screens/Console/Tenants/ListTenants/TenantListItem.tsx +++ b/portal-ui/src/screens/Console/Tenants/ListTenants/TenantListItem.tsx @@ -160,7 +160,7 @@ const TenantListItem = ({ tenant, classes }: ITenantListItem) => { return ( -
+
{tenant.name}
diff --git a/portal-ui/src/screens/LoginPage/LoginPage.tsx b/portal-ui/src/screens/LoginPage/LoginPage.tsx index 10ce447da..8b8835089 100644 --- a/portal-ui/src/screens/LoginPage/LoginPage.tsx +++ b/portal-ui/src/screens/LoginPage/LoginPage.tsx @@ -436,6 +436,7 @@ const Login = ({ type="submit" variant="contained" color="primary" + id="do-login" className={classes.submit} disabled={secretKey === "" || accessKey === "" || loginSending} > @@ -459,6 +460,7 @@ const Login = ({ type="submit" variant="contained" color="primary" + id="sso-login" className={classes.submit} > Login with SSO @@ -502,6 +504,7 @@ const Login = ({ type="submit" variant="contained" color="primary" + id="do-login" className={classes.submit} disabled={jwt === "" || loginSending} > @@ -534,6 +537,7 @@ const Login = ({ endIcon={} color={"primary"} variant="outlined" + id="retry" className={classes.retryButton} > Retry diff --git a/portal-ui/tests/operator/list-tenants.ts b/portal-ui/tests/operator/list-tenants.ts deleted file mode 100644 index ea6464c4c..000000000 --- a/portal-ui/tests/operator/list-tenants.ts +++ /dev/null @@ -1,41 +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 . - -import { diagnosticsElement, supportElement } from "../utils/elements-menu"; -import { Selector } from "testcafe"; - -fixture("For user with default permissions").page("http://localhost:9090"); - -test("Create Tenant and List Tenants", async (t) => { - const osCount = Selector( - `#root > div > main > div[class] > div > div > div > div:nth-child(1) > div > div > div` - ).count; - - await t - .navigateTo("http://localhost:9090/login") - .typeText("#jwt", "anyrandompasswordwillwork") - .click("button.MuiButton-root") - .click( - Selector('button[tabindex="0"][type="button"]').withText("Create Tenant") - ) - .typeText("#tenant-name", "thufeb1754epm") - .typeText("#namespace", "default") - .wait(2000) - .click('button[tabindex="0"]:nth-of-type(2)') - .click(Selector('button[tabindex="0"][type="button"]').withText("Done")) - .expect(osCount) - .eql(2); -}); diff --git a/portal-ui/tests/operator/tenants.ts b/portal-ui/tests/operator/tenants.ts new file mode 100644 index 000000000..856cd5b5d --- /dev/null +++ b/portal-ui/tests/operator/tenants.ts @@ -0,0 +1,61 @@ +// 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 . + +import { Selector } from "testcafe"; + +fixture("For user with default permissions").page("http://localhost:9090"); + +test("Create Tenant and List Tenants", async (t) => { + const tenantName = `tenant-${Math.floor(Math.random() * 10000)}`; + + await t + .navigateTo("http://localhost:9090/login") + .typeText("#jwt", "anyrandompasswordwillwork") + .click("#do-login") + .click("#create-tenant") + .typeText("#tenant-name", tenantName) + .typeText("#namespace", tenantName) + .click("#add-namespace") + .click("#confirm-ok") + .wait(1000) + .click("#wizard-button-Create") + .wait(1000) + .click("#done-button") + .expect(Selector(`#list-tenant-${tenantName}`).exists) + .ok(); +}); + +test("Create Tenant Without Audit Log", async (t) => { + const tenantName = `tenant-${Math.floor(Math.random() * 10000)}`; + + await t + .navigateTo("http://localhost:9090/login") + .typeText("#jwt", "anyrandompasswordwillwork") + .click("#do-login") + .click("#create-tenant") + .typeText("#tenant-name", tenantName) + .typeText("#namespace", tenantName) + .click("#add-namespace") + .click("#confirm-ok") + .wait(1000) + .click("#wizard-step-audit-log") + .click("#log-search-enabled") + .click("#wizard-button-Create") + .wait(1000) + .click("#done-button") + .expect(Selector(`#list-tenant-${tenantName}`).exists) + .ok(); +}); diff --git a/portal-ui/tests/permissions/inspect.ts b/portal-ui/tests/permissions/inspect.ts index 870ddedd7..a562dcebe 100644 --- a/portal-ui/tests/permissions/inspect.ts +++ b/portal-ui/tests/permissions/inspect.ts @@ -16,6 +16,8 @@ import { Role, Selector } from "testcafe"; import { readFileSync } from "fs"; +import { IAM_PAGES } from "../../src/common/SecureComponent/permissions"; +import { monitoringElement } from "../utils/elements-menu"; const data = readFileSync(__dirname + "/../constants/timestamp.txt", "utf-8"); const $TIMESTAMP = data.trim(); @@ -48,12 +50,12 @@ const loginSubmitBtn = Selector("form button"); export const supportSidebarEl = Selector(".MuiPaper-root") .find("ul") - .child("#tools"); + .child("#support"); -export const supportChildren = Selector("#tools-children"); +export const supportChildren = Selector("#support-children"); export const inspectEl = supportChildren .find("a") - .withAttribute("href", "/tools/inspect"); + .withAttribute("href", IAM_PAGES.TOOLS_INSPECT); export const inspect_volume_input = Selector('[data-test-id="inspect_volume"]'); export const inspect_path_input = Selector('[data-test-id="inspect_path"]'); @@ -190,9 +192,9 @@ test("Inspect page can NOT be opened", async (t) => { test("Inspect link should NOT exists in Menu list", async (t) => { await t - .expect(supportSidebarEl.exists) + .expect(monitoringElement.exists) .ok() - .click(supportSidebarEl) + .click(monitoringElement) .expect(inspectEl.exists) .notOk( "Inspect Link should not exist in the menu list as per inspect not allowed policy"