version_download.cy.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils'
  6. import type { User } from '@nextcloud/cypress'
  7. import { getRowForFile } from '../files/FilesUtils'
  8. describe('Versions download', () => {
  9. let randomFileName = ''
  10. let user: User
  11. before(() => {
  12. randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
  13. cy.createRandomUser()
  14. .then((_user) => {
  15. user = _user
  16. uploadThreeVersions(user, randomFileName)
  17. cy.login(user)
  18. cy.visit('/apps/files')
  19. openVersionsPanel(randomFileName)
  20. })
  21. })
  22. it('Download versions and assert their content', () => {
  23. assertVersionContent(0, 'v3')
  24. assertVersionContent(1, 'v2')
  25. assertVersionContent(2, 'v1')
  26. })
  27. context('Download versions of shared file', () => {
  28. it('Works with download permission', () => {
  29. setupTestSharedFileFromUser(user, randomFileName, { download: true })
  30. openVersionsPanel(randomFileName)
  31. assertVersionContent(0, 'v3')
  32. assertVersionContent(1, 'v2')
  33. assertVersionContent(2, 'v1')
  34. })
  35. it('Does not show action without download permission', () => {
  36. setupTestSharedFileFromUser(user, randomFileName, { download: false })
  37. openVersionsPanel(randomFileName)
  38. cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
  39. cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="download"]').should('not.exist')
  40. doesNotHaveAction(1, 'download')
  41. doesNotHaveAction(2, 'download')
  42. })
  43. it('Does not work without download permission through direct API access', () => {
  44. let hostname: string
  45. let fileId: string|undefined
  46. let versionId: string|undefined
  47. setupTestSharedFileFromUser(user, randomFileName, { download: false })
  48. .then(recipient => {
  49. openVersionsPanel(randomFileName)
  50. cy.url().then(url => { hostname = new URL(url).hostname })
  51. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  52. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  53. cy.then(() => {
  54. cy.logout()
  55. cy.request({
  56. auth: { user: recipient.userId, pass: recipient.password },
  57. headers: {
  58. cookie: '',
  59. },
  60. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  61. failOnStatusCode: false,
  62. })
  63. .then(({ status }) => {
  64. expect(status).to.equal(403)
  65. })
  66. })
  67. })
  68. })
  69. })
  70. })