From 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 10:49:46 +0200 Subject: Add user adminFlags --- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/api/videos/video-blacklist.ts | 115 +++++++++++++++++++--- server/tests/api/videos/video-change-ownership.ts | 32 +++++- server/tests/api/videos/video-channels.ts | 2 +- server/tests/api/videos/video-nsfw.ts | 2 +- server/tests/api/videos/video-playlists.ts | 7 +- server/tests/api/videos/video-privacy.ts | 2 +- server/tests/api/videos/videos-filter.ts | 16 +-- server/tests/api/videos/videos-history.ts | 2 +- 9 files changed, 149 insertions(+), 31 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index f91678140..46486b777 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -164,7 +164,7 @@ describe('Test multiple servers', function () { username: 'user1', password: 'super_password' } - await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) + await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password }) const userAccessToken = await userLogin(servers[1], user) const videoAttributes = { diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index 10b412a80..1feae19e9 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -5,29 +5,31 @@ import { orderBy } from 'lodash' import 'mocha' import { addVideoToBlacklist, + createUser, flushAndRunMultipleServers, getBlacklistedVideosList, - getBlacklistedVideosListWithTypeFilter, getMyVideos, - getSortedBlacklistedVideosList, getVideosList, killallServers, removeVideoFromBlacklist, + reRunServer, searchVideo, ServerInfo, setAccessTokensToServers, updateVideo, updateVideoBlacklist, uploadVideo, - viewVideo + userLogin } from '../../../../shared/utils/index' import { doubleFollow } from '../../../../shared/utils/server/follows' import { waitJobs } from '../../../../shared/utils/server/jobs' import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' +import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { UserRole } from '../../../../shared/models/users' const expect = chai.expect -describe('Test video blacklist management', function () { +describe('Test video blacklist', function () { let servers: ServerInfo[] = [] let videoId: number @@ -104,7 +106,7 @@ describe('Test video blacklist management', 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) + const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(2) @@ -119,7 +121,11 @@ 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) + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.MANUAL + }) expect(res.body.total).to.equal(2) @@ -129,7 +135,11 @@ describe('Test video blacklist management', function () { }) 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 + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) expect(res.body.total).to.equal(0) @@ -139,7 +149,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by descending id', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -152,7 +162,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by descending video name', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -165,7 +175,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by ascending creation date', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -182,7 +192,7 @@ describe('Test video blacklist management', function () { it('Should change the reason', async function () { await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) const video = res.body.data.find(b => b.video.id === videoId) expect(video.reason).to.equal('my super reason updated') @@ -218,7 +228,7 @@ describe('Test video blacklist management', function () { it('Should remove a video from the blacklist on server 1', async function () { // Get one video in the blacklist - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) videoToRemove = res.body.data[0] blacklist = res.body.data.slice(1) @@ -239,7 +249,7 @@ describe('Test video blacklist management', function () { }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) expect(res.body.total).to.equal(1) const videos = res.body.data @@ -313,7 +323,7 @@ describe('Test video blacklist management', function () { }) it('Should have the correct video blacklist unfederate attribute', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) const blacklistedVideos: VideoBlacklist[] = res.body.data const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) @@ -338,6 +348,83 @@ describe('Test video blacklist management', function () { }) + describe('When auto blacklist videos', function () { + let userWithoutFlag: string + let userWithFlag: string + + 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 user = { username: 'user_with_flag', password: 'password' } + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: user.username, + adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST, + password: user.password, + role: UserRole.USER + }) + + userWithFlag = await userLogin(servers[0], user) + } + + await waitJobs(servers) + }) + + it('Should auto blacklist a video', async function () { + await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) + + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) + + expect(res.body.total).to.equal(1) + expect(res.body.data[0].video.name).to.equal('blacklisted') + }) + + it('Should not auto blacklist a video', async function () { + await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) + + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) + + expect(res.body.total).to.equal(1) + }) + }) + after(async function () { killallServers(servers) }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 25675a966..a23e30dc0 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -46,8 +46,20 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) const videoQuota = 42000000 - await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota) - await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota) + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: firstUser.username, + password: firstUser.password, + videoQuota: videoQuota + }) + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: secondUser.username, + password: secondUser.password, + videoQuota: videoQuota + }) firstUserAccessToken = await userLogin(servers[0], firstUser) secondUserAccessToken = await userLogin(servers[0], secondUser) @@ -219,8 +231,20 @@ describe('Test video change ownership - quota too small', function () { const videoQuota = 42000000 const limitedVideoQuota = 10 - await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) - await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) + await createUser({ + url: server.url, + accessToken: server.accessToken, + username: firstUser.username, + password: firstUser.password, + videoQuota: videoQuota + }) + await createUser({ + url: server.url, + accessToken: server.accessToken, + username: secondUser.username, + password: secondUser.password, + videoQuota: limitedVideoQuota + }) firstUserAccessToken = await userLogin(server, firstUser) secondUserAccessToken = await userLogin(server, secondUser) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 63514d69c..bd672cf41 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -270,7 +270,7 @@ describe('Test video channels', function () { } { - await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, 'toto', 'password') + await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' }) const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) const res = await getMyUserInformation(servers[ 0 ].url, accessToken) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index df1ee2eb9..cb972d921 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -144,7 +144,7 @@ describe('Test video NSFW policy', function () { it('Should create a user having the default nsfw policy', async function () { const username = 'user1' const password = 'my super password' - await createUser(server.url, server.accessToken, username, password) + await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) userAccessToken = await userLogin(server, { username, password }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index fc2662808..d9cb71992 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -815,7 +815,12 @@ describe('Test video playlists', function () { this.timeout(30000) const user = { username: 'user_1', password: 'password' } - const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) + const res = await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: user.username, + password: user.password + }) const userId = res.body.user.id const userAccessToken = await userLogin(servers[0], user) diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 0b4e66369..e1b5fb193 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -78,7 +78,7 @@ describe('Test video privacy', function () { username: 'hello', password: 'super password' } - await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) + await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) const token = await userLogin(servers[0], user) await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 59e37ad86..920ca0023 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -64,13 +64,15 @@ describe('Test videos filter validator', function () { for (const server of servers) { const moderator = { username: 'moderator', password: 'my super password' } await createUser( - server.url, - server.accessToken, - moderator.username, - moderator.password, - undefined, - undefined, - UserRole.MODERATOR + { + url: server.url, + accessToken: server.accessToken, + username: moderator.username, + password: moderator.password, + videoQuota: undefined, + videoQuotaDaily: undefined, + role: UserRole.MODERATOR + } ) server['moderatorAccessToken'] = await userLogin(server, moderator) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index f7d3a6aeb..ab40bb64c 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -58,7 +58,7 @@ describe('Test videos history', function () { username: 'user_1', password: 'super password' } - await createUser(server.url, server.accessToken, user.username, user.password) + await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) userAccessToken = await userLogin(server, user) }) -- cgit v1.2.3