diff --git a/tests/e2e/cucumber/features/smoke/spaces/publicLink.feature b/tests/e2e/cucumber/features/smoke/spaces/publicLink.feature index 0640c176218..adb54ac84c8 100644 --- a/tests/e2e/cucumber/features/smoke/spaces/publicLink.feature +++ b/tests/e2e/cucumber/features/smoke/spaces/publicLink.feature @@ -87,9 +87,17 @@ Feature: spaces public link """ Unfortunately, your password is commonly used. please pick a harder-to-guess password for your safety """ + And "Alice" closes the public link password dialog box When "Alice" tries to sets the password of the public link named "myPublicLink" of resource "lorem.txt" to "12345678" Then "Alice" should see an error message """ Unfortunately, your password is commonly used. please pick a harder-to-guess password for your safety """ + And "Alice" reveals the password of the public link + And "Alice" hides the password of the public link + And "Alice" generates the password for the public link + And "Alice" copies the password of the public link + And "Alice" sets the password of the public link + And "Anonymous" opens the public link "myPublicLink" + And "Anonymous" unlocks the public link with password "%copied_password%" And "Alice" logs out diff --git a/tests/e2e/cucumber/steps/ui/links.ts b/tests/e2e/cucumber/steps/ui/links.ts index 1a9f347d250..946b2f9e1c4 100644 --- a/tests/e2e/cucumber/steps/ui/links.ts +++ b/tests/e2e/cucumber/steps/ui/links.ts @@ -89,6 +89,51 @@ When( } ) +When( + /^"([^"]*)" (reveals|hides) the password of the public link$/, + async function (this: World, stepUser: string, showOrHide: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const linkObject = new objects.applicationFiles.Link({ page }) + await linkObject.showOrHidePassword({ showOrHide }) + } +) + +When( + '{string} closes the public link password dialog box', + async function (this: World, stepUser: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const linkObject = new objects.applicationFiles.Link({ page }) + await linkObject.clickOnCancelButton() + } +) + +When( + '{string} copies the password of the public link', + async function (this: World, stepUser: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const linkObject = new objects.applicationFiles.Link({ page }) + await linkObject.copyEnteredPassword() + } +) + +When( + '{string} generates the password for the public link', + async function (this: World, stepUser: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const linkObject = new objects.applicationFiles.Link({ page }) + await linkObject.generatePassword() + } +) + +When( + '{string} sets the password of the public link', + async function (this: World, stepUser: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const linkObject = new objects.applicationFiles.Link({ page }) + await linkObject.setPassword() + } +) + When( '{string} edits the public link named {string} of resource {string} changing role to {string}', async function ( @@ -158,7 +203,6 @@ Then( const linkObject = new objects.applicationFiles.Link({ page }) const actualErrorMessage = await linkObject.checkErrorMessage() expect(actualErrorMessage).toBe(errorMessage) - await linkObject.clickOnCancelButton() } ) diff --git a/tests/e2e/cucumber/steps/ui/public.ts b/tests/e2e/cucumber/steps/ui/public.ts index 307918bfaae..e9a0910b30a 100644 --- a/tests/e2e/cucumber/steps/ui/public.ts +++ b/tests/e2e/cucumber/steps/ui/public.ts @@ -32,6 +32,9 @@ When( async function (this: World, stepUser: string, password: string): Promise { const { page } = this.actorsEnvironment.getActor({ key: stepUser }) const pageObject = new objects.applicationFiles.page.Public({ page }) + if (password === '%copied_password%') { + password = await page.evaluate('navigator.clipboard.readText()') + } await pageObject.authenticate({ password }) } ) diff --git a/tests/e2e/support/objects/app-files/link/actions.ts b/tests/e2e/support/objects/app-files/link/actions.ts index 7058ee8da4f..23ef5039588 100644 --- a/tests/e2e/support/objects/app-files/link/actions.ts +++ b/tests/e2e/support/objects/app-files/link/actions.ts @@ -93,6 +93,10 @@ const confirmDeleteButton = `//button[contains(@class,"oc-modal-body-actions-con const notificationContainer = 'div.oc-notification' const publicLinkPasswordErrorMessage = `//div[contains(@class, "oc-text-input-message oc-text-input-danger")]/span` const cancelButton = '.oc-modal-body-actions-cancel' +const showOrHidePasswordButton = '.oc-text-input-show-password-toggle' +const copyPasswordButton = '.oc-text-input-copy-password-button' +const generatePasswordButton = '.oc-text-input-generate-password-button' +const expectedRegexForGeneratedPassword = /^[A-Za-z0-9\s\S]{12}$/ const getRecentLinkUrl = async (page: Page): Promise => { return page.locator(publicLinkUrlList).first().textContent() @@ -204,6 +208,39 @@ export const addPassword = async (args: addPasswordArgs): Promise => { expect(message.trim()).toBe('Link was updated successfully') } +export const showOrHidePassword = async (args): Promise => { + const { page, showOrHide } = args + await page.locator(showOrHidePasswordButton).click() + showOrHide === 'reveals' + ? expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'text') + : expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'password') +} + +export const copyEnteredPassword = async (page: Page): Promise => { + const enteredPassword = await page.locator(editPublicLinkInput).inputValue() + await page.locator(copyPasswordButton).click() + const copiedPassword = await page.evaluate('navigator.clipboard.readText()') + expect(enteredPassword).toBe(copiedPassword) +} + +export const generatePassword = async (page: Page): Promise => { + await page.locator(generatePasswordButton).click() + const generatedPassword = await page.locator(editPublicLinkInput).inputValue() + expect(generatedPassword).toMatch(expectedRegexForGeneratedPassword) +} + +export const setPassword = async (page: Page): Promise => { + await Promise.all([ + page.waitForResponse( + (res) => + res.url().includes('api/v1/shares/') && + res.request().method() === 'PUT' && + res.status() === 200 + ), + page.locator(editPublicLinkRenameConfirm).click() + ]) +} + export const addExpiration = async (args: addExpirationArgs): Promise => { const { page, resource, linkName, expireDate } = args const resourcePaths = resource.split('/') diff --git a/tests/e2e/support/objects/app-files/link/index.ts b/tests/e2e/support/objects/app-files/link/index.ts index da3930a9e3e..a9610e54ac9 100644 --- a/tests/e2e/support/objects/app-files/link/index.ts +++ b/tests/e2e/support/objects/app-files/link/index.ts @@ -59,6 +59,22 @@ export class Link { await po.fillPassword({ page: this.#page, ...args }) } + async showOrHidePassword(args): Promise { + return po.showOrHidePassword({ page: this.#page, ...args }) + } + + async copyEnteredPassword(): Promise { + return po.copyEnteredPassword(this.#page) + } + + async generatePassword(): Promise { + return po.generatePassword(this.#page) + } + + async setPassword(): Promise { + return po.setPassword(this.#page) + } + async changeRole(args: Omit): Promise { const startUrl = this.#page.url() const role = await po.changeRole({ page: this.#page, ...args })