Skip to content

Commit b386acf

Browse files
committed
Add test cases for tampered content length on uploads
1 parent d79c3f0 commit b386acf

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

test/api/fileUploadSpec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,15 @@ describe('/file-upload', () => {
160160
return frisby.post(URL + '/file-upload', { headers: { 'Content-Type': form.getHeaders()['content-type'] }, body: form })
161161
.expect('status', 204)
162162
})
163+
164+
it('POST valid file with tampered content length', () => {
165+
const file = path.resolve(__dirname, '../files/validSizeAndTypeForClient.pdf')
166+
const form = frisby.formData()
167+
form.append('file', fs.createReadStream(file))
168+
169+
// @ts-expect-error FIXME form.getHeaders() is not found
170+
return frisby.post(URL + '/file-upload', { headers: { 'Content-Type': form.getHeaders()['content-type'], 'Content-Length': 42 }, body: form })
171+
.expect('status', 500)
172+
.expect('bodyContains', 'Unexpected end of form')
173+
})
163174
})

test/api/profileImageUploadSpec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,33 @@ describe('/profile/image/url', () => {
151151
.expect('header', 'content-type', /text\/html/)
152152
.expect('bodyContains', 'Error: Blocked illegal activity')
153153
})
154+
155+
it('POST valid image with tampered content length', () => {
156+
const file = path.resolve(__dirname, '../files/validProfileImage.jpg')
157+
const form = frisby.formData()
158+
form.append('file', fs.createReadStream(file))
159+
160+
return frisby.post(`${REST_URL}/user/login`, {
161+
headers: jsonHeader,
162+
body: {
163+
email: `jim@${config.get<string>('application.domain')}`,
164+
password: 'ncc-1701'
165+
}
166+
})
167+
.expect('status', 200)
168+
.then(({ json: jsonLogin }) => {
169+
return frisby.post(`${URL}/profile/image/file`, {
170+
headers: {
171+
Cookie: `token=${jsonLogin.authentication.token}`,
172+
// @ts-expect-error FIXME form.getHeaders() is not found
173+
'Content-Type': form.getHeaders()['content-type'],
174+
'Content-Length': 42
175+
},
176+
body: form,
177+
redirect: 'manual'
178+
})
179+
.expect('status', 500)
180+
.expect('bodyContains', 'Unexpected end of form')
181+
})
182+
})
154183
})

0 commit comments

Comments
 (0)