diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/accounts.ts | 3 | ||||
-rw-r--r-- | server/tests/api/check-params/contact-form.ts | 59 | ||||
-rw-r--r-- | server/tests/api/check-params/users.ts | 12 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.ts | 18 |
4 files changed, 72 insertions, 20 deletions
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index c29af7cd7..d1712cff6 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts | |||
@@ -9,6 +9,7 @@ import { | |||
9 | checkBadStartPagination | 9 | checkBadStartPagination |
10 | } from '../../../../shared/extra-utils/requests/check-api-params' | 10 | } from '../../../../shared/extra-utils/requests/check-api-params' |
11 | import { getAccount } from '../../../../shared/extra-utils/users/accounts' | 11 | import { getAccount } from '../../../../shared/extra-utils/users/accounts' |
12 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
12 | 13 | ||
13 | describe('Test accounts API validators', function () { | 14 | describe('Test accounts API validators', function () { |
14 | const path = '/api/v1/accounts/' | 15 | const path = '/api/v1/accounts/' |
@@ -38,7 +39,7 @@ describe('Test accounts API validators', function () { | |||
38 | 39 | ||
39 | describe('When getting an account', function () { | 40 | describe('When getting an account', function () { |
40 | it('Should return 404 with a non existing name', async function () { | 41 | it('Should return 404 with a non existing name', async function () { |
41 | await getAccount(server.url, 'arfaze', 404) | 42 | await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) |
42 | }) | 43 | }) |
43 | }) | 44 | }) |
44 | 45 | ||
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index b2126b9b0..c7f9c1b47 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts | |||
@@ -5,6 +5,7 @@ import 'mocha' | |||
5 | import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' | 5 | import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' |
6 | import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' | 6 | import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' |
7 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | 7 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' |
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | 9 | ||
9 | describe('Test contact form API validators', function () { | 10 | describe('Test contact form API validators', function () { |
10 | let server: ServerInfo | 11 | let server: ServerInfo |
@@ -29,7 +30,7 @@ describe('Test contact form API validators', function () { | |||
29 | }) | 30 | }) |
30 | 31 | ||
31 | it('Should not accept a contact form if emails are disabled', async function () { | 32 | it('Should not accept a contact form if emails are disabled', async function () { |
32 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | 33 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) |
33 | }) | 34 | }) |
34 | 35 | ||
35 | it('Should not accept a contact form if it is disabled in the configuration', async function () { | 36 | it('Should not accept a contact form if it is disabled in the configuration', async function () { |
@@ -39,7 +40,7 @@ describe('Test contact form API validators', function () { | |||
39 | 40 | ||
40 | // Contact form is disabled | 41 | // Contact form is disabled |
41 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) | 42 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) |
42 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | 43 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) |
43 | }) | 44 | }) |
44 | 45 | ||
45 | it('Should not accept a contact form if from email is invalid', async function () { | 46 | it('Should not accept a contact form if from email is invalid', async function () { |
@@ -50,21 +51,57 @@ describe('Test contact form API validators', function () { | |||
50 | // Email & contact form enabled | 51 | // Email & contact form enabled |
51 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) | 52 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) |
52 | 53 | ||
53 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' })) | 54 | await sendContactForm(immutableAssign(defaultBody, { |
54 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' })) | 55 | url: server.url, |
55 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined })) | 56 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, |
57 | fromEmail: 'badEmail' | ||
58 | })) | ||
59 | await sendContactForm(immutableAssign(defaultBody, { | ||
60 | url: server.url, | ||
61 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
62 | fromEmail: 'badEmail@' | ||
63 | })) | ||
64 | await sendContactForm(immutableAssign(defaultBody, { | ||
65 | url: server.url, | ||
66 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
67 | fromEmail: undefined | ||
68 | })) | ||
56 | }) | 69 | }) |
57 | 70 | ||
58 | it('Should not accept a contact form if from name is invalid', async function () { | 71 | it('Should not accept a contact form if from name is invalid', async function () { |
59 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) })) | 72 | await sendContactForm(immutableAssign(defaultBody, { |
60 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' })) | 73 | url: server.url, |
61 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined })) | 74 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, |
75 | fromName: 'name'.repeat(100) | ||
76 | })) | ||
77 | await sendContactForm(immutableAssign(defaultBody, { | ||
78 | url: server.url, | ||
79 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
80 | fromName: '' | ||
81 | })) | ||
82 | await sendContactForm(immutableAssign(defaultBody, { | ||
83 | url: server.url, | ||
84 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
85 | fromName: undefined | ||
86 | })) | ||
62 | }) | 87 | }) |
63 | 88 | ||
64 | it('Should not accept a contact form if body is invalid', async function () { | 89 | it('Should not accept a contact form if body is invalid', async function () { |
65 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) })) | 90 | await sendContactForm(immutableAssign(defaultBody, { |
66 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' })) | 91 | url: server.url, |
67 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined })) | 92 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, |
93 | body: 'body'.repeat(5000) | ||
94 | })) | ||
95 | await sendContactForm(immutableAssign(defaultBody, { | ||
96 | url: server.url, | ||
97 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
98 | body: 'a' | ||
99 | })) | ||
100 | await sendContactForm(immutableAssign(defaultBody, { | ||
101 | url: server.url, | ||
102 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | ||
103 | body: undefined | ||
104 | })) | ||
68 | }) | 105 | }) |
69 | 106 | ||
70 | it('Should accept a contact form with the correct parameters', async function () { | 107 | it('Should accept a contact form with the correct parameters', async function () { |
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 21ace36aa..0a13f5b67 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -1102,7 +1102,7 @@ describe('Test users API validators', function () { | |||
1102 | videoQuota: 42 | 1102 | videoQuota: 42 |
1103 | }) | 1103 | }) |
1104 | 1104 | ||
1105 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) | 1105 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
1106 | }) | 1106 | }) |
1107 | 1107 | ||
1108 | it('Should fail with a registered user having too many videos', async function () { | 1108 | it('Should fail with a registered user having too many videos', async function () { |
@@ -1120,7 +1120,7 @@ describe('Test users API validators', function () { | |||
1120 | await uploadVideo(server.url, userAccessToken, videoAttributes) | 1120 | await uploadVideo(server.url, userAccessToken, videoAttributes) |
1121 | await uploadVideo(server.url, userAccessToken, videoAttributes) | 1121 | await uploadVideo(server.url, userAccessToken, videoAttributes) |
1122 | await uploadVideo(server.url, userAccessToken, videoAttributes) | 1122 | await uploadVideo(server.url, userAccessToken, videoAttributes) |
1123 | await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.FORBIDDEN_403) | 1123 | await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
1124 | }) | 1124 | }) |
1125 | 1125 | ||
1126 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | 1126 | it('Should fail to import with HTTP/Torrent/magnet', async function () { |
@@ -1151,7 +1151,7 @@ describe('Test users API validators', function () { | |||
1151 | }) | 1151 | }) |
1152 | 1152 | ||
1153 | describe('When having a daily video quota', function () { | 1153 | describe('When having a daily video quota', function () { |
1154 | it('Should fail with a user having too many videos', async function () { | 1154 | it('Should fail with a user having too many videos daily', async function () { |
1155 | await updateUser({ | 1155 | await updateUser({ |
1156 | url: server.url, | 1156 | url: server.url, |
1157 | userId: rootId, | 1157 | userId: rootId, |
@@ -1159,7 +1159,7 @@ describe('Test users API validators', function () { | |||
1159 | videoQuotaDaily: 42 | 1159 | videoQuotaDaily: 42 |
1160 | }) | 1160 | }) |
1161 | 1161 | ||
1162 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) | 1162 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
1163 | }) | 1163 | }) |
1164 | }) | 1164 | }) |
1165 | 1165 | ||
@@ -1173,7 +1173,7 @@ describe('Test users API validators', function () { | |||
1173 | videoQuotaDaily: 1024 * 1024 * 1024 | 1173 | videoQuotaDaily: 1024 * 1024 * 1024 |
1174 | }) | 1174 | }) |
1175 | 1175 | ||
1176 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) | 1176 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
1177 | }) | 1177 | }) |
1178 | 1178 | ||
1179 | it('Should fail if exceeding daily quota', async function () { | 1179 | it('Should fail if exceeding daily quota', async function () { |
@@ -1185,7 +1185,7 @@ describe('Test users API validators', function () { | |||
1185 | videoQuotaDaily: 42 | 1185 | videoQuotaDaily: 42 |
1186 | }) | 1186 | }) |
1187 | 1187 | ||
1188 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) | 1188 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413) |
1189 | }) | 1189 | }) |
1190 | }) | 1190 | }) |
1191 | 1191 | ||
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index d60546917..5faba82c4 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts | |||
@@ -348,12 +348,26 @@ describe('Test videos API validator', function () { | |||
348 | let attaches = { | 348 | let attaches = { |
349 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') | 349 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') |
350 | } | 350 | } |
351 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 351 | await makeUploadRequest({ |
352 | url: server.url, | ||
353 | path: path + '/upload', | ||
354 | token: server.accessToken, | ||
355 | fields, | ||
356 | attaches, | ||
357 | statusCodeExpected: HttpStatusCode.UNPROCESSABLE_ENTITY_422 | ||
358 | }) | ||
352 | 359 | ||
353 | attaches = { | 360 | attaches = { |
354 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') | 361 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') |
355 | } | 362 | } |
356 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 363 | await makeUploadRequest({ |
364 | url: server.url, | ||
365 | path: path + '/upload', | ||
366 | token: server.accessToken, | ||
367 | fields, | ||
368 | attaches, | ||
369 | statusCodeExpected: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 | ||
370 | }) | ||
357 | }) | 371 | }) |
358 | 372 | ||
359 | it('Should fail with an incorrect thumbnail file', async function () { | 373 | it('Should fail with an incorrect thumbnail file', async function () { |