Skip to content

Commit

Permalink
Add Testcafe tests (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed Mar 1, 2022
1 parent 4fa2f16 commit d82bd31
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 5 deletions.
11 changes: 7 additions & 4 deletions portal-ui/src/common/SecureComponent/accessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const hasPermission = (
}
});

const simpleResources = get(sessionGrants, rsItem, []);
let simpleResources = get(sessionGrants, rsItem, []);
simpleResources = simpleResources || [];
const s3Resources = get(sessionGrants, `arn:aws:s3:::${rsItem}/*`, []);
const bucketOnly = get(sessionGrants, `arn:aws:s3:::${rsItem}/`, []);
const bckOnlyNoSlash = get(sessionGrants, `arn:aws:s3:::${rsItem}`, []);
Expand All @@ -106,10 +107,12 @@ const hasPermission = (
}

let anyResourceGrant: string[] = [];
let validScopes = scopes || [];
if (resource === "*") {
Object.entries(sessionGrants).forEach(([key, values]) => {
scopes.forEach((scope) => {
values.forEach((val) => {
Object.entries(sessionGrants).forEach(([key, values = []]) => {
let validValues = values || [];
validScopes.forEach((scope) => {
validValues.forEach((val) => {
if (val === scope || val === "s3:*") {
anyResourceGrant = [...anyResourceGrant, scope];
}
Expand Down
80 changes: 80 additions & 0 deletions portal-ui/tests/permissions/test-fix-ui-crash-for-policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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";

const data = readFileSync(__dirname + "/../constants/timestamp.txt", "utf-8");
const $TIMESTAMP = data.trim();

let testDomainUrl = "http://localhost:9090";

let insAllowedAccKey = `prefix-policy-ui-crash-${$TIMESTAMP}`;
let insAllowedSeckey = "poluicrashfix1234";

/* 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 = `prefix-policy-ui-crash`;
insAllowedSeckey = "poluicrashfix1234";*/
/* End Local Testing config block */

const loginUrl = `${testDomainUrl}/login`;
const bucketsScreenUrl = `${testDomainUrl}/buckets`;

const loginSubmitBtn = Selector("form button");

export const bucketsSidebarEl = Selector(".MuiPaper-root")
.find("ul")
.child("#buckets");

export const menuListchildren = Selector("#tools-children");
export const bucketsEl = menuListchildren
.find("a")
.withAttribute("href", "/buckets");

export const inspectAllowedRole = Role(
loginUrl,
async (t) => {
await t
.typeText("#accessKey", insAllowedAccKey)
.typeText("#secretKey", insAllowedSeckey)
.click(loginSubmitBtn);
},
{ preserveUrl: true }
);

fixture("For user with Bucket Prefix permissions")
.page(testDomainUrl)
.beforeEach(async (t) => {
await t.useRole(inspectAllowedRole);
});

test("Bucket page can be opened", async (t) => {
await t.navigateTo(bucketsScreenUrl);
});
test("Buckets sidebar item exists", async (t) => {
await t.expect(bucketsSidebarEl.exists).ok();
});

/**
* Without the fix UI crashes with
* TypeError: simpleResources is not iterable (if fixed -> )
* TypeError: scopes is not iterable (if fixed -> )
* TypeError: values is not iterable
*/
31 changes: 31 additions & 0 deletions portal-ui/tests/policies/fix-prefix-policy-ui-crash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"admin:*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::*testcafe/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::*testcafe/write/*"
]
}
]
}
4 changes: 3 additions & 1 deletion portal-ui/tests/scripts/cleanup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ remove_users() {
mc admin user remove minio watch-$TIMESTAMP
mc admin user remove minio inspect-allowed-$TIMESTAMP
mc admin user remove minio inspect-not-allowed-$TIMESTAMP
mc admin user remove minio prefix-policy-ui-crash-$TIMESTAMP
}

remove_policies() {
Expand All @@ -44,7 +45,8 @@ remove_policies() {
mc admin policy remove minio users-$TIMESTAMP
mc admin policy remove minio watch-$TIMESTAMP
mc admin policy remove minio inspect-allowed-$TIMESTAMP
mc admin policy remove minio inspect-not-allowed-$TIMESTAMP
mc admin policy remove minio inspect-not-allowed-$TIMESTAMPmc
mc admin policy remove minio fix-prefix-policy-ui-crash-$TIMESTAMP
}

__init__() {
Expand Down
2 changes: 2 additions & 0 deletions portal-ui/tests/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ create_policies() {
mc admin policy add minio bucketwriteprefixonlypolicy-$TIMESTAMP portal-ui/tests/policies/bucketWritePrefixOnlyPolicy.json
mc admin policy add minio inspect-allowed-$TIMESTAMP portal-ui/tests/policies/inspect-allowed.json
mc admin policy add minio inspect-not-allowed-$TIMESTAMP portal-ui/tests/policies/inspect-not-allowed.json
mc admin policy add minio fix-prefix-policy-ui-crash-$TIMESTAMP portal-ui/tests/policies/fix-prefix-policy-ui-crash.json
}

create_users() {
Expand All @@ -64,6 +65,7 @@ create_users() {
mc admin user add minio bucketwriteprefixonlypolicy-$TIMESTAMP bucketwriteprefixonlypolicy
mc admin user add minio inspect-allowed-$TIMESTAMP insallowed1234
mc admin user add minio inspect-not-allowed-$TIMESTAMP insnotallowed1234
mc admin user add minio prefix-policy-ui-crash-$TIMESTAMP poluicrashfix1234
}

create_buckets() {
Expand Down
2 changes: 2 additions & 0 deletions portal-ui/tests/scripts/permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ remove_users() {
mc admin user remove minio bucketwriteprefixonlypolicy-$TIMESTAMP
mc admin user remove minio inspect-allowed-$TIMESTAMP
mc admin user remove minio inspect-not-allowed-$TIMESTAMP
mc admin user remove minio prefix-policy-ui-crash-$TIMESTAMP
}

remove_policies() {
Expand All @@ -55,6 +56,7 @@ remove_policies() {
mc admin policy remove minio bucketwriteprefixonlypolicy-$TIMESTAMP
mc admin policy remove minio inspect-allowed-$TIMESTAMP
mc admin policy remove minio inspect-not-allowed-$TIMESTAMP
mc admin policy remove minio fix-prefix-policy-ui-crash-$TIMESTAMP
}

remove_buckets() {
Expand Down

0 comments on commit d82bd31

Please sign in to comment.