From 7ccddd7b5250bd25a917a6e77e58b87b9484a2a4 Mon Sep 17 00:00:00 2001 From: Josh Morel Date: Tue, 2 Apr 2019 05:26:47 -0400 Subject: add quarantine videos feature (#1637) * add quarantine videos feature * increase Notification settings test timeout to 20000ms. was completing 7000 locally but timing out after 10000 on travis * fix quarantine video test issues -propagate misspelling -remove skip from server/tests/client.ts * WIP use blacklist for moderator video approval instead of video.quarantine boolean * finish auto-blacklist feature --- server/tests/api/check-params/config.ts | 7 + .../tests/api/check-params/user-notifications.ts | 1 + server/tests/api/check-params/video-blacklist.ts | 11 +- server/tests/api/check-params/videos.ts | 3 +- server/tests/api/server/config.ts | 9 + server/tests/api/users/user-notifications.ts | 191 ++++++++++++++++++++- server/tests/api/videos/video-blacklist.ts | 25 ++- 7 files changed, 237 insertions(+), 10 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index c6b460f23..0b333e2f4 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -80,6 +80,13 @@ describe('Test config API validators', function () { enabled: false } } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: false + } + } } } diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 714f481e9..36eaceac7 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -168,6 +168,7 @@ describe('Test user notifications API validators', function () { newVideoFromSubscription: UserNotificationSettingValue.WEB, newCommentOnMyVideo: UserNotificationSettingValue.WEB, videoAbuseAsModerator: UserNotificationSettingValue.WEB, + videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB, blacklistOnMyVideo: UserNotificationSettingValue.WEB, myVideoImportFinished: UserNotificationSettingValue.WEB, myVideoPublished: UserNotificationSettingValue.WEB, diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 6b82643f4..fc039e847 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -8,6 +8,7 @@ import { flushAndRunMultipleServers, flushTests, getBlacklistedVideosList, + getBlacklistedVideosListWithTypeFilter, getVideo, getVideoWithToken, killallServers, @@ -24,7 +25,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/utils/requests/check-api-params' -import { VideoDetails } from '../../../../shared/models/videos' +import { VideoDetails, VideoBlacklistType } from '../../../../shared/models/videos' import { expect } from 'chai' describe('Test video blacklist API validators', function () { @@ -238,6 +239,14 @@ describe('Test video blacklist API validators', function () { it('Should fail with an incorrect sort', async function () { await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken) }) + + it('Should fail with an invalid type', async function () { + await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, 0, 400) + }) + + it('Should succeed with the correct parameters', async function () { + await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) + }) }) after(async function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 3eccaee44..5a013b890 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -7,7 +7,8 @@ import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, - makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin + makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, uploadVideo, + runServer, ServerInfo, setAccessTokensToServers, userLogin, updateCustomSubConfig } from '../../../../shared/utils' import { checkBadCountPagination, diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 42927605d..b9f05e952 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -62,6 +62,7 @@ function checkInitialConfig (data: CustomConfig) { expect(data.import.videos.http.enabled).to.be.true expect(data.import.videos.torrent.enabled).to.be.true + expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false } function checkUpdatedConfig (data: CustomConfig) { @@ -103,6 +104,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.import.videos.http.enabled).to.be.false expect(data.import.videos.torrent.enabled).to.be.false + expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true } describe('Test config', function () { @@ -225,6 +227,13 @@ describe('Test config', function () { enabled: false } } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: true + } + } } } await updateCustomConfig(server.url, server.accessToken, newCustomConfig) diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index d573bf024..1b66df79b 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts @@ -17,7 +17,9 @@ import { updateVideo, updateVideoChannel, userLogin, - wait + wait, + getCustomConfig, + updateCustomConfig } from '../../../../shared/utils' import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' import { setAccessTokensToServers } from '../../../../shared/utils/users/login' @@ -31,6 +33,7 @@ import { checkNewBlacklistOnMyVideo, checkNewCommentOnMyVideo, checkNewVideoAbuseForModerators, + checkVideoAutoBlacklistForModerators, checkNewVideoFromSubscription, checkUserRegistered, checkVideoIsPublished, @@ -54,6 +57,7 @@ import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../sha import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' import * as uuidv4 from 'uuid/v4' import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' +import { CustomConfig } from '../../../../shared/models/server' const expect = chai.expect @@ -92,6 +96,7 @@ describe('Test users notifications', function () { newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, @@ -305,7 +310,7 @@ describe('Test users notifications', function () { }) it('Should send a new video notification after a video import', async function () { - this.timeout(30000) + this.timeout(100000) const name = 'video import ' + uuidv4() @@ -907,6 +912,180 @@ describe('Test users notifications', function () { }) }) + describe('Video-related notifications when video auto-blacklist is enabled', function () { + let userBaseParams: CheckerBaseParams + let adminBaseParamsServer1: CheckerBaseParams + let adminBaseParamsServer2: CheckerBaseParams + let videoUUID: string + let videoName: string + let currentCustomConfig: CustomConfig + + before(async () => { + + adminBaseParamsServer1 = { + server: servers[0], + emails, + socketNotifications: adminNotifications, + token: servers[0].accessToken + } + + adminBaseParamsServer2 = { + server: servers[1], + emails, + socketNotifications: adminNotificationsServer2, + token: servers[1].accessToken + } + + userBaseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + + const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) + currentCustomConfig = resCustomConfig.body + const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { + autoBlacklist: { + videos: { + ofUsers: { + enabled: true + } + } + } + }) + // enable transcoding otherwise own publish notification after transcoding not expected + autoBlacklistTestsCustomConfig.transcoding.enabled = true + await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) + + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + + }) + + it('Should send notification to moderators on new video with auto-blacklist', async function () { + this.timeout(20000) + + videoName = 'video with auto-blacklist ' + uuidv4() + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + videoUUID = resVideo.body.video.uuid + + await waitJobs(servers) + await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') + }) + + it('Should not send video publish notification if auto-blacklisted', async function () { + await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') + }) + + it('Should not send a local user subscription notification if auto-blacklisted', async function () { + await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') + }) + + it('Should not send a remote user subscription notification if auto-blacklisted', async function () { + await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') + }) + + it('Should send video published and unblacklist after video unblacklisted', async function () { + this.timeout(20000) + + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) + + await waitJobs(servers) + + // FIXME: Can't test as two notifications sent to same user and util only checks last one + // One notification might be better anyways + // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') + // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') + }) + + it('Should send a local user subscription notification after removed from blacklist', async function () { + await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') + }) + + it('Should send a remote user subscription notification after removed from blacklist', async function () { + await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') + }) + + it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { + this.timeout(20000) + + let updateAt = new Date(new Date().getTime() + 100000) + + const name = 'video with auto-blacklist and future schedule ' + uuidv4() + + const data = { + name, + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) + const uuid = resVideo.body.video.uuid + + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) + + await waitJobs(servers) + await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') + + // FIXME: Can't test absence as two notifications sent to same user and util only checks last one + // One notification might be better anyways + // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') + + await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') + await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') + }) + + it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { + this.timeout(20000) + + // In 2 seconds + let updateAt = new Date(new Date().getTime() + 2000) + + const name = 'video with schedule done and still auto-blacklisted ' + uuidv4() + + const data = { + name, + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) + const uuid = resVideo.body.video.uuid + + await wait(6000) + await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') + await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') + await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') + }) + + it('Should not send a notification to moderators on new video without auto-blacklist', async function () { + this.timeout(20000) + + const name = 'video without auto-blacklist ' + uuidv4() + + // admin with blacklist right will not be auto-blacklisted + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) + const uuid = resVideo.body.video.uuid + + await waitJobs(servers) + await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') + }) + + after(async () => { + await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) + + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + }) + }) + describe('Mark as read', function () { it('Should mark as read some notifications', async function () { const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) @@ -968,7 +1147,7 @@ describe('Test users notifications', function () { }) it('Should not have notifications', async function () { - this.timeout(10000) + this.timeout(20000) await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.NONE @@ -987,7 +1166,7 @@ describe('Test users notifications', function () { }) it('Should only have web notifications', async function () { - this.timeout(10000) + this.timeout(20000) await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.WEB @@ -1013,7 +1192,7 @@ describe('Test users notifications', function () { }) it('Should only have mail notifications', async function () { - this.timeout(10000) + this.timeout(20000) await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.EMAIL @@ -1039,7 +1218,7 @@ describe('Test users notifications', function () { }) it('Should have email and web notifications', async function () { - this.timeout(10000) + this.timeout(20000) await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index d39ad63b4..10b412a80 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -7,6 +7,7 @@ import { addVideoToBlacklist, flushAndRunMultipleServers, getBlacklistedVideosList, + getBlacklistedVideosListWithTypeFilter, getMyVideos, getSortedBlacklistedVideosList, getVideosList, @@ -22,7 +23,7 @@ import { } from '../../../../shared/utils/index' import { doubleFollow } from '../../../../shared/utils/server/follows' import { waitJobs } from '../../../../shared/utils/server/jobs' -import { VideoBlacklist } from '../../../../shared/models/videos' +import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' const expect = chai.expect @@ -101,7 +102,7 @@ describe('Test video blacklist management', function () { }) }) - describe('When listing blacklisted videos', function () { + describe('When listing manually blacklisted videos', function () { it('Should display all the blacklisted videos', async function () { const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) @@ -117,6 +118,26 @@ describe('Test video blacklist management', function () { } }) + it('Should display all the blacklisted videos when applying manual type filter', async function () { + const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) + + expect(res.body.total).to.equal(2) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(2) + }) + + it('Should display nothing when applying automatic type filter', async function () { + const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length + + expect(res.body.total).to.equal(0) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(0) + }) + it('Should get the correct sort when sorting by descending id', async function () { const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') expect(res.body.total).to.equal(2) -- cgit v1.2.3