UNPKG

passbolt-styleguide

Version:

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

181 lines (152 loc) 7.8 kB
/** * Passbolt ~ Open source password manager for teams * Copyright (c) 2020 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) 2020 Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 2.11.0 */ /** * Unit tests on DisplayMfaAdministration in regard of specifications */ import "../../../../../test/mocks/mockPortal.js"; import { defaultProps, mockMfaSettings } from "./DisplayMfaAdministration.test.data"; import { defaultAppContext } from "../../../contexts/ApiAppContext.test.data"; import DisplayMfaAdministrationPage from "./DisplayMfaAdministration.test.page"; import { ActionFeedbackContext } from "../../../contexts/ActionFeedbackContext"; import { mockApiResponse } from "../../../../../test/mocks/mockApiResponse"; import { enableFetchMocks } from "jest-fetch-mock"; import { act } from "react"; beforeEach(() => { enableFetchMocks(); jest.resetModules(); }); describe("See the MFA settings", () => { let page; // The page to test against const context = defaultAppContext(); // The applicative context const props = defaultProps(); // The props to pass describe("As AD I should see the MFA provider activation state on the administration settings page", () => { /** * I should see the MFA provider activation state on the administration settings page */ beforeEach(async () => { fetch.doMockOnceIf(/mfa\/settings*/, () => mockApiResponse(mockMfaSettings)); await act(() => (page = new DisplayMfaAdministrationPage(context, props))); }); it("As AD I should see if all fields is available for my Passbolt instance on the administration settings page", async () => { expect.assertions(9); expect(page.exists()).toBeTruthy(); // check fields in the form expect(page.totp.checked).toBeTruthy(); expect(page.yubikey.checked).toBeTruthy(); expect(page.duo.checked).toBeTruthy(); await page.checkDuo(); expect(page.yubikeyClientIdentifier.value).toBe(mockMfaSettings.yubikey.clientId); expect(page.yubikeySecretKey.value).toBe(mockMfaSettings.yubikey.secretKey); expect(page.duoHostname).toBe(null); expect(page.duoClientId).toBe(null); expect(page.duoClientSecret).toBe(null); }); it("As a logged in administrator I can see an help box in the MFA policy administration screen ", async () => { expect.assertions(6); expect(page.exists()).toBeTruthy(); expect(page.helpBox).not.toBeNull(); expect(page.helpBoxTitle.textContent).toBe("Need some help?"); expect(page.helpBoxDescription.textContent).toBe( "Check out our Multi Factor Authentication configuration guide.", ); expect(page.helpBoxButton.textContent).toEqual("Read the documentation"); expect(page.helpBoxButton.getAttribute("href")).toEqual("https://passbolt.com/docs/admin/authentication/mfa/"); }); it("As AD I should save mfa on the administration settings page", async () => { //button should be disable by default expect(page.isSaveButtonEnabled()).toBeFalsy(); //Call to save the settings fetch.doMockOnceIf(/mfa\/settings*/, () => mockApiResponse({})); //Call to API to retrieve the settings fetch.doMockOnceIf(/mfa\/settings*/, () => mockApiResponse(mockMfaSettings)); jest.spyOn(ActionFeedbackContext._currentValue, "displaySuccess").mockImplementation(() => {}); await page.checkYubikey(); await page.saveSettings(); expect.assertions(3); expect(ActionFeedbackContext._currentValue.displaySuccess).toHaveBeenCalledWith( "The multi factor authentication settings for the organization were updated.", ); // We expect the button to be disable expect(page.isSaveButtonEnabled()).toBeFalsy(); }); it("As AD I should see an error toaster if the submit operation fails for an unexpected reason", async () => { //button should be disable by default expect(page.isSaveButtonEnabled()).toBeFalsy(); await page.checkYubikey(); // Mock the request function to make it return an error. const error = { message: "Unable to reach the server, an unexpected error occurred" }; fetch.doMockOnceIf(/mfa\/settings*/, () => Promise.reject(error)); jest.spyOn(ActionFeedbackContext._currentValue, "displayError").mockImplementation(() => {}); await page.saveSettings(); expect.assertions(2); // Throw general error message expect(ActionFeedbackContext._currentValue.displayError).toHaveBeenCalledWith(error.message); }); it("As AD I should see an error message if inputs are empty", async () => { //button should be disable by default expect(page.isSaveButtonEnabled()).toBeFalsy(); page.fillYubikeySecret(""); page.fillYubikeyClientIdentifier(""); page.fillClientSecret(""); page.fillClientId(""); page.fillDuoHostname(""); await page.saveSettings(); expect.assertions(6); // Throw general error message expect(page.yubikeyClientIdentifierErrorMessage).toBe("A client identifier is required."); expect(page.yubikeySecretKeyErrorMessage).toBe("A secret key is required."); expect(page.duoHostnameErrorMessage).toBe("A hostname is required."); expect(page.duoClientIdErrorMessage).toBe("A client id is required."); expect(page.duoClientSecretErrorMessage).toBe("A client secret is required."); }); it("As AD I should not be able to click on save if there is no change", async () => { expect.assertions(2); //button should be disable by default expect(page.isSaveButtonEnabled()).toBeFalsy(); await page.checkYubikey(); //We set the value by default await page.checkYubikey(); //button should be disable by default expect(page.isSaveButtonEnabled()).toBeFalsy(); }); it("As AD I want to see the passwords I entered in the MFA administration settings forms", async () => { await page.toggleObfuscate(page.duoClientSecretButton); await page.toggleObfuscate(page.yubikeySecretKeyButton); expect.assertions(2); expect(page.isObfuscated(page.yubikeySecretKeyButton)).toBeFalsy(); expect(page.isObfuscated(page.duoClientSecretButton)).toBeFalsy(); }); it("I should see all fields disabled”", () => { fetch.doMockOnceIf(/mfa\/settings*/, () => mockApiResponse(mockMfaSettings)); expect.assertions(3); page = new DisplayMfaAdministrationPage(context, props); expect(page.totp.getAttribute("disabled")).not.toBeNull(); expect(page.yubikey.getAttribute("disabled")).not.toBeNull(); expect(page.duo.getAttribute("disabled")).not.toBeNull(); }); }); describe("Should not display the form if the site is not running under https", () => { it("Should display a message to the admin explaining the reason why the form is not displayed", () => { expect.assertions(1); const context = defaultAppContext({ trustedDomain: "http://localhost", }); // The applicative context const props = defaultProps({ context }); // The props to pass const page = new DisplayMfaAdministrationPage(context, props); expect(page.formNotDisplayedMessage.textContent).toStrictEqual( "Sorry the multi factor authentication feature is only available in a secure context (HTTPS).", ); }); }); });