-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2942 from nextcloud/fix-encryption-wrapper-not-se…
…en-by-groupfolder-cache Fix encryption wrapper not seen by groupfolder cache
- Loading branch information
Showing
6 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { | ||
addUserToGroup, | ||
createGroup, | ||
createGroupFolder, | ||
deleteGroupFolder, | ||
disableEncryption, | ||
disableEncryptionModule, | ||
disableGroupfoldersEncryption, | ||
disableHomeStorageEncryption, | ||
enableEncryption, | ||
enableEncryptionModule, | ||
enableGroupfoldersEncryption, | ||
enableHomeStorageEncryption, | ||
enterFolder, | ||
fileOrFolderExists, | ||
PERMISSION_DELETE, | ||
PERMISSION_READ, | ||
PERMISSION_WRITE, | ||
} from './groupfoldersUtils' | ||
|
||
import { | ||
assertFileContent, | ||
moveFile, | ||
} from './files/filesUtils' | ||
|
||
import { randHash } from '../utils' | ||
|
||
import type { User } from '@nextcloud/cypress' | ||
|
||
describe('Groupfolders encryption behavior', () => { | ||
let user1: User | ||
let groupFolderId: string | ||
let groupName: string | ||
let groupFolderName: string | ||
|
||
before(() => { | ||
enableEncryptionModule() | ||
enableEncryption() | ||
}) | ||
|
||
beforeEach(() => { | ||
if (groupFolderId) { | ||
deleteGroupFolder(groupFolderId) | ||
} | ||
groupName = `test_group_${randHash()}` | ||
groupFolderName = `test_group_folder_${randHash()}` | ||
|
||
cy.createRandomUser() | ||
.then(_user => { | ||
user1 = _user | ||
}) | ||
createGroup(groupName) | ||
.then(() => { | ||
addUserToGroup(groupName, user1.userId) | ||
createGroupFolder(groupFolderName, groupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE]) | ||
}) | ||
}) | ||
|
||
after(() => { | ||
// Restore default values | ||
disableGroupfoldersEncryption() | ||
enableHomeStorageEncryption() | ||
disableEncryption() | ||
disableEncryptionModule() | ||
}) | ||
|
||
it('Move file from encrypted storage to encrypted groupfolder', () => { | ||
enableHomeStorageEncryption() | ||
enableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt') | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
moveFile('file1.txt', groupFolderName) | ||
|
||
enterFolder(groupFolderName) | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
|
||
it('Move file from encrypted storage to non encrypted groupfolder', () => { | ||
enableHomeStorageEncryption() | ||
disableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt') | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
moveFile('file1.txt', groupFolderName) | ||
|
||
enterFolder(groupFolderName) | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
|
||
it('Move file from non encrypted storage to encrypted groupfolder', () => { | ||
disableHomeStorageEncryption() | ||
enableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', '/file1.txt') | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
moveFile('file1.txt', groupFolderName) | ||
|
||
enterFolder(groupFolderName) | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
|
||
it('Move file from encrypted groupfolder to encrypted storage', () => { | ||
enableHomeStorageEncryption() | ||
enableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`) | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
enterFolder(groupFolderName) | ||
moveFile('file1.txt', '/') | ||
|
||
cy.visit('/apps/files') | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
|
||
it('Move file from encrypted groupfolder to non encrypted storage', () => { | ||
disableHomeStorageEncryption() | ||
enableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`) | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
enterFolder(groupFolderName) | ||
moveFile('file1.txt', '/') | ||
|
||
cy.visit('/apps/files') | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
|
||
it('Move file from non encrypted groupfolder to encrypted storage', () => { | ||
enableHomeStorageEncryption() | ||
disableGroupfoldersEncryption() | ||
|
||
cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/file1.txt`) | ||
|
||
cy.login(user1) | ||
cy.visit('/apps/files') | ||
|
||
enterFolder(groupFolderName) | ||
moveFile('file1.txt', '/') | ||
|
||
cy.visit('/apps/files') | ||
fileOrFolderExists('file1.txt') | ||
assertFileContent('file1.txt', 'Content of the file') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\GroupFolders\Mount; | ||
|
||
use OC\Files\Cache\Wrapper\CacheJail; | ||
use OC\Files\Storage\Wrapper\Jail; | ||
|
||
/** | ||
* Jail with overridden behaviors specific to group folders when encryption is | ||
* enabled. | ||
*/ | ||
class GroupFolderEncryptionJail extends Jail { | ||
public function getCache($path = '', $storage = null) { | ||
if (!$storage) { | ||
$storage = $this->getWrapperStorage(); | ||
} | ||
// By default the Jail reuses the inner cache, but when encryption is | ||
// enabled the storage needs to be passed to the cache so it takes into | ||
// account the outer Encryption wrapper. | ||
$sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage); | ||
return new CacheJail($sourceCache, $this->rootPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters