1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// @ts-expect-error The package is currently broken - but works...
import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
import { createLinkShare, getShareUrl, openLinkShareDetails, setupPublicShare, type ShareContext } from './PublicShareUtils.ts'
import { getRowForFile, getRowForFileId, triggerActionForFile, triggerActionForFileId } from '../../files/FilesUtils.ts'
import { zipFileContains } from '../../../support/utils/assertions.ts'
import type { User } from '@nextcloud/cypress'
describe('files_sharing: Public share - downloading files', { testIsolation: true }, () => {
// in general there is no difference except downloading
// as file shares have the source of the share token but a different displayname
describe('file share', () => {
let fileId: number
before(() => {
cy.createRandomUser().then((user) => {
const context: ShareContext = { user }
cy.uploadContent(user, new Blob(['<content>foo</content>']), 'text/plain', '/file.txt')
.then(({ headers }) => { fileId = Number.parseInt(headers['oc-fileid']) })
cy.login(user)
createLinkShare(context, 'file.txt')
.then(() => cy.logout())
.then(() => cy.visit(context.url!))
})
})
it('can download the file', () => {
getRowForFileId(fileId)
.should('be.visible')
getRowForFileId(fileId)
.find('[data-cy-files-list-row-name]')
.should((el) => expect(el.text()).to.match(/file\s*\.txt/)) // extension is sparated so there might be a space between
triggerActionForFileId(fileId, 'download')
// check a file is downloaded with the correct name
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/file.txt`, 'utf-8', { timeout: 15000 })
.should('exist')
.and('have.length.gt', 5)
.and('contain', '<content>foo</content>')
})
})
describe('folder share', () => {
before(() => setupPublicShare())
deleteDownloadsFolderBeforeEach()
beforeEach(() => {
cy.logout()
cy.visit(getShareUrl())
})
it('Can download all files', () => {
getRowForFile('foo.txt').should('be.visible')
cy.get('[data-cy-files-list]').within(() => {
cy.findByRole('checkbox', { name: /Toggle selection for all files/i })
.should('exist')
.check({ force: true })
// see that two files are selected
cy.contains('2 selected').should('be.visible')
// click download
cy.findByRole('button', { name: 'Download (selected)' })
.should('be.visible')
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'foo.txt',
'subfolder/',
'subfolder/bar.txt',
]))
})
})
it('Can download selected files', () => {
getRowForFile('subfolder')
.should('be.visible')
cy.get('[data-cy-files-list]').within(() => {
getRowForFile('subfolder')
.findByRole('checkbox')
.check({ force: true })
// see that two files are selected
cy.contains('1 selected').should('be.visible')
// click download
cy.findByRole('button', { name: 'Download (selected)' })
.should('be.visible')
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'subfolder/',
'subfolder/bar.txt',
]))
})
})
it('Can download folder by action', () => {
getRowForFile('subfolder')
.should('be.visible')
cy.get('[data-cy-files-list]').within(() => {
triggerActionForFile('subfolder', 'download')
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'subfolder/',
'subfolder/bar.txt',
]))
})
})
it('Can download file by action', () => {
getRowForFile('foo.txt')
.should('be.visible')
cy.get('[data-cy-files-list]').within(() => {
triggerActionForFile('foo.txt', 'download')
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
.should('exist')
.and('have.length.gt', 5)
.and('contain', '<content>foo</content>')
})
})
it('Can download file by selection', () => {
getRowForFile('foo.txt')
.should('be.visible')
cy.get('[data-cy-files-list]').within(() => {
getRowForFile('foo.txt')
.findByRole('checkbox')
.check({ force: true })
cy.findByRole('button', { name: 'Download (selected)' })
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
.should('exist')
.and('have.length.gt', 5)
.and('contain', '<content>foo</content>')
})
})
})
describe('download permission - link share', () => {
let context: ShareContext
beforeEach(() => {
cy.createRandomUser().then((user) => {
cy.mkdir(user, '/test')
context = { user }
createLinkShare(context, 'test')
cy.login(context.user)
cy.visit('/apps/files')
})
})
deleteDownloadsFolderBeforeEach()
it('download permission is retained', () => {
getRowForFile('test').should('be.visible')
triggerActionForFile('test', 'details')
openLinkShareDetails(0)
cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('update')
cy.findByRole('checkbox', { name: /hide download/i })
.should('exist')
.and('not.be.checked')
.check({ force: true })
cy.findByRole('checkbox', { name: /hide download/i })
.should('be.checked')
cy.findByRole('button', { name: /update share/i })
.click()
cy.wait('@update')
openLinkShareDetails(0)
cy.findByRole('checkbox', { name: /hide download/i })
.should('be.checked')
cy.reload()
getRowForFile('test').should('be.visible')
triggerActionForFile('test', 'details')
openLinkShareDetails(0)
cy.findByRole('checkbox', { name: /hide download/i })
.should('be.checked')
})
})
describe('download permission - mail share', () => {
let user: User
beforeEach(() => {
cy.createRandomUser().then(($user) => {
user = $user
cy.mkdir(user, '/test')
cy.login(user)
cy.visit('/apps/files')
})
})
it('download permission is retained', () => {
getRowForFile('test').should('be.visible')
triggerActionForFile('test', 'details')
cy.findByRole('combobox', { name: /Enter external recipients/i })
.type('test@example.com')
cy.get('.option[sharetype="4"][user="test@example.com"]')
.parent('li')
.click()
cy.findByRole('button', { name: /advanced settings/i })
.should('be.visible')
.click()
cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('update')
cy.findByRole('checkbox', { name: /hide download/i })
.should('exist')
.and('not.be.checked')
.check({ force: true })
cy.findByRole('button', { name: /save share/i })
.click()
cy.wait('@update')
openLinkShareDetails(1)
cy.findByRole('button', { name: /advanced settings/i })
.click()
cy.findByRole('checkbox', { name: /hide download/i })
.should('exist')
.and('be.checked')
})
})
})
|