Skip to content

Commit 06b83d6

Browse files
committed
test: Add E2E tests for moving encrypted files
These tests should be written as integration tests instead, but for practical reasons, as the integration tests have not been setup yet in the groupfolders app, they were written as E2E tests. Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent e50a84e commit 06b83d6

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed

cypress/e2e/encryption.cy.ts

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/**
2+
* @copyright Copyright (c) 2024 Daniel Calviño Sánchez <[email protected]>
3+
*
4+
* @author Daniel Calviño Sánchez <[email protected]>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
import {
23+
addUserToGroup,
24+
createGroup,
25+
createGroupFolder,
26+
deleteGroupFolder,
27+
disableEncryption,
28+
disableEncryptionModule,
29+
disableGroupfoldersEncryption,
30+
disableHomeStorageEncryption,
31+
enableEncryption,
32+
enableEncryptionModule,
33+
enableGroupfoldersEncryption,
34+
enableHomeStorageEncryption,
35+
enterFolder,
36+
fileOrFolderExists,
37+
PERMISSION_DELETE,
38+
PERMISSION_READ,
39+
PERMISSION_WRITE,
40+
} from './groupfoldersUtils'
41+
42+
import {
43+
assertFileContent,
44+
moveFile,
45+
} from './files/filesUtils'
46+
47+
import { randHash } from '../utils'
48+
49+
import type { User } from '@nextcloud/cypress'
50+
51+
describe('Groupfolders encryption behavior', () => {
52+
let user1: User
53+
let groupFolderId: string
54+
let groupName: string
55+
let groupFolderName: string
56+
57+
before(() => {
58+
enableEncryptionModule()
59+
enableEncryption()
60+
})
61+
62+
beforeEach(() => {
63+
if (groupFolderId) {
64+
deleteGroupFolder(groupFolderId)
65+
}
66+
groupName = `test_group_${randHash()}`
67+
groupFolderName = `test_group_folder_${randHash()}`
68+
69+
cy.createRandomUser()
70+
.then(_user => {
71+
user1 = _user
72+
})
73+
createGroup(groupName)
74+
.then(() => {
75+
addUserToGroup(groupName, user1.userId)
76+
createGroupFolder(groupFolderName, groupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])
77+
})
78+
})
79+
80+
after(() => {
81+
// Restore default values
82+
disableGroupfoldersEncryption()
83+
enableHomeStorageEncryption()
84+
disableEncryption()
85+
disableEncryptionModule()
86+
})
87+
88+
it('Move file from encrypted storage to encrypted groupfolder', () => {
89+
enableHomeStorageEncryption()
90+
enableGroupfoldersEncryption()
91+
92+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt')
93+
94+
cy.login(user1)
95+
cy.visit('/apps/files')
96+
97+
moveFile('file1.txt', groupFolderName)
98+
99+
enterFolder(groupFolderName)
100+
fileOrFolderExists('file1.txt')
101+
assertFileContent('file1.txt', 'Content of the file')
102+
})
103+
104+
it('Move file from encrypted storage to non encrypted groupfolder', () => {
105+
enableHomeStorageEncryption()
106+
disableGroupfoldersEncryption()
107+
108+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt')
109+
110+
cy.login(user1)
111+
cy.visit('/apps/files')
112+
113+
moveFile('file1.txt', groupFolderName)
114+
115+
enterFolder(groupFolderName)
116+
fileOrFolderExists('file1.txt')
117+
assertFileContent('file1.txt', 'Content of the file')
118+
})
119+
120+
it('Move file from non encrypted storage to encrypted groupfolder', () => {
121+
disableHomeStorageEncryption()
122+
enableGroupfoldersEncryption()
123+
124+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt')
125+
126+
cy.login(user1)
127+
cy.visit('/apps/files')
128+
129+
moveFile('file1.txt', groupFolderName)
130+
131+
enterFolder(groupFolderName)
132+
fileOrFolderExists('file1.txt')
133+
assertFileContent('file1.txt', 'Content of the file')
134+
})
135+
136+
it('Move file from encrypted groupfolder to encrypted storage', () => {
137+
enableHomeStorageEncryption()
138+
enableGroupfoldersEncryption()
139+
140+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`)
141+
142+
cy.login(user1)
143+
cy.visit('/apps/files')
144+
145+
enterFolder(groupFolderName)
146+
moveFile('file1.txt', '/')
147+
148+
cy.visit('/apps/files')
149+
fileOrFolderExists('file1.txt')
150+
assertFileContent('file1.txt', 'Content of the file')
151+
})
152+
153+
it('Move file from encrypted groupfolder to non encrypted storage', () => {
154+
disableHomeStorageEncryption()
155+
enableGroupfoldersEncryption()
156+
157+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`)
158+
159+
cy.login(user1)
160+
cy.visit('/apps/files')
161+
162+
enterFolder(groupFolderName)
163+
moveFile('file1.txt', '/')
164+
165+
cy.visit('/apps/files')
166+
fileOrFolderExists('file1.txt')
167+
assertFileContent('file1.txt', 'Content of the file')
168+
})
169+
170+
it('Move file from non encrypted groupfolder to encrypted storage', () => {
171+
enableHomeStorageEncryption()
172+
disableGroupfoldersEncryption()
173+
174+
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`)
175+
176+
cy.login(user1)
177+
cy.visit('/apps/files')
178+
179+
enterFolder(groupFolderName)
180+
moveFile('file1.txt', '/')
181+
182+
cy.visit('/apps/files')
183+
fileOrFolderExists('file1.txt')
184+
assertFileContent('file1.txt', 'Content of the file')
185+
})
186+
})

cypress/e2e/files/filesUtils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ export const clickOnBreadcumbs = (label: string) => {
111111
cy.get('[data-cy-files-content-breadcrumbs]').contains(label).click()
112112
cy.wait('@propfind')
113113
}
114+
115+
export const assertFileContent = (fileName: string, expectedContent: string) => {
116+
cy.intercept({ method: 'GET', times: 1, url: 'remote.php/**' }).as('downloadFile')
117+
getRowForFile(fileName).should('be.visible')
118+
triggerActionForFile(fileName, 'download')
119+
cy.wait('@downloadFile')
120+
.then(({ response }) => expect(response?.body).to.equal(expectedContent))
121+
}

cypress/e2e/groupfoldersUtils.ts

+33
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,39 @@ export function deleteGroupFolder(groupFolderId: string) {
7474
return cy.runOccCommand(`groupfolders:delete ${groupFolderId}`)
7575
}
7676

77+
export function enableEncryptionModule() {
78+
return cy.runOccCommand(`app:enable encryption`)
79+
}
80+
81+
export function disableEncryptionModule() {
82+
return cy.runOccCommand(`app:disable encryption`)
83+
}
84+
85+
export function enableEncryption() {
86+
return cy.runOccCommand(`config:app:set --value=yes core encryption_enabled`)
87+
}
88+
89+
export function disableEncryption() {
90+
return cy.runOccCommand(`config:app:delete core encryption_enabled`)
91+
}
92+
93+
export function enableHomeStorageEncryption() {
94+
// Default value is enabled
95+
return cy.runOccCommand(`config:app:delete encryption encryptHomeStorage`)
96+
}
97+
98+
export function disableHomeStorageEncryption() {
99+
return cy.runOccCommand(`config:app:set --value=0 encryption encryptHomeStorage`)
100+
}
101+
102+
export function enableGroupfoldersEncryption() {
103+
return cy.runOccCommand(`config:app:set --value=true groupfolders enable_encryption`)
104+
}
105+
106+
export function disableGroupfoldersEncryption() {
107+
return cy.runOccCommand(`config:app:delete groupfolders enable_encryption`)
108+
}
109+
77110
export function fileOrFolderExists(name: string) {
78111
// Make sure file list is loaded first
79112
cy.get('[data-cy-files-list-tfoot],[data-cy-files-content-empty]').should('be.visible')

0 commit comments

Comments
 (0)