diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-09 15:14:29 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-10 11:32:37 +0100 |
commit | a4101923e699e49ceb9ff36e971c75417fafc9f0 (patch) | |
tree | c098a87ac5a85e1bc7454facbb59ecbd6c7dac82 /server/tests/api | |
parent | 8d00889b6038c38d9c86cbeca88a9f3c23962c48 (diff) | |
download | PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.gz PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.zst PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.zip |
Implement contact form on server side
Diffstat (limited to 'server/tests/api')
-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 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 19 | ||||
-rw-r--r-- | server/tests/api/server/contact-form.ts | 84 | ||||
-rw-r--r-- | server/tests/api/server/handle-down.ts | 11 | ||||
-rw-r--r-- | server/tests/api/server/index.ts | 1 |
7 files changed, 205 insertions, 7 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' |
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 4c163d47d..bebfc7398 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -33,14 +33,20 @@ function checkInitialConfig (data: CustomConfig) { | |||
33 | expect(data.instance.defaultNSFWPolicy).to.equal('display') | 33 | expect(data.instance.defaultNSFWPolicy).to.equal('display') |
34 | expect(data.instance.customizations.css).to.be.empty | 34 | expect(data.instance.customizations.css).to.be.empty |
35 | expect(data.instance.customizations.javascript).to.be.empty | 35 | expect(data.instance.customizations.javascript).to.be.empty |
36 | |||
36 | expect(data.services.twitter.username).to.equal('@Chocobozzz') | 37 | expect(data.services.twitter.username).to.equal('@Chocobozzz') |
37 | expect(data.services.twitter.whitelisted).to.be.false | 38 | expect(data.services.twitter.whitelisted).to.be.false |
39 | |||
38 | expect(data.cache.previews.size).to.equal(1) | 40 | expect(data.cache.previews.size).to.equal(1) |
39 | expect(data.cache.captions.size).to.equal(1) | 41 | expect(data.cache.captions.size).to.equal(1) |
42 | |||
40 | expect(data.signup.enabled).to.be.true | 43 | expect(data.signup.enabled).to.be.true |
41 | expect(data.signup.limit).to.equal(4) | 44 | expect(data.signup.limit).to.equal(4) |
42 | expect(data.signup.requiresEmailVerification).to.be.false | 45 | expect(data.signup.requiresEmailVerification).to.be.false |
46 | |||
43 | expect(data.admin.email).to.equal('admin1@example.com') | 47 | expect(data.admin.email).to.equal('admin1@example.com') |
48 | expect(data.contactForm.enabled).to.be.true | ||
49 | |||
44 | expect(data.user.videoQuota).to.equal(5242880) | 50 | expect(data.user.videoQuota).to.equal(5242880) |
45 | expect(data.user.videoQuotaDaily).to.equal(-1) | 51 | expect(data.user.videoQuotaDaily).to.equal(-1) |
46 | expect(data.transcoding.enabled).to.be.false | 52 | expect(data.transcoding.enabled).to.be.false |
@@ -64,16 +70,23 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
64 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') | 70 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') |
65 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') | 71 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') |
66 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') | 72 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') |
73 | |||
67 | expect(data.services.twitter.username).to.equal('@Kuja') | 74 | expect(data.services.twitter.username).to.equal('@Kuja') |
68 | expect(data.services.twitter.whitelisted).to.be.true | 75 | expect(data.services.twitter.whitelisted).to.be.true |
76 | |||
69 | expect(data.cache.previews.size).to.equal(2) | 77 | expect(data.cache.previews.size).to.equal(2) |
70 | expect(data.cache.captions.size).to.equal(3) | 78 | expect(data.cache.captions.size).to.equal(3) |
79 | |||
71 | expect(data.signup.enabled).to.be.false | 80 | expect(data.signup.enabled).to.be.false |
72 | expect(data.signup.limit).to.equal(5) | 81 | expect(data.signup.limit).to.equal(5) |
73 | expect(data.signup.requiresEmailVerification).to.be.true | 82 | expect(data.signup.requiresEmailVerification).to.be.true |
83 | |||
74 | expect(data.admin.email).to.equal('superadmin1@example.com') | 84 | expect(data.admin.email).to.equal('superadmin1@example.com') |
85 | expect(data.contactForm.enabled).to.be.false | ||
86 | |||
75 | expect(data.user.videoQuota).to.equal(5242881) | 87 | expect(data.user.videoQuota).to.equal(5242881) |
76 | expect(data.user.videoQuotaDaily).to.equal(318742) | 88 | expect(data.user.videoQuotaDaily).to.equal(318742) |
89 | |||
77 | expect(data.transcoding.enabled).to.be.true | 90 | expect(data.transcoding.enabled).to.be.true |
78 | expect(data.transcoding.threads).to.equal(1) | 91 | expect(data.transcoding.threads).to.equal(1) |
79 | expect(data.transcoding.allowAdditionalExtensions).to.be.true | 92 | expect(data.transcoding.allowAdditionalExtensions).to.be.true |
@@ -82,6 +95,7 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
82 | expect(data.transcoding.resolutions['480p']).to.be.true | 95 | expect(data.transcoding.resolutions['480p']).to.be.true |
83 | expect(data.transcoding.resolutions['720p']).to.be.false | 96 | expect(data.transcoding.resolutions['720p']).to.be.false |
84 | expect(data.transcoding.resolutions['1080p']).to.be.false | 97 | expect(data.transcoding.resolutions['1080p']).to.be.false |
98 | |||
85 | expect(data.import.videos.http.enabled).to.be.false | 99 | expect(data.import.videos.http.enabled).to.be.false |
86 | expect(data.import.videos.torrent.enabled).to.be.false | 100 | expect(data.import.videos.torrent.enabled).to.be.false |
87 | } | 101 | } |
@@ -127,6 +141,8 @@ describe('Test config', function () { | |||
127 | expect(data.video.file.extensions).to.contain('.mp4') | 141 | expect(data.video.file.extensions).to.contain('.mp4') |
128 | expect(data.video.file.extensions).to.contain('.webm') | 142 | expect(data.video.file.extensions).to.contain('.webm') |
129 | expect(data.video.file.extensions).to.contain('.ogv') | 143 | expect(data.video.file.extensions).to.contain('.ogv') |
144 | |||
145 | expect(data.contactForm.enabled).to.be.true | ||
130 | }) | 146 | }) |
131 | 147 | ||
132 | it('Should get the customized configuration', async function () { | 148 | it('Should get the customized configuration', async function () { |
@@ -172,6 +188,9 @@ describe('Test config', function () { | |||
172 | admin: { | 188 | admin: { |
173 | email: 'superadmin1@example.com' | 189 | email: 'superadmin1@example.com' |
174 | }, | 190 | }, |
191 | contactForm: { | ||
192 | enabled: false | ||
193 | }, | ||
175 | user: { | 194 | user: { |
176 | videoQuota: 5242881, | 195 | videoQuota: 5242881, |
177 | videoQuotaDaily: 318742 | 196 | videoQuotaDaily: 318742 |
diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts new file mode 100644 index 000000000..1a165331b --- /dev/null +++ b/server/tests/api/server/contact-form.ts | |||
@@ -0,0 +1,84 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/utils' | ||
6 | import { MockSmtpServer } from '../../../../shared/utils/miscs/email' | ||
7 | import { waitJobs } from '../../../../shared/utils/server/jobs' | ||
8 | import { sendContactForm } from '../../../../shared/utils/server/contact-form' | ||
9 | |||
10 | const expect = chai.expect | ||
11 | |||
12 | describe('Test contact form', function () { | ||
13 | let server: ServerInfo | ||
14 | const emails: object[] = [] | ||
15 | |||
16 | before(async function () { | ||
17 | this.timeout(30000) | ||
18 | |||
19 | await MockSmtpServer.Instance.collectEmails(emails) | ||
20 | |||
21 | await flushTests() | ||
22 | |||
23 | const overrideConfig = { | ||
24 | smtp: { | ||
25 | hostname: 'localhost' | ||
26 | } | ||
27 | } | ||
28 | server = await runServer(1, overrideConfig) | ||
29 | await setAccessTokensToServers([ server ]) | ||
30 | }) | ||
31 | |||
32 | it('Should send a contact form', async function () { | ||
33 | await sendContactForm({ | ||
34 | url: server.url, | ||
35 | fromEmail: 'toto@example.com', | ||
36 | body: 'my super message', | ||
37 | fromName: 'Super toto' | ||
38 | }) | ||
39 | |||
40 | await waitJobs(server) | ||
41 | |||
42 | expect(emails).to.have.lengthOf(1) | ||
43 | |||
44 | const email = emails[0] | ||
45 | |||
46 | expect(email['from'][0]['address']).equal('toto@example.com') | ||
47 | expect(email['to'][0]['address']).equal('admin1@example.com') | ||
48 | expect(email['subject']).contains('Contact form') | ||
49 | expect(email['text']).contains('my super message') | ||
50 | }) | ||
51 | |||
52 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | ||
53 | await sendContactForm({ | ||
54 | url: server.url, | ||
55 | fromEmail: 'toto@example.com', | ||
56 | body: 'my super message', | ||
57 | fromName: 'Super toto' | ||
58 | }) | ||
59 | |||
60 | await sendContactForm({ | ||
61 | url: server.url, | ||
62 | fromEmail: 'toto@example.com', | ||
63 | body: 'my super message', | ||
64 | fromName: 'Super toto', | ||
65 | expectedStatus: 403 | ||
66 | }) | ||
67 | }) | ||
68 | |||
69 | it('Should be able to send another contact form after a while', async function () { | ||
70 | await wait(1000) | ||
71 | |||
72 | await sendContactForm({ | ||
73 | url: server.url, | ||
74 | fromEmail: 'toto@example.com', | ||
75 | body: 'my super message', | ||
76 | fromName: 'Super toto' | ||
77 | }) | ||
78 | }) | ||
79 | |||
80 | after(async function () { | ||
81 | MockSmtpServer.Instance.kill() | ||
82 | killallServers([ server ]) | ||
83 | }) | ||
84 | }) | ||
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 8e162b69e..cd7baadad 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts | |||
@@ -8,18 +8,17 @@ import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-c | |||
8 | 8 | ||
9 | import { | 9 | import { |
10 | completeVideoCheck, | 10 | completeVideoCheck, |
11 | getVideo, | ||
12 | immutableAssign, | ||
13 | reRunServer, | ||
14 | unfollow, | ||
15 | viewVideo, | ||
16 | flushAndRunMultipleServers, | 11 | flushAndRunMultipleServers, |
12 | getVideo, | ||
17 | getVideosList, | 13 | getVideosList, |
14 | immutableAssign, | ||
18 | killallServers, | 15 | killallServers, |
16 | reRunServer, | ||
19 | ServerInfo, | 17 | ServerInfo, |
20 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
21 | uploadVideo, | 19 | unfollow, |
22 | updateVideo, | 20 | updateVideo, |
21 | uploadVideo, | ||
23 | wait | 22 | wait |
24 | } from '../../../../shared/utils' | 23 | } from '../../../../shared/utils' |
25 | import { follow, getFollowersListPaginationAndSort } from '../../../../shared/utils/server/follows' | 24 | import { follow, getFollowersListPaginationAndSort } from '../../../../shared/utils/server/follows' |
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 6afcab1f9..1f80cc6cf 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import './config' | 1 | import './config' |
2 | import './contact-form' | ||
2 | import './email' | 3 | import './email' |
3 | import './follow-constraints' | 4 | import './follow-constraints' |
4 | import './follows' | 5 | import './follows' |