Skip to content

Commit 54d09dc

Browse files
committed
enforce password for writable public links
1 parent 11b4601 commit 54d09dc

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

tests/e2e/cucumber/features/shares/link.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,24 @@ Feature: link
341341
| resource |
342342
| lorem.txt |
343343
And "Alice" logs out
344+
345+
346+
Scenario: password is triggered when changing public link to writable role
347+
Given "Admin" assigns following roles to the users using API
348+
| id | role |
349+
| Alice | Admin |
350+
When "Alice" logs in
351+
And "Alice" creates the following folders in personal space using API
352+
| name |
353+
| folderPublic |
354+
And "Alice" opens the "files" app
355+
And "Alice" creates a public link of following resource using the sidebar panel
356+
| resource | role | password |
357+
| folderPublic | Can view | %public% |
358+
359+
# @issue-2048
360+
# Admin feature: ensure password is required for writable public links
361+
# in case when OC_SHARING_PUBLIC_WRITEABLE_SHARE_MUST_HAVE_PASSWORD=true and OC_SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD=false
362+
And "Alice" deletes a password of the public link named "Unnamed link" of resource "folderPublic"
363+
And "Alice" edits the public link named "Unnamed link" of resource "folderPublic" changing role to "Secret File Drop" and setting a password
364+
And "Alice" logs out

tests/e2e/cucumber/steps/ui/links.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,22 @@ When(
202202
}
203203
)
204204

205+
When(
206+
'{string} edits the public link named {string} of resource {string} changing role to {string} and setting a password',
207+
async function (
208+
this: World,
209+
stepUser: string,
210+
linkName: any,
211+
resource: string,
212+
role: string
213+
): Promise<void> {
214+
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
215+
const linkObject = new objects.applicationFiles.Link({ page })
216+
const roleText = await linkObject.changeRole({ linkName, resource, role, password: true })
217+
expect(roleText.toLowerCase()).toBe(role.toLowerCase())
218+
}
219+
)
220+
205221
When(
206222
'{string} copies the link {string} of resource {string}',
207223
async function (
@@ -216,3 +232,12 @@ When(
216232
expect(clipboard).toBe(this.linksEnvironment.getLink({ name: linkName }).url)
217233
}
218234
)
235+
236+
When(
237+
'{string} deletes a password of the public link named {string} of resource {string}',
238+
async function (this: World, stepUser: string, name: string, resource: string): Promise<void> {
239+
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
240+
const linkObject = new objects.applicationFiles.Link({ page })
241+
await linkObject.deletePassword({ resource, name })
242+
}
243+
)

tests/e2e/support/objects/app-files/link/actions.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type changeRoleArgs = {
5050
linkName: string
5151
role: string
5252
space?: boolean
53+
password?: boolean
5354
}
5455

5556
export type deleteLinkArgs = {
@@ -102,6 +103,8 @@ const copyLinkButton =
102103
'//span[contains(@class, "files-links-name") and text()="%s"]//ancestor::li//button[contains(@class, "oc-files-public-link-copy-url")]'
103104
const linkRoleDropdown = '.link-role-dropdown'
104105
const createLinkModal = '.oc-modal-body'
106+
const removePublicLinkPasswordButton =
107+
'//div[contains(@id,"edit-public-link-dropdown")]//button/span[text()="Remove password"]'
105108

106109
const getRecentLinkUrl = async (page: Page, name: string): Promise<string> => {
107110
const linkElement = page.locator(util.format(copyLinkButton, name))
@@ -173,7 +176,7 @@ export const createLink = async (args: createLinkArgs): Promise<string> => {
173176
}
174177

175178
export const changeRole = async (args: changeRoleArgs): Promise<string> => {
176-
const { page, resource, linkName, role, space } = args
179+
const { page, resource, linkName, role, space, password = false } = args
177180

178181
// clear all popups
179182
await clearAllPopups(page)
@@ -199,7 +202,14 @@ export const changeRole = async (args: changeRoleArgs): Promise<string> => {
199202
res.request().method() === 'PATCH' &&
200203
res.status() === 200
201204
),
202-
page.locator(util.format(publicLinkSetRoleButton, role)).click()
205+
(async () => {
206+
await page.locator(util.format(publicLinkSetRoleButton, role)).click()
207+
208+
if (password) {
209+
await generatePassword(page)
210+
await setPassword(page)
211+
}
212+
})()
203213
])
204214

205215
const message = await page.locator(linkUpdateDialog).textContent()
@@ -374,3 +384,23 @@ export const copyLinkToClipboard = async (args: copyLinkArgs): Promise<string> =
374384
await page.getByLabel('Copy link to clipboard').click()
375385
return await page.evaluate('navigator.clipboard.readText()')
376386
}
387+
388+
export const deletePassword = async (args: createLinkArgs): Promise<void> => {
389+
const { page, resource, name } = args
390+
391+
// clear all popups
392+
await clearAllPopups(page)
393+
394+
const resourcePaths = resource.split('/')
395+
const resourceName = resourcePaths.pop()
396+
if (resourcePaths.length) {
397+
await clickResource({ page: page, path: resourcePaths.join('/') })
398+
}
399+
await sidebar.open({ page: page, resource: resourceName })
400+
await sidebar.openPanel({ page: page, name: 'sharing' })
401+
await page.locator(util.format(editPublicLinkButton, name)).click()
402+
403+
const passwordIndication = page.locator('.oc-files-file-link-has-password')
404+
await page.locator(removePublicLinkPasswordButton).click()
405+
await expect(passwordIndication).not.toBeVisible()
406+
}

tests/e2e/support/objects/app-files/link/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ export class Link {
9696
copyLinkToClipboard(args: Omit<po.copyLinkArgs, 'page'>): Promise<string> {
9797
return po.copyLinkToClipboard({ ...args, page: this.#page })
9898
}
99+
100+
async deletePassword(args: Omit<po.createLinkArgs, 'page'>): Promise<void> {
101+
await po.deletePassword({ page: this.#page, ...args })
102+
}
99103
}

0 commit comments

Comments
 (0)