testscafe test for upload file button on bucket (#1491)
Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com> Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
This commit is contained in:
61
portal-ui/tests/permissions/bucketWritePrefixOnly.ts
Normal file
61
portal-ui/tests/permissions/bucketWritePrefixOnly.ts
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import * as roles from "../utils/roles";
|
||||
import * as elements from "../utils/elements";
|
||||
import { Selector } from "testcafe";
|
||||
|
||||
fixture("For user with Bucket Write to specific prefix permissions").page(
|
||||
"http://localhost:9090"
|
||||
);
|
||||
|
||||
test
|
||||
.before(async (t) => {})(
|
||||
"Upload File button is disable and Upload Folder button is enabled on bucket root path",
|
||||
async (t) => {
|
||||
const uploadButton = elements.uploadButton;
|
||||
await t
|
||||
.useRole(roles.bucketWritePrefixOnly)
|
||||
.navigateTo("http://localhost:9090/buckets/testcafe/browse")
|
||||
.click(uploadButton)
|
||||
.expect(Selector("li").withText("Upload File").hasClass("Mui-disabled"))
|
||||
.ok()
|
||||
.expect(
|
||||
Selector("li").withText("Upload Folder").hasClass("Mui-disabled")
|
||||
)
|
||||
.notOk();
|
||||
}
|
||||
)
|
||||
.after(async (t) => {});
|
||||
|
||||
test
|
||||
.before(async (t) => {})(
|
||||
"Upload File and Folder buttons are enabled on bucket prefix path",
|
||||
async (t) => {
|
||||
const uploadButton = elements.uploadButton;
|
||||
await t
|
||||
.useRole(roles.bucketWritePrefixOnly)
|
||||
.navigateTo("http://localhost:9090/buckets/testcafe/browse/d3JpdGU=/")
|
||||
.click(uploadButton)
|
||||
.expect(Selector("li").withText("Upload File").hasClass("Mui-disabled"))
|
||||
.notOk()
|
||||
.expect(
|
||||
Selector("li").withText("Upload Folder").hasClass("Mui-disabled")
|
||||
)
|
||||
.notOk();
|
||||
}
|
||||
)
|
||||
.after(async (t) => {});
|
||||
25
portal-ui/tests/policies/bucketWritePrefixOnlyPolicy.json
Normal file
25
portal-ui/tests/policies/bucketWritePrefixOnlyPolicy.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": ["s3:ListBucket","s3:GetBucketLocation"],
|
||||
"Effect": "Allow",
|
||||
"Resource": ["arn:aws:s3:::testcafe"]
|
||||
},
|
||||
{
|
||||
"Action": ["s3:ListBucket","s3:GetObject"],
|
||||
"Effect": "Allow",
|
||||
"Resource": ["arn:aws:s3:::testcafe/*"]
|
||||
},
|
||||
{
|
||||
"Action": [
|
||||
"s3:ListBucket",
|
||||
"s3:GetObject",
|
||||
"s3:PutObject",
|
||||
"s3:DeleteObject"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
"Resource": ["arn:aws:s3:::testcafe/write/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -23,6 +23,7 @@ create_policies() {
|
||||
mc admin policy add minio trace-$TIMESTAMP portal-ui/tests/policies/trace.json
|
||||
mc admin policy add minio users-$TIMESTAMP portal-ui/tests/policies/users.json
|
||||
mc admin policy add minio watch-$TIMESTAMP portal-ui/tests/policies/watch.json
|
||||
mc admin policy add minio bucketwriteprefixonlypolicy-$TIMESTAMP portal-ui/tests/policies/bucketWritePrefixOnlyPolicy.json
|
||||
}
|
||||
|
||||
create_users() {
|
||||
@@ -41,6 +42,11 @@ create_users() {
|
||||
mc admin user add minio trace-$TIMESTAMP trace1234
|
||||
mc admin user add minio users-$TIMESTAMP users1234
|
||||
mc admin user add minio watch-$TIMESTAMP watch1234
|
||||
mc admin user add minio bucketwriteprefixonlypolicy-$TIMESTAMP bucketwriteprefixonlypolicy
|
||||
}
|
||||
|
||||
create_buckets() {
|
||||
mc mb minio/testcafe && mc cp ./portal-ui/tests/uploads/test.txt minio/testcafe/write/test.txt
|
||||
}
|
||||
|
||||
assign_policies() {
|
||||
@@ -59,6 +65,7 @@ assign_policies() {
|
||||
mc admin policy set minio trace-$TIMESTAMP user=trace-$TIMESTAMP
|
||||
mc admin policy set minio users-$TIMESTAMP user=users-$TIMESTAMP
|
||||
mc admin policy set minio watch-$TIMESTAMP user=watch-$TIMESTAMP
|
||||
mc admin policy set minio bucketwriteprefixonlypolicy-$TIMESTAMP user=bucketwriteprefixonlypolicy-$TIMESTAMP
|
||||
}
|
||||
|
||||
remove_users() {
|
||||
@@ -77,6 +84,7 @@ remove_users() {
|
||||
mc admin user remove minio trace-$TIMESTAMP
|
||||
mc admin user remove minio users-$TIMESTAMP
|
||||
mc admin user remove minio watch-$TIMESTAMP
|
||||
mc admin user remove minio bucketwriteprefixonlypolicy-$TIMESTAMP
|
||||
}
|
||||
|
||||
remove_policies() {
|
||||
@@ -95,13 +103,17 @@ remove_policies() {
|
||||
mc admin policy remove minio trace-$TIMESTAMP
|
||||
mc admin policy remove minio users-$TIMESTAMP
|
||||
mc admin policy remove minio watch-$TIMESTAMP
|
||||
mc admin policy remove minio bucketwriteprefixonlypolicy-$TIMESTAMP
|
||||
}
|
||||
|
||||
remove_buckets() {
|
||||
mc rm minio/testcafe/write/test.txt && mc rm minio/testcafe
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
remove_users
|
||||
remove_policies
|
||||
pkill console
|
||||
kill -9 `lsof -i:5005 -t`
|
||||
remove_buckets
|
||||
}
|
||||
|
||||
__init__() {
|
||||
@@ -117,6 +129,7 @@ __init__() {
|
||||
create_policies
|
||||
create_users
|
||||
assign_policies
|
||||
create_buckets
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -67,6 +67,10 @@ export const testBucketBrowseButtonFor = (modifier) => {
|
||||
.withText("Browse");
|
||||
};
|
||||
|
||||
export const uploadFilesButton = () => {
|
||||
return Selector("button").withText("Upload Files");
|
||||
};
|
||||
|
||||
export const cleanUpBucketAndUploads = (t, modifier) => {
|
||||
const bucket = `${constants.TEST_BUCKET_NAME}-${modifier}`;
|
||||
|
||||
|
||||
@@ -53,6 +53,17 @@ export const bucketWrite = Role(
|
||||
{ preserveUrl: true }
|
||||
);
|
||||
|
||||
export const bucketWritePrefixOnly = Role(
|
||||
loginUrl,
|
||||
async (t) => {
|
||||
await t
|
||||
.typeText("#accessKey", "bucketwriteprefixonlypolicy-" + unixTimestamp)
|
||||
.typeText("#secretKey", "bucketwriteprefixonlypolicy")
|
||||
.click(submitButton);
|
||||
},
|
||||
{ preserveUrl: true }
|
||||
);
|
||||
|
||||
export const dashboard = Role(
|
||||
loginUrl,
|
||||
async (t) => {
|
||||
|
||||
Reference in New Issue
Block a user