diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-15 10:49:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-15 14:39:52 +0200 |
commit | 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a (patch) | |
tree | 91a10310cdf924779527525d39f8eb7e09e4ba49 /server | |
parent | 31b48aad478506d4214586f02792816efa968e4b (diff) | |
download | PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.gz PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.zst PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.zip |
Add user adminFlags
Diffstat (limited to 'server')
52 files changed, 860 insertions, 516 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 28c8de303..0aafba66e 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -45,6 +45,7 @@ import { Notifier } from '../../../lib/notifier' | |||
45 | import { mySubscriptionsRouter } from './my-subscriptions' | 45 | import { mySubscriptionsRouter } from './my-subscriptions' |
46 | import { CONFIG } from '../../../initializers/config' | 46 | import { CONFIG } from '../../../initializers/config' |
47 | import { sequelizeTypescript } from '../../../initializers/database' | 47 | import { sequelizeTypescript } from '../../../initializers/database' |
48 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
48 | 49 | ||
49 | const auditLogger = auditLoggerFactory('users') | 50 | const auditLogger = auditLoggerFactory('users') |
50 | 51 | ||
@@ -175,7 +176,8 @@ async function createUser (req: express.Request, res: express.Response) { | |||
175 | autoPlayVideo: true, | 176 | autoPlayVideo: true, |
176 | role: body.role, | 177 | role: body.role, |
177 | videoQuota: body.videoQuota, | 178 | videoQuota: body.videoQuota, |
178 | videoQuotaDaily: body.videoQuotaDaily | 179 | videoQuotaDaily: body.videoQuotaDaily, |
180 | adminFlags: body.adminFlags || UserAdminFlag.NONE | ||
179 | }) | 181 | }) |
180 | 182 | ||
181 | const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate) | 183 | const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate) |
@@ -241,7 +243,7 @@ async function blockUser (req: express.Request, res: express.Response) { | |||
241 | } | 243 | } |
242 | 244 | ||
243 | function getUser (req: express.Request, res: express.Response) { | 245 | function getUser (req: express.Request, res: express.Response) { |
244 | return res.json(res.locals.user.toFormattedJSON()) | 246 | return res.json(res.locals.user.toFormattedJSON({ withAdminFlags: true })) |
245 | } | 247 | } |
246 | 248 | ||
247 | async function autocompleteUsers (req: express.Request, res: express.Response) { | 249 | async function autocompleteUsers (req: express.Request, res: express.Response) { |
@@ -253,7 +255,7 @@ async function autocompleteUsers (req: express.Request, res: express.Response) { | |||
253 | async function listUsers (req: express.Request, res: express.Response) { | 255 | async function listUsers (req: express.Request, res: express.Response) { |
254 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) | 256 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) |
255 | 257 | ||
256 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 258 | return res.json(getFormattedObjects(resultList.data, resultList.total, { withAdminFlags: true })) |
257 | } | 259 | } |
258 | 260 | ||
259 | async function removeUser (req: express.Request, res: express.Response) { | 261 | async function removeUser (req: express.Request, res: express.Response) { |
@@ -278,6 +280,7 @@ async function updateUser (req: express.Request, res: express.Response) { | |||
278 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota | 280 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota |
279 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily | 281 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily |
280 | if (body.role !== undefined) userToUpdate.role = body.role | 282 | if (body.role !== undefined) userToUpdate.role = body.role |
283 | if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags | ||
281 | 284 | ||
282 | const user = await userToUpdate.save() | 285 | const user = await userToUpdate.save() |
283 | 286 | ||
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index ce9e78463..ddb239e7b 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -129,7 +129,7 @@ async function getUserInformation (req: express.Request, res: express.Response) | |||
129 | // We did not load channels in res.locals.user | 129 | // We did not load channels in res.locals.user |
130 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) | 130 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) |
131 | 131 | ||
132 | return res.json(user.toFormattedJSON()) | 132 | return res.json(user.toFormattedJSON({})) |
133 | } | 133 | } |
134 | 134 | ||
135 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { | 135 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { |
@@ -164,7 +164,7 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
164 | 164 | ||
165 | await user.destroy() | 165 | await user.destroy() |
166 | 166 | ||
167 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) | 167 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({}))) |
168 | 168 | ||
169 | return res.sendStatus(204) | 169 | return res.sendStatus(204) |
170 | } | 170 | } |
@@ -173,7 +173,7 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
173 | const body: UserUpdateMe = req.body | 173 | const body: UserUpdateMe = req.body |
174 | 174 | ||
175 | const user = res.locals.oauth.token.user | 175 | const user = res.locals.oauth.token.user |
176 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 176 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) |
177 | 177 | ||
178 | if (body.password !== undefined) user.password = body.password | 178 | if (body.password !== undefined) user.password = body.password |
179 | if (body.email !== undefined) user.email = body.email | 179 | if (body.email !== undefined) user.email = body.email |
@@ -193,7 +193,7 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
193 | 193 | ||
194 | await sendUpdateActor(userAccount, t) | 194 | await sendUpdateActor(userAccount, t) |
195 | 195 | ||
196 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 196 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) |
197 | }) | 197 | }) |
198 | 198 | ||
199 | return res.sendStatus(204) | 199 | return res.sendStatus(204) |
@@ -202,13 +202,13 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
202 | async function updateMyAvatar (req: express.Request, res: express.Response) { | 202 | async function updateMyAvatar (req: express.Request, res: express.Response) { |
203 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 203 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
204 | const user = res.locals.oauth.token.user | 204 | const user = res.locals.oauth.token.user |
205 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 205 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) |
206 | 206 | ||
207 | const userAccount = await AccountModel.load(user.Account.id) | 207 | const userAccount = await AccountModel.load(user.Account.id) |
208 | 208 | ||
209 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) | 209 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) |
210 | 210 | ||
211 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 211 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) |
212 | 212 | ||
213 | return res.json({ avatar: avatar.toFormattedJSON() }) | 213 | return res.json({ avatar: avatar.toFormattedJSON() }) |
214 | } | 214 | } |
diff --git a/server/helpers/custom-jsonld-signature.ts b/server/helpers/custom-jsonld-signature.ts index 27a187db1..a3bceb047 100644 --- a/server/helpers/custom-jsonld-signature.ts +++ b/server/helpers/custom-jsonld-signature.ts | |||
@@ -1,13 +1,77 @@ | |||
1 | import * as AsyncLRU from 'async-lru' | 1 | import * as AsyncLRU from 'async-lru' |
2 | import * as jsonld from 'jsonld' | 2 | import * as jsonld from 'jsonld' |
3 | import * as jsig from 'jsonld-signatures' | 3 | import * as jsig from 'jsonld-signatures' |
4 | import { logger } from './logger' | ||
5 | |||
6 | const CACHE = { | ||
7 | 'https://w3id.org/security/v1': { | ||
8 | '@context': { | ||
9 | 'id': '@id', | ||
10 | 'type': '@type', | ||
11 | |||
12 | 'dc': 'http://purl.org/dc/terms/', | ||
13 | 'sec': 'https://w3id.org/security#', | ||
14 | 'xsd': 'http://www.w3.org/2001/XMLSchema#', | ||
15 | |||
16 | 'EcdsaKoblitzSignature2016': 'sec:EcdsaKoblitzSignature2016', | ||
17 | 'Ed25519Signature2018': 'sec:Ed25519Signature2018', | ||
18 | 'EncryptedMessage': 'sec:EncryptedMessage', | ||
19 | 'GraphSignature2012': 'sec:GraphSignature2012', | ||
20 | 'LinkedDataSignature2015': 'sec:LinkedDataSignature2015', | ||
21 | 'LinkedDataSignature2016': 'sec:LinkedDataSignature2016', | ||
22 | 'CryptographicKey': 'sec:Key', | ||
23 | |||
24 | 'authenticationTag': 'sec:authenticationTag', | ||
25 | 'canonicalizationAlgorithm': 'sec:canonicalizationAlgorithm', | ||
26 | 'cipherAlgorithm': 'sec:cipherAlgorithm', | ||
27 | 'cipherData': 'sec:cipherData', | ||
28 | 'cipherKey': 'sec:cipherKey', | ||
29 | 'created': { '@id': 'dc:created', '@type': 'xsd:dateTime' }, | ||
30 | 'creator': { '@id': 'dc:creator', '@type': '@id' }, | ||
31 | 'digestAlgorithm': 'sec:digestAlgorithm', | ||
32 | 'digestValue': 'sec:digestValue', | ||
33 | 'domain': 'sec:domain', | ||
34 | 'encryptionKey': 'sec:encryptionKey', | ||
35 | 'expiration': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' }, | ||
36 | 'expires': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' }, | ||
37 | 'initializationVector': 'sec:initializationVector', | ||
38 | 'iterationCount': 'sec:iterationCount', | ||
39 | 'nonce': 'sec:nonce', | ||
40 | 'normalizationAlgorithm': 'sec:normalizationAlgorithm', | ||
41 | 'owner': { '@id': 'sec:owner', '@type': '@id' }, | ||
42 | 'password': 'sec:password', | ||
43 | 'privateKey': { '@id': 'sec:privateKey', '@type': '@id' }, | ||
44 | 'privateKeyPem': 'sec:privateKeyPem', | ||
45 | 'publicKey': { '@id': 'sec:publicKey', '@type': '@id' }, | ||
46 | 'publicKeyBase58': 'sec:publicKeyBase58', | ||
47 | 'publicKeyPem': 'sec:publicKeyPem', | ||
48 | 'publicKeyWif': 'sec:publicKeyWif', | ||
49 | 'publicKeyService': { '@id': 'sec:publicKeyService', '@type': '@id' }, | ||
50 | 'revoked': { '@id': 'sec:revoked', '@type': 'xsd:dateTime' }, | ||
51 | 'salt': 'sec:salt', | ||
52 | 'signature': 'sec:signature', | ||
53 | 'signatureAlgorithm': 'sec:signingAlgorithm', | ||
54 | 'signatureValue': 'sec:signatureValue' | ||
55 | } | ||
56 | } | ||
57 | } | ||
4 | 58 | ||
5 | const nodeDocumentLoader = jsonld.documentLoaders.node() | 59 | const nodeDocumentLoader = jsonld.documentLoaders.node() |
6 | 60 | ||
7 | const lru = new AsyncLRU({ | 61 | const lru = new AsyncLRU({ |
8 | max: 10, | 62 | max: 10, |
9 | load: (key, cb) => { | 63 | load: (url, cb) => { |
10 | nodeDocumentLoader(key, cb) | 64 | if (CACHE[ url ] !== undefined) { |
65 | logger.debug('Using cache for JSON-LD %s.', url) | ||
66 | |||
67 | return cb(null, { | ||
68 | contextUrl: null, | ||
69 | document: CACHE[ url ], | ||
70 | documentUrl: url | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | nodeDocumentLoader(url, cb) | ||
11 | } | 75 | } |
12 | }) | 76 | }) |
13 | 77 | ||
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 70af5f1f0..e3ad9102a 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { UserRole } from '../../../shared' | 3 | import { UserNotificationSettingValue, UserRole } from '../../../shared' |
4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' |
5 | import { exists, isFileValid, isBooleanValid } from './misc' | 5 | import { exists, isFileValid, isBooleanValid } from './misc' |
6 | import { values } from 'lodash' | 6 | import { values } from 'lodash' |
7 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | ||
7 | 8 | ||
8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS | 9 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
9 | 10 | ||
@@ -54,6 +55,10 @@ function isUserAutoPlayVideoValid (value: any) { | |||
54 | return isBooleanValid(value) | 55 | return isBooleanValid(value) |
55 | } | 56 | } |
56 | 57 | ||
58 | function isUserAdminFlagsValid (value: any) { | ||
59 | return exists(value) && validator.isInt('' + value) | ||
60 | } | ||
61 | |||
57 | function isUserBlockedValid (value: any) { | 62 | function isUserBlockedValid (value: any) { |
58 | return isBooleanValid(value) | 63 | return isBooleanValid(value) |
59 | } | 64 | } |
@@ -85,6 +90,7 @@ export { | |||
85 | isUserVideoQuotaValid, | 90 | isUserVideoQuotaValid, |
86 | isUserVideoQuotaDailyValid, | 91 | isUserVideoQuotaDailyValid, |
87 | isUserUsernameValid, | 92 | isUserUsernameValid, |
93 | isUserAdminFlagsValid, | ||
88 | isUserEmailVerifiedValid, | 94 | isUserEmailVerifiedValid, |
89 | isUserNSFWPolicyValid, | 95 | isUserNSFWPolicyValid, |
90 | isUserWebTorrentEnabledValid, | 96 | isUserWebTorrentEnabledValid, |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 8f6ef1a81..50a437b3d 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
14 | 14 | ||
15 | // --------------------------------------------------------------------------- | 15 | // --------------------------------------------------------------------------- |
16 | 16 | ||
17 | const LAST_MIGRATION_VERSION = 360 | 17 | const LAST_MIGRATION_VERSION = 365 |
18 | 18 | ||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
20 | 20 | ||
diff --git a/server/initializers/migrations/0365-user-admin-flags.ts b/server/initializers/migrations/0365-user-admin-flags.ts new file mode 100644 index 000000000..20553100a --- /dev/null +++ b/server/initializers/migrations/0365-user-admin-flags.ts | |||
@@ -0,0 +1,40 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize, | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | const data = { | ||
11 | type: Sequelize.INTEGER, | ||
12 | defaultValue: null, | ||
13 | allowNull: true | ||
14 | } | ||
15 | await utils.queryInterface.addColumn('user', 'adminFlags', data) | ||
16 | } | ||
17 | |||
18 | { | ||
19 | const query = 'UPDATE "user" SET "adminFlags" = 0' | ||
20 | await utils.sequelize.query(query) | ||
21 | } | ||
22 | |||
23 | { | ||
24 | const data = { | ||
25 | type: Sequelize.INTEGER, | ||
26 | defaultValue: null, | ||
27 | allowNull: false | ||
28 | } | ||
29 | await utils.queryInterface.changeColumn('user', 'adminFlags', data) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | function down (options) { | ||
34 | throw new Error('Not implemented.') | ||
35 | } | ||
36 | |||
37 | export { | ||
38 | up, | ||
39 | down | ||
40 | } | ||
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts index a5c6fcbb2..985b89e31 100644 --- a/server/lib/video-blacklist.ts +++ b/server/lib/video-blacklist.ts | |||
@@ -1,15 +1,16 @@ | |||
1 | import * as sequelize from 'sequelize' | 1 | import * as sequelize from 'sequelize' |
2 | import { CONFIG } from '../initializers/config' | 2 | import { CONFIG } from '../initializers/config' |
3 | import { VideoBlacklistType, UserRight } from '../../shared/models' | 3 | import { UserRight, VideoBlacklistType } from '../../shared/models' |
4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | 4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' |
5 | import { UserModel } from '../models/account/user' | 5 | import { UserModel } from '../models/account/user' |
6 | import { VideoModel } from '../models/video/video' | 6 | import { VideoModel } from '../models/video/video' |
7 | import { logger } from '../helpers/logger' | 7 | import { logger } from '../helpers/logger' |
8 | import { UserAdminFlag } from '../../shared/models/users/user-flag.model' | ||
8 | 9 | ||
9 | async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) { | 10 | async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) { |
10 | if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false | 11 | if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false |
11 | 12 | ||
12 | if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return false | 13 | if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false |
13 | 14 | ||
14 | const sequelizeOptions = { transaction } | 15 | const sequelizeOptions = { transaction } |
15 | const videoBlacklistToCreate = { | 16 | const videoBlacklistToCreate = { |
@@ -19,6 +20,7 @@ async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, t | |||
19 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | 20 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
20 | } | 21 | } |
21 | await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions) | 22 | await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions) |
23 | |||
22 | logger.info('Video %s auto-blacklisted.', video.uuid) | 24 | logger.info('Video %s auto-blacklisted.', video.uuid) |
23 | 25 | ||
24 | return true | 26 | return true |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index eceded1c4..6d8cd7894 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -5,6 +5,7 @@ import { body, param } from 'express-validator/check' | |||
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
7 | import { | 7 | import { |
8 | isUserAdminFlagsValid, | ||
8 | isUserAutoPlayVideoValid, | 9 | isUserAutoPlayVideoValid, |
9 | isUserBlockedReasonValid, | 10 | isUserBlockedReasonValid, |
10 | isUserDescriptionValid, | 11 | isUserDescriptionValid, |
@@ -32,6 +33,7 @@ const usersAddValidator = [ | |||
32 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 33 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
33 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 34 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
34 | body('role').custom(isUserRoleValid).withMessage('Should have a valid role'), | 35 | body('role').custom(isUserRoleValid).withMessage('Should have a valid role'), |
36 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), | ||
35 | 37 | ||
36 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
37 | logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') }) | 39 | logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') }) |
@@ -120,6 +122,7 @@ const usersUpdateValidator = [ | |||
120 | body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 122 | body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
121 | body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 123 | body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
122 | body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'), | 124 | body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'), |
125 | body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), | ||
123 | 126 | ||
124 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 127 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
125 | logger.debug('Checking usersUpdate parameters', { parameters: req.body }) | 128 | logger.debug('Checking usersUpdate parameters', { parameters: req.body }) |
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 38585c016..b66458351 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -22,6 +22,7 @@ import { | |||
22 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' | 22 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' |
23 | import { User, UserRole } from '../../../shared/models/users' | 23 | import { User, UserRole } from '../../../shared/models/users' |
24 | import { | 24 | import { |
25 | isUserAdminFlagsValid, | ||
25 | isUserAutoPlayVideoValid, | 26 | isUserAutoPlayVideoValid, |
26 | isUserBlockedReasonValid, | 27 | isUserBlockedReasonValid, |
27 | isUserBlockedValid, | 28 | isUserBlockedValid, |
@@ -49,6 +50,7 @@ import { VideoModel } from '../video/video' | |||
49 | import { ActorModel } from '../activitypub/actor' | 50 | import { ActorModel } from '../activitypub/actor' |
50 | import { ActorFollowModel } from '../activitypub/actor-follow' | 51 | import { ActorFollowModel } from '../activitypub/actor-follow' |
51 | import { VideoImportModel } from '../video/video-import' | 52 | import { VideoImportModel } from '../video/video-import' |
53 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | ||
52 | 54 | ||
53 | enum ScopeNames { | 55 | enum ScopeNames { |
54 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' | 56 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' |
@@ -141,6 +143,12 @@ export class UserModel extends Model<UserModel> { | |||
141 | autoPlayVideo: boolean | 143 | autoPlayVideo: boolean |
142 | 144 | ||
143 | @AllowNull(false) | 145 | @AllowNull(false) |
146 | @Default(UserAdminFlag.NONE) | ||
147 | @Is('UserAdminFlags', value => throwIfNotValid(value, isUserAdminFlagsValid, 'user admin flags')) | ||
148 | @Column | ||
149 | adminFlags?: UserAdminFlag | ||
150 | |||
151 | @AllowNull(false) | ||
144 | @Default(false) | 152 | @Default(false) |
145 | @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean')) | 153 | @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean')) |
146 | @Column | 154 | @Column |
@@ -516,11 +524,15 @@ export class UserModel extends Model<UserModel> { | |||
516 | return hasUserRight(this.role, right) | 524 | return hasUserRight(this.role, right) |
517 | } | 525 | } |
518 | 526 | ||
527 | hasAdminFlag (flag: UserAdminFlag) { | ||
528 | return this.adminFlags & flag | ||
529 | } | ||
530 | |||
519 | isPasswordMatch (password: string) { | 531 | isPasswordMatch (password: string) { |
520 | return comparePassword(password, this.password) | 532 | return comparePassword(password, this.password) |
521 | } | 533 | } |
522 | 534 | ||
523 | toFormattedJSON (): User { | 535 | toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User { |
524 | const videoQuotaUsed = this.get('videoQuotaUsed') | 536 | const videoQuotaUsed = this.get('videoQuotaUsed') |
525 | const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') | 537 | const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') |
526 | 538 | ||
@@ -551,6 +563,10 @@ export class UserModel extends Model<UserModel> { | |||
551 | : undefined | 563 | : undefined |
552 | } | 564 | } |
553 | 565 | ||
566 | if (parameters.withAdminFlags) { | ||
567 | Object.assign(json, { adminFlags: this.adminFlags }) | ||
568 | } | ||
569 | |||
554 | if (Array.isArray(this.Account.VideoChannels) === true) { | 570 | if (Array.isArray(this.Account.VideoChannels) === true) { |
555 | json.videoChannels = this.Account.VideoChannels | 571 | json.videoChannels = this.Account.VideoChannels |
556 | .map(c => c.toFormattedJSON()) | 572 | .map(c => c.toFormattedJSON()) |
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 5c617de10..9cbc7dd84 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -38,7 +38,7 @@ describe('Test ActivityPub fetcher', function () { | |||
38 | 38 | ||
39 | const user = { username: 'user1', password: 'password' } | 39 | const user = { username: 'user1', password: 'password' } |
40 | for (const server of servers) { | 40 | for (const server of servers) { |
41 | await createUser(server.url, server.accessToken, user.username, user.password) | 41 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
42 | } | 42 | } |
43 | 43 | ||
44 | const userAccessToken = await userLogin(servers[0], user) | 44 | const userAccessToken = await userLogin(servers[0], user) |
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index c20453c16..62a2c2a52 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts | |||
@@ -36,7 +36,7 @@ describe('Test blocklist API validators', function () { | |||
36 | server = servers[0] | 36 | server = servers[0] |
37 | 37 | ||
38 | const user = { username: 'user1', password: 'password' } | 38 | const user = { username: 'user1', password: 'password' } |
39 | await createUser(server.url, server.accessToken, user.username, user.password) | 39 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
40 | 40 | ||
41 | userAccessToken = await userLogin(server, user) | 41 | userAccessToken = await userLogin(server, user) |
42 | 42 | ||
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 01ab84584..3bcb015d9 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -110,7 +110,7 @@ describe('Test config API validators', function () { | |||
110 | username: 'user1', | 110 | username: 'user1', |
111 | password: 'password' | 111 | password: 'password' |
112 | } | 112 | } |
113 | await createUser(server.url, server.accessToken, user.username, user.password) | 113 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
114 | userAccessToken = await userLogin(server, user) | 114 | userAccessToken = await userLogin(server, user) |
115 | }) | 115 | }) |
116 | 116 | ||
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 9bf664657..da94beffe 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts | |||
@@ -33,7 +33,7 @@ describe('Test debug API validators', function () { | |||
33 | username: 'user1', | 33 | username: 'user1', |
34 | password: 'my super password' | 34 | password: 'my super password' |
35 | } | 35 | } |
36 | await createUser(server.url, server.accessToken, user.username, user.password) | 36 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
37 | userAccessToken = await userLogin(server, user) | 37 | userAccessToken = await userLogin(server, user) |
38 | }) | 38 | }) |
39 | 39 | ||
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index ed1d2db59..5bb337682 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts | |||
@@ -35,7 +35,7 @@ describe('Test server follows API validators', function () { | |||
35 | password: 'password' | 35 | password: 'password' |
36 | } | 36 | } |
37 | 37 | ||
38 | await createUser(server.url, server.accessToken, user.username, user.password) | 38 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
39 | userAccessToken = await userLogin(server, user) | 39 | userAccessToken = await userLogin(server, user) |
40 | }) | 40 | }) |
41 | 41 | ||
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 89760ff98..5fb2b9606 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts | |||
@@ -38,7 +38,7 @@ describe('Test jobs API validators', function () { | |||
38 | username: 'user1', | 38 | username: 'user1', |
39 | password: 'my super password' | 39 | password: 'my super password' |
40 | } | 40 | } |
41 | await createUser(server.url, server.accessToken, user.username, user.password) | 41 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
42 | userAccessToken = await userLogin(server, user) | 42 | userAccessToken = await userLogin(server, user) |
43 | }) | 43 | }) |
44 | 44 | ||
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index d6a40da61..9bc6ac244 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts | |||
@@ -33,7 +33,7 @@ describe('Test logs API validators', function () { | |||
33 | username: 'user1', | 33 | username: 'user1', |
34 | password: 'my super password' | 34 | password: 'my super password' |
35 | } | 35 | } |
36 | await createUser(server.url, server.accessToken, user.username, user.password) | 36 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
37 | userAccessToken = await userLogin(server, user) | 37 | userAccessToken = await userLogin(server, user) |
38 | }) | 38 | }) |
39 | 39 | ||
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index ff4726ceb..d14e35cf2 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts | |||
@@ -34,7 +34,7 @@ describe('Test server redundancy API validators', function () { | |||
34 | password: 'password' | 34 | password: 'password' |
35 | } | 35 | } |
36 | 36 | ||
37 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 37 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
38 | userAccessToken = await userLogin(servers[0], user) | 38 | userAccessToken = await userLogin(servers[0], user) |
39 | }) | 39 | }) |
40 | 40 | ||
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 04a3eb97c..a18e1a43b 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts | |||
@@ -42,7 +42,7 @@ describe('Test user subscriptions API validators', function () { | |||
42 | username: 'user1', | 42 | username: 'user1', |
43 | password: 'my super password' | 43 | password: 'my super password' |
44 | } | 44 | } |
45 | await createUser(server.url, server.accessToken, user.username, user.password) | 45 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
46 | userAccessToken = await userLogin(server, user) | 46 | userAccessToken = await userLogin(server, user) |
47 | }) | 47 | }) |
48 | 48 | ||
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index f3ee99e85..b5c812e8f 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -19,6 +19,7 @@ import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from | |||
19 | import { VideoPrivacy } from '../../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../../shared/models/videos' |
20 | import { waitJobs } from '../../../../shared/utils/server/jobs' | 20 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
21 | import { expect } from 'chai' | 21 | import { expect } from 'chai' |
22 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
22 | 23 | ||
23 | describe('Test users API validators', function () { | 24 | describe('Test users API validators', function () { |
24 | const path = '/api/v1/users/' | 25 | const path = '/api/v1/users/' |
@@ -47,7 +48,13 @@ describe('Test users API validators', function () { | |||
47 | await setAccessTokensToServers([ server ]) | 48 | await setAccessTokensToServers([ server ]) |
48 | 49 | ||
49 | const videoQuota = 42000000 | 50 | const videoQuota = 42000000 |
50 | await createUser(server.url, server.accessToken, user.username, user.password, videoQuota) | 51 | await createUser({ |
52 | url: server.url, | ||
53 | accessToken: server.accessToken, | ||
54 | username: user.username, | ||
55 | password: user.password, | ||
56 | videoQuota: videoQuota | ||
57 | }) | ||
51 | userAccessToken = await userLogin(server, user) | 58 | userAccessToken = await userLogin(server, user) |
52 | 59 | ||
53 | { | 60 | { |
@@ -99,7 +106,8 @@ describe('Test users API validators', function () { | |||
99 | password: 'my super password', | 106 | password: 'my super password', |
100 | videoQuota: -1, | 107 | videoQuota: -1, |
101 | videoQuotaDaily: -1, | 108 | videoQuotaDaily: -1, |
102 | role: UserRole.USER | 109 | role: UserRole.USER, |
110 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | ||
103 | } | 111 | } |
104 | 112 | ||
105 | it('Should fail with a too small username', async function () { | 113 | it('Should fail with a too small username', async function () { |
@@ -150,6 +158,12 @@ describe('Test users API validators', function () { | |||
150 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 158 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
151 | }) | 159 | }) |
152 | 160 | ||
161 | it('Should fail with invalid admin flags', async function () { | ||
162 | const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) | ||
163 | |||
164 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
165 | }) | ||
166 | |||
153 | it('Should fail with an non authenticated user', async function () { | 167 | it('Should fail with an non authenticated user', async function () { |
154 | await makePostBodyRequest({ | 168 | await makePostBodyRequest({ |
155 | url: server.url, | 169 | url: server.url, |
@@ -498,6 +512,12 @@ describe('Test users API validators', function () { | |||
498 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) | 512 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) |
499 | }) | 513 | }) |
500 | 514 | ||
515 | it('Should fail with invalid admin flags', async function () { | ||
516 | const fields = { adminFlags: 'toto' } | ||
517 | |||
518 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
519 | }) | ||
520 | |||
501 | it('Should succeed with the correct params', async function () { | 521 | it('Should succeed with the correct params', async function () { |
502 | const fields = { | 522 | const fields = { |
503 | email: 'email@example.com', | 523 | email: 'email@example.com', |
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index 3b8f5f14d..7edc8e39d 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts | |||
@@ -41,7 +41,7 @@ describe('Test video abuses API validators', function () { | |||
41 | 41 | ||
42 | const username = 'user1' | 42 | const username = 'user1' |
43 | const password = 'my super password' | 43 | const password = 'my super password' |
44 | await createUser(server.url, server.accessToken, username, password) | 44 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
45 | userAccessToken = await userLogin(server, { username, password }) | 45 | userAccessToken = await userLogin(server, { username, password }) |
46 | 46 | ||
47 | const res = await uploadVideo(server.url, server.accessToken, {}) | 47 | const res = await uploadVideo(server.url, server.accessToken, {}) |
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index fc039e847..81423aee9 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -8,7 +8,6 @@ import { | |||
8 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
9 | flushTests, | 9 | flushTests, |
10 | getBlacklistedVideosList, | 10 | getBlacklistedVideosList, |
11 | getBlacklistedVideosListWithTypeFilter, | ||
12 | getVideo, | 11 | getVideo, |
13 | getVideoWithToken, | 12 | getVideoWithToken, |
14 | killallServers, | 13 | killallServers, |
@@ -49,14 +48,14 @@ describe('Test video blacklist API validators', function () { | |||
49 | { | 48 | { |
50 | const username = 'user1' | 49 | const username = 'user1' |
51 | const password = 'my super password' | 50 | const password = 'my super password' |
52 | await createUser(servers[0].url, servers[0].accessToken, username, password) | 51 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password }) |
53 | userAccessToken1 = await userLogin(servers[0], { username, password }) | 52 | userAccessToken1 = await userLogin(servers[0], { username, password }) |
54 | } | 53 | } |
55 | 54 | ||
56 | { | 55 | { |
57 | const username = 'user2' | 56 | const username = 'user2' |
58 | const password = 'my super password' | 57 | const password = 'my super password' |
59 | await createUser(servers[0].url, servers[0].accessToken, username, password) | 58 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password }) |
60 | userAccessToken2 = await userLogin(servers[0], { username, password }) | 59 | userAccessToken2 = await userLogin(servers[0], { username, password }) |
61 | } | 60 | } |
62 | 61 | ||
@@ -221,11 +220,11 @@ describe('Test video blacklist API validators', function () { | |||
221 | const basePath = '/api/v1/videos/blacklist/' | 220 | const basePath = '/api/v1/videos/blacklist/' |
222 | 221 | ||
223 | it('Should fail with a non authenticated user', async function () { | 222 | it('Should fail with a non authenticated user', async function () { |
224 | await getBlacklistedVideosList(servers[0].url, 'fake token', 401) | 223 | await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 }) |
225 | }) | 224 | }) |
226 | 225 | ||
227 | it('Should fail with a non admin user', async function () { | 226 | it('Should fail with a non admin user', async function () { |
228 | await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403) | 227 | await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 }) |
229 | }) | 228 | }) |
230 | 229 | ||
231 | it('Should fail with a bad start pagination', async function () { | 230 | it('Should fail with a bad start pagination', async function () { |
@@ -241,11 +240,11 @@ describe('Test video blacklist API validators', function () { | |||
241 | }) | 240 | }) |
242 | 241 | ||
243 | it('Should fail with an invalid type', async function () { | 242 | it('Should fail with an invalid type', async function () { |
244 | await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, 0, 400) | 243 | await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 }) |
245 | }) | 244 | }) |
246 | 245 | ||
247 | it('Should succeed with the correct parameters', async function () { | 246 | it('Should succeed with the correct parameters', async function () { |
248 | await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) | 247 | await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) |
249 | }) | 248 | }) |
250 | }) | 249 | }) |
251 | 250 | ||
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index e4d36fd4f..de2ca8cd1 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts | |||
@@ -45,7 +45,7 @@ describe('Test video captions API validator', function () { | |||
45 | username: 'user1', | 45 | username: 'user1', |
46 | password: 'my super password' | 46 | password: 'my super password' |
47 | } | 47 | } |
48 | await createUser(server.url, server.accessToken, user.username, user.password) | 48 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
49 | userAccessToken = await userLogin(server, user) | 49 | userAccessToken = await userLogin(server, user) |
50 | } | 50 | } |
51 | }) | 51 | }) |
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 14e4deaf7..b72fc4220 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts | |||
@@ -53,7 +53,7 @@ describe('Test video channels API validator', function () { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | { | 55 | { |
56 | await createUser(server.url, server.accessToken, user.username, user.password) | 56 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
57 | accessTokenUser = await userLogin(server, user) | 57 | accessTokenUser = await userLogin(server, user) |
58 | } | 58 | } |
59 | }) | 59 | }) |
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 5981780ed..5f70998ef 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts | |||
@@ -52,7 +52,7 @@ describe('Test video comments API validator', function () { | |||
52 | username: 'user1', | 52 | username: 'user1', |
53 | password: 'my super password' | 53 | password: 'my super password' |
54 | } | 54 | } |
55 | await createUser(server.url, server.accessToken, user.username, user.password) | 55 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
56 | userAccessToken = await userLogin(server, user) | 56 | userAccessToken = await userLogin(server, user) |
57 | } | 57 | } |
58 | }) | 58 | }) |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 6dd9f15f7..4d2bf2e8d 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -46,7 +46,7 @@ describe('Test video imports API validator', function () { | |||
46 | 46 | ||
47 | const username = 'user1' | 47 | const username = 'user1' |
48 | const password = 'my super password' | 48 | const password = 'my super password' |
49 | await createUser(server.url, server.accessToken, username, password) | 49 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
50 | userAccessToken = await userLogin(server, { username, password }) | 50 | userAccessToken = await userLogin(server, { username, password }) |
51 | 51 | ||
52 | { | 52 | { |
@@ -167,7 +167,7 @@ describe('Test video imports API validator', function () { | |||
167 | username: 'fake', | 167 | username: 'fake', |
168 | password: 'fake_password' | 168 | password: 'fake_password' |
169 | } | 169 | } |
170 | await createUser(server.url, server.accessToken, user.username, user.password) | 170 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
171 | 171 | ||
172 | const accessTokenUser = await userLogin(server, user) | 172 | const accessTokenUser = await userLogin(server, user) |
173 | const res = await getMyUserInformation(server.url, accessTokenUser) | 173 | const res = await getMyUserInformation(server.url, accessTokenUser) |
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index d5557cd07..7c487ae81 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts | |||
@@ -56,18 +56,20 @@ describe('Test videos filters', function () { | |||
56 | await setDefaultVideoChannel([ server ]) | 56 | await setDefaultVideoChannel([ server ]) |
57 | 57 | ||
58 | const user = { username: 'user1', password: 'my super password' } | 58 | const user = { username: 'user1', password: 'my super password' } |
59 | await createUser(server.url, server.accessToken, user.username, user.password) | 59 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
60 | userAccessToken = await userLogin(server, user) | 60 | userAccessToken = await userLogin(server, user) |
61 | 61 | ||
62 | const moderator = { username: 'moderator', password: 'my super password' } | 62 | const moderator = { username: 'moderator', password: 'my super password' } |
63 | await createUser( | 63 | await createUser( |
64 | server.url, | 64 | { |
65 | server.accessToken, | 65 | url: server.url, |
66 | moderator.username, | 66 | accessToken: server.accessToken, |
67 | moderator.password, | 67 | username: moderator.username, |
68 | undefined, | 68 | password: moderator.password, |
69 | undefined, | 69 | videoQuota: undefined, |
70 | UserRole.MODERATOR | 70 | videoQuotaDaily: undefined, |
71 | role: UserRole.MODERATOR | ||
72 | } | ||
71 | ) | 73 | ) |
72 | moderatorAccessToken = await userLogin(server, moderator) | 74 | moderatorAccessToken = await userLogin(server, moderator) |
73 | 75 | ||
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 5a013b890..3f0e0d646 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts | |||
@@ -41,7 +41,7 @@ describe('Test videos API validator', function () { | |||
41 | 41 | ||
42 | const username = 'user1' | 42 | const username = 'user1' |
43 | const password = 'my super password' | 43 | const password = 'my super password' |
44 | await createUser(server.url, server.accessToken, username, password) | 44 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
45 | userAccessToken = await userLogin(server, { username, password }) | 45 | userAccessToken = await userLogin(server, { username, password }) |
46 | 46 | ||
47 | { | 47 | { |
@@ -265,7 +265,7 @@ describe('Test videos API validator', function () { | |||
265 | username: 'fake', | 265 | username: 'fake', |
266 | password: 'fake_password' | 266 | password: 'fake_password' |
267 | } | 267 | } |
268 | await createUser(server.url, server.accessToken, user.username, user.password) | 268 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
269 | 269 | ||
270 | const accessTokenUser = await userLogin(server, user) | 270 | const accessTokenUser = await userLogin(server, user) |
271 | const res = await getMyUserInformation(server.url, accessTokenUser) | 271 | const res = await getMyUserInformation(server.url, accessTokenUser) |
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 7bff52796..d1d6f3c35 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -133,7 +133,13 @@ describe('Test users notifications', function () { | |||
133 | username: 'user_1', | 133 | username: 'user_1', |
134 | password: 'super password' | 134 | password: 'super password' |
135 | } | 135 | } |
136 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) | 136 | await createUser({ |
137 | url: servers[ 0 ].url, | ||
138 | accessToken: servers[ 0 ].accessToken, | ||
139 | username: user.username, | ||
140 | password: user.password, | ||
141 | videoQuota: 10 * 1000 * 1000 | ||
142 | }) | ||
137 | userAccessToken = await userLogin(servers[0], user) | 143 | userAccessToken = await userLogin(servers[0], user) |
138 | 144 | ||
139 | await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) | 145 | await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) |
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index a411e973b..682bd262a 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts | |||
@@ -40,7 +40,7 @@ describe('Test a ActivityPub video channels search', function () { | |||
40 | await setAccessTokensToServers(servers) | 40 | await setAccessTokensToServers(servers) |
41 | 41 | ||
42 | { | 42 | { |
43 | await createUser(servers[0].url, servers[0].accessToken, 'user1_server1', 'password') | 43 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'user1_server1', password: 'password' }) |
44 | const channel = { | 44 | const channel = { |
45 | name: 'channel1_server1', | 45 | name: 'channel1_server1', |
46 | displayName: 'Channel 1 server 1' | 46 | displayName: 'Channel 1 server 1' |
@@ -50,7 +50,7 @@ describe('Test a ActivityPub video channels search', function () { | |||
50 | 50 | ||
51 | { | 51 | { |
52 | const user = { username: 'user1_server2', password: 'password' } | 52 | const user = { username: 'user1_server2', password: 'password' } |
53 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | 53 | await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password }) |
54 | userServer2Token = await userLogin(servers[1], user) | 54 | userServer2Token = await userLogin(servers[1], user) |
55 | 55 | ||
56 | const channel = { | 56 | const channel = { |
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 164905651..bc45102d2 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts | |||
@@ -54,7 +54,7 @@ describe('Test emails', function () { | |||
54 | await setAccessTokensToServers([ server ]) | 54 | await setAccessTokensToServers([ server ]) |
55 | 55 | ||
56 | { | 56 | { |
57 | const res = await createUser(server.url, server.accessToken, user.username, user.password) | 57 | const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
58 | userId = res.body.user.id | 58 | userId = res.body.user.id |
59 | 59 | ||
60 | userAccessToken = await userLogin(server, user) | 60 | userAccessToken = await userLogin(server, user) |
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 8bb073c41..28862a1c6 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts | |||
@@ -47,7 +47,7 @@ describe('Test follow constraints', function () { | |||
47 | username: 'user1', | 47 | username: 'user1', |
48 | password: 'super_password' | 48 | password: 'super_password' |
49 | } | 49 | } |
50 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 50 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
51 | userAccessToken = await userLogin(servers[0], user) | 51 | userAccessToken = await userLogin(servers[0], user) |
52 | 52 | ||
53 | await doubleFollow(servers[0], servers[1]) | 53 | await doubleFollow(servers[0], servers[1]) |
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 80f54b7ad..a5e6c3c1e 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts | |||
@@ -263,7 +263,7 @@ describe('Test follows', function () { | |||
263 | 263 | ||
264 | { | 264 | { |
265 | const user = { username: 'captain', password: 'password' } | 265 | const user = { username: 'captain', password: 'password' } |
266 | await createUser(servers[ 2 ].url, servers[ 2 ].accessToken, user.username, user.password) | 266 | await createUser({ url: servers[ 2 ].url, accessToken: servers[ 2 ].accessToken, username: user.username, password: user.password }) |
267 | const userAccessToken = await userLogin(servers[ 2 ], user) | 267 | const userAccessToken = await userLogin(servers[ 2 ], user) |
268 | 268 | ||
269 | const resVideos = await getVideosList(servers[ 2 ].url) | 269 | const resVideos = await getVideosList(servers[ 2 ].url) |
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index aaa6c62f7..eadbcaf83 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts | |||
@@ -37,7 +37,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
37 | username: 'user1', | 37 | username: 'user1', |
38 | password: 'super_password' | 38 | password: 'super_password' |
39 | } | 39 | } |
40 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 40 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
41 | 41 | ||
42 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) | 42 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) |
43 | const videoUUID = resVideo.body.video.uuid | 43 | const videoUUID = resVideo.body.video.uuid |
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts index 4bca27a94..638a443ba 100644 --- a/server/tests/api/users/blocklist.ts +++ b/server/tests/api/users/blocklist.ts | |||
@@ -86,7 +86,7 @@ describe('Test blocklist', function () { | |||
86 | 86 | ||
87 | { | 87 | { |
88 | const user = { username: 'user1', password: 'password' } | 88 | const user = { username: 'user1', password: 'password' } |
89 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 89 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
90 | 90 | ||
91 | userToken1 = await userLogin(servers[0], user) | 91 | userToken1 = await userLogin(servers[0], user) |
92 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) | 92 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) |
@@ -94,14 +94,14 @@ describe('Test blocklist', function () { | |||
94 | 94 | ||
95 | { | 95 | { |
96 | const user = { username: 'moderator', password: 'password' } | 96 | const user = { username: 'moderator', password: 'password' } |
97 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 97 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
98 | 98 | ||
99 | userModeratorToken = await userLogin(servers[0], user) | 99 | userModeratorToken = await userLogin(servers[0], user) |
100 | } | 100 | } |
101 | 101 | ||
102 | { | 102 | { |
103 | const user = { username: 'user2', password: 'password' } | 103 | const user = { username: 'user2', password: 'password' } |
104 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | 104 | await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password }) |
105 | 105 | ||
106 | userToken2 = await userLogin(servers[1], user) | 106 | userToken2 = await userLogin(servers[1], user) |
107 | await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) | 107 | await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) |
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 88a7187d6..037a79a76 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -45,7 +45,7 @@ describe('Test users subscriptions', function () { | |||
45 | { | 45 | { |
46 | for (const server of servers) { | 46 | for (const server of servers) { |
47 | const user = { username: 'user' + server.serverNumber, password: 'password' } | 47 | const user = { username: 'user' + server.serverNumber, password: 'password' } |
48 | await createUser(server.url, server.accessToken, user.username, user.password) | 48 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
49 | 49 | ||
50 | const accessToken = await userLogin(server, user) | 50 | const accessToken = await userLogin(server, user) |
51 | users.push({ accessToken }) | 51 | users.push({ accessToken }) |
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index c46c2b7d7..0510b2de9 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts | |||
@@ -57,7 +57,12 @@ describe('Test users with multiple servers', function () { | |||
57 | username: 'user1', | 57 | username: 'user1', |
58 | password: 'password' | 58 | password: 'password' |
59 | } | 59 | } |
60 | const res = await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, user.username, user.password) | 60 | const res = await createUser({ |
61 | url: servers[ 0 ].url, | ||
62 | accessToken: servers[ 0 ].accessToken, | ||
63 | username: user.username, | ||
64 | password: user.password | ||
65 | }) | ||
61 | userId = res.body.user.id | 66 | userId = res.body.user.id |
62 | userAccessToken = await userLogin(servers[ 0 ], user) | 67 | userAccessToken = await userLogin(servers[ 0 ], user) |
63 | } | 68 | } |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6e7de9c38..13511e070 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -37,6 +37,7 @@ import { | |||
37 | import { follow } from '../../../../shared/utils/server/follows' | 37 | import { follow } from '../../../../shared/utils/server/follows' |
38 | import { setAccessTokensToServers } from '../../../../shared/utils/users/login' | 38 | import { setAccessTokensToServers } from '../../../../shared/utils/users/login' |
39 | import { getMyVideos } from '../../../../shared/utils/videos/videos' | 39 | import { getMyVideos } from '../../../../shared/utils/videos/videos' |
40 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
40 | 41 | ||
41 | const expect = chai.expect | 42 | const expect = chai.expect |
42 | 43 | ||
@@ -60,563 +61,622 @@ describe('Test users', function () { | |||
60 | await setAccessTokensToServers([ server ]) | 61 | await setAccessTokensToServers([ server ]) |
61 | }) | 62 | }) |
62 | 63 | ||
63 | it('Should create a new client') | 64 | describe('OAuth client', function () { |
65 | it('Should create a new client') | ||
64 | 66 | ||
65 | it('Should return the first client') | 67 | it('Should return the first client') |
66 | 68 | ||
67 | it('Should remove the last client') | 69 | it('Should remove the last client') |
68 | 70 | ||
69 | it('Should not login with an invalid client id', async function () { | 71 | it('Should not login with an invalid client id', async function () { |
70 | const client = { id: 'client', secret: server.client.secret } | 72 | const client = { id: 'client', secret: server.client.secret } |
71 | const res = await login(server.url, client, server.user, 400) | 73 | const res = await login(server.url, client, server.user, 400) |
72 | 74 | ||
73 | expect(res.body.error).to.contain('client is invalid') | 75 | expect(res.body.error).to.contain('client is invalid') |
74 | }) | 76 | }) |
75 | 77 | ||
76 | it('Should not login with an invalid client secret', async function () { | 78 | it('Should not login with an invalid client secret', async function () { |
77 | const client = { id: server.client.id, secret: 'coucou' } | 79 | const client = { id: server.client.id, secret: 'coucou' } |
78 | const res = await login(server.url, client, server.user, 400) | 80 | const res = await login(server.url, client, server.user, 400) |
79 | 81 | ||
80 | expect(res.body.error).to.contain('client is invalid') | 82 | expect(res.body.error).to.contain('client is invalid') |
83 | }) | ||
81 | }) | 84 | }) |
82 | 85 | ||
83 | it('Should not login with an invalid username', async function () { | 86 | describe('Login', function () { |
84 | const user = { username: 'captain crochet', password: server.user.password } | ||
85 | const res = await login(server.url, server.client, user, 400) | ||
86 | |||
87 | expect(res.body.error).to.contain('credentials are invalid') | ||
88 | }) | ||
89 | 87 | ||
90 | it('Should not login with an invalid password', async function () { | 88 | it('Should not login with an invalid username', async function () { |
91 | const user = { username: server.user.username, password: 'mew_three' } | 89 | const user = { username: 'captain crochet', password: server.user.password } |
92 | const res = await login(server.url, server.client, user, 400) | 90 | const res = await login(server.url, server.client, user, 400) |
93 | 91 | ||
94 | expect(res.body.error).to.contain('credentials are invalid') | 92 | expect(res.body.error).to.contain('credentials are invalid') |
95 | }) | 93 | }) |
96 | 94 | ||
97 | it('Should not be able to upload a video', async function () { | 95 | it('Should not login with an invalid password', async function () { |
98 | accessToken = 'my_super_token' | 96 | const user = { username: server.user.username, password: 'mew_three' } |
97 | const res = await login(server.url, server.client, user, 400) | ||
99 | 98 | ||
100 | const videoAttributes = {} | 99 | expect(res.body.error).to.contain('credentials are invalid') |
101 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | 100 | }) |
102 | }) | ||
103 | 101 | ||
104 | it('Should not be able to follow', async function () { | 102 | it('Should not be able to upload a video', async function () { |
105 | accessToken = 'my_super_token' | 103 | accessToken = 'my_super_token' |
106 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | ||
107 | }) | ||
108 | 104 | ||
109 | it('Should not be able to unfollow') | 105 | const videoAttributes = {} |
106 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | ||
107 | }) | ||
110 | 108 | ||
111 | it('Should be able to login', async function () { | 109 | it('Should not be able to follow', async function () { |
112 | const res = await login(server.url, server.client, server.user, 200) | 110 | accessToken = 'my_super_token' |
111 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | ||
112 | }) | ||
113 | 113 | ||
114 | accessToken = res.body.access_token | 114 | it('Should not be able to unfollow') |
115 | }) | ||
116 | 115 | ||
117 | it('Should upload the video with the correct token', async function () { | 116 | it('Should be able to login', async function () { |
118 | const videoAttributes = {} | 117 | const res = await login(server.url, server.client, server.user, 200) |
119 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
120 | const res = await getVideosList(server.url) | ||
121 | const video = res.body.data[ 0 ] | ||
122 | 118 | ||
123 | expect(video.account.name).to.equal('root') | 119 | accessToken = res.body.access_token |
124 | videoId = video.id | 120 | }) |
125 | }) | 121 | }) |
126 | 122 | ||
127 | it('Should upload the video again with the correct token', async function () { | 123 | describe('Upload', function () { |
128 | const videoAttributes = {} | ||
129 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
130 | }) | ||
131 | 124 | ||
132 | it('Should retrieve a video rating', async function () { | 125 | it('Should upload the video with the correct token', async function () { |
133 | await rateVideo(server.url, accessToken, videoId, 'like') | 126 | const videoAttributes = {} |
134 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | 127 | await uploadVideo(server.url, accessToken, videoAttributes) |
135 | const rating = res.body | 128 | const res = await getVideosList(server.url) |
129 | const video = res.body.data[ 0 ] | ||
136 | 130 | ||
137 | expect(rating.videoId).to.equal(videoId) | 131 | expect(video.account.name).to.equal('root') |
138 | expect(rating.rating).to.equal('like') | 132 | videoId = video.id |
133 | }) | ||
134 | |||
135 | it('Should upload the video again with the correct token', async function () { | ||
136 | const videoAttributes = {} | ||
137 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
138 | }) | ||
139 | }) | 139 | }) |
140 | 140 | ||
141 | it('Should retrieve ratings list', async function () { | 141 | describe('Ratings', function () { |
142 | await rateVideo(server.url, accessToken, videoId, 'like') | ||
143 | 142 | ||
144 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) | 143 | it('Should retrieve a video rating', async function () { |
145 | const ratings = res.body | 144 | await rateVideo(server.url, accessToken, videoId, 'like') |
145 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | ||
146 | const rating = res.body | ||
146 | 147 | ||
147 | expect(ratings.total).to.equal(1) | 148 | expect(rating.videoId).to.equal(videoId) |
148 | expect(ratings.data[0].video.id).to.equal(videoId) | 149 | expect(rating.rating).to.equal('like') |
149 | expect(ratings.data[0].rating).to.equal('like') | 150 | }) |
150 | }) | ||
151 | 151 | ||
152 | it('Should retrieve ratings list by rating type', async function () { | 152 | it('Should retrieve ratings list', async function () { |
153 | { | 153 | await rateVideo(server.url, accessToken, videoId, 'like') |
154 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | ||
155 | const ratings = res.body | ||
156 | expect(ratings.data.length).to.equal(1) | ||
157 | } | ||
158 | 154 | ||
159 | { | 155 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) |
160 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | ||
161 | const ratings = res.body | 156 | const ratings = res.body |
162 | expect(ratings.data.length).to.equal(0) | ||
163 | } | ||
164 | }) | ||
165 | |||
166 | it('Should not be able to remove the video with an incorrect token', async function () { | ||
167 | await removeVideo(server.url, 'bad_token', videoId, 401) | ||
168 | }) | ||
169 | 157 | ||
170 | it('Should not be able to remove the video with the token of another account') | 158 | expect(ratings.total).to.equal(1) |
159 | expect(ratings.data[ 0 ].video.id).to.equal(videoId) | ||
160 | expect(ratings.data[ 0 ].rating).to.equal('like') | ||
161 | }) | ||
171 | 162 | ||
172 | it('Should be able to remove the video with the correct token', async function () { | 163 | it('Should retrieve ratings list by rating type', async function () { |
173 | await removeVideo(server.url, accessToken, videoId) | 164 | { |
165 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | ||
166 | const ratings = res.body | ||
167 | expect(ratings.data.length).to.equal(1) | ||
168 | } | ||
169 | |||
170 | { | ||
171 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | ||
172 | const ratings = res.body | ||
173 | expect(ratings.data.length).to.equal(0) | ||
174 | } | ||
175 | }) | ||
174 | }) | 176 | }) |
175 | 177 | ||
176 | it('Should logout (revoke token)') | 178 | describe('Remove video', function () { |
177 | 179 | it('Should not be able to remove the video with an incorrect token', async function () { | |
178 | it('Should not be able to get the user information') | 180 | await removeVideo(server.url, 'bad_token', videoId, 401) |
179 | 181 | }) | |
180 | it('Should not be able to upload a video') | ||
181 | |||
182 | it('Should not be able to remove a video') | ||
183 | 182 | ||
184 | it('Should not be able to rate a video', async function () { | 183 | it('Should not be able to remove the video with the token of another account') |
185 | const path = '/api/v1/videos/' | ||
186 | const data = { | ||
187 | rating: 'likes' | ||
188 | } | ||
189 | 184 | ||
190 | const options = { | 185 | it('Should be able to remove the video with the correct token', async function () { |
191 | url: server.url, | 186 | await removeVideo(server.url, accessToken, videoId) |
192 | path: path + videoId, | 187 | }) |
193 | token: 'wrong token', | ||
194 | fields: data, | ||
195 | statusCodeExpected: 401 | ||
196 | } | ||
197 | await makePutBodyRequest(options) | ||
198 | }) | 188 | }) |
199 | 189 | ||
200 | it('Should be able to login again') | 190 | describe('Logout', function () { |
191 | it('Should logout (revoke token)') | ||
201 | 192 | ||
202 | it('Should have an expired access token') | 193 | it('Should not be able to get the user information') |
203 | 194 | ||
204 | it('Should refresh the token') | 195 | it('Should not be able to upload a video') |
205 | 196 | ||
206 | it('Should be able to upload a video again') | 197 | it('Should not be able to remove a video') |
207 | 198 | ||
208 | it('Should be able to create a new user', async function () { | 199 | it('Should not be able to rate a video', async function () { |
209 | await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024) | 200 | const path = '/api/v1/videos/' |
210 | }) | 201 | const data = { |
202 | rating: 'likes' | ||
203 | } | ||
211 | 204 | ||
212 | it('Should be able to login with this user', async function () { | 205 | const options = { |
213 | accessTokenUser = await userLogin(server, user) | 206 | url: server.url, |
214 | }) | 207 | path: path + videoId, |
208 | token: 'wrong token', | ||
209 | fields: data, | ||
210 | statusCodeExpected: 401 | ||
211 | } | ||
212 | await makePutBodyRequest(options) | ||
213 | }) | ||
215 | 214 | ||
216 | it('Should be able to get the user information', async function () { | 215 | it('Should be able to login again') |
217 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
218 | const user = res.body | ||
219 | |||
220 | expect(user.username).to.equal('user_1') | ||
221 | expect(user.email).to.equal('user_1@example.com') | ||
222 | expect(user.nsfwPolicy).to.equal('display') | ||
223 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
224 | expect(user.roleLabel).to.equal('User') | ||
225 | expect(user.id).to.be.a('number') | ||
226 | expect(user.account.displayName).to.equal('user_1') | ||
227 | expect(user.account.description).to.be.null | ||
228 | }) | ||
229 | 216 | ||
230 | it('Should be able to upload a video with this user', async function () { | 217 | it('Should have an expired access token') |
231 | this.timeout(5000) | ||
232 | 218 | ||
233 | const videoAttributes = { | 219 | it('Should refresh the token') |
234 | name: 'super user video', | 220 | |
235 | fixture: 'video_short.webm' | 221 | it('Should be able to upload a video again') |
236 | } | ||
237 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
238 | }) | 222 | }) |
239 | 223 | ||
240 | it('Should have video quota updated', async function () { | 224 | describe('Creating a user', function () { |
241 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | ||
242 | const data = res.body | ||
243 | 225 | ||
244 | expect(data.videoQuotaUsed).to.equal(218910) | 226 | it('Should be able to create a new user', async function () { |
227 | await createUser({ | ||
228 | url: server.url, | ||
229 | accessToken: accessToken, | ||
230 | username: user.username, | ||
231 | password: user.password, | ||
232 | videoQuota: 2 * 1024 * 1024, | ||
233 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | ||
234 | }) | ||
235 | }) | ||
245 | 236 | ||
246 | const resUsers = await getUsersList(server.url, server.accessToken) | 237 | it('Should be able to login with this user', async function () { |
238 | accessTokenUser = await userLogin(server, user) | ||
239 | }) | ||
247 | 240 | ||
248 | const users: User[] = resUsers.body.data | 241 | it('Should be able to get user information', async function () { |
249 | const tmpUser = users.find(u => u.username === user.username) | 242 | const res1 = await getMyUserInformation(server.url, accessTokenUser) |
250 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | 243 | const userMe: User = res1.body |
244 | |||
245 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id) | ||
246 | const userGet: User = res2.body | ||
247 | |||
248 | for (const user of [ userMe, userGet ]) { | ||
249 | expect(user.username).to.equal('user_1') | ||
250 | expect(user.email).to.equal('user_1@example.com') | ||
251 | expect(user.nsfwPolicy).to.equal('display') | ||
252 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
253 | expect(user.roleLabel).to.equal('User') | ||
254 | expect(user.id).to.be.a('number') | ||
255 | expect(user.account.displayName).to.equal('user_1') | ||
256 | expect(user.account.description).to.be.null | ||
257 | } | ||
258 | |||
259 | expect(userMe.adminFlags).to.be.undefined | ||
260 | expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST) | ||
261 | }) | ||
251 | }) | 262 | }) |
252 | 263 | ||
253 | it('Should be able to list my videos', async function () { | 264 | describe('My videos & quotas', function () { |
254 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | ||
255 | expect(res.body.total).to.equal(1) | ||
256 | |||
257 | const videos = res.body.data | ||
258 | expect(videos).to.have.lengthOf(1) | ||
259 | 265 | ||
260 | expect(videos[ 0 ].name).to.equal('super user video') | 266 | it('Should be able to upload a video with this user', async function () { |
261 | }) | 267 | this.timeout(5000) |
262 | |||
263 | it('Should list all the users', async function () { | ||
264 | const res = await getUsersList(server.url, server.accessToken) | ||
265 | const result = res.body | ||
266 | const total = result.total | ||
267 | const users = result.data | ||
268 | 268 | ||
269 | expect(total).to.equal(2) | 269 | const videoAttributes = { |
270 | expect(users).to.be.an('array') | 270 | name: 'super user video', |
271 | expect(users.length).to.equal(2) | 271 | fixture: 'video_short.webm' |
272 | } | ||
273 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
274 | }) | ||
272 | 275 | ||
273 | const user = users[ 0 ] | 276 | it('Should have video quota updated', async function () { |
274 | expect(user.username).to.equal('user_1') | 277 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) |
275 | expect(user.email).to.equal('user_1@example.com') | 278 | const data = res.body |
276 | expect(user.nsfwPolicy).to.equal('display') | ||
277 | 279 | ||
278 | const rootUser = users[ 1 ] | 280 | expect(data.videoQuotaUsed).to.equal(218910) |
279 | expect(rootUser.username).to.equal('root') | ||
280 | expect(rootUser.email).to.equal('admin1@example.com') | ||
281 | expect(user.nsfwPolicy).to.equal('display') | ||
282 | 281 | ||
283 | userId = user.id | 282 | const resUsers = await getUsersList(server.url, server.accessToken) |
284 | }) | ||
285 | 283 | ||
286 | it('Should list only the first user by username asc', async function () { | 284 | const users: User[] = resUsers.body.data |
287 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | 285 | const tmpUser = users.find(u => u.username === user.username) |
286 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | ||
287 | }) | ||
288 | 288 | ||
289 | const result = res.body | 289 | it('Should be able to list my videos', async function () { |
290 | const total = result.total | 290 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) |
291 | const users = result.data | 291 | expect(res.body.total).to.equal(1) |
292 | 292 | ||
293 | expect(total).to.equal(2) | 293 | const videos = res.body.data |
294 | expect(users.length).to.equal(1) | 294 | expect(videos).to.have.lengthOf(1) |
295 | 295 | ||
296 | const user = users[ 0 ] | 296 | expect(videos[ 0 ].name).to.equal('super user video') |
297 | expect(user.username).to.equal('root') | 297 | }) |
298 | expect(user.email).to.equal('admin1@example.com') | ||
299 | expect(user.roleLabel).to.equal('Administrator') | ||
300 | expect(user.nsfwPolicy).to.equal('display') | ||
301 | }) | 298 | }) |
302 | 299 | ||
303 | it('Should list only the first user by username desc', async function () { | 300 | describe('Users listing', function () { |
304 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | ||
305 | const result = res.body | ||
306 | const total = result.total | ||
307 | const users = result.data | ||
308 | 301 | ||
309 | expect(total).to.equal(2) | 302 | it('Should list all the users', async function () { |
310 | expect(users.length).to.equal(1) | 303 | const res = await getUsersList(server.url, server.accessToken) |
304 | const result = res.body | ||
305 | const total = result.total | ||
306 | const users = result.data | ||
311 | 307 | ||
312 | const user = users[ 0 ] | 308 | expect(total).to.equal(2) |
313 | expect(user.username).to.equal('user_1') | 309 | expect(users).to.be.an('array') |
314 | expect(user.email).to.equal('user_1@example.com') | 310 | expect(users.length).to.equal(2) |
315 | expect(user.nsfwPolicy).to.equal('display') | ||
316 | }) | ||
317 | 311 | ||
318 | it('Should list only the second user by createdAt desc', async function () { | 312 | const user = users[ 0 ] |
319 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | 313 | expect(user.username).to.equal('user_1') |
320 | const result = res.body | 314 | expect(user.email).to.equal('user_1@example.com') |
321 | const total = result.total | 315 | expect(user.nsfwPolicy).to.equal('display') |
322 | const users = result.data | ||
323 | 316 | ||
324 | expect(total).to.equal(2) | 317 | const rootUser = users[ 1 ] |
325 | expect(users.length).to.equal(1) | 318 | expect(rootUser.username).to.equal('root') |
319 | expect(rootUser.email).to.equal('admin1@example.com') | ||
320 | expect(user.nsfwPolicy).to.equal('display') | ||
326 | 321 | ||
327 | const user = users[ 0 ] | 322 | userId = user.id |
328 | expect(user.username).to.equal('user_1') | 323 | }) |
329 | expect(user.email).to.equal('user_1@example.com') | ||
330 | expect(user.nsfwPolicy).to.equal('display') | ||
331 | }) | ||
332 | 324 | ||
333 | it('Should list all the users by createdAt asc', async function () { | 325 | it('Should list only the first user by username asc', async function () { |
334 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | 326 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') |
335 | const result = res.body | ||
336 | const total = result.total | ||
337 | const users = result.data | ||
338 | 327 | ||
339 | expect(total).to.equal(2) | 328 | const result = res.body |
340 | expect(users.length).to.equal(2) | 329 | const total = result.total |
330 | const users = result.data | ||
341 | 331 | ||
342 | expect(users[ 0 ].username).to.equal('root') | 332 | expect(total).to.equal(2) |
343 | expect(users[ 0 ].email).to.equal('admin1@example.com') | 333 | expect(users.length).to.equal(1) |
344 | expect(users[ 0 ].nsfwPolicy).to.equal('display') | ||
345 | 334 | ||
346 | expect(users[ 1 ].username).to.equal('user_1') | 335 | const user = users[ 0 ] |
347 | expect(users[ 1 ].email).to.equal('user_1@example.com') | 336 | expect(user.username).to.equal('root') |
348 | expect(users[ 1 ].nsfwPolicy).to.equal('display') | 337 | expect(user.email).to.equal('admin1@example.com') |
349 | }) | 338 | expect(user.roleLabel).to.equal('Administrator') |
339 | expect(user.nsfwPolicy).to.equal('display') | ||
340 | }) | ||
350 | 341 | ||
351 | it('Should search user by username', async function () { | 342 | it('Should list only the first user by username desc', async function () { |
352 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | 343 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') |
353 | const users = res.body.data as User[] | 344 | const result = res.body |
345 | const total = result.total | ||
346 | const users = result.data | ||
354 | 347 | ||
355 | expect(res.body.total).to.equal(1) | 348 | expect(total).to.equal(2) |
356 | expect(users.length).to.equal(1) | 349 | expect(users.length).to.equal(1) |
357 | 350 | ||
358 | expect(users[ 0 ].username).to.equal('root') | 351 | const user = users[ 0 ] |
359 | }) | 352 | expect(user.username).to.equal('user_1') |
353 | expect(user.email).to.equal('user_1@example.com') | ||
354 | expect(user.nsfwPolicy).to.equal('display') | ||
355 | }) | ||
360 | 356 | ||
361 | it('Should search user by email', async function () { | 357 | it('Should list only the second user by createdAt desc', async function () { |
362 | { | 358 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') |
363 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | 359 | const result = res.body |
364 | const users = res.body.data as User[] | 360 | const total = result.total |
361 | const users = result.data | ||
365 | 362 | ||
366 | expect(res.body.total).to.equal(1) | 363 | expect(total).to.equal(2) |
367 | expect(users.length).to.equal(1) | 364 | expect(users.length).to.equal(1) |
368 | 365 | ||
369 | expect(users[ 0 ].username).to.equal('user_1') | 366 | const user = users[ 0 ] |
370 | expect(users[ 0 ].email).to.equal('user_1@example.com') | 367 | expect(user.username).to.equal('user_1') |
371 | } | 368 | expect(user.email).to.equal('user_1@example.com') |
369 | expect(user.nsfwPolicy).to.equal('display') | ||
370 | }) | ||
372 | 371 | ||
373 | { | 372 | it('Should list all the users by createdAt asc', async function () { |
374 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | 373 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') |
375 | const users = res.body.data as User[] | 374 | const result = res.body |
375 | const total = result.total | ||
376 | const users = result.data | ||
376 | 377 | ||
377 | expect(res.body.total).to.equal(2) | 378 | expect(total).to.equal(2) |
378 | expect(users.length).to.equal(2) | 379 | expect(users.length).to.equal(2) |
379 | 380 | ||
380 | expect(users[ 0 ].username).to.equal('root') | 381 | expect(users[ 0 ].username).to.equal('root') |
381 | expect(users[ 1 ].username).to.equal('user_1') | 382 | expect(users[ 0 ].email).to.equal('admin1@example.com') |
382 | } | 383 | expect(users[ 0 ].nsfwPolicy).to.equal('display') |
383 | }) | ||
384 | 384 | ||
385 | it('Should update my password', async function () { | 385 | expect(users[ 1 ].username).to.equal('user_1') |
386 | await updateMyUser({ | 386 | expect(users[ 1 ].email).to.equal('user_1@example.com') |
387 | url: server.url, | 387 | expect(users[ 1 ].nsfwPolicy).to.equal('display') |
388 | accessToken: accessTokenUser, | ||
389 | currentPassword: 'super password', | ||
390 | newPassword: 'new password' | ||
391 | }) | 388 | }) |
392 | user.password = 'new password' | ||
393 | 389 | ||
394 | await userLogin(server, user, 200) | 390 | it('Should search user by username', async function () { |
395 | }) | 391 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') |
392 | const users = res.body.data as User[] | ||
393 | |||
394 | expect(res.body.total).to.equal(1) | ||
395 | expect(users.length).to.equal(1) | ||
396 | 396 | ||
397 | it('Should be able to change the NSFW display attribute', async function () { | 397 | expect(users[ 0 ].username).to.equal('root') |
398 | await updateMyUser({ | ||
399 | url: server.url, | ||
400 | accessToken: accessTokenUser, | ||
401 | nsfwPolicy: 'do_not_list' | ||
402 | }) | 398 | }) |
403 | 399 | ||
404 | const res = await getMyUserInformation(server.url, accessTokenUser) | 400 | it('Should search user by email', async function () { |
405 | const user = res.body | 401 | { |
402 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | ||
403 | const users = res.body.data as User[] | ||
406 | 404 | ||
407 | expect(user.username).to.equal('user_1') | 405 | expect(res.body.total).to.equal(1) |
408 | expect(user.email).to.equal('user_1@example.com') | 406 | expect(users.length).to.equal(1) |
409 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
410 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
411 | expect(user.id).to.be.a('number') | ||
412 | expect(user.account.displayName).to.equal('user_1') | ||
413 | expect(user.account.description).to.be.null | ||
414 | }) | ||
415 | 407 | ||
416 | it('Should be able to change the autoPlayVideo attribute', async function () { | 408 | expect(users[ 0 ].username).to.equal('user_1') |
417 | await updateMyUser({ | 409 | expect(users[ 0 ].email).to.equal('user_1@example.com') |
418 | url: server.url, | 410 | } |
419 | accessToken: accessTokenUser, | ||
420 | autoPlayVideo: false | ||
421 | }) | ||
422 | 411 | ||
423 | const res = await getMyUserInformation(server.url, accessTokenUser) | 412 | { |
424 | const user = res.body | 413 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') |
414 | const users = res.body.data as User[] | ||
425 | 415 | ||
426 | expect(user.autoPlayVideo).to.be.false | 416 | expect(res.body.total).to.equal(2) |
427 | }) | 417 | expect(users.length).to.equal(2) |
428 | 418 | ||
429 | it('Should be able to change the email display attribute', async function () { | 419 | expect(users[ 0 ].username).to.equal('root') |
430 | await updateMyUser({ | 420 | expect(users[ 1 ].username).to.equal('user_1') |
431 | url: server.url, | 421 | } |
432 | accessToken: accessTokenUser, | ||
433 | email: 'updated@example.com' | ||
434 | }) | 422 | }) |
435 | |||
436 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
437 | const user = res.body | ||
438 | |||
439 | expect(user.username).to.equal('user_1') | ||
440 | expect(user.email).to.equal('updated@example.com') | ||
441 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
442 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
443 | expect(user.id).to.be.a('number') | ||
444 | expect(user.account.displayName).to.equal('user_1') | ||
445 | expect(user.account.description).to.be.null | ||
446 | }) | 423 | }) |
447 | 424 | ||
448 | it('Should be able to update my avatar', async function () { | 425 | describe('Update my account', function () { |
449 | const fixture = 'avatar.png' | 426 | it('Should update my password', async function () { |
427 | await updateMyUser({ | ||
428 | url: server.url, | ||
429 | accessToken: accessTokenUser, | ||
430 | currentPassword: 'super password', | ||
431 | newPassword: 'new password' | ||
432 | }) | ||
433 | user.password = 'new password' | ||
450 | 434 | ||
451 | await updateMyAvatar({ | 435 | await userLogin(server, user, 200) |
452 | url: server.url, | ||
453 | accessToken: accessTokenUser, | ||
454 | fixture | ||
455 | }) | 436 | }) |
456 | 437 | ||
457 | const res = await getMyUserInformation(server.url, accessTokenUser) | 438 | it('Should be able to change the NSFW display attribute', async function () { |
458 | const user = res.body | 439 | await updateMyUser({ |
440 | url: server.url, | ||
441 | accessToken: accessTokenUser, | ||
442 | nsfwPolicy: 'do_not_list' | ||
443 | }) | ||
444 | |||
445 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
446 | const user = res.body | ||
447 | |||
448 | expect(user.username).to.equal('user_1') | ||
449 | expect(user.email).to.equal('user_1@example.com') | ||
450 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
451 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
452 | expect(user.id).to.be.a('number') | ||
453 | expect(user.account.displayName).to.equal('user_1') | ||
454 | expect(user.account.description).to.be.null | ||
455 | }) | ||
459 | 456 | ||
460 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') | 457 | it('Should be able to change the autoPlayVideo attribute', async function () { |
461 | }) | 458 | await updateMyUser({ |
459 | url: server.url, | ||
460 | accessToken: accessTokenUser, | ||
461 | autoPlayVideo: false | ||
462 | }) | ||
462 | 463 | ||
463 | it('Should be able to update my display name', async function () { | 464 | const res = await getMyUserInformation(server.url, accessTokenUser) |
464 | await updateMyUser({ | 465 | const user = res.body |
465 | url: server.url, | 466 | |
466 | accessToken: accessTokenUser, | 467 | expect(user.autoPlayVideo).to.be.false |
467 | displayName: 'new display name' | ||
468 | }) | 468 | }) |
469 | 469 | ||
470 | const res = await getMyUserInformation(server.url, accessTokenUser) | 470 | it('Should be able to change the email display attribute', async function () { |
471 | const user = res.body | 471 | await updateMyUser({ |
472 | url: server.url, | ||
473 | accessToken: accessTokenUser, | ||
474 | email: 'updated@example.com' | ||
475 | }) | ||
476 | |||
477 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
478 | const user = res.body | ||
479 | |||
480 | expect(user.username).to.equal('user_1') | ||
481 | expect(user.email).to.equal('updated@example.com') | ||
482 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
483 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
484 | expect(user.id).to.be.a('number') | ||
485 | expect(user.account.displayName).to.equal('user_1') | ||
486 | expect(user.account.description).to.be.null | ||
487 | }) | ||
472 | 488 | ||
473 | expect(user.username).to.equal('user_1') | 489 | it('Should be able to update my avatar', async function () { |
474 | expect(user.email).to.equal('updated@example.com') | 490 | const fixture = 'avatar.png' |
475 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
476 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
477 | expect(user.id).to.be.a('number') | ||
478 | expect(user.account.displayName).to.equal('new display name') | ||
479 | expect(user.account.description).to.be.null | ||
480 | }) | ||
481 | 491 | ||
482 | it('Should be able to update my description', async function () { | 492 | await updateMyAvatar({ |
483 | await updateMyUser({ | 493 | url: server.url, |
484 | url: server.url, | 494 | accessToken: accessTokenUser, |
485 | accessToken: accessTokenUser, | 495 | fixture |
486 | description: 'my super description updated' | 496 | }) |
487 | }) | ||
488 | 497 | ||
489 | const res = await getMyUserInformation(server.url, accessTokenUser) | 498 | const res = await getMyUserInformation(server.url, accessTokenUser) |
490 | const user = res.body | 499 | const user = res.body |
491 | 500 | ||
492 | expect(user.username).to.equal('user_1') | 501 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') |
493 | expect(user.email).to.equal('updated@example.com') | 502 | }) |
494 | expect(user.nsfwPolicy).to.equal('do_not_list') | 503 | |
495 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 504 | it('Should be able to update my display name', async function () { |
496 | expect(user.id).to.be.a('number') | 505 | await updateMyUser({ |
497 | expect(user.account.displayName).to.equal('new display name') | 506 | url: server.url, |
498 | expect(user.account.description).to.equal('my super description updated') | 507 | accessToken: accessTokenUser, |
499 | }) | 508 | displayName: 'new display name' |
509 | }) | ||
510 | |||
511 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
512 | const user = res.body | ||
513 | |||
514 | expect(user.username).to.equal('user_1') | ||
515 | expect(user.email).to.equal('updated@example.com') | ||
516 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
517 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
518 | expect(user.id).to.be.a('number') | ||
519 | expect(user.account.displayName).to.equal('new display name') | ||
520 | expect(user.account.description).to.be.null | ||
521 | }) | ||
500 | 522 | ||
501 | it('Should be able to update another user', async function () { | 523 | it('Should be able to update my description', async function () { |
502 | await updateUser({ | 524 | await updateMyUser({ |
503 | url: server.url, | 525 | url: server.url, |
504 | userId, | 526 | accessToken: accessTokenUser, |
505 | accessToken, | 527 | description: 'my super description updated' |
506 | email: 'updated2@example.com', | 528 | }) |
507 | emailVerified: true, | 529 | |
508 | videoQuota: 42, | 530 | const res = await getMyUserInformation(server.url, accessTokenUser) |
509 | role: UserRole.MODERATOR | 531 | const user = res.body |
510 | }) | 532 | |
511 | 533 | expect(user.username).to.equal('user_1') | |
512 | const res = await getUserInformation(server.url, accessToken, userId) | 534 | expect(user.email).to.equal('updated@example.com') |
513 | const user = res.body | 535 | expect(user.nsfwPolicy).to.equal('do_not_list') |
514 | 536 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
515 | expect(user.username).to.equal('user_1') | 537 | expect(user.id).to.be.a('number') |
516 | expect(user.email).to.equal('updated2@example.com') | 538 | expect(user.account.displayName).to.equal('new display name') |
517 | expect(user.emailVerified).to.be.true | 539 | expect(user.account.description).to.equal('my super description updated') |
518 | expect(user.nsfwPolicy).to.equal('do_not_list') | 540 | }) |
519 | expect(user.videoQuota).to.equal(42) | ||
520 | expect(user.roleLabel).to.equal('Moderator') | ||
521 | expect(user.id).to.be.a('number') | ||
522 | }) | 541 | }) |
523 | 542 | ||
524 | it('Should have removed the user token', async function () { | 543 | describe('Updating another user', function () { |
525 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 544 | |
545 | it('Should be able to update another user', async function () { | ||
546 | await updateUser({ | ||
547 | url: server.url, | ||
548 | userId, | ||
549 | accessToken, | ||
550 | email: 'updated2@example.com', | ||
551 | emailVerified: true, | ||
552 | videoQuota: 42, | ||
553 | role: UserRole.MODERATOR, | ||
554 | adminFlags: UserAdminFlag.NONE | ||
555 | }) | ||
556 | |||
557 | const res = await getUserInformation(server.url, accessToken, userId) | ||
558 | const user = res.body | ||
559 | |||
560 | expect(user.username).to.equal('user_1') | ||
561 | expect(user.email).to.equal('updated2@example.com') | ||
562 | expect(user.emailVerified).to.be.true | ||
563 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
564 | expect(user.videoQuota).to.equal(42) | ||
565 | expect(user.roleLabel).to.equal('Moderator') | ||
566 | expect(user.id).to.be.a('number') | ||
567 | expect(user.adminFlags).to.equal(UserAdminFlag.NONE) | ||
568 | }) | ||
526 | 569 | ||
527 | accessTokenUser = await userLogin(server, user) | 570 | it('Should have removed the user token', async function () { |
528 | }) | 571 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
529 | 572 | ||
530 | it('Should be able to update another user password', async function () { | 573 | accessTokenUser = await userLogin(server, user) |
531 | await updateUser({ | ||
532 | url: server.url, | ||
533 | userId, | ||
534 | accessToken, | ||
535 | password: 'password updated' | ||
536 | }) | 574 | }) |
537 | 575 | ||
538 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 576 | it('Should be able to update another user password', async function () { |
577 | await updateUser({ | ||
578 | url: server.url, | ||
579 | userId, | ||
580 | accessToken, | ||
581 | password: 'password updated' | ||
582 | }) | ||
539 | 583 | ||
540 | await userLogin(server, user, 400) | 584 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
541 | 585 | ||
542 | user.password = 'password updated' | 586 | await userLogin(server, user, 400) |
543 | accessTokenUser = await userLogin(server, user) | ||
544 | }) | ||
545 | 587 | ||
546 | it('Should be able to list video blacklist by a moderator', async function () { | 588 | user.password = 'password updated' |
547 | await getBlacklistedVideosList(server.url, accessTokenUser) | 589 | accessTokenUser = await userLogin(server, user) |
590 | }) | ||
548 | }) | 591 | }) |
549 | 592 | ||
550 | it('Should be able to remove this user', async function () { | 593 | describe('Video blacklists', function () { |
551 | await removeUser(server.url, userId, accessToken) | 594 | it('Should be able to list video blacklist by a moderator', async function () { |
595 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | ||
596 | }) | ||
552 | }) | 597 | }) |
553 | 598 | ||
554 | it('Should not be able to login with this user', async function () { | 599 | describe('Remove a user', function () { |
555 | await userLogin(server, user, 400) | 600 | it('Should be able to remove this user', async function () { |
556 | }) | 601 | await removeUser(server.url, userId, accessToken) |
602 | }) | ||
557 | 603 | ||
558 | it('Should not have videos of this user', async function () { | 604 | it('Should not be able to login with this user', async function () { |
559 | const res = await getVideosList(server.url) | 605 | await userLogin(server, user, 400) |
606 | }) | ||
560 | 607 | ||
561 | expect(res.body.total).to.equal(1) | 608 | it('Should not have videos of this user', async function () { |
609 | const res = await getVideosList(server.url) | ||
562 | 610 | ||
563 | const video = res.body.data[ 0 ] | 611 | expect(res.body.total).to.equal(1) |
564 | expect(video.account.name).to.equal('root') | ||
565 | }) | ||
566 | 612 | ||
567 | it('Should register a new user', async function () { | 613 | const video = res.body.data[ 0 ] |
568 | await registerUser(server.url, 'user_15', 'my super password') | 614 | expect(video.account.name).to.equal('root') |
615 | }) | ||
569 | }) | 616 | }) |
570 | 617 | ||
571 | it('Should be able to login with this registered user', async function () { | 618 | describe('Registering a new user', function () { |
572 | const user15 = { | 619 | it('Should register a new user', async function () { |
573 | username: 'user_15', | 620 | await registerUser(server.url, 'user_15', 'my super password') |
574 | password: 'my super password' | 621 | }) |
575 | } | ||
576 | 622 | ||
577 | accessToken = await userLogin(server, user15) | 623 | it('Should be able to login with this registered user', async function () { |
578 | }) | 624 | const user15 = { |
625 | username: 'user_15', | ||
626 | password: 'my super password' | ||
627 | } | ||
579 | 628 | ||
580 | it('Should have the correct video quota', async function () { | 629 | accessToken = await userLogin(server, user15) |
581 | const res = await getMyUserInformation(server.url, accessToken) | 630 | }) |
582 | const user = res.body | ||
583 | 631 | ||
584 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 632 | it('Should have the correct video quota', async function () { |
585 | }) | 633 | const res = await getMyUserInformation(server.url, accessToken) |
634 | const user = res.body | ||
586 | 635 | ||
587 | it('Should remove me', async function () { | 636 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
588 | { | 637 | }) |
589 | const res = await getUsersList(server.url, server.accessToken) | ||
590 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | ||
591 | } | ||
592 | 638 | ||
593 | await deleteMe(server.url, accessToken) | 639 | it('Should remove me', async function () { |
640 | { | ||
641 | const res = await getUsersList(server.url, server.accessToken) | ||
642 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | ||
643 | } | ||
594 | 644 | ||
595 | { | 645 | await deleteMe(server.url, accessToken) |
596 | const res = await getUsersList(server.url, server.accessToken) | 646 | |
597 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | 647 | { |
598 | } | 648 | const res = await getUsersList(server.url, server.accessToken) |
649 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | ||
650 | } | ||
651 | }) | ||
599 | }) | 652 | }) |
600 | 653 | ||
601 | it('Should block and unblock a user', async function () { | 654 | describe('User blocking', function () { |
602 | const user16 = { | 655 | it('Should block and unblock a user', async function () { |
603 | username: 'user_16', | 656 | const user16 = { |
604 | password: 'my super password' | 657 | username: 'user_16', |
605 | } | 658 | password: 'my super password' |
606 | const resUser = await createUser(server.url, server.accessToken, user16.username, user16.password) | 659 | } |
607 | const user16Id = resUser.body.user.id | 660 | const resUser = await createUser({ |
661 | url: server.url, | ||
662 | accessToken: server.accessToken, | ||
663 | username: user16.username, | ||
664 | password: user16.password | ||
665 | }) | ||
666 | const user16Id = resUser.body.user.id | ||
608 | 667 | ||
609 | accessToken = await userLogin(server, user16) | 668 | accessToken = await userLogin(server, user16) |
610 | 669 | ||
611 | await getMyUserInformation(server.url, accessToken, 200) | 670 | await getMyUserInformation(server.url, accessToken, 200) |
612 | await blockUser(server.url, user16Id, server.accessToken) | 671 | await blockUser(server.url, user16Id, server.accessToken) |
613 | 672 | ||
614 | await getMyUserInformation(server.url, accessToken, 401) | 673 | await getMyUserInformation(server.url, accessToken, 401) |
615 | await userLogin(server, user16, 400) | 674 | await userLogin(server, user16, 400) |
616 | 675 | ||
617 | await unblockUser(server.url, user16Id, server.accessToken) | 676 | await unblockUser(server.url, user16Id, server.accessToken) |
618 | accessToken = await userLogin(server, user16) | 677 | accessToken = await userLogin(server, user16) |
619 | await getMyUserInformation(server.url, accessToken, 200) | 678 | await getMyUserInformation(server.url, accessToken, 200) |
679 | }) | ||
620 | }) | 680 | }) |
621 | 681 | ||
622 | after(async function () { | 682 | after(async function () { |
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 () { | |||
164 | username: 'user1', | 164 | username: 'user1', |
165 | password: 'super_password' | 165 | password: 'super_password' |
166 | } | 166 | } |
167 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | 167 | await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password }) |
168 | const userAccessToken = await userLogin(servers[1], user) | 168 | const userAccessToken = await userLogin(servers[1], user) |
169 | 169 | ||
170 | const videoAttributes = { | 170 | 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' | |||
5 | import 'mocha' | 5 | import 'mocha' |
6 | import { | 6 | import { |
7 | addVideoToBlacklist, | 7 | addVideoToBlacklist, |
8 | createUser, | ||
8 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
9 | getBlacklistedVideosList, | 10 | getBlacklistedVideosList, |
10 | getBlacklistedVideosListWithTypeFilter, | ||
11 | getMyVideos, | 11 | getMyVideos, |
12 | getSortedBlacklistedVideosList, | ||
13 | getVideosList, | 12 | getVideosList, |
14 | killallServers, | 13 | killallServers, |
15 | removeVideoFromBlacklist, | 14 | removeVideoFromBlacklist, |
15 | reRunServer, | ||
16 | searchVideo, | 16 | searchVideo, |
17 | ServerInfo, | 17 | ServerInfo, |
18 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
19 | updateVideo, | 19 | updateVideo, |
20 | updateVideoBlacklist, | 20 | updateVideoBlacklist, |
21 | uploadVideo, | 21 | uploadVideo, |
22 | viewVideo | 22 | userLogin |
23 | } from '../../../../shared/utils/index' | 23 | } from '../../../../shared/utils/index' |
24 | import { doubleFollow } from '../../../../shared/utils/server/follows' | 24 | import { doubleFollow } from '../../../../shared/utils/server/follows' |
25 | import { waitJobs } from '../../../../shared/utils/server/jobs' | 25 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
26 | import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' | 26 | import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' |
27 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
28 | import { UserRole } from '../../../../shared/models/users' | ||
27 | 29 | ||
28 | const expect = chai.expect | 30 | const expect = chai.expect |
29 | 31 | ||
30 | describe('Test video blacklist management', function () { | 32 | describe('Test video blacklist', function () { |
31 | let servers: ServerInfo[] = [] | 33 | let servers: ServerInfo[] = [] |
32 | let videoId: number | 34 | let videoId: number |
33 | 35 | ||
@@ -104,7 +106,7 @@ describe('Test video blacklist management', function () { | |||
104 | 106 | ||
105 | describe('When listing manually blacklisted videos', function () { | 107 | describe('When listing manually blacklisted videos', function () { |
106 | it('Should display all the blacklisted videos', async function () { | 108 | it('Should display all the blacklisted videos', async function () { |
107 | const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) | 109 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) |
108 | 110 | ||
109 | expect(res.body.total).to.equal(2) | 111 | expect(res.body.total).to.equal(2) |
110 | 112 | ||
@@ -119,7 +121,11 @@ describe('Test video blacklist management', function () { | |||
119 | }) | 121 | }) |
120 | 122 | ||
121 | it('Should display all the blacklisted videos when applying manual type filter', async function () { | 123 | it('Should display all the blacklisted videos when applying manual type filter', async function () { |
122 | const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) | 124 | const res = await getBlacklistedVideosList({ |
125 | url: servers[ 0 ].url, | ||
126 | token: servers[ 0 ].accessToken, | ||
127 | type: VideoBlacklistType.MANUAL | ||
128 | }) | ||
123 | 129 | ||
124 | expect(res.body.total).to.equal(2) | 130 | expect(res.body.total).to.equal(2) |
125 | 131 | ||
@@ -129,7 +135,11 @@ describe('Test video blacklist management', function () { | |||
129 | }) | 135 | }) |
130 | 136 | ||
131 | it('Should display nothing when applying automatic type filter', async function () { | 137 | it('Should display nothing when applying automatic type filter', async function () { |
132 | const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length | 138 | const res = await getBlacklistedVideosList({ |
139 | url: servers[ 0 ].url, | ||
140 | token: servers[ 0 ].accessToken, | ||
141 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
142 | }) | ||
133 | 143 | ||
134 | expect(res.body.total).to.equal(0) | 144 | expect(res.body.total).to.equal(0) |
135 | 145 | ||
@@ -139,7 +149,7 @@ describe('Test video blacklist management', function () { | |||
139 | }) | 149 | }) |
140 | 150 | ||
141 | it('Should get the correct sort when sorting by descending id', async function () { | 151 | it('Should get the correct sort when sorting by descending id', async function () { |
142 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | 152 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' }) |
143 | expect(res.body.total).to.equal(2) | 153 | expect(res.body.total).to.equal(2) |
144 | 154 | ||
145 | const blacklistedVideos = res.body.data | 155 | const blacklistedVideos = res.body.data |
@@ -152,7 +162,7 @@ describe('Test video blacklist management', function () { | |||
152 | }) | 162 | }) |
153 | 163 | ||
154 | it('Should get the correct sort when sorting by descending video name', async function () { | 164 | it('Should get the correct sort when sorting by descending video name', async function () { |
155 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 165 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
156 | expect(res.body.total).to.equal(2) | 166 | expect(res.body.total).to.equal(2) |
157 | 167 | ||
158 | const blacklistedVideos = res.body.data | 168 | const blacklistedVideos = res.body.data |
@@ -165,7 +175,7 @@ describe('Test video blacklist management', function () { | |||
165 | }) | 175 | }) |
166 | 176 | ||
167 | it('Should get the correct sort when sorting by ascending creation date', async function () { | 177 | it('Should get the correct sort when sorting by ascending creation date', async function () { |
168 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | 178 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) |
169 | expect(res.body.total).to.equal(2) | 179 | expect(res.body.total).to.equal(2) |
170 | 180 | ||
171 | const blacklistedVideos = res.body.data | 181 | const blacklistedVideos = res.body.data |
@@ -182,7 +192,7 @@ describe('Test video blacklist management', function () { | |||
182 | it('Should change the reason', async function () { | 192 | it('Should change the reason', async function () { |
183 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') | 193 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') |
184 | 194 | ||
185 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 195 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
186 | const video = res.body.data.find(b => b.video.id === videoId) | 196 | const video = res.body.data.find(b => b.video.id === videoId) |
187 | 197 | ||
188 | expect(video.reason).to.equal('my super reason updated') | 198 | expect(video.reason).to.equal('my super reason updated') |
@@ -218,7 +228,7 @@ describe('Test video blacklist management', function () { | |||
218 | 228 | ||
219 | it('Should remove a video from the blacklist on server 1', async function () { | 229 | it('Should remove a video from the blacklist on server 1', async function () { |
220 | // Get one video in the blacklist | 230 | // Get one video in the blacklist |
221 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 231 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
222 | videoToRemove = res.body.data[0] | 232 | videoToRemove = res.body.data[0] |
223 | blacklist = res.body.data.slice(1) | 233 | blacklist = res.body.data.slice(1) |
224 | 234 | ||
@@ -239,7 +249,7 @@ describe('Test video blacklist management', function () { | |||
239 | }) | 249 | }) |
240 | 250 | ||
241 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | 251 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { |
242 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 252 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
243 | expect(res.body.total).to.equal(1) | 253 | expect(res.body.total).to.equal(1) |
244 | 254 | ||
245 | const videos = res.body.data | 255 | const videos = res.body.data |
@@ -313,7 +323,7 @@ describe('Test video blacklist management', function () { | |||
313 | }) | 323 | }) |
314 | 324 | ||
315 | it('Should have the correct video blacklist unfederate attribute', async function () { | 325 | it('Should have the correct video blacklist unfederate attribute', async function () { |
316 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | 326 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) |
317 | 327 | ||
318 | const blacklistedVideos: VideoBlacklist[] = res.body.data | 328 | const blacklistedVideos: VideoBlacklist[] = res.body.data |
319 | const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) | 329 | const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) |
@@ -338,6 +348,83 @@ describe('Test video blacklist management', function () { | |||
338 | 348 | ||
339 | }) | 349 | }) |
340 | 350 | ||
351 | describe('When auto blacklist videos', function () { | ||
352 | let userWithoutFlag: string | ||
353 | let userWithFlag: string | ||
354 | |||
355 | before(async function () { | ||
356 | this.timeout(20000) | ||
357 | |||
358 | killallServers([ servers[0] ]) | ||
359 | |||
360 | const config = { | ||
361 | 'auto_blacklist': { | ||
362 | videos: { | ||
363 | 'of_users': { | ||
364 | enabled: true | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | } | ||
369 | await reRunServer(servers[0], config) | ||
370 | |||
371 | { | ||
372 | const user = { username: 'user_without_flag', password: 'password' } | ||
373 | await createUser({ | ||
374 | url: servers[ 0 ].url, | ||
375 | accessToken: servers[ 0 ].accessToken, | ||
376 | username: user.username, | ||
377 | adminFlags: UserAdminFlag.NONE, | ||
378 | password: user.password, | ||
379 | role: UserRole.USER | ||
380 | }) | ||
381 | |||
382 | userWithoutFlag = await userLogin(servers[0], user) | ||
383 | } | ||
384 | |||
385 | { | ||
386 | const user = { username: 'user_with_flag', password: 'password' } | ||
387 | await createUser({ | ||
388 | url: servers[ 0 ].url, | ||
389 | accessToken: servers[ 0 ].accessToken, | ||
390 | username: user.username, | ||
391 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST, | ||
392 | password: user.password, | ||
393 | role: UserRole.USER | ||
394 | }) | ||
395 | |||
396 | userWithFlag = await userLogin(servers[0], user) | ||
397 | } | ||
398 | |||
399 | await waitJobs(servers) | ||
400 | }) | ||
401 | |||
402 | it('Should auto blacklist a video', async function () { | ||
403 | await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) | ||
404 | |||
405 | const res = await getBlacklistedVideosList({ | ||
406 | url: servers[ 0 ].url, | ||
407 | token: servers[ 0 ].accessToken, | ||
408 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
409 | }) | ||
410 | |||
411 | expect(res.body.total).to.equal(1) | ||
412 | expect(res.body.data[0].video.name).to.equal('blacklisted') | ||
413 | }) | ||
414 | |||
415 | it('Should not auto blacklist a video', async function () { | ||
416 | await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) | ||
417 | |||
418 | const res = await getBlacklistedVideosList({ | ||
419 | url: servers[ 0 ].url, | ||
420 | token: servers[ 0 ].accessToken, | ||
421 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
422 | }) | ||
423 | |||
424 | expect(res.body.total).to.equal(1) | ||
425 | }) | ||
426 | }) | ||
427 | |||
341 | after(async function () { | 428 | after(async function () { |
342 | killallServers(servers) | 429 | killallServers(servers) |
343 | }) | 430 | }) |
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 () { | |||
46 | await setAccessTokensToServers(servers) | 46 | await setAccessTokensToServers(servers) |
47 | 47 | ||
48 | const videoQuota = 42000000 | 48 | const videoQuota = 42000000 |
49 | await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota) | 49 | await createUser({ |
50 | await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota) | 50 | url: servers[ 0 ].url, |
51 | accessToken: servers[ 0 ].accessToken, | ||
52 | username: firstUser.username, | ||
53 | password: firstUser.password, | ||
54 | videoQuota: videoQuota | ||
55 | }) | ||
56 | await createUser({ | ||
57 | url: servers[ 0 ].url, | ||
58 | accessToken: servers[ 0 ].accessToken, | ||
59 | username: secondUser.username, | ||
60 | password: secondUser.password, | ||
61 | videoQuota: videoQuota | ||
62 | }) | ||
51 | 63 | ||
52 | firstUserAccessToken = await userLogin(servers[0], firstUser) | 64 | firstUserAccessToken = await userLogin(servers[0], firstUser) |
53 | secondUserAccessToken = await userLogin(servers[0], secondUser) | 65 | secondUserAccessToken = await userLogin(servers[0], secondUser) |
@@ -219,8 +231,20 @@ describe('Test video change ownership - quota too small', function () { | |||
219 | 231 | ||
220 | const videoQuota = 42000000 | 232 | const videoQuota = 42000000 |
221 | const limitedVideoQuota = 10 | 233 | const limitedVideoQuota = 10 |
222 | await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) | 234 | await createUser({ |
223 | await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) | 235 | url: server.url, |
236 | accessToken: server.accessToken, | ||
237 | username: firstUser.username, | ||
238 | password: firstUser.password, | ||
239 | videoQuota: videoQuota | ||
240 | }) | ||
241 | await createUser({ | ||
242 | url: server.url, | ||
243 | accessToken: server.accessToken, | ||
244 | username: secondUser.username, | ||
245 | password: secondUser.password, | ||
246 | videoQuota: limitedVideoQuota | ||
247 | }) | ||
224 | 248 | ||
225 | firstUserAccessToken = await userLogin(server, firstUser) | 249 | firstUserAccessToken = await userLogin(server, firstUser) |
226 | secondUserAccessToken = await userLogin(server, secondUser) | 250 | 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 () { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | { | 272 | { |
273 | await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, 'toto', 'password') | 273 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' }) |
274 | const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) | 274 | const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) |
275 | 275 | ||
276 | const res = await getMyUserInformation(servers[ 0 ].url, accessToken) | 276 | 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 () { | |||
144 | it('Should create a user having the default nsfw policy', async function () { | 144 | it('Should create a user having the default nsfw policy', async function () { |
145 | const username = 'user1' | 145 | const username = 'user1' |
146 | const password = 'my super password' | 146 | const password = 'my super password' |
147 | await createUser(server.url, server.accessToken, username, password) | 147 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
148 | 148 | ||
149 | userAccessToken = await userLogin(server, { username, password }) | 149 | userAccessToken = await userLogin(server, { username, password }) |
150 | 150 | ||
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 () { | |||
815 | this.timeout(30000) | 815 | this.timeout(30000) |
816 | 816 | ||
817 | const user = { username: 'user_1', password: 'password' } | 817 | const user = { username: 'user_1', password: 'password' } |
818 | const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 818 | const res = await createUser({ |
819 | url: servers[ 0 ].url, | ||
820 | accessToken: servers[ 0 ].accessToken, | ||
821 | username: user.username, | ||
822 | password: user.password | ||
823 | }) | ||
819 | 824 | ||
820 | const userId = res.body.user.id | 825 | const userId = res.body.user.id |
821 | const userAccessToken = await userLogin(servers[0], user) | 826 | 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 () { | |||
78 | username: 'hello', | 78 | username: 'hello', |
79 | password: 'super password' | 79 | password: 'super password' |
80 | } | 80 | } |
81 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | 81 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
82 | 82 | ||
83 | const token = await userLogin(servers[0], user) | 83 | const token = await userLogin(servers[0], user) |
84 | await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) | 84 | 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 () { | |||
64 | for (const server of servers) { | 64 | for (const server of servers) { |
65 | const moderator = { username: 'moderator', password: 'my super password' } | 65 | const moderator = { username: 'moderator', password: 'my super password' } |
66 | await createUser( | 66 | await createUser( |
67 | server.url, | 67 | { |
68 | server.accessToken, | 68 | url: server.url, |
69 | moderator.username, | 69 | accessToken: server.accessToken, |
70 | moderator.password, | 70 | username: moderator.username, |
71 | undefined, | 71 | password: moderator.password, |
72 | undefined, | 72 | videoQuota: undefined, |
73 | UserRole.MODERATOR | 73 | videoQuotaDaily: undefined, |
74 | role: UserRole.MODERATOR | ||
75 | } | ||
74 | ) | 76 | ) |
75 | server['moderatorAccessToken'] = await userLogin(server, moderator) | 77 | server['moderatorAccessToken'] = await userLogin(server, moderator) |
76 | 78 | ||
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 () { | |||
58 | username: 'user_1', | 58 | username: 'user_1', |
59 | password: 'super password' | 59 | password: 'super password' |
60 | } | 60 | } |
61 | await createUser(server.url, server.accessToken, user.username, user.password) | 61 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
62 | userAccessToken = await userLogin(server, user) | 62 | userAccessToken = await userLogin(server, user) |
63 | }) | 63 | }) |
64 | 64 | ||
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index e2836d0c3..b0ae876d3 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -24,7 +24,7 @@ describe('Test CLI wrapper', function () { | |||
24 | server = await runServer(1) | 24 | server = await runServer(1) |
25 | await setAccessTokensToServers([ server ]) | 25 | await setAccessTokensToServers([ server ]) |
26 | 26 | ||
27 | await createUser(server.url, server.accessToken, 'user_1', 'super password') | 27 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' }) |
28 | }) | 28 | }) |
29 | 29 | ||
30 | it('Should display no selected instance', async function () { | 30 | it('Should display no selected instance', async function () { |
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts index 1b65f7e39..4c9f0c5f8 100644 --- a/server/tests/cli/reset-password.ts +++ b/server/tests/cli/reset-password.ts | |||
@@ -22,7 +22,7 @@ describe('Test reset password scripts', function () { | |||
22 | server = await runServer(1) | 22 | server = await runServer(1) |
23 | await setAccessTokensToServers([ server ]) | 23 | await setAccessTokensToServers([ server ]) |
24 | 24 | ||
25 | await createUser(server.url, server.accessToken, 'user_1', 'super password') | 25 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' }) |
26 | }) | 26 | }) |
27 | 27 | ||
28 | it('Should change the user password from CLI', async function () { | 28 | it('Should change the user password from CLI', async function () { |
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index d38bb4331..39533edea 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts | |||
@@ -50,7 +50,7 @@ describe('Test update host scripts', function () { | |||
50 | await uploadVideo(server.url, server.accessToken, videoAttributes) | 50 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
51 | 51 | ||
52 | // Create a user | 52 | // Create a user |
53 | await createUser(server.url, server.accessToken, 'toto', 'coucou') | 53 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' }) |
54 | 54 | ||
55 | // Create channel | 55 | // Create channel |
56 | const videoChannel = { | 56 | const videoChannel = { |
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index a771474bc..d632be427 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts | |||
@@ -50,7 +50,7 @@ describe('Test syndication feeds', () => { | |||
50 | 50 | ||
51 | { | 51 | { |
52 | const attr = { username: 'john', password: 'password' } | 52 | const attr = { username: 'john', password: 'password' } |
53 | await createUser(servers[0].url, servers[0].accessToken, attr.username, attr.password) | 53 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password }) |
54 | userAccessToken = await userLogin(servers[0], attr) | 54 | userAccessToken = await userLogin(servers[0], attr) |
55 | 55 | ||
56 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | 56 | const res = await getMyUserInformation(servers[0].url, userAccessToken) |
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts index 5f82719da..104876f2f 100644 --- a/server/tests/misc-endpoints.ts +++ b/server/tests/misc-endpoints.ts | |||
@@ -149,8 +149,8 @@ describe('Test misc endpoints', function () { | |||
149 | await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' }) | 149 | await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' }) |
150 | await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' }) | 150 | await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' }) |
151 | 151 | ||
152 | await createUser(server.url, server.accessToken, 'user1', 'password') | 152 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) |
153 | await createUser(server.url, server.accessToken, 'user2', 'password') | 153 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' }) |
154 | 154 | ||
155 | const res = await makeGetRequest({ | 155 | const res = await makeGetRequest({ |
156 | url: server.url, | 156 | url: server.url, |
diff --git a/server/tests/real-world/populate-database.ts b/server/tests/real-world/populate-database.ts index 016503498..3616127ad 100644 --- a/server/tests/real-world/populate-database.ts +++ b/server/tests/real-world/populate-database.ts | |||
@@ -78,7 +78,7 @@ function createUserCustom (server: ServerInfo) { | |||
78 | const username = Date.now().toString() + getRandomInt(0, 100000) | 78 | const username = Date.now().toString() + getRandomInt(0, 100000) |
79 | console.log('Creating user %s.', username) | 79 | console.log('Creating user %s.', username) |
80 | 80 | ||
81 | return createUser(server.url, server.accessToken, username, 'coucou') | 81 | return createUser({ url: server.url, accessToken: server.accessToken, username: username, password: 'coucou' }) |
82 | } | 82 | } |
83 | 83 | ||
84 | function uploadCustom (server: ServerInfo) { | 84 | function uploadCustom (server: ServerInfo) { |