UNPKG

passbolt-styleguide

Version:

Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.

290 lines (247 loc) 10.9 kB
/** * Passbolt ~ Open source password manager for teams * Copyright (c) 2023 Passbolt SA (https://www.passbolt.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) 2023 Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 4.1.0 */ import "../../../../test/mocks/mockClipboard"; import ResourceViewPagePage from "./ResourceViewPage.test.page"; import { defaultProps, deniedRbacProps, disabledApiFlagsProps, multipleUrisResourceProps, standaloneTotpResourceProps, totpResourceProps, } from "./ResourceViewPage.test.data"; import { TotpCodeGeneratorService } from "../../../shared/services/otp/TotpCodeGeneratorService"; import { denyRbacContext } from "../../../shared/context/Rbac/RbacContext.test.data"; import { defaultTotpViewModelDto } from "../../../shared/models/entity/totp/totpDto.test.data"; import { act } from "react"; beforeEach(() => { jest.resetModules(); jest.clearAllMocks(); }); describe("ResourceViewPage", () => { const mockContextRequest = (context, implementation) => jest.spyOn(context.port, "request").mockImplementationOnce(implementation); describe("As LU, I should preview the secret.", () => { it("As LU, I should preview the secret password of a resource ", async () => { expect.assertions(2); const props = defaultProps(); // The props to pass mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description" })); const page = new ResourceViewPagePage(props); expect(page.previewPasswordButton.hasAttribute("disabled")).toBeFalsy(); await page.click(page.previewPasswordButton); expect(page.passwordText).toStrictEqual("secret-decrypted"); }); it("As LU, I should see username, URI of a resource", async () => { expect.assertions(2); const props = defaultProps(); // The props to pass let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.username.textContent).toStrictEqual("admin@passbolt.com"); expect(page.uri.textContent).toStrictEqual("https://passbolt.com"); }); it("As LU, I shouldn't be able to preview secret password of a resource if disabled by API flag", async () => { expect.assertions(1); const props = disabledApiFlagsProps(); mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description" })); const page = new ResourceViewPagePage(props); expect(page.previewPasswordButton).toBeNull(); }); it("As LU, I shouldn't be able to preview secret password of a resource if denied by RBAC.", async () => { expect.assertions(1); const props = deniedRbacProps(); // The props to pass mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description" })); const page = new ResourceViewPagePage(props); expect(page.previewPasswordButton).toBeNull(); }); it("As LU, I should preview the secret totp of a resource ", async () => { expect.assertions(2); const props = totpResourceProps(); // The props to pass const totp = defaultTotpViewModelDto(); mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description", totp: totp, })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.previewTotpButton.hasAttribute("disabled")).toBeFalsy(); await page.click(page.previewTotpButton); const code = TotpCodeGeneratorService.generate(totp); expect(page.totpText.replace(/\s/, "")).toStrictEqual(code); }); it("As LU, I should not see username and password of a resource from a standalone totp", async () => { expect.assertions(3); const props = standaloneTotpResourceProps(); // The props to pass const totp = defaultTotpViewModelDto(); mockContextRequest(props.context, () => ({ totp: totp })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.username).toBeNull(); expect(page.password).toBeNull(); expect(page.totp).not.toBeNull(); }); it("As LU, I shouldn't be able to preview secret totp of a resource if disabled by API flag", async () => { expect.assertions(1); const props = disabledApiFlagsProps(); mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description", totp: defaultTotpViewModelDto(), })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.previewTotpButton).toBeNull(); }); it("As LU, I shouldn't be able to preview secret totp of a resource if denied by RBAC.", async () => { expect.assertions(1); const props = deniedRbacProps(); // The props to pass mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description", totp: defaultTotpViewModelDto(), })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.previewTotpButton).toBeNull(); }); }); describe("As LU, I should copy the secret.", () => { it("As LU, I should be able to copy the secret password of resource by clicking on the password", async () => { expect.assertions(4); const props = defaultProps(); // The props to pass mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description" })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.passwordText).toStrictEqual("Copy to clipboard"); expect(page.password.hasAttribute("disabled")).toBeFalsy(); await page.click(page.password); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.secret.find-by-resource-id", props.context.storage.local.get(["resources"]).resources[0].id, ); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.clipboard.copy-temporarily", "secret-decrypted", ); }); it("As LU, I should be able to copy the secret password of resource by clicking on the copy icon", async () => { expect.assertions(2); const props = defaultProps(); // The props to pass mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description" })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); await page.click(page.copyPasswordButton); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.secret.find-by-resource-id", props.context.storage.local.get(["resources"]).resources[0].id, ); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.clipboard.copy-temporarily", "secret-decrypted", ); }); it("As LU, I should not be able to copy the secret password of resource if denied by RBAC.", async () => { expect.assertions(3); const props = deniedRbacProps(); // The props to pass let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.passwordText).toStrictEqual("Copy to clipboard"); expect(page.password.hasAttribute("disabled")).toBeTruthy(); expect(page.copyPasswordButton).toBeNull(); }); it("As LU, I should be able to copy the secret totp of resource by clicking on the password", async () => { expect.assertions(4); const props = totpResourceProps(); // The props to pass const totp = defaultTotpViewModelDto(); mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description", totp: totp, })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.totpText).toStrictEqual("Copy TOTP to clipboard"); expect(page.totp.hasAttribute("disabled")).toBeFalsy(); await page.click(page.totp); const code = TotpCodeGeneratorService.generate(totp); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.secret.find-by-resource-id", props.context.storage.local.get(["resources"]).resources[0].id, ); expect(props.context.port.request).toHaveBeenCalledWith("passbolt.clipboard.copy-temporarily", code); }); it("As LU, I should be able to copy the secret totp of resource by clicking on the copy icon", async () => { expect.assertions(2); const props = totpResourceProps(); // The props to pass const totp = defaultTotpViewModelDto(); mockContextRequest(props.context, () => ({ password: "secret-decrypted", description: "description", totp: totp, })); let page; await act(async () => { page = new ResourceViewPagePage(props); }); await page.click(page.copyTotpButton); const code = TotpCodeGeneratorService.generate(totp); expect(props.context.port.request).toHaveBeenCalledWith( "passbolt.secret.find-by-resource-id", props.context.storage.local.get(["resources"]).resources[0].id, ); expect(props.context.port.request).toHaveBeenCalledWith("passbolt.clipboard.copy-temporarily", code); }); it("As LU, I should not be able to copy the secret totp of resource if denied by RBAC.", async () => { expect.assertions(3); const props = totpResourceProps({ rbacContext: denyRbacContext() }); // The props to pass let page; await act(async () => { page = new ResourceViewPagePage(props); }); expect(page.totpText).toStrictEqual("Copy TOTP to clipboard"); expect(page.totp.hasAttribute("disabled")).toBeTruthy(); expect(page.copyTotpButton).toBeNull(); }); }); describe("As LU, I should see additional uris.", () => { it("As LU, I should be able to see additional uris", async () => { expect.assertions(1); const props = multipleUrisResourceProps(); // The props to pass let page; await act(async () => { page = new ResourceViewPagePage(props); }); await page.click(page.additionalUrisSection); expect(page.listUris.length).toStrictEqual(4); }); }); });