|
| 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 | +}) |
0 commit comments