From 6190ea71a04cab2fc096aec8533c7094400c4eab Mon Sep 17 00:00:00 2001 From: Stan Ryzhov <60649800+stasryzhov@users.noreply.github.com> Date: Tue, 5 Sep 2023 10:00:19 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20create=20password?= =?UTF-8?q?=20auth=20method=20test=20(#1843)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/tests/e2e/helpers/boundary-ui.js | 137 +++++++++++++++++++ ui/admin/tests/e2e/tests/auth-method.spec.js | 55 ++++++++ 2 files changed, 192 insertions(+) create mode 100644 ui/admin/tests/e2e/tests/auth-method.spec.js diff --git a/ui/admin/tests/e2e/helpers/boundary-ui.js b/ui/admin/tests/e2e/helpers/boundary-ui.js index deba9aaf0..f4fe17df8 100644 --- a/ui/admin/tests/e2e/helpers/boundary-ui.js +++ b/ui/admin/tests/e2e/helpers/boundary-ui.js @@ -287,3 +287,140 @@ exports.addBrokeredCredentialsToTarget = async ( await page.getByRole('button', { name: 'Dismiss' }).click(); await expect(page.getByRole('link', { name: credentialName })).toBeVisible(); }; + +/** + * Uses the UI to create new Auth Method. Assumes you have selected the desired scope. + * @param {Page} page Playwright page object + * @param {string} authMethodName Name of new auth method + */ +exports.createNewPasswordAuthMethod = async (page, authMethodName) => { + await page + .getByRole('navigation', { name: 'IAM' }) + .getByRole('link', { name: 'Auth Methods' }) + .click(); + await page.getByTitle('New', { exact: true }).click(); + await page.getByText('Password', { exact: true }).click(); + await page.getByLabel('Name').fill(authMethodName); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page + .getByRole('navigation', { name: 'breadcrumbs' }) + .getByRole('link', { name: authMethodName }) + ).toBeVisible(); +}; + +/** + * Uses the UI to make the first available auth method primary. + * Assumes you have created new auth method. + * @param {Page} page Playwright page object + */ +exports.makeAuthMethodPrimary = async (page) => { + await page + .getByRole('navigation', { name: 'IAM' }) + .getByRole('link', { name: 'Auth Methods' }) + .click(); + await page.getByRole('button', { name: 'Manage' }).click() + await page.getByText('Make Primary', { exact: true }).click(); + await page.getByText('OK', { exact: true }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); +}; + +/** + * Uses the UI to create new Account. Assumes you have selected the desired Auth Method + * which the account will be created for. + * @param {Page} page Playwright page object + * @param {string} accountName Name of new account + * @param {string} login Login of new account + * @param {string} password Password of new account + */ +exports.addAccountToAuthMethod = async (page, accountName, login, password) => { + await page.getByRole('link', { name: 'Accounts' }).click(); + await page + .getByRole('article') + .getByRole('link', { name: 'Create Account', exact: true }) + .click(); + await page.getByLabel('Name', { exact: true }).fill(accountName); + await page.getByLabel('Login Name').fill(login); + await page.getByLabel('Password').fill(password); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page + .getByRole('navigation', { name: 'breadcrumbs' }) + .getByRole('link', { name: accountName }) + ).toBeVisible(); +}; + +/** + * Uses the UI to set a new password to an account. + * Assumes you have selected the desired Account. + * @param {Page} page Playwright page object + * @param {string} password New password of the account + */ +exports.setPasswordToAccount = async (page, password) => { + await page.getByRole('link', { name: 'Set Password' }).click(); + await page.getByLabel('Password').fill(password); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); +}; + +/** + * Uses the UI to create a new user. + * @param {Page} page Playwright page object + * @param {string} userName Name of new user + */ +exports.createNewUser = async (page, userName) => { + await page + .getByRole('navigation', { name: 'IAM' }) + .getByRole('link', { name: 'Users' }) + .click(); + await page + .getByRole('article') + .getByRole('link', { name: 'New', exact: true }) + .click(); + await page.getByLabel('Name').fill(userName); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page + .getByRole('navigation', { name: 'breadcrumbs' }) + .getByRole('link', { name: userName }) + ).toBeVisible(); +}; + +/** + * Uses the UI to add the first available account to a user. + * Assumes you have selected the desired user. + * Assumes you have created new account. + * @param {Page} page Playwright page object + */ +exports.addAccountToUser = async (page) => { + await page.getByRole('link', { name: 'Accounts', exact: true }).click(); + await page + .getByRole('article') + .getByRole('link', { name: 'Add Accounts', exact: true }) + .click(); + + await page.getByRole('checkbox').click(); + await page.getByRole('button', { name: 'Add Accounts', exact: true }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }) + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); +}; diff --git a/ui/admin/tests/e2e/tests/auth-method.spec.js b/ui/admin/tests/e2e/tests/auth-method.spec.js new file mode 100644 index 000000000..3a4c7d2e9 --- /dev/null +++ b/ui/admin/tests/e2e/tests/auth-method.spec.js @@ -0,0 +1,55 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +/* eslint-disable no-undef */ +const { test } = require('@playwright/test'); +const { execSync } = require('child_process'); +const { authenticatedState } = require('../helpers/general'); +const { + authenticateBoundaryCli, + checkBoundaryCli, + deleteOrg, +} = require('../helpers/boundary-cli'); +const { + createNewOrg, + createNewPasswordAuthMethod, + addAccountToAuthMethod, + setPasswordToAccount, + createNewUser, + addAccountToUser, + makeAuthMethodPrimary, +} = require('../helpers/boundary-ui'); + +test.use({ storageState: authenticatedState }); + +test.beforeAll(async () => { + await checkBoundaryCli(); +}); + +test('Verify new auth-method can be created and assigned to users', async ({ + page, +}) => { + await page.goto('/'); + let org; + try { + const orgName = await createNewOrg(page); + await authenticateBoundaryCli(); + const orgs = JSON.parse(execSync('boundary scopes list -format json')); + org = orgs.items.filter((obj) => obj.name == orgName)[0]; + await createNewPasswordAuthMethod(page, 'UI Test Auth Method'); + await addAccountToAuthMethod( + page, + 'UI Test Account', + 'test-user', + 'password' + ); + await setPasswordToAccount(page, 'password2'); + await makeAuthMethodPrimary(page); + await createNewUser(page, 'UI Test User'); + await addAccountToUser(page); + } finally { + await deleteOrg(org.id); + } +});