Skip to content

Commit 1ab6dba

Browse files
committed
test(files_external): Ensure Home folder permissions are correct
Signed-off-by: Louis Chemineau <[email protected]>
1 parent 553793c commit 1ab6dba

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

cypress/e2e/files_external/StorageUtils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ export type StorageConfig = {
99
[key: string]: string
1010
}
1111

12+
export type StorageMountOption = {
13+
readonly: boolean
14+
}
15+
1216
export enum StorageBackend {
1317
DAV = 'dav',
1418
SMB = 'smb',
1519
SFTP = 'sftp',
20+
LOCAL = 'local',
1621
}
1722

1823
export enum AuthBackend {
@@ -22,6 +27,7 @@ export enum AuthBackend {
2227
SessionCredentials = 'password::sessioncredentials',
2328
UserGlobalAuth = 'password::global::user',
2429
UserProvided = 'password::userprovided',
30+
Null = 'null::null',
2531
}
2632

2733
/**
@@ -35,4 +41,20 @@ export function createStorageWithConfig(mountPoint: string, storageBackend: Stor
3541

3642
cy.log(`Creating storage with command: ${command}`)
3743
return cy.runOccCommand(command)
44+
.then(({ stdout }) => {
45+
return stdout.replace('Storage created with id ', '')
46+
})
47+
}
48+
49+
export function setStorageMountOptions(mountId: string, options: StorageMountOption) {
50+
for (const [key, value] of Object.entries(options)) {
51+
cy.runOccCommand(`files_external:option ${mountId} ${key} ${value}`)
52+
}
53+
}
54+
55+
export function deleteAllExternalStorages() {
56+
cy.runOccCommand('files_external:list --all --output=json').then(({ stdout }) => {
57+
const list = JSON.parse(stdout)
58+
list.forEach((storage) => cy.runOccCommand(`files_external:delete --yes ${storage.mount_id}`), { failOnNonZeroExit: false })
59+
})
3860
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { User } from '@nextcloud/cypress'
7+
import { AuthBackend, createStorageWithConfig, deleteAllExternalStorages, setStorageMountOptions, StorageBackend } from './StorageUtils'
8+
9+
describe('Home folder root mount permissions', { testIsolation: true }, () => {
10+
let user1: User
11+
12+
before(() => {
13+
cy.runOccCommand('app:enable files_external')
14+
cy.createRandomUser().then((user) => { user1 = user })
15+
})
16+
17+
after(() => {
18+
deleteAllExternalStorages()
19+
cy.runOccCommand('app:disable files_external')
20+
})
21+
22+
it('Does not show write actions on read-only storage mounted at the root of the user\'s home folder', () => {
23+
cy.login(user1)
24+
cy.visit('/apps/files/')
25+
cy.runOccCommand('config:app:get files overwrites_home_folders --default-value=[]')
26+
.then(({ stdout }) => assert.equal(stdout.trim(), '[]'))
27+
28+
cy.get('[data-cy-upload-picker=""]').should('exist')
29+
30+
createStorageWithConfig('/', StorageBackend.LOCAL, AuthBackend.Null, { datadir: '/tmp' })
31+
.then((id) => setStorageMountOptions(id, { readonly: true }))
32+
// HACK: somehow, we need to create an external folder targeting a subpath for the previous one to show.
33+
createStorageWithConfig('/a', StorageBackend.LOCAL, AuthBackend.Null, { datadir: '/tmp' })
34+
cy.visit('/apps/files/')
35+
cy.visit('/apps/files/')
36+
cy.runOccCommand('config:app:get files overwrites_home_folders')
37+
.then(({ stdout }) => assert.equal(stdout.trim(), '["files_external"]'))
38+
cy.get('[data-cy-upload-picker=""]').should('not.exist')
39+
40+
deleteAllExternalStorages()
41+
cy.visit('/apps/files/')
42+
cy.runOccCommand('config:app:get files overwrites_home_folders')
43+
.then(({ stdout }) => assert.equal(stdout.trim(), '[]'))
44+
cy.get('[data-cy-upload-picker=""]').should('exist')
45+
})
46+
})

0 commit comments

Comments
 (0)