1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
import { HttpStatusCode } from '@peertube/peertube-models'
import {
cleanupTests,
createMultipleServers,
doubleFollow,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@peertube/peertube-server-commands'
describe('Official plugin Akismet', function () {
let servers: PeerTubeServer[]
let videoUUID: string
before(async function () {
this.timeout(30000)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
await servers[0].plugins.install({
npmName: 'peertube-plugin-akismet'
})
if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')
await servers[0].plugins.updateSettings({
npmName: 'peertube-plugin-akismet',
settings: {
'akismet-api-key': process.env.AKISMET_KEY
}
})
await doubleFollow(servers[0], servers[1])
})
describe('Local threads/replies', function () {
before(async function () {
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
videoUUID = uuid
})
it('Should not detect a thread as spam', async function () {
await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
})
it('Should not detect a reply as spam', async function () {
await servers[0].comments.addReplyToLastThread({ text: 'reply' })
})
it('Should detect a thread as spam', async function () {
await servers[0].comments.createThread({
videoId: videoUUID,
text: 'akismet-guaranteed-spam',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
it('Should detect a thread as spam', async function () {
await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
await servers[0].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
})
describe('Remote threads/replies', function () {
before(async function () {
this.timeout(60000)
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
videoUUID = uuid
await waitJobs(servers)
})
it('Should not detect a thread as spam', async function () {
this.timeout(30000)
await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 1' })
await waitJobs(servers)
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
expect(data).to.have.lengthOf(1)
})
it('Should not detect a reply as spam', async function () {
this.timeout(30000)
await servers[1].comments.addReplyToLastThread({ text: 'I agree with you' })
await waitJobs(servers)
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
expect(data).to.have.lengthOf(1)
const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: data[0].id })
expect(tree.children).to.have.lengthOf(1)
})
it('Should detect a thread as spam', async function () {
this.timeout(30000)
await servers[1].comments.createThread({ videoId: videoUUID, text: 'akismet-guaranteed-spam' })
await waitJobs(servers)
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
expect(data).to.have.lengthOf(1)
})
it('Should detect a thread as spam', async function () {
this.timeout(30000)
await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' })
await waitJobs(servers)
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
expect(data).to.have.lengthOf(1)
const thread = data[0]
const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id })
expect(tree.children).to.have.lengthOf(1)
})
})
describe('Signup', function () {
before(async function () {
await servers[0].config.updateExistingSubConfig({
newConfig: {
signup: {
enabled: true
}
}
})
})
it('Should allow signup', async function () {
await servers[0].registrations.register({
username: 'user1',
displayName: 'user 1'
})
})
it('Should detect a signup as SPAM', async function () {
await servers[0].registrations.register({
username: 'user2',
displayName: 'user 2',
email: 'akismet-guaranteed-spam@example.com',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
})
after(async function () {
await cleanupTests(servers)
})
})
|