2020-01-31 15:56:52 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-01-09 14:14:29 +00:00
|
|
|
|
2021-07-06 08:36:54 +00:00
|
|
|
import * as chai from 'chai'
|
2021-12-17 10:58:15 +00:00
|
|
|
import { MockSmtpServer } from '@server/tests/shared'
|
|
|
|
import { wait } from '@shared/core-utils'
|
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-07-16 07:47:51 +00:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
ContactFormCommand,
|
|
|
|
createSingleServer,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
2021-12-17 08:29:23 +00:00
|
|
|
} from '@shared/server-commands'
|
2019-01-09 14:14:29 +00:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test contact form', function () {
|
2021-07-16 07:47:51 +00:00
|
|
|
let server: PeerTubeServer
|
2019-01-09 14:14:29 +00:00
|
|
|
const emails: object[] = []
|
2021-07-06 13:53:25 +00:00
|
|
|
let command: ContactFormCommand
|
2019-01-09 14:14:29 +00:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-25 15:14:49 +00:00
|
|
|
const port = await MockSmtpServer.Instance.collectEmails(emails)
|
2019-01-09 14:14:29 +00:00
|
|
|
|
|
|
|
const overrideConfig = {
|
|
|
|
smtp: {
|
2019-04-25 15:14:49 +00:00
|
|
|
hostname: 'localhost',
|
|
|
|
port
|
2019-01-09 14:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 07:47:51 +00:00
|
|
|
server = await createSingleServer(1, overrideConfig)
|
2019-01-09 14:14:29 +00:00
|
|
|
await setAccessTokensToServers([ server ])
|
2021-07-06 13:53:25 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
command = server.contactForm
|
2019-01-09 14:14:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a contact form', async function () {
|
2019-01-10 10:51:25 +00:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-06 13:53:25 +00:00
|
|
|
await command.send({
|
2019-01-09 14:14:29 +00:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
2019-06-21 06:49:35 +00:00
|
|
|
subject: 'my subject',
|
2019-01-09 14:14:29 +00:00
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(server)
|
|
|
|
|
|
|
|
expect(emails).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
const email = emails[0]
|
|
|
|
|
2019-02-14 10:56:23 +00:00
|
|
|
expect(email['from'][0]['address']).equal('test-admin@localhost')
|
2020-05-05 18:22:22 +00:00
|
|
|
expect(email['replyTo'][0]['address']).equal('toto@example.com')
|
2019-04-26 06:50:52 +00:00
|
|
|
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
|
2019-06-21 06:49:35 +00:00
|
|
|
expect(email['subject']).contains('my subject')
|
2019-01-09 14:14:29 +00: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 13:45:06 +00:00
|
|
|
it('Should not have duplicated email address in text message', async function () {
|
2022-04-15 12:19:07 +00: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 14:14:29 +00:00
|
|
|
it('Should not be able to send another contact form because of the anti spam checker', async function () {
|
2021-06-14 14:52:22 +00:00
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
await wait(1000)
|
|
|
|
|
2021-07-06 13:53:25 +00:00
|
|
|
await command.send({
|
2019-01-09 14:14:29 +00:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
2019-06-21 06:49:35 +00:00
|
|
|
subject: 'my subject',
|
2019-01-09 14:14:29 +00:00
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
2021-07-06 13:53:25 +00:00
|
|
|
await command.send({
|
2019-01-09 14:14:29 +00:00
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto',
|
2019-06-21 06:49:35 +00:00
|
|
|
subject: 'my subject',
|
2020-12-08 20:16:10 +00:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2019-01-09 14:14:29 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to send another contact form after a while', async function () {
|
|
|
|
await wait(1000)
|
|
|
|
|
2021-07-06 13:53:25 +00:00
|
|
|
await command.send({
|
2019-01-09 14:14:29 +00:00
|
|
|
fromEmail: 'toto@example.com',
|
2019-06-21 06:49:35 +00:00
|
|
|
fromName: 'Super toto',
|
|
|
|
subject: 'my subject',
|
|
|
|
body: 'my super message'
|
2019-01-09 14:14:29 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-10 14:56:13 +00: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 13:10:37 +00:00
|
|
|
after(async function () {
|
2019-01-09 14:14:29 +00:00
|
|
|
MockSmtpServer.Instance.kill()
|
2019-04-24 13:10:37 +00:00
|
|
|
|
|
|
|
await cleanupTests([ server ])
|
2019-01-09 14:14:29 +00:00
|
|
|
})
|
|
|
|
})
|