diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/check-params/contact-form.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/check-params/contact-form.ts')
-rw-r--r-- | server/tests/api/check-params/contact-form.ts | 84 |
1 files changed, 24 insertions, 60 deletions
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index c7f9c1b47..1df9993da 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts | |||
@@ -1,14 +1,12 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils' | |
5 | import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' | 5 | import { ContactFormCommand } from '@shared/extra-utils/server' |
6 | import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' | 6 | import { HttpStatusCode } from '@shared/models' |
7 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
9 | 7 | ||
10 | describe('Test contact form API validators', function () { | 8 | describe('Test contact form API validators', function () { |
11 | let server: ServerInfo | 9 | let server: PeerTubeServer |
12 | const emails: object[] = [] | 10 | const emails: object[] = [] |
13 | const defaultBody = { | 11 | const defaultBody = { |
14 | fromName: 'super name', | 12 | fromName: 'super name', |
@@ -17,6 +15,7 @@ describe('Test contact form API validators', function () { | |||
17 | body: 'Hello, how are you?' | 15 | body: 'Hello, how are you?' |
18 | } | 16 | } |
19 | let emailPort: number | 17 | let emailPort: number |
18 | let command: ContactFormCommand | ||
20 | 19 | ||
21 | // --------------------------------------------------------------- | 20 | // --------------------------------------------------------------- |
22 | 21 | ||
@@ -26,86 +25,51 @@ describe('Test contact form API validators', function () { | |||
26 | emailPort = await MockSmtpServer.Instance.collectEmails(emails) | 25 | emailPort = await MockSmtpServer.Instance.collectEmails(emails) |
27 | 26 | ||
28 | // Email is disabled | 27 | // Email is disabled |
29 | server = await flushAndRunServer(1) | 28 | server = await createSingleServer(1) |
29 | command = server.contactForm | ||
30 | }) | 30 | }) |
31 | 31 | ||
32 | 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 () { |
33 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) | 33 | await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 }) |
34 | }) | 34 | }) |
35 | 35 | ||
36 | 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 () { |
37 | this.timeout(10000) | 37 | this.timeout(10000) |
38 | 38 | ||
39 | killallServers([ server ]) | 39 | await killallServers([ server ]) |
40 | 40 | ||
41 | // Contact form is disabled | 41 | // Contact form is disabled |
42 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) | 42 | await server.run({ smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) |
43 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) | 43 | await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 }) |
44 | }) | 44 | }) |
45 | 45 | ||
46 | 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 () { |
47 | this.timeout(10000) | 47 | this.timeout(10000) |
48 | 48 | ||
49 | killallServers([ server ]) | 49 | await killallServers([ server ]) |
50 | 50 | ||
51 | // Email & contact form enabled | 51 | // Email & contact form enabled |
52 | await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) | 52 | await server.run({ smtp: { hostname: 'localhost', port: emailPort } }) |
53 | 53 | ||
54 | await sendContactForm(immutableAssign(defaultBody, { | 54 | await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
55 | url: server.url, | 55 | await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
56 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | 56 | await command.send({ ...defaultBody, fromEmail: undefined, 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 | })) | ||
69 | }) | 57 | }) |
70 | 58 | ||
71 | it('Should not accept a contact form if from name is invalid', async function () { | 59 | it('Should not accept a contact form if from name is invalid', async function () { |
72 | await sendContactForm(immutableAssign(defaultBody, { | 60 | await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
73 | url: server.url, | 61 | await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
74 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | 62 | await command.send({ ...defaultBody, fromName: undefined, 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 | })) | ||
87 | }) | 63 | }) |
88 | 64 | ||
89 | it('Should not accept a contact form if body is invalid', async function () { | 65 | it('Should not accept a contact form if body is invalid', async function () { |
90 | await sendContactForm(immutableAssign(defaultBody, { | 66 | await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
91 | url: server.url, | 67 | await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
92 | expectedStatus: HttpStatusCode.BAD_REQUEST_400, | 68 | await command.send({ ...defaultBody, body: undefined, 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 | })) | ||
105 | }) | 69 | }) |
106 | 70 | ||
107 | it('Should accept a contact form with the correct parameters', async function () { | 71 | it('Should accept a contact form with the correct parameters', async function () { |
108 | await sendContactForm(immutableAssign(defaultBody, { url: server.url })) | 72 | await command.send(defaultBody) |
109 | }) | 73 | }) |
110 | 74 | ||
111 | after(async function () { | 75 | after(async function () { |