github.com/minio/console@v1.4.1/web-app/tests/permissions-A/iamPolicies.ts (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2022 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  import * as roles from "../utils/roles";
    18  import * as elements from "../utils/elements";
    19  import * as constants from "../utils/constants";
    20  import { Selector } from "testcafe";
    21  import {
    22    iamPoliciesElement,
    23    identityElement,
    24    usersElement,
    25  } from "../utils/elements-menu";
    26  import { IAM_PAGES } from "../../src/common/SecureComponent/permissions";
    27  
    28  const iamPolicyListItem = Selector(
    29    ".ReactVirtualized__Table__rowColumn",
    30  ).withText(constants.TEST_IAM_POLICY_NAME);
    31  
    32  const iamPolicyDelete = iamPolicyListItem
    33    .nextSibling()
    34    .child("button")
    35    .withAttribute("aria-label", "delete");
    36  
    37  fixture("For user with IAM Policies permissions")
    38    .page("http://localhost:9090")
    39    .beforeEach(async (t) => {
    40      await t.useRole(roles.iamPolicies);
    41    });
    42  
    43  test("IAM Policies sidebar item exists", async (t) => {
    44    const iamPoliciesExist = iamPoliciesElement.exists;
    45    await t
    46      .expect(identityElement.exists)
    47      .ok()
    48      .click(identityElement)
    49      .expect(iamPoliciesExist)
    50      .ok();
    51  });
    52  
    53  test("Create Policy button exists", async (t) => {
    54    const createPolicyButtonExists = elements.createPolicyButton.exists;
    55    await t
    56      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    57      .expect(createPolicyButtonExists)
    58      .ok();
    59  });
    60  
    61  test("Create Policy button is clickable", async (t) => {
    62    await t
    63      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    64      .click(elements.createPolicyButton);
    65  });
    66  
    67  test("Policy Name input exists in the Create Policy modal", async (t) => {
    68    const policyNameInputExists = elements.createPolicyName.exists;
    69    await t
    70      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    71      .click(elements.createPolicyButton)
    72      .expect(policyNameInputExists)
    73      .ok();
    74  });
    75  
    76  test("Policy textfield exists in the Create Policy modal", async (t) => {
    77    const policyTextfieldExists = elements.createPolicyTextfield.exists;
    78    await t
    79      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    80      .click(elements.createPolicyButton)
    81      .expect(policyTextfieldExists)
    82      .ok();
    83  });
    84  
    85  test("Create Policy modal can be submitted after inputs are entered", async (t) => {
    86    await t
    87      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    88      .click(elements.createPolicyButton)
    89      .typeText(elements.createPolicyName, constants.TEST_IAM_POLICY_NAME)
    90      .typeText(elements.createPolicyTextfield, constants.TEST_IAM_POLICY, {
    91        paste: true,
    92        replace: true,
    93      })
    94      .click(elements.saveButton);
    95  }).after(async (t) => {
    96    // Clean up created policy
    97    await t
    98      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
    99      .typeText(elements.searchResourceInput, constants.TEST_IAM_POLICY_NAME)
   100      .click(iamPolicyDelete)
   101      .click(elements.deleteButton);
   102  });
   103  
   104  test("Created Policy can be viewed and deleted", async (t) => {
   105    const iamPolicyListItemExists = iamPolicyListItem.exists;
   106    await t
   107      .navigateTo(`http://localhost:9090${IAM_PAGES.POLICIES}`)
   108      .click(elements.createPolicyButton)
   109      .typeText(elements.createPolicyName, constants.TEST_IAM_POLICY_NAME)
   110      .typeText(elements.createPolicyTextfield, constants.TEST_IAM_POLICY, {
   111        paste: true,
   112        replace: true,
   113      })
   114      .click(elements.saveButton)
   115      .typeText(elements.searchResourceInput, constants.TEST_IAM_POLICY_NAME)
   116      .expect(iamPolicyListItemExists)
   117      .ok()
   118      .click(iamPolicyDelete)
   119      .click(elements.deleteButton)
   120      .expect(iamPolicyListItemExists)
   121      .notOk();
   122  });