Skip to content

Commit

Permalink
Add cypress test for ACLs and trashbin
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Nov 30, 2023
1 parent 959e081 commit ec26b0e
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 13 deletions.
1 change: 1 addition & 0 deletions cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const configureNextcloud = async function(branch = 'master') {
// Enable the app and give status
await runExec(container, ['php', 'occ', 'app:enable', '--force', 'viewer'], true)
await runExec(container, ['php', 'occ', 'app:enable', 'groupfolders', '--force'], true)
await runExec(container, ['php', 'occ', 'app:enable', 'files_trashbin', '--force'], true)
// await runExec(container, ['php', 'occ', 'app:list'], true)

console.log('└─ Nextcloud is now ready to use 🎉')
Expand Down
116 changes: 107 additions & 9 deletions cypress/e2e/groupfolders.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
*
*/
import {
addACLManagerUser,
addUserToGroup,
createGroup,
createGroupFolder,
deleteGroupFolder,
enableACLPermissions,
setACLPermissions,
PERMISSION_DELETE,
PERMISSION_READ,
PERMISSION_WRITE,
} from './groupfoldersUtils'
Expand All @@ -32,8 +36,10 @@ import { randHash } from '../utils'

import type { User } from '@nextcloud/cypress'

describe('Manage groupfolders', () => {
let user: User
describe('Groupfolders ACLs and trashbin behavior', () => {
let user1: User
let user2: User
let managerUser: User
let groupFolderId: string
let groupName: string
let groupFolderName: string
Expand All @@ -44,16 +50,24 @@ describe('Manage groupfolders', () => {

cy.createRandomUser()
.then(_user => {
user = _user
cy.login(user)
user1 = _user
})
cy.createRandomUser()
.then(_user => {
user2 = _user
})
cy.createRandomUser()
.then(_user => {
managerUser = _user

createGroup(groupName)
.then(() => {
addUserToGroup(groupName, user.userId)
createGroupFolder(groupFolderName, groupName, [PERMISSION_READ, PERMISSION_WRITE])
addUserToGroup(groupName, user1.userId)
addUserToGroup(groupName, user2.userId)
addUserToGroup(groupName, managerUser.userId)
createGroupFolder(groupFolderName, groupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])
.then(_groupFolderId => {
groupFolderId = _groupFolderId
cy.visit('/apps/files')
})
})
})
Expand All @@ -65,7 +79,91 @@ describe('Manage groupfolders', () => {
}
})

it('Visite the group folder', () => {
return true
it('Configure ACL manager', () => {
enableACLPermissions(groupFolderId)
addACLManagerUser(groupFolderId,managerUser.userId)
})

it('Visit the group folder as user1', () => {
cy.login(user1)
cy.visit('/apps/files')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).should('be.visible')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).click()
})

it('Create two subfolders and a file as manager', () => {
cy.login(managerUser)
cy.mkdir(managerUser, `/${groupFolderName}/subfolder1`)
cy.mkdir(managerUser, `/${groupFolderName}/subfolder1/subfolder2`)
cy.uploadContent(managerUser, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/subfolder1/subfolder2/file.txt`)
})

it('Set ACL permissions', () => {
setACLPermissions(groupFolderId, '/subfolder1', [`+${PERMISSION_READ}`,`-${PERMISSION_WRITE}`], undefined, user1.userId)
setACLPermissions(groupFolderId, '/subfolder1', [`-${PERMISSION_READ}`], undefined, user2.userId)
})

it('User1 has access', () => {
cy.login(user1)
cy.visit('/apps/files')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder1"]`).should('be.visible')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder1"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder2"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="file.txt"]`).should('be.visible')
})

it('User2 has no access', () => {
cy.login(user2)
cy.visit('/apps/files')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder1"]`).should('not.exist')
})

it('Delete file.txt', () => {
cy.login(managerUser)
cy.visit('/apps/files')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder1"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder2"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="file.txt"] [data-cy-files-list-row-actions]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).scrollIntoView()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).click()
})

it('User1 sees it in trash', () => {
cy.login(user1)
cy.visit('/apps/files/trashbin')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="file.txt.d"]`).should('be.visible')
})

it('User2 does not', () => {
cy.login(user2)
cy.visit('/apps/files/trashbin')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="file.txt.d"]`).should('not.exist')
})

it('Rename subfolder2', () => {
cy.login(managerUser)
cy.visit('/apps/files')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${groupFolderName}"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder1"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder2"] [data-cy-files-list-row-actions]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="rename"]`).scrollIntoView()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="rename"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder2"] [class="files-list__row-rename"] [class="input-field__input"]`).type('subfolder2renamed{enter}')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="subfolder2renamed"]`).should('be.visible')
})

it('User1 still sees it in trash', () => {
cy.login(user1)
cy.visit('/apps/files/trashbin')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="file.txt.d"]`).should('be.visible')
})

it('User2 still does not', () => {
cy.login(user2)
cy.visit('/apps/files/trashbin')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="file.txt.d"]`).should('not.exist')
})
})
6 changes: 3 additions & 3 deletions cypress/e2e/groupfoldersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function disableACLPermissions(groupFolderId: string) {
return cy.runOccCommand(`groupfolders:permissions ${groupFolderId} --disable`)
}

export function addACLManager(groupFolderId: string, groupOrUserName: string) {
return cy.runOccCommand(`groupfolders:permissions ${groupFolderId} --manage-add ${groupOrUserName}`)
export function addACLManagerUser(groupFolderId: string, userName: string) {
return cy.runOccCommand(`groupfolders:permissions ${groupFolderId} --manage-add --user ${userName}`)
}

export function removeACLManager(groupFolderId: string, groupOrUserName: string) {
Expand All @@ -67,7 +67,7 @@ export function setACLPermissions(
userId?: string,
) {
const target = groupId !== undefined ? `--group ${groupId}` : `--user ${userId}`
return cy.runOccCommand(`groupfolders:permissions ${groupFolderId} ${path} ${aclPermissions} ${target}`)
return cy.runOccCommand(`groupfolders:permissions ${groupFolderId} ${path} ${target} -- ${aclPermissions.join(' ')}`)
}

export function deleteGroupFolder(groupFolderId: string) {
Expand Down
32 changes: 31 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ declare global {
*/
uploadContent(user: User, content: Blob, mimeType: string, target: string): Cypress.Chainable<void>,

/**
* Create a new directory
* **Warning**: Using this function will reset the previous session
*/
mkdir(user: User, target: string): Cypress.Chainable<void>,

/**
* Run an occ command in the docker container.
*/
Expand All @@ -56,6 +62,30 @@ declare global {
const url = (Cypress.config('baseUrl') || '').replace(/\/index.php\/?$/g, '')
Cypress.env('baseUrl', url)


Cypress.Commands.add('mkdir', (user: User, target: string) => {
// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.clearCookies()
.then({timeout:8000}, async () => {
try {
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
const filePath = target.split('/').map(encodeURIComponent).join('/')
const response = await axios({
url: `${rootPath}${filePath}`,
method: 'MKCOL',
auth: {
username: user.userId,
password: user.password,
},
})
cy.log(`Created directory ${target}`, response)
} catch (error) {
cy.log('error', error)
throw new Error('Unable to process fixture')
}
})
})

/**
* cy.uploadedFile - uploads a file from the fixtures folder
* TODO: standardise in @nextcloud/cypress
Expand Down Expand Up @@ -85,7 +115,7 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima
*/
Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => {
cy.clearCookies()
.then(async () => {
.then({timeout:8000}, async () => {
const fileName = basename(target)

// Process paths
Expand Down

0 comments on commit ec26b0e

Please sign in to comment.