aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users
diff options
context:
space:
mode:
authorJosh Morel <morel.josh@hotmail.com>2019-04-02 05:26:47 -0400
committerChocobozzz <chocobozzz@cpy.re>2019-04-02 11:26:47 +0200
commit7ccddd7b5250bd25a917a6e77e58b87b9484a2a4 (patch)
treee75dc991369c1768804fefa114eb2a832881087f /server/tests/api/users
parent12fed49ebab0c414713d57ea316b6488ae6bef99 (diff)
downloadPeerTube-7ccddd7b5250bd25a917a6e77e58b87b9484a2a4.tar.gz
PeerTube-7ccddd7b5250bd25a917a6e77e58b87b9484a2a4.tar.zst
PeerTube-7ccddd7b5250bd25a917a6e77e58b87b9484a2a4.zip
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
Diffstat (limited to 'server/tests/api/users')
-rw-r--r--server/tests/api/users/user-notifications.ts191
1 files changed, 185 insertions, 6 deletions
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 {
17 updateVideo, 17 updateVideo,
18 updateVideoChannel, 18 updateVideoChannel,
19 userLogin, 19 userLogin,
20 wait 20 wait,
21 getCustomConfig,
22 updateCustomConfig
21} from '../../../../shared/utils' 23} from '../../../../shared/utils'
22import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' 24import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
23import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 25import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
@@ -31,6 +33,7 @@ import {
31 checkNewBlacklistOnMyVideo, 33 checkNewBlacklistOnMyVideo,
32 checkNewCommentOnMyVideo, 34 checkNewCommentOnMyVideo,
33 checkNewVideoAbuseForModerators, 35 checkNewVideoAbuseForModerators,
36 checkVideoAutoBlacklistForModerators,
34 checkNewVideoFromSubscription, 37 checkNewVideoFromSubscription,
35 checkUserRegistered, 38 checkUserRegistered,
36 checkVideoIsPublished, 39 checkVideoIsPublished,
@@ -54,6 +57,7 @@ import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../sha
54import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' 57import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
55import * as uuidv4 from 'uuid/v4' 58import * as uuidv4 from 'uuid/v4'
56import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' 59import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
60import { CustomConfig } from '../../../../shared/models/server'
57 61
58const expect = chai.expect 62const expect = chai.expect
59 63
@@ -92,6 +96,7 @@ describe('Test users notifications', function () {
92 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 96 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
93 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 97 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
94 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 98 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
95 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 100 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
96 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 101 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 102 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
@@ -305,7 +310,7 @@ describe('Test users notifications', function () {
305 }) 310 })
306 311
307 it('Should send a new video notification after a video import', async function () { 312 it('Should send a new video notification after a video import', async function () {
308 this.timeout(30000) 313 this.timeout(100000)
309 314
310 const name = 'video import ' + uuidv4() 315 const name = 'video import ' + uuidv4()
311 316
@@ -907,6 +912,180 @@ describe('Test users notifications', function () {
907 }) 912 })
908 }) 913 })
909 914
915 describe('Video-related notifications when video auto-blacklist is enabled', function () {
916 let userBaseParams: CheckerBaseParams
917 let adminBaseParamsServer1: CheckerBaseParams
918 let adminBaseParamsServer2: CheckerBaseParams
919 let videoUUID: string
920 let videoName: string
921 let currentCustomConfig: CustomConfig
922
923 before(async () => {
924
925 adminBaseParamsServer1 = {
926 server: servers[0],
927 emails,
928 socketNotifications: adminNotifications,
929 token: servers[0].accessToken
930 }
931
932 adminBaseParamsServer2 = {
933 server: servers[1],
934 emails,
935 socketNotifications: adminNotificationsServer2,
936 token: servers[1].accessToken
937 }
938
939 userBaseParams = {
940 server: servers[0],
941 emails,
942 socketNotifications: userNotifications,
943 token: userAccessToken
944 }
945
946 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
947 currentCustomConfig = resCustomConfig.body
948 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
949 autoBlacklist: {
950 videos: {
951 ofUsers: {
952 enabled: true
953 }
954 }
955 }
956 })
957 // enable transcoding otherwise own publish notification after transcoding not expected
958 autoBlacklistTestsCustomConfig.transcoding.enabled = true
959 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
960
961 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
962 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
963
964 })
965
966 it('Should send notification to moderators on new video with auto-blacklist', async function () {
967 this.timeout(20000)
968
969 videoName = 'video with auto-blacklist ' + uuidv4()
970 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
971 videoUUID = resVideo.body.video.uuid
972
973 await waitJobs(servers)
974 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
975 })
976
977 it('Should not send video publish notification if auto-blacklisted', async function () {
978 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
979 })
980
981 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
982 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
983 })
984
985 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
986 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
987 })
988
989 it('Should send video published and unblacklist after video unblacklisted', async function () {
990 this.timeout(20000)
991
992 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
993
994 await waitJobs(servers)
995
996 // FIXME: Can't test as two notifications sent to same user and util only checks last one
997 // One notification might be better anyways
998 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
999 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1000 })
1001
1002 it('Should send a local user subscription notification after removed from blacklist', async function () {
1003 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1004 })
1005
1006 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1007 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1008 })
1009
1010 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1011 this.timeout(20000)
1012
1013 let updateAt = new Date(new Date().getTime() + 100000)
1014
1015 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1016
1017 const data = {
1018 name,
1019 privacy: VideoPrivacy.PRIVATE,
1020 scheduleUpdate: {
1021 updateAt: updateAt.toISOString(),
1022 privacy: VideoPrivacy.PUBLIC
1023 }
1024 }
1025
1026 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1027 const uuid = resVideo.body.video.uuid
1028
1029 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1030
1031 await waitJobs(servers)
1032 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1033
1034 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1035 // One notification might be better anyways
1036 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1037
1038 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1039 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1040 })
1041
1042 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1043 this.timeout(20000)
1044
1045 // In 2 seconds
1046 let updateAt = new Date(new Date().getTime() + 2000)
1047
1048 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1049
1050 const data = {
1051 name,
1052 privacy: VideoPrivacy.PRIVATE,
1053 scheduleUpdate: {
1054 updateAt: updateAt.toISOString(),
1055 privacy: VideoPrivacy.PUBLIC
1056 }
1057 }
1058
1059 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1060 const uuid = resVideo.body.video.uuid
1061
1062 await wait(6000)
1063 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1064 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1065 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1066 })
1067
1068 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1069 this.timeout(20000)
1070
1071 const name = 'video without auto-blacklist ' + uuidv4()
1072
1073 // admin with blacklist right will not be auto-blacklisted
1074 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1075 const uuid = resVideo.body.video.uuid
1076
1077 await waitJobs(servers)
1078 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1079 })
1080
1081 after(async () => {
1082 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1083
1084 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1085 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1086 })
1087 })
1088
910 describe('Mark as read', function () { 1089 describe('Mark as read', function () {
911 it('Should mark as read some notifications', async function () { 1090 it('Should mark as read some notifications', async function () {
912 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) 1091 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
@@ -968,7 +1147,7 @@ describe('Test users notifications', function () {
968 }) 1147 })
969 1148
970 it('Should not have notifications', async function () { 1149 it('Should not have notifications', async function () {
971 this.timeout(10000) 1150 this.timeout(20000)
972 1151
973 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1152 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
974 newVideoFromSubscription: UserNotificationSettingValue.NONE 1153 newVideoFromSubscription: UserNotificationSettingValue.NONE
@@ -987,7 +1166,7 @@ describe('Test users notifications', function () {
987 }) 1166 })
988 1167
989 it('Should only have web notifications', async function () { 1168 it('Should only have web notifications', async function () {
990 this.timeout(10000) 1169 this.timeout(20000)
991 1170
992 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1171 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
993 newVideoFromSubscription: UserNotificationSettingValue.WEB 1172 newVideoFromSubscription: UserNotificationSettingValue.WEB
@@ -1013,7 +1192,7 @@ describe('Test users notifications', function () {
1013 }) 1192 })
1014 1193
1015 it('Should only have mail notifications', async function () { 1194 it('Should only have mail notifications', async function () {
1016 this.timeout(10000) 1195 this.timeout(20000)
1017 1196
1018 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1197 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1019 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 1198 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
@@ -1039,7 +1218,7 @@ describe('Test users notifications', function () {
1039 }) 1218 })
1040 1219
1041 it('Should have email and web notifications', async function () { 1220 it('Should have email and web notifications', async function () {
1042 this.timeout(10000) 1221 this.timeout(20000)
1043 1222
1044 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1223 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1045 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 1224 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL