version_download.cy.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
  3. *
  4. * @author Louis Chmn <louis@chmn.me>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { assertVersionContent, doesNotHaveAction, openVersionsPanel, setupTestSharedFileFromUser, uploadThreeVersions } from './filesVersionsUtils'
  23. import type { User } from '@nextcloud/cypress'
  24. import { getRowForFile } from '../files/FilesUtils'
  25. describe('Versions download', () => {
  26. let randomFileName = ''
  27. let user: User
  28. before(() => {
  29. randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
  30. cy.createRandomUser()
  31. .then((_user) => {
  32. user = _user
  33. uploadThreeVersions(user, randomFileName)
  34. cy.login(user)
  35. cy.visit('/apps/files')
  36. openVersionsPanel(randomFileName)
  37. })
  38. })
  39. it('Download versions and assert their content', () => {
  40. assertVersionContent(randomFileName, 0, 'v3')
  41. assertVersionContent(randomFileName, 1, 'v2')
  42. assertVersionContent(randomFileName, 2, 'v1')
  43. })
  44. context('Download versions of shared file', () => {
  45. it('Works with download permission', () => {
  46. setupTestSharedFileFromUser(user, randomFileName, { download: true })
  47. openVersionsPanel(randomFileName)
  48. assertVersionContent(randomFileName, 0, 'v3')
  49. assertVersionContent(randomFileName, 1, 'v2')
  50. assertVersionContent(randomFileName, 2, 'v1')
  51. })
  52. it('Does not show action without download permission', () => {
  53. setupTestSharedFileFromUser(user, randomFileName, { download: false })
  54. openVersionsPanel(randomFileName)
  55. cy.get('[data-files-versions-version]').eq(0).find('.action-item__menutoggle').should('not.exist')
  56. cy.get('[data-files-versions-version]').eq(0).get('[data-cy-version-action="download"]').should('not.exist')
  57. doesNotHaveAction(1, 'download')
  58. doesNotHaveAction(2, 'download')
  59. })
  60. it('Does not work without download permission through direct API access', () => {
  61. let hostname: string
  62. let fileId: string|undefined
  63. let versionId: string|undefined
  64. setupTestSharedFileFromUser(user, randomFileName, { download: false })
  65. .then(recipient => {
  66. openVersionsPanel(randomFileName)
  67. cy.url().then(url => { hostname = new URL(url).hostname })
  68. getRowForFile(randomFileName).invoke('attr', 'data-cy-files-list-row-fileid').then(_fileId => { fileId = _fileId })
  69. cy.get('[data-files-versions-version]').eq(1).invoke('attr', 'data-files-versions-version').then(_versionId => { versionId = _versionId })
  70. cy.then(() => {
  71. cy.logout()
  72. cy.request({
  73. auth: { user: recipient.userId, pass: recipient.password },
  74. headers: {
  75. cookie: '',
  76. },
  77. url: `http://${hostname}/remote.php/dav/versions/${recipient.userId}/versions/${fileId}/${versionId}`,
  78. failOnStatusCode: false,
  79. })
  80. .then(({ status }) => {
  81. expect(status).to.equal(403)
  82. })
  83. })
  84. })
  85. })
  86. })
  87. })