diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/config.ts | 3 | ||||
-rw-r--r-- | server/tests/api/check-params/contact-form.ts | 92 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 2 |
3 files changed, 96 insertions, 1 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index b7bf41b58..4038ecbf0 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -48,6 +48,9 @@ describe('Test config API validators', function () { | |||
48 | admin: { | 48 | admin: { |
49 | email: 'superadmin1@example.com' | 49 | email: 'superadmin1@example.com' |
50 | }, | 50 | }, |
51 | contactForm: { | ||
52 | enabled: false | ||
53 | }, | ||
51 | user: { | 54 | user: { |
52 | videoQuota: 5242881, | 55 | videoQuota: 5242881, |
53 | videoQuotaDaily: 318742 | 56 | videoQuotaDaily: 318742 |
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts new file mode 100644 index 000000000..2407ac0b5 --- /dev/null +++ b/server/tests/api/check-params/contact-form.ts | |||
@@ -0,0 +1,92 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | flushTests, | ||
7 | immutableAssign, | ||
8 | killallServers, | ||
9 | reRunServer, | ||
10 | runServer, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers | ||
13 | } from '../../../../shared/utils' | ||
14 | import { | ||
15 | checkBadCountPagination, | ||
16 | checkBadSortPagination, | ||
17 | checkBadStartPagination | ||
18 | } from '../../../../shared/utils/requests/check-api-params' | ||
19 | import { getAccount } from '../../../../shared/utils/users/accounts' | ||
20 | import { sendContactForm } from '../../../../shared/utils/server/contact-form' | ||
21 | import { MockSmtpServer } from '../../../../shared/utils/miscs/email' | ||
22 | |||
23 | describe('Test contact form API validators', function () { | ||
24 | let server: ServerInfo | ||
25 | const emails: object[] = [] | ||
26 | const defaultBody = { | ||
27 | fromName: 'super name', | ||
28 | fromEmail: 'toto@example.com', | ||
29 | body: 'Hello, how are you?' | ||
30 | } | ||
31 | |||
32 | // --------------------------------------------------------------- | ||
33 | |||
34 | before(async function () { | ||
35 | this.timeout(60000) | ||
36 | |||
37 | await flushTests() | ||
38 | await MockSmtpServer.Instance.collectEmails(emails) | ||
39 | |||
40 | // Email is disabled | ||
41 | server = await runServer(1) | ||
42 | }) | ||
43 | |||
44 | it('Should not accept a contact form if emails are disabled', async function () { | ||
45 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | ||
46 | }) | ||
47 | |||
48 | it('Should not accept a contact form if it is disabled in the configuration', async function () { | ||
49 | killallServers([ server ]) | ||
50 | |||
51 | // Contact form is disabled | ||
52 | await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } }) | ||
53 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | ||
54 | }) | ||
55 | |||
56 | it('Should not accept a contact form if from email is invalid', async function () { | ||
57 | killallServers([ server ]) | ||
58 | |||
59 | // Email & contact form enabled | ||
60 | await reRunServer(server, { smtp: { hostname: 'localhost' } }) | ||
61 | |||
62 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' })) | ||
63 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' })) | ||
64 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined })) | ||
65 | }) | ||
66 | |||
67 | it('Should not accept a contact form if from name is invalid', async function () { | ||
68 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) })) | ||
69 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' })) | ||
70 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined })) | ||
71 | }) | ||
72 | |||
73 | it('Should not accept a contact form if body is invalid', async function () { | ||
74 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) })) | ||
75 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' })) | ||
76 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined })) | ||
77 | }) | ||
78 | |||
79 | it('Should accept a contact form with the correct parameters', async function () { | ||
80 | await sendContactForm(immutableAssign(defaultBody, { url: server.url })) | ||
81 | }) | ||
82 | |||
83 | after(async function () { | ||
84 | MockSmtpServer.Instance.kill() | ||
85 | killallServers([ server ]) | ||
86 | |||
87 | // Keep the logs if the test failed | ||
88 | if (this['ok']) { | ||
89 | await flushTests() | ||
90 | } | ||
91 | }) | ||
92 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 7a181d1d6..77c17036a 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './accounts' | 1 | import './accounts' |
3 | import './blocklist' | 2 | import './blocklist' |
4 | import './config' | 3 | import './config' |
4 | import './contact-form' | ||
5 | import './follows' | 5 | import './follows' |
6 | import './jobs' | 6 | import './jobs' |
7 | import './redundancy' | 7 | import './redundancy' |