Skip to content

Commit 049607e

Browse files
committed
test: Add test for read only shares
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent b4fcba0 commit 049607e

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

playwright/e2e/sharing.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Ferdinand Thiessen <opensource@fthiessen.de>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { expect } from '@playwright/test'
7+
import { test } from '../support/fixtures/sharing-user'
8+
9+
test('Share a file read only that cannot be locked by the recipient', async ({ pageOwner, pageRecipient, owner, recipient, request }) => {
10+
// Create a test file as owner
11+
const filename = 'test-share.txt'
12+
const response = await request.put(`/remote.php/dav/files/${owner.userId}/${filename}`, {
13+
headers: {
14+
Authorization: `Basic ${Buffer.from(`${owner.userId}:${owner.password}`).toString('base64')}`,
15+
},
16+
data: 'Test file content',
17+
})
18+
expect(response.ok()).toBeTruthy()
19+
20+
// Share the file with recipient
21+
const shareResponse = await request.post('/ocs/v2.php/apps/files_sharing/api/v1/shares', {
22+
headers: {
23+
'OCS-APIRequest': 'true',
24+
'Content-Type': 'application/json',
25+
Authorization: `Basic ${Buffer.from(`${owner.userId}:${owner.password}`).toString('base64')}`,
26+
},
27+
data: {
28+
path: `/${filename}`,
29+
shareType: '0', // User share
30+
shareWith: recipient.userId,
31+
permissions: '1',
32+
},
33+
})
34+
expect(shareResponse.ok()).toBeTruthy()
35+
36+
// Check recipient cannot lock
37+
await pageRecipient.goto('/apps/files')
38+
await pageRecipient.waitForURL(/apps\/files/)
39+
const rowRecipient = await pageRecipient.getByRole('row', { name: filename })
40+
await rowRecipient.getByRole('button', { name: 'Actions' }).click()
41+
await expect(pageRecipient.getByRole('menuitem', { name: 'Lock file' })).not.toBeVisible()
42+
43+
// Check owner can still lock
44+
await pageOwner.goto('/apps/files')
45+
await pageOwner.waitForURL(/apps\/files/)
46+
const rowOwner = await pageOwner.getByRole('row', { name: filename })
47+
await rowOwner.getByRole('button', { name: 'Actions' }).click()
48+
await expect(pageOwner.getByRole('menuitem', { name: 'Lock file' })).toBeVisible()
49+
})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Ferdinand Thiessen <opensource@fthiessen.de>
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { test as base } from '@playwright/test'
7+
import { createRandomUser, login } from '@nextcloud/e2e-test-server/playwright'
8+
9+
// The User type from e2e-test-server
10+
interface User {
11+
userId: string
12+
password: string
13+
language: string
14+
}
15+
16+
interface SharingUserFixture {
17+
owner: User
18+
recipient: User
19+
pageOwner: Page
20+
pageRecipient: Page
21+
}
22+
23+
/**
24+
* This test fixture ensures two new random users are created:
25+
* - owner: The user who will be sharing files/folders
26+
* - recipient: The user who will receive the shares
27+
*/
28+
export const test = base.extend<SharingUserFixture>({
29+
owner: async ({ }, use) => {
30+
const user = await createRandomUser()
31+
await use(user)
32+
},
33+
recipient: async ({ }, use) => {
34+
const user = await createRandomUser()
35+
await use(user)
36+
},
37+
pageOwner: async ({ browser, baseURL, owner }, use) => {
38+
const page = await browser.newPage({
39+
storageState: undefined,
40+
baseURL,
41+
})
42+
43+
await login(page.request, owner)
44+
45+
await use(page)
46+
await page.close()
47+
},
48+
pageRecipient: async ({ browser, baseURL, recipient }, use) => {
49+
const page = await browser.newPage({
50+
storageState: undefined,
51+
baseURL,
52+
})
53+
54+
await login(page.request, recipient)
55+
56+
await use(page)
57+
await page.close()
58+
},
59+
})

0 commit comments

Comments
 (0)