ActivityPub-federated video streaming platform using P2P directly in your web browser
Add tests for akismet plugin 0.2.0
Chocobozzze95084e42c44
diff --git a/packages/models/src/plugins/server/server-hook.model.ts b/packages/models/src/plugins/server/server-hook.model.tsindex d5f93ec7d4..ea58f8790a 100644--- a/packages/models/src/plugins/server/server-hook.model.ts+++ b/packages/models/src/plugins/server/server-hook.model.ts@@ -101,6 +101,7 @@ export const serverFilterHookObject = {'filter:api.user.signup.allowed.result': true,// Filter result used to check if signup requires approval on the instance+ // PeerTube >= 8.2'filter:api.user.signup.requires-approval.result': true,// Filter result used to check if a user can send a registration request on the instancediff --git a/packages/server-commands/src/users/registrations-command.ts b/packages/server-commands/src/users/registrations-command.tsindex 89628c88cf..547924e045 100644--- a/packages/server-commands/src/users/registrations-command.ts+++ b/packages/server-commands/src/users/registrations-command.ts@@ -15,7 +15,7 @@ export class RegistrationsCommand extends AbstractCommand {const { password = 'password', email = options.username + '@example.com' } = optionsconst path = '/api/v1/users/register'- return this.postBodyRequest({+ return unwrapBody<{ state: { id: UserRegistrationStateType, label: string } }>(this.postBodyRequest({...options,path,@@ -27,7 +27,7 @@ export class RegistrationsCommand extends AbstractCommand {},implicitToken: false,defaultExpectedStatus: HttpStatusCode.OK_200- })+ }))}requestRegistration (diff --git a/packages/server-commands/src/videos/comments-command.ts b/packages/server-commands/src/videos/comments-command.tsindex 55c8af9960..dcf49b21bc 100644--- a/packages/server-commands/src/videos/comments-command.ts+++ b/packages/server-commands/src/videos/comments-command.ts@@ -151,8 +151,10 @@ export class CommentsCommand extends AbstractCommand {defaultExpectedStatus: HttpStatusCode.OK_200}))- this.lastThreadId = body.comment?.id- this.lastVideoId = videoId+ if (options.expectedStatus !== HttpStatusCode.OK_200) {+ this.lastThreadId = body.comment?.id+ this.lastVideoId = videoId+ }return body.comment}@@ -178,7 +180,9 @@ export class CommentsCommand extends AbstractCommand {defaultExpectedStatus: HttpStatusCode.OK_200}))- this.lastReplyId = body.comment?.id+ if (options.expectedStatus !== HttpStatusCode.OK_200) {+ this.lastReplyId = body.comment?.id+ }return body.comment}diff --git a/packages/tests/src/external-plugins/akismet.ts b/packages/tests/src/external-plugins/akismet.tsindex 1ce4be04bf..9f48a80cb2 100644--- a/packages/tests/src/external-plugins/akismet.ts+++ b/packages/tests/src/external-plugins/akismet.ts@@ -1,7 +1,7 @@/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import { expect } from 'chai'-import { HttpStatusCode } from '@peertube/peertube-models'+import { HttpStatusCode, UserRegistrationState } from '@peertube/peertube-models'import {cleanupTests,createMultipleServers,@@ -22,7 +22,8 @@ describe('Official plugin Akismet', function () {await setAccessTokensToServers(servers)await servers[0].plugins.install({- npmName: 'peertube-plugin-akismet'+ // npmName: 'peertube-plugin-akismet',+ path: '/home/florian/Coding/NodeJS/peertube-official-plugins/peertube-plugin-akismet'})if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')@@ -44,11 +45,11 @@ describe('Official plugin Akismet', function () {})it('Should not detect a thread as spam', async function () {- await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })+ await servers[0].comments.createThread({ videoId: videoUUID, text: 'this is my comment' })})it('Should not detect a reply as spam', async function () {- await servers[0].comments.addReplyToLastThread({ text: 'reply' })+ await servers[0].comments.addReplyToLastThread({ text: 'this is my reply to your comment' })})it('Should detect a thread as spam', async function () {@@ -60,7 +61,6 @@ describe('Official plugin Akismet', function () {})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 })})})@@ -149,6 +149,25 @@ describe('Official plugin Akismet', function () {expectedStatus: HttpStatusCode.FORBIDDEN_403})})++ it('Should detect a signup as SPAM and set it as approval', async function () {+ await servers[0].plugins.updateSettings({+ npmName: 'peertube-plugin-akismet',+ settings: {+ 'akismet-api-key': process.env.AKISMET_KEY,+ 'akismet-spam-marked-user-registration-strategy': 'mark-for-approval'+ }+ })++ const { state } = await servers[0].registrations.register({+ username: 'user2',+ displayName: 'user 2',+ email: '[email protected]',+ expectedStatus: HttpStatusCode.OK_200+ })++ expect(state.id).to.equal(UserRegistrationState.PENDING)+ })})after(async function () {