Skip to content

Cypress: Upload of file sometimes fails with 401 #4317

@juliusknorr

Description

@juliusknorr

I seen this occasionally on random tests, though I'm not sure how this could happen. Maybe the individual requests are not properly waited for so it is a timing issue?

Happens on PUT/MKCOL, after CSRF token should already have been obtained.

Screenshot 2023-06-20 at 08 22 30 Screenshot 2023-06-20 at 08 23 33
Screenshot 2023-06-20 at 08 31 51

// Init user
cy.createUser(user)
cy.login(user)
// Upload test files
;(files || []).forEach(file => {
cy.uploadFile(file, 'text/markdown')
})

return cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const file = new File([blob], fileName, { type: mimeType })
if (typeof target !== 'undefined') {
fileName = target
}
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return axios.put(`${url}/remote.php/webdav/${fileName}`, file, {
headers: {
requesttoken,
'Content-Type': mimeType,
},
}).then(response => {
const fileId = Number(
response.headers['oc-fileid']?.split('oc')?.[0]
)
cy.log(`Uploaded ${fileName}`,
response.status,
{ fileId }
)
return fileId
})
})
})

const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(auth.user)}`
const dirPath = target.split('/').map(encodeURIComponent).join('/')
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return axios.request(`${rootPath}/${dirPath}`, {
method: 'MKCOL',
auth,
headers: {
requesttoken,
},
})
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtestsIf you write them we ♥ you

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions