aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-09-23 16:23:06 +0200
committerChocobozzz <me@florianbigard.com>2022-09-26 16:27:06 +0200
commit84e7ff2757b6736df4277fb2c1d48d3ca0a760ae (patch)
treedf30213d777327d9513782ee5d4894473109ff93
parent4f3814808791d8f380e75d152e0e14a01b758b9a (diff)
downloadPeerTube-84e7ff2757b6736df4277fb2c1d48d3ca0a760ae.tar.gz
PeerTube-84e7ff2757b6736df4277fb2c1d48d3ca0a760ae.tar.zst
PeerTube-84e7ff2757b6736df4277fb2c1d48d3ca0a760ae.zip
Test akismet plugin signup
-rw-r--r--server/tests/external-plugins/akismet.ts45
-rw-r--r--shared/server-commands/users/users-command.ts5
2 files changed, 40 insertions, 10 deletions
diff --git a/server/tests/external-plugins/akismet.ts b/server/tests/external-plugins/akismet.ts
index 557fc3daf..974bf0011 100644
--- a/server/tests/external-plugins/akismet.ts
+++ b/server/tests/external-plugins/akismet.ts
@@ -21,7 +21,9 @@ describe('Official plugin Akismet', function () {
21 servers = await createMultipleServers(2) 21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers) 22 await setAccessTokensToServers(servers)
23 23
24 await servers[0].plugins.install({ npmName: 'peertube-plugin-akismet' }) 24 await servers[0].plugins.install({
25 npmName: 'peertube-plugin-akismet'
26 })
25 27
26 if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env') 28 if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')
27 29
@@ -71,6 +73,8 @@ describe('Official plugin Akismet', function () {
71 73
72 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) 74 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
73 videoUUID = uuid 75 videoUUID = uuid
76
77 await waitJobs(servers)
74 }) 78 })
75 79
76 it('Should not detect a thread as spam', async function () { 80 it('Should not detect a thread as spam', async function () {
@@ -109,19 +113,44 @@ describe('Official plugin Akismet', function () {
109 it('Should detect a thread as spam', async function () { 113 it('Should detect a thread as spam', async function () {
110 this.timeout(30000) 114 this.timeout(30000)
111 115
112 await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 2' })
113 await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' }) 116 await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' })
114 await waitJobs(servers) 117 await waitJobs(servers)
115 118
116 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) 119 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
117 expect(data).to.have.lengthOf(2) 120 expect(data).to.have.lengthOf(1)
118 121
119 for (const thread of data) { 122 const thread = data[0]
120 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id }) 123 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id })
121 if (tree.comment.text === 'remote comment 1') continue 124 expect(tree.children).to.have.lengthOf(1)
125 })
126 })
122 127
123 expect(tree.children).to.have.lengthOf(0) 128 describe('Signup', function () {
124 } 129
130 before(async function () {
131 await servers[0].config.updateExistingSubConfig({
132 newConfig: {
133 signup: {
134 enabled: true
135 }
136 }
137 })
138 })
139
140 it('Should allow signup', async function () {
141 await servers[0].users.register({
142 username: 'user1',
143 displayName: 'user 1'
144 })
145 })
146
147 it('Should detect a signup as SPAM', async function () {
148 await servers[0].users.register({
149 username: 'user2',
150 displayName: 'user 2',
151 email: 'akismet-guaranteed-spam@example.com',
152 expectedStatus: HttpStatusCode.FORBIDDEN_403
153 })
125 }) 154 })
126 }) 155 })
127 156
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts
index d8303848d..e7d021059 100644
--- a/shared/server-commands/users/users-command.ts
+++ b/shared/server-commands/users/users-command.ts
@@ -217,12 +217,13 @@ export class UsersCommand extends AbstractCommand {
217 username: string 217 username: string
218 password?: string 218 password?: string
219 displayName?: string 219 displayName?: string
220 email?: string
220 channel?: { 221 channel?: {
221 name: string 222 name: string
222 displayName: string 223 displayName: string
223 } 224 }
224 }) { 225 }) {
225 const { username, password = 'password', displayName, channel } = options 226 const { username, password = 'password', displayName, channel, email = username + '@example.com' } = options
226 const path = '/api/v1/users/register' 227 const path = '/api/v1/users/register'
227 228
228 return this.postBodyRequest({ 229 return this.postBodyRequest({
@@ -232,7 +233,7 @@ export class UsersCommand extends AbstractCommand {
232 fields: { 233 fields: {
233 username, 234 username,
234 password, 235 password,
235 email: username + '@example.com', 236 email,
236 displayName, 237 displayName,
237 channel 238 channel
238 }, 239 },