diff options
Diffstat (limited to 'server/tests/api/check-params/contact-form.ts')
-rw-r--r-- | server/tests/api/check-params/contact-form.ts | 59 |
1 files changed, 48 insertions, 11 deletions
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 () { |