+ describe('When auto blacklist videos', function () {
+ let userWithoutFlag: string
+ let userWithFlag: string
+ let channelOfUserWithoutFlag: number
+
+ before(async function () {
+ this.timeout(20000)
+
+ killallServers([ servers[0] ])
+
+ const config = {
+ auto_blacklist: {
+ videos: {
+ of_users: {
+ enabled: true
+ }
+ }
+ }
+ }
+ await reRunServer(servers[0], config)
+
+ {
+ const user = { username: 'user_without_flag', password: 'password' }
+ await createUser({
+ url: servers[0].url,
+ accessToken: servers[0].accessToken,
+ username: user.username,
+ adminFlags: UserAdminFlag.NONE,
+ password: user.password,
+ role: UserRole.USER
+ })
+
+ userWithoutFlag = await userLogin(servers[0], user)
+
+ const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
+ const body: User = res.body
+ channelOfUserWithoutFlag = body.videoChannels[0].id
+ }
+
+ {
+ const user = { username: 'user_with_flag', password: 'password' }
+ await createUser({
+ url: servers[0].url,
+ accessToken: servers[0].accessToken,
+ username: user.username,
+ adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLOCK,
+ password: user.password,
+ role: UserRole.USER
+ })
+
+ userWithFlag = await userLogin(servers[0], user)
+ }
+
+ await waitJobs(servers)
+ })
+
+ it('Should auto blacklist a video on upload', async function () {
+ await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
+
+ const res = await getBlacklistedVideosList({
+ url: servers[0].url,
+ token: servers[0].accessToken,
+ type: VideoBlockType.AUTO_BEFORE_PUBLISHED
+ })
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data[0].video.name).to.equal('blacklisted')
+ })
+
+ it('Should auto blacklist a video on URL import', async function () {
+ this.timeout(15000)
+
+ const attributes = {
+ targetUrl: getYoutubeVideoUrl(),
+ name: 'URL import',
+ channelId: channelOfUserWithoutFlag
+ }
+ await importVideo(servers[0].url, userWithoutFlag, attributes)
+
+ const res = await getBlacklistedVideosList({
+ url: servers[0].url,
+ token: servers[0].accessToken,
+ sort: 'createdAt',
+ type: VideoBlockType.AUTO_BEFORE_PUBLISHED
+ })
+
+ expect(res.body.total).to.equal(2)
+ expect(res.body.data[1].video.name).to.equal('URL import')
+ })
+
+ it('Should auto blacklist a video on torrent import', async function () {
+ const attributes = {
+ magnetUri: getMagnetURI(),
+ name: 'Torrent import',
+ channelId: channelOfUserWithoutFlag
+ }
+ await importVideo(servers[0].url, userWithoutFlag, attributes)
+
+ const res = await getBlacklistedVideosList({
+ url: servers[0].url,
+ token: servers[0].accessToken,
+ sort: 'createdAt',
+ type: VideoBlockType.AUTO_BEFORE_PUBLISHED
+ })
+
+ expect(res.body.total).to.equal(3)
+ expect(res.body.data[2].video.name).to.equal('Torrent import')
+ })
+
+ it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
+ await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
+
+ const res = await getBlacklistedVideosList({
+ url: servers[0].url,
+ token: servers[0].accessToken,
+ type: VideoBlockType.AUTO_BEFORE_PUBLISHED
+ })