|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { User } from "@nextcloud/cypress" |
| 7 | +import { createShare } from "./FilesSharingUtils.ts" |
| 8 | + |
| 9 | +describe('Limit to sharing to people in the same group', () => { |
| 10 | + let alice: User |
| 11 | + let bob: User |
| 12 | + let randomFileName1 = '' |
| 13 | + let randomFileName2 = '' |
| 14 | + let randomGroupName = '' |
| 15 | + let randomGroupName2 = '' |
| 16 | + let randomGroupName3 = '' |
| 17 | + |
| 18 | + before(() => { |
| 19 | + randomFileName1 = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' |
| 20 | + randomFileName2 = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' |
| 21 | + randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 22 | + randomGroupName2 = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 23 | + randomGroupName3 = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 24 | + |
| 25 | + cy.runOccCommand('config:app:set core shareapi_only_share_with_group_members --value yes') |
| 26 | + |
| 27 | + cy.createRandomUser() |
| 28 | + .then(user => { |
| 29 | + alice = user |
| 30 | + cy.createRandomUser() |
| 31 | + }) |
| 32 | + .then(user => { |
| 33 | + bob = user |
| 34 | + |
| 35 | + cy.runOccCommand(`group:add ${randomGroupName}`) |
| 36 | + cy.runOccCommand(`group:add ${randomGroupName2}`) |
| 37 | + cy.runOccCommand(`group:add ${randomGroupName3}`) |
| 38 | + cy.runOccCommand(`group:adduser ${randomGroupName} ${alice.userId}`) |
| 39 | + cy.runOccCommand(`group:adduser ${randomGroupName} ${bob.userId}`) |
| 40 | + cy.runOccCommand(`group:adduser ${randomGroupName2} ${alice.userId}`) |
| 41 | + cy.runOccCommand(`group:adduser ${randomGroupName2} ${bob.userId}`) |
| 42 | + cy.runOccCommand(`group:adduser ${randomGroupName3} ${bob.userId}`) |
| 43 | + |
| 44 | + cy.uploadContent(alice, new Blob(['share to bob'], { type: 'text/plain' }), 'text/plain', `/${randomFileName1}`) |
| 45 | + cy.uploadContent(bob, new Blob(['share by bob'], { type: 'text/plain' }), 'text/plain', `/${randomFileName2}`) |
| 46 | + |
| 47 | + cy.login(alice) |
| 48 | + cy.visit('/apps/files') |
| 49 | + createShare(randomFileName1, bob.userId) |
| 50 | + cy.login(bob) |
| 51 | + cy.visit('/apps/files') |
| 52 | + createShare(randomFileName2, alice.userId) |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + after(() => { |
| 57 | + cy.runOccCommand('config:app:set core shareapi_only_share_with_group_members --value no') |
| 58 | + }) |
| 59 | + |
| 60 | + it('Alice can see the shared file', () => { |
| 61 | + cy.login(alice) |
| 62 | + cy.visit('/apps/files') |
| 63 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName2}"]`).should('exist') |
| 64 | + }) |
| 65 | + |
| 66 | + it('Bob can see the shared file', () => { |
| 67 | + cy.login(alice) |
| 68 | + cy.visit('/apps/files') |
| 69 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName1}"]`).should('exist') |
| 70 | + }) |
| 71 | + |
| 72 | + context('Bob is removed from the first group', () => { |
| 73 | + before(() => { |
| 74 | + cy.runOccCommand(`group:removeuser ${randomGroupName} ${bob.userId}`) |
| 75 | + }) |
| 76 | + |
| 77 | + it('Alice can see the shared file', () => { |
| 78 | + cy.login(alice) |
| 79 | + cy.visit('/apps/files') |
| 80 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName2}"]`).should('exist') |
| 81 | + }) |
| 82 | + |
| 83 | + it('Bob can see the shared file', () => { |
| 84 | + cy.login(alice) |
| 85 | + cy.visit('/apps/files') |
| 86 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName1}"]`).should('exist') |
| 87 | + }) |
| 88 | + }) |
| 89 | + |
| 90 | + context('Bob is removed from the second group', () => { |
| 91 | + before(() => { |
| 92 | + cy.runOccCommand(`group:removeuser ${randomGroupName2} ${bob.userId}`) |
| 93 | + }) |
| 94 | + |
| 95 | + it('Alice cannot see the shared file', () => { |
| 96 | + cy.login(alice) |
| 97 | + cy.visit('/apps/files') |
| 98 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName2}"]`).should('not.exist') |
| 99 | + }) |
| 100 | + |
| 101 | + it('Bob cannot see the shared file', () => { |
| 102 | + cy.login(alice) |
| 103 | + cy.visit('/apps/files') |
| 104 | + cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${randomFileName1}"]`).should('not.exist') |
| 105 | + }) |
| 106 | + }) |
| 107 | +}) |
0 commit comments