limit_to_same_group.cy.ts 3.6 KB

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