2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-01-09 08:14:29 -06:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-06 03:36:54 -05:00
|
|
|
import * as chai from 'chai'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { MockSmtpServer } from '@server/tests/shared'
|
|
|
|
import { wait } from '@shared/core-utils'
|
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-07-16 02:47:51 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
ContactFormCommand,
|
|
|
|
createSingleServer,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2019-01-09 08:14:29 -06:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test contact form', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let server: PeerTubeServer
|
2019-01-09 08:14:29 -06:00
|
|
|
const emails: object[] = []
|
2021-07-06 08:53:25 -05:00
|
|
|
let command: ContactFormCommand
|
2019-01-09 08:14:29 -06:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-25 10:14:49 -05:00
|
|
|
const port = await MockSmtpServer.Instance.collectEmails(emails)
|
2019-01-09 08:14:29 -06:00
|
|
|
|
|
|
|
const overrideConfig = {
|
|
|
|
smtp: {
|
2019-04-25 10:14:49 -05:00
|
|
|
hostname: 'localhost',
|
|
|
|
port
|
2019-01-09 08:14:29 -06:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 02:47:51 -05:00
|
|
|
server = await createSingleServer(1, overrideConfig)
|
2019-01-09 08:14:29 -06:00
|
|
|
await setAccessTokensToServers([ server ])
|
2021-07-06 08:53:25 -05:00
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
command = server.contactForm
|
2019-01-09 08:14:29 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a contact form', async function () {
|
2019-01-10 04:51:25 -06:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-06 08:53:25 -05:00
|
|
|
await command.send({
|
2019-01-09 08:14:29 -06:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
2019-06-21 01:49:35 -05:00
|
|
|
subject: 'my subject',
|
2019-01-09 08:14:29 -06:00
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(server)
|
|
|
|
|
|
|
|
expect(emails).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
const email = emails[0]
|
|
|
|
|
2019-02-14 04:56:23 -06:00
|
|
|
expect(email['from'][0]['address']).equal('test-admin@localhost')
|
2020-05-05 13:22:22 -05:00
|
|
|
expect(email['replyTo'][0]['address']).equal('toto@example.com')
|
2019-04-26 01:50:52 -05:00
|
|
|
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
|
2019-06-21 01:49:35 -05:00
|
|
|
expect(email['subject']).contains('my subject')
|
2019-01-09 08:14:29 -06:00
|
|
|
expect(email['text']).contains('my super message')
|
|
|
|
})
|
|
|
|
|
Fix various typos
Found via `codespell -q 3 -S ./CREDITS.md,./CHANGELOG.md,./client/src/locale,./yarn.lock,./client/yarn.lock -L doubleclick,followings,nd,ot,ro,serie,splitted,tread,truthy`
2022-06-07 08:45:06 -05:00
|
|
|
it('Should not have duplicated email address in text message', async function () {
|
2022-04-15 07:19:07 -05:00
|
|
|
const text = emails[0]['text'] as string
|
|
|
|
|
|
|
|
const matches = text.match(/toto@example.com/g)
|
|
|
|
expect(matches).to.have.lengthOf(1)
|
|
|
|
})
|
|
|
|
|
2019-01-09 08:14:29 -06:00
|
|
|
it('Should not be able to send another contact form because of the anti spam checker', async function () {
|
2021-06-14 09:52:22 -05:00
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
await wait(1000)
|
|
|
|
|
2021-07-06 08:53:25 -05:00
|
|
|
await command.send({
|
2019-01-09 08:14:29 -06:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
2019-06-21 01:49:35 -05:00
|
|
|
subject: 'my subject',
|
2019-01-09 08:14:29 -06:00
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
2021-07-06 08:53:25 -05:00
|
|
|
await command.send({
|
2019-01-09 08:14:29 -06:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto',
|
2019-06-21 01:49:35 -05:00
|
|
|
subject: 'my subject',
|
2020-12-08 14:16:10 -06:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2019-01-09 08:14:29 -06:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to send another contact form after a while', async function () {
|
|
|
|
await wait(1000)
|
|
|
|
|
2021-07-06 08:53:25 -05:00
|
|
|
await command.send({
|
2019-01-09 08:14:29 -06:00
|
|
|
fromEmail: 'toto@example.com',
|
2019-06-21 01:49:35 -05:00
|
|
|
fromName: 'Super toto',
|
|
|
|
subject: 'my subject',
|
|
|
|
body: 'my super message'
|
2019-01-09 08:14:29 -06:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-10 08:56:13 -06:00
|
|
|
it('Should not have the manage preferences link in the email', async function () {
|
|
|
|
const email = emails[0]
|
|
|
|
expect(email['text']).to.not.contain('Manage your notification preferences')
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
2019-01-09 08:14:29 -06:00
|
|
|
MockSmtpServer.Instance.kill()
|
2019-04-24 08:10:37 -05:00
|
|
|
|
|
|
|
await cleanupTests([ server ])
|
2019-01-09 08:14:29 -06:00
|
|
|
})
|
|
|
|
})
|