]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/contact-form.ts
Fix scroll menu on touch devices
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / contact-form.ts
CommitLineData
a4101923
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 flushTests,
7 immutableAssign,
8 killallServers,
9 reRunServer,
210feb6c 10 flushAndRunServer,
a4101923 11 ServerInfo,
7c3b7976 12 setAccessTokensToServers, cleanupTests
94565d52 13} from '../../../../shared/extra-utils'
a4101923
C
14import {
15 checkBadCountPagination,
16 checkBadSortPagination,
17 checkBadStartPagination
94565d52
C
18} from '../../../../shared/extra-utils/requests/check-api-params'
19import { getAccount } from '../../../../shared/extra-utils/users/accounts'
20import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
21import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
a4101923
C
22
23describe('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',
4e9fa5b7 29 subject: 'my subject',
a4101923
C
30 body: 'Hello, how are you?'
31 }
7c3b7976 32 let emailPort: number
a4101923
C
33
34 // ---------------------------------------------------------------
35
36 before(async function () {
37 this.timeout(60000)
38
7c3b7976 39 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
a4101923
C
40
41 // Email is disabled
210feb6c 42 server = await flushAndRunServer(1)
a4101923
C
43 })
44
45 it('Should not accept a contact form if emails are disabled', async function () {
46 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
47 })
48
49 it('Should not accept a contact form if it is disabled in the configuration', async function () {
848f499d
C
50 this.timeout(10000)
51
a4101923
C
52 killallServers([ server ])
53
54 // Contact form is disabled
7c3b7976 55 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
a4101923
C
56 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
57 })
58
59 it('Should not accept a contact form if from email is invalid', async function () {
848f499d
C
60 this.timeout(10000)
61
a4101923
C
62 killallServers([ server ])
63
64 // Email & contact form enabled
7c3b7976 65 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
a4101923
C
66
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
68 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
69 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
70 })
71
72 it('Should not accept a contact form if from name is invalid', async function () {
73 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
74 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
75 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
76 })
77
78 it('Should not accept a contact form if body is invalid', async function () {
79 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
80 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
81 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
82 })
83
84 it('Should accept a contact form with the correct parameters', async function () {
85 await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
86 })
87
7c3b7976 88 after(async function () {
a4101923 89 MockSmtpServer.Instance.kill()
7c3b7976 90
8519cc92 91 await cleanupTests([ server ])
a4101923
C
92 })
93})