github.com/minio/console@v1.4.1/web-app/tests/permissions-2/inspect.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 { Role, Selector } from "testcafe";
    18  import { readFileSync } from "fs";
    19  import { IAM_PAGES } from "../../src/common/SecureComponent/permissions";
    20  import { inspectElement, monitoringElement } from "../utils/elements-menu";
    21  
    22  const data = readFileSync(__dirname + "/../constants/timestamp.txt", "utf-8");
    23  const $TIMESTAMP = data.trim();
    24  
    25  let testDomainUrl = "http://localhost:9090";
    26  
    27  let insAllowedAccKey = `inspect-allowed-${$TIMESTAMP}`;
    28  let insAllowedSeckey = "insallowed1234";
    29  let insNotAllowedAccKey = `inspect-not-allowed-${$TIMESTAMP}`;
    30  let insNotAllowedSeckey = "insnotallowed1234";
    31  
    32  /* Begin Local Testing config block */
    33  
    34  // For local Testing Create users and assign policies then update here.
    35  // Command to invoke the test locally: testcafe chrome tests/permissions/inspect.ts
    36  /*
    37  testDomainUrl = "http://localhost:5005";
    38  insAllowedAccKey = `all-actions`;
    39  insAllowedSeckey = "minio123";
    40  insNotAllowedAccKey = `deny-admin`;
    41  insNotAllowedSeckey = "minio123";
    42  */
    43  
    44  /* End Local Testing config block */
    45  
    46  const loginUrl = `${testDomainUrl}/login`;
    47  const inspectScreenUrl = `${testDomainUrl}${IAM_PAGES.SUPPORT_INSPECT}`;
    48  
    49  const loginSubmitBtn = Selector("button").withAttribute("id", "do-login");
    50  
    51  export const inspectEl = Selector(".MuiPaper-root")
    52    .find("ul")
    53    .child("#inspect");
    54  
    55  export const inspect_volume_input = Selector("#inspect_volume");
    56  export const inspect_path_input = Selector("#inspect_path");
    57  
    58  export const inspect_volume_input_err =
    59    Selector("#inspect_volume").sibling("div.errorText");
    60  export const inspect_path_input_err =
    61    Selector("#inspect_path").sibling("div.errorText");
    62  
    63  export const inspect_encrypt_input = Selector("#inspect_encrypt");
    64  export const inspect_form_clear_btn = Selector(
    65    '[data-test-id="inspect-clear-button"]',
    66  );
    67  export const inspect_form_submit_btn = Selector(
    68    '[data-test-id="inspect-submit-button"]',
    69  );
    70  /**  Begin Allowed Policy Test **/
    71  
    72  export const inspectAllowedRole = Role(
    73    loginUrl,
    74    async (t) => {
    75      await t
    76        .typeText("#accessKey", insAllowedAccKey)
    77        .typeText("#secretKey", insAllowedSeckey)
    78        .click(loginSubmitBtn);
    79    },
    80    { preserveUrl: true },
    81  );
    82  
    83  fixture("For user with Inspect permissions")
    84    .page(testDomainUrl)
    85    .beforeEach(async (t) => {
    86      await t.useRole(inspectAllowedRole);
    87    });
    88  
    89  test("Inspect page can be opened", async (t) => {
    90    await t.navigateTo(inspectScreenUrl);
    91  });
    92  
    93  test("Inspect link exists in Menu list", async (t) => {
    94    await t.useRole(inspectAllowedRole).expect(inspectElement.exists).ok();
    95  });
    96  
    97  test("Form Input states verification", async (t) => {
    98    const volumeValue = "test";
    99    const pathValue = "test.txt/xl.meta";
   100  
   101    await t.navigateTo(inspectScreenUrl);
   102  
   103    //Initial state verification
   104    await t.expect(inspect_volume_input.value).eql("");
   105    await t.expect(inspect_path_input.value).eql("");
   106    await t.expect(inspect_form_submit_btn.hasAttribute("disabled")).ok();
   107    await t.expect(inspect_encrypt_input.hasAttribute("checked")).ok();
   108    await t
   109      .expect(inspect_volume_input_err.innerText)
   110      .eql("This field is required");
   111    await t
   112      .expect(inspect_path_input_err.innerText)
   113      .eql("This field is required");
   114  });
   115  /**  End Allowed Policy Test **/
   116  
   117  /**  Begin Not Allowed Policy Test **/
   118  
   119  export const inspectNotAllowedRole = Role(
   120    loginUrl,
   121    async (t) => {
   122      await t
   123        .typeText("#accessKey", insNotAllowedAccKey)
   124        .typeText("#secretKey", insNotAllowedSeckey)
   125        .click(loginSubmitBtn);
   126    },
   127    { preserveUrl: true },
   128  );
   129  
   130  fixture("For user with Denied Inspect permissions")
   131    .page(testDomainUrl)
   132    .beforeEach(async (t) => {
   133      await t.useRole(inspectNotAllowedRole);
   134    });
   135  
   136  test("Inspect page can NOT be opened", async (t) => {
   137    try {
   138      await t.navigateTo(inspectScreenUrl);
   139    } catch (e) {
   140      await t.expect(e).ok();
   141    }
   142  });
   143  
   144  test("Inspect link should NOT exists in Menu list", async (t) => {
   145    await t
   146      .expect(monitoringElement.exists)
   147      .ok()
   148      .click(monitoringElement)
   149      .expect(inspectEl.exists)
   150      .notOk(
   151        "Inspect Link should not exist in the menu list as per inspect not allowed policy",
   152      );
   153  });
   154  /**  End Not Allowed Policy Test **/