aboutsummaryrefslogtreecommitdiffstats
path: root/cypress
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-02-26 19:05:23 +0100
committerLouis Chemineau <louis@chmn.me>2024-02-27 09:28:23 +0100
commitf7a0246290c0b4fd73fa11017004066f037d21f6 (patch)
tree852a5fe22a9c529826617dd99ba68ef7e9fbd516 /cypress
parent77148905f0ebfdbd7bff33023ed037d1a29583ce (diff)
downloadnextcloud-server-f7a0246290c0b4fd73fa11017004066f037d21f6.tar.gz
nextcloud-server-f7a0246290c0b4fd73fa11017004066f037d21f6.zip
test(files_versions): Add tests for versions actions
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'cypress')
-rw-r--r--cypress/e2e/files_versions/filesVersionsUtils.ts66
-rw-r--r--cypress/e2e/files_versions/version_deletion.cy.ts110
-rw-r--r--cypress/e2e/files_versions/version_download.cy.ts62
-rw-r--r--cypress/e2e/files_versions/version_naming.cy.ts96
-rw-r--r--cypress/e2e/files_versions/version_restoration.cy.ts85
5 files changed, 381 insertions, 38 deletions
diff --git a/cypress/e2e/files_versions/filesVersionsUtils.ts b/cypress/e2e/files_versions/filesVersionsUtils.ts
index ffaa96f9518..7f655d2c303 100644
--- a/cypress/e2e/files_versions/filesVersionsUtils.ts
+++ b/cypress/e2e/files_versions/filesVersionsUtils.ts
@@ -1,3 +1,4 @@
+/* eslint-disable jsdoc/require-jsdoc */
/**
* @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me>
*
@@ -22,6 +23,7 @@
import type { User } from '@nextcloud/cypress'
import path from 'path'
+import { createShare, type ShareSetting } from '../files_sharing/filesSharingUtils'
export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur
@@ -35,7 +37,7 @@ export const uploadThreeVersions = (user: User, fileName: string) => {
cy.login(user)
}
-export const openVersionsPanel = (fileName: string) =>{
+export function openVersionsPanel(fileName: string) {
// Detect the versions list fetch
cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions')
@@ -50,35 +52,61 @@ export const openVersionsPanel = (fileName: string) =>{
cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 })
}
-export const openVersionMenu = (index: number) => {
- cy.get('#tab-version_vue').within(() => {
- cy.get('[data-files-versions-version]')
- .eq(index).within(() => {
- cy.get('.action-item__menutoggle').filter(':visible')
- .click()
- })
- })
+export function toggleVersionMenu(index: number) {
+ cy.get('#tab-version_vue [data-files-versions-version]')
+ .eq(index)
+ .find('button')
+ .click()
}
-export const clickPopperAction = (actionName: string) => {
- cy.get('.v-popper__popper').filter(':visible')
- .contains(actionName)
- .click()
+export function triggerVersionAction(index: number, actionName: string) {
+ toggleVersionMenu(index)
+ cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).filter(':visible').click()
}
-export const nameVersion = (index: number, name: string) => {
- openVersionMenu(index)
- clickPopperAction('Name this version')
+export function nameVersion(index: number, name: string) {
+ cy.intercept('PROPPATCH', '**/dav/versions/*/versions/**').as('labelVersion')
+ triggerVersionAction(index, 'label')
cy.get(':focused').type(`${name}{enter}`)
+ cy.wait('@labelVersion')
}
-export const assertVersionContent = (filename: string, index: number, expectedContent: string) => {
+export function restoreVersion(index: number) {
+ cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion')
+ triggerVersionAction(index, 'restore')
+ cy.wait('@restoreVersion')
+}
+
+export function deleteVersion(index: number) {
+ cy.intercept('DELETE', '**/dav/versions/*/versions/**').as('deleteVersion')
+ triggerVersionAction(index, 'delete')
+ cy.wait('@deleteVersion')
+}
+
+export function doesNotHaveAction(index: number, actionName: string) {
+ toggleVersionMenu(index)
+ cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).should('not.exist')
+ toggleVersionMenu(index)
+}
+
+export function assertVersionContent(filename: string, index: number, expectedContent: string) {
const downloadsFolder = Cypress.config('downloadsFolder')
- openVersionMenu(index)
- clickPopperAction('Download version')
+ triggerVersionAction(index, 'download')
return cy.readFile(path.join(downloadsFolder, filename))
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
}
+
+export function setupTestSharedFileFromUser(owner: User, randomFileName: string, shareOptions: Partial<ShareSetting>) {
+ return cy.createRandomUser()
+ .then((recipient) => {
+ cy.login(owner)
+ cy.visit('/apps/files')
+ createShare(randomFileName, recipient.userId, shareOptions)
+ cy.login(recipient)
+ cy.visit('/apps/files')
+ return cy.wrap(recipient)
+ })
+}
diff --git a/cypress/e2e/files_versions/version_deletion.cy.ts b/cypress/e2e/files_versions/version_deletion.cy.ts
new file mode 100644
index 00000000000..1e90c79fafa
--- /dev/null
+++ b/cypress/e2e/files_versions/version_deletion.cy.ts
@@ -0,0 +1,110 @@
+/**
+ * @copyright Copyright (c) 2024 Louis Chmn <louis@chmn.me>
+ *
+ * @author Louis Chmn <louis@chmn.me>
+ *
+ * @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 type { User } from '@nextcloud/cypress'
+import { doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
+import { navigateToFolder, getRowForFile } from '../files/FilesUtils'
+
+describe('Versions restoration', () => {
+ const folderName = 'shared_folder'
+ const randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+ const randomFilePath = `/${folderName}/${randomFileName}`
+ let user: User
+ let versionCount = 0
+
+ before(() => {
+ cy.createRandomUser()
+ .then((_user) => {
+ user = _user
+ cy.mkdir(user, `/${folderName}`)
+ uploadThreeVersions(user, randomFilePath)
+ uploadThreeVersions(user, randomFilePath)
+ versionCount = 6
+ cy.login(user)
+ cy.visit('/apps/files')
+ navigateToFolder(folderName)
+ openVersionsPanel(randomFilePath)
+ })
+ })
+
+ it('Delete initial version', () => {
+ cy.get('[data-files-versions-version]').should('have.length', versionCount)
+ deleteVersion(2)
+ versionCount--
+ cy.get('[data-files-versions-version]').should('have.length', versionCount)
+ })
+
+ context('Delete versions of shared file', () => {
+ it('Works with delete permission', () => {
+ setupTestSharedFileFromUser(user, folderName, { delete: true })
+ navigateToFolder(folderName)
+ openVersionsPanel(randomFilePath)
+
+ cy.get('[data-files-versions-version]').should('have.length', versionCount)
+ deleteVersion(2)
+ versionCount--
+ cy.get('[data-files-versions-version]').should('have.length', versionCount)
+ })
+
+ it('Does not work without delete permission', () => {
+ setupTestSharedFileFromUser(user, folderName, { delete: false })
+ navigateToFolder(folderName)
+ openVersionsPanel(randomFilePath)
+
+ doesNotHaveAction(0, 'delete')
+ doesNotHaveAction(1, 'delete')
+ doesNotHaveAction(2, 'delete')
+ })
+
+ it('Does not work without delete permission through direct API access', () => {
+ let hostname: string
+ let fileId: string|undefined
+ let versionId: string|undefined
+
+ setupTestSharedFileFromUser(user, folderName, { delete: false })
+ .then(recipient => {
+ navigateToFolder(folderName)
+ openVersionsPanel(randomFilePath)
+
+ cy.url().then(url => { hostname = new URL(url).hostname })
+ getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
+ cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
+
+ cy.then(() => {
+ cy.logout()
+ cy.request({
+ method: 'DELETE',
+ auth: { user: recipient.userId, pass: recipient.password },
+ headers: {
+ cookie: '',
+ },
+ url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
+ failOnStatusCode: false,
+ })
+ .then(({ status }) => {
+ expect(status).to.equal(403)
+ })
+ })
+ })
+ })
+ })
+})
diff --git a/cypress/e2e/files_versions/version_download.cy.ts b/cypress/e2e/files_versions/version_download.cy.ts
index 30299e9f8e1..f6a994322a8 100644
--- a/cypress/e2e/files_versions/version_download.cy.ts
+++ b/cypress/e2e/files_versions/version_download.cy.ts
@@ -20,16 +20,20 @@
*
*/
-import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
+import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils'
+import type { User } from '@nextcloud/cypress'
+import { getRowForFile } from '../files/FilesUtils'
describe('Versions download', () => {
let randomFileName = ''
+ let user: User
before(() => {
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
cy.createRandomUser()
- .then((user) => {
+ .then((_user) => {
+ user = _user
uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
@@ -37,9 +41,61 @@ describe('Versions download', () => {
})
})
- it('Download versions and assert there content', () => {
+ it('Download versions and assert their content', () => {
assertVersionContent(randomFileName, 0, 'v3')
assertVersionContent(randomFileName, 1, 'v2')
assertVersionContent(randomFileName, 2, 'v1')
})
+
+ context('Download versions of shared file', () => {
+ it('Works with download permission', () => {
+ setupTestSharedFileFromUser(user, randomFileName, { download: true })
+ openVersionsPanel(randomFileName)
+
+ assertVersionContent(randomFileName, 0, 'v3')
+ assertVersionContent(randomFileName, 1, 'v2')
+ assertVersionContent(randomFileName, 2, 'v1')
+ })
+
+ it('Does not show action without download permission', () => {
+ setupTestSharedFileFromUser(user, randomFileName, { download: false })
+ openVersionsPanel(randomFileName)
+
+ cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
+ cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="download"]').should('not.exist')
+
+ doesNotHaveAction(1, 'download')
+ doesNotHaveAction(2, 'download')
+ })
+
+ it('Does not work without download permission through direct API access', () => {
+ let hostname: string
+ let fileId: string|undefined
+ let versionId: string|undefined
+
+ setupTestSharedFileFromUser(user, randomFileName, { download: false })
+ .then(recipient => {
+ openVersionsPanel(randomFileName)
+
+ cy.url().then(url => { hostname = new URL(url).hostname })
+ getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
+ cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
+
+ cy.then(() => {
+ cy.logout()
+ cy.request({
+ auth: { user: recipient.userId, pass: recipient.password },
+ headers: {
+ cookie: '',
+ },
+ url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
+ failOnStatusCode: false,
+ })
+ .then(({ status }) => {
+ expect(status).to.equal(403)
+ })
+ })
+ })
+ })
+ })
})
diff --git a/cypress/e2e/files_versions/version_naming.cy.ts b/cypress/e2e/files_versions/version_naming.cy.ts
index 4b662e31b94..a2f0514dfa0 100644
--- a/cypress/e2e/files_versions/version_naming.cy.ts
+++ b/cypress/e2e/files_versions/version_naming.cy.ts
@@ -20,16 +20,20 @@
*
*/
-import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
+import type { User } from '@nextcloud/cypress'
+import { nameVersion, openVersionsPanel, uploadThreeVersions, doesNotHaveAction, setupTestSharedFileFromUser } from './filesVersionsUtils'
+import { getRowForFile } from '../files/FilesUtils'
describe('Versions naming', () => {
let randomFileName = ''
+ let user: User
before(() => {
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
cy.createRandomUser()
- .then((user) => {
+ .then((_user) => {
+ user = _user
uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
@@ -37,25 +41,103 @@ describe('Versions naming', () => {
})
})
- it('Names the initial version as v1', () => {
+ it('Names the versions', () => {
nameVersion(2, 'v1')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(2).contains('v1')
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
})
- })
- it('Names the second version as v2', () => {
nameVersion(1, 'v2')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(1).contains('v2')
})
- })
- it('Names the current version as v3', () => {
nameVersion(0, 'v3')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(0).contains('v3 (Current version)')
})
})
+
+ context('Name versions of shared file', () => {
+ context('with edit permission', () => {
+ before(() => {
+ setupTestSharedFileFromUser(user, randomFileName, { update: true })
+ openVersionsPanel(randomFileName)
+ })
+
+ it('Names the versions', () => {
+ nameVersion(2, 'v1 - shared')
+ cy.get('#tab-version_vue').within(() => {
+ cy.get('[data-files-versions-version]').eq(2).contains('v1 - shared')
+ cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
+ })
+
+ nameVersion(1, 'v2 - shared')
+ cy.get('#tab-version_vue').within(() => {
+ cy.get('[data-files-versions-version]').eq(1).contains('v2 - shared')
+ })
+
+ nameVersion(0, 'v3 - shared')
+ cy.get('#tab-version_vue').within(() => {
+ cy.get('[data-files-versions-version]').eq(0).contains('v3 - shared (Current version)')
+ })
+ })
+ })
+
+ context('without edit permission', () => {
+ it('Does not show action', () => {
+ setupTestSharedFileFromUser(user, randomFileName, { update: false })
+ openVersionsPanel(randomFileName)
+
+ cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
+ cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="label"]').should('not.exist')
+
+ doesNotHaveAction(1, 'label')
+ doesNotHaveAction(2, 'label')
+ })
+
+ it('Does not work without update permission through direct API access', () => {
+ let hostname: string
+ let fileId: string|undefined
+ let versionId: string|undefined
+
+ setupTestSharedFileFromUser(user, randomFileName, { update: false })
+ .then(recipient => {
+ openVersionsPanel(randomFileName)
+
+ cy.url().then(url => { hostname = new URL(url).hostname })
+ getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
+ cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
+
+ cy.then(() => {
+ cy.logout()
+ cy.request({
+ method: 'PROPPATCH',
+ auth: { user: recipient.userId, pass: recipient.password },
+ headers: {
+ cookie: '',
+ },
+ body: `<?xml version="1.0"?>
+ <d:propertyupdate xmlns:d="DAV:"
+ xmlns:oc="http://owncloud.org/ns"
+ xmlns:nc="http://nextcloud.org/ns"
+ xmlns:ocs="http://open-collaboration-services.org/ns">
+ <d:set>
+ <d:prop>
+ <nc:version-label>not authorized labeling</nc:version-label>
+ </d:prop>
+ </d:set>
+ </d:propertyupdate>`,
+ url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
+ failOnStatusCode: false,
+ })
+ .then(({ status }) => {
+ expect(status).to.equal(403)
+ })
+ })
+ })
+ })
+ })
+ })
})
diff --git a/cypress/e2e/files_versions/version_restoration.cy.ts b/cypress/e2e/files_versions/version_restoration.cy.ts
index fe6b798299a..c5dbaeab964 100644
--- a/cypress/e2e/files_versions/version_restoration.cy.ts
+++ b/cypress/e2e/files_versions/version_restoration.cy.ts
@@ -20,23 +20,20 @@
*
*/
-import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
-
-const restoreVersion = (index: number) => {
- cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion')
- openVersionMenu(index)
- clickPopperAction('Restore version')
- cy.wait('@restoreVersion')
-}
+import type { User } from '@nextcloud/cypress'
+import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, restoreVersion, uploadThreeVersions } from './filesVersionsUtils'
+import { getRowForFile } from '../files/FilesUtils'
describe('Versions restoration', () => {
let randomFileName = ''
+ let user: User
before(() => {
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
cy.createRandomUser()
- .then((user) => {
+ .then((_user) => {
+ user = _user
uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
@@ -44,8 +41,13 @@ describe('Versions restoration', () => {
})
})
+ it('Current version does not have restore action', () => {
+ doesNotHaveAction(0, 'restore')
+ })
+
it('Restores initial version', () => {
restoreVersion(2)
+
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 3)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
@@ -58,4 +60,69 @@ describe('Versions restoration', () => {
assertVersionContent(randomFileName, 1, 'v3')
assertVersionContent(randomFileName, 2, 'v2')
})
+
+ context('Restore versions of shared file', () => {
+ it('Works with update permission', () => {
+ setupTestSharedFileFromUser(user, randomFileName, { update: true })
+ openVersionsPanel(randomFileName)
+
+ it('Restores initial version', () => {
+ restoreVersion(2)
+ cy.get('#tab-version_vue').within(() => {
+ cy.get('[data-files-versions-version]').should('have.length', 3)
+ cy.get('[data-files-versions-version]').eq(0).contains('Current version')
+ cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
+ })
+ })
+
+ it('Downloads versions and assert there content', () => {
+ assertVersionContent(randomFileName, 0, 'v1')
+ assertVersionContent(randomFileName, 1, 'v3')
+ assertVersionContent(randomFileName, 2, 'v2')
+ })
+ })
+
+ it('Does not show action without delete permission', () => {
+ setupTestSharedFileFromUser(user, randomFileName, { update: false })
+ openVersionsPanel(randomFileName)
+
+ cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
+ cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="restore"]').should('not.exist')
+
+ doesNotHaveAction(1, 'restore')
+ doesNotHaveAction(2, 'restore')
+ })
+
+ it('Does not work without update permission through direct API access', () => {
+ let hostname: string
+ let fileId: string|undefined
+ let versionId: string|undefined
+
+ setupTestSharedFileFromUser(user, randomFileName, { update: false })
+ .then(recipient => {
+ openVersionsPanel(randomFileName)
+
+ cy.url().then(url => { hostname = new URL(url).hostname })
+ getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
+ cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
+
+ cy.then(() => {
+ cy.logout()
+ cy.request({
+ method: 'MOVE',
+ auth: { user: recipient.userId, pass: recipient.password },
+ headers: {
+ cookie: '',
+ Destination: 'https://nextcloud_server1.test/remote.php/dav/versions/admin/restore/target',
+ },
+ url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
+ failOnStatusCode: false,
+ })
+ .then(({ status }) => {
+ expect(status).to.equal(403)
+ })
+ })
+ })
+ })
+ })
})