Skip to content

Commit

Permalink
test: Add E2E tests for moving encrypted files
Browse files Browse the repository at this point in the history
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 <danxuliu@gmail.com>
  • Loading branch information
danxuliu authored and icewind1991 committed Jul 26, 2024
1 parent 9998a5d commit 54e770e
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 0 deletions.
186 changes: 186 additions & 0 deletions cypress/e2e/encryption.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* @copyright Copyright (c) 2024 Daniel CalviΓ±o SΓ‘nchez <danxuliu@gmail.com>
*
* @author Daniel CalviΓ±o SΓ‘nchez <danxuliu@gmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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')
})
})
8 changes: 8 additions & 0 deletions cypress/e2e/files/filesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ export const clickOnBreadcumbs = (label: string) => {
cy.get('[data-cy-files-content-breadcrumbs]').contains(label).click()
cy.wait('@propfind')
}

export const assertFileContent = (fileName: string, expectedContent: string) => {
cy.intercept({ method: 'GET', times: 1, url: 'remote.php/**' }).as('downloadFile')
getRowForFile(fileName).should('be.visible')
triggerActionForFile(fileName, 'download')
cy.wait('@downloadFile')
.then(({ response }) => expect(response?.body).to.equal(expectedContent))
}
33 changes: 33 additions & 0 deletions cypress/e2e/groupfoldersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ export function deleteGroupFolder(groupFolderId: string) {
return cy.runOccCommand(`groupfolders:delete ${groupFolderId}`)
}

export function enableEncryptionModule() {
return cy.runOccCommand(`app:enable encryption`)
}

export function disableEncryptionModule() {
return cy.runOccCommand(`app:disable encryption`)
}

export function enableEncryption() {
return cy.runOccCommand(`config:app:set --value=yes core encryption_enabled`)
}

export function disableEncryption() {
return cy.runOccCommand(`config:app:delete core encryption_enabled`)
}

export function enableHomeStorageEncryption() {
// Default value is enabled
return cy.runOccCommand(`config:app:delete encryption encryptHomeStorage`)
}

export function disableHomeStorageEncryption() {
return cy.runOccCommand(`config:app:set --value=0 encryption encryptHomeStorage`)
}

export function enableGroupfoldersEncryption() {
return cy.runOccCommand(`config:app:set --value=true groupfolders enable_encryption`)
}

export function disableGroupfoldersEncryption() {
return cy.runOccCommand(`config:app:delete groupfolders enable_encryption`)
}

export function fileOrFolderExists(name: string) {
// Make sure file list is loaded first
cy.get('[data-cy-files-list-tfoot],[data-cy-files-content-empty]').should('be.visible')
Expand Down

0 comments on commit 54e770e

Please sign in to comment.