Introduce user command

This commit is contained in:
Chocobozzz 2021-07-13 14:23:01 +02:00
parent d0a0fa429d
commit 7926c5f9b3
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
85 changed files with 1011 additions and 1505 deletions

View File

@ -4,7 +4,7 @@ import { tokensRouter } from '@server/controllers/api/users/token'
import { Hooks } from '@server/lib/plugins/hooks' import { Hooks } from '@server/lib/plugins/hooks'
import { OAuthTokenModel } from '@server/models/oauth/oauth-token' import { OAuthTokenModel } from '@server/models/oauth/oauth-token'
import { MUser, MUserAccountDefault } from '@server/types/models' import { MUser, MUserAccountDefault } from '@server/types/models'
import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' import { UserCreate, UserCreateResult, UserRight, UserRole, UserUpdate } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { UserRegister } from '../../../../shared/models/users/user-register.model' import { UserRegister } from '../../../../shared/models/users/user-register.model'
@ -220,7 +220,7 @@ async function createUser (req: express.Request, res: express.Response) {
account: { account: {
id: account.id id: account.id
} }
} } as UserCreateResult
}) })
} }

View File

@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosListSort, getVideosListSort,
@ -32,7 +31,7 @@ describe('Test ActivityPub fetcher', function () {
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
for (const server of servers) { for (const server of servers) {
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
} }
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userAccessToken = await servers[0].loginCommand.getAccessToken(user)

View File

@ -6,7 +6,6 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateUserAccessToken,
getVideo, getVideo,
killallServers, killallServers,
reRunServer, reRunServer,
@ -44,10 +43,10 @@ describe('Test AP refresher', function () {
} }
{ {
const a1 = await generateUserAccessToken(servers[1], 'user1') const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
await uploadVideo(servers[1].url, a1, { name: 'video4' }) await uploadVideo(servers[1].url, a1, { name: 'video4' })
const a2 = await generateUserAccessToken(servers[1], 'user2') const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
await uploadVideo(servers[1].url, a2, { name: 'video5' }) await uploadVideo(servers[1].url, a2, { name: 'video5' })
} }

View File

@ -8,10 +8,8 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunServer, flushAndRunServer,
generateUserAccessToken,
getVideoIdFromUUID, getVideoIdFromUUID,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
@ -45,10 +43,10 @@ describe('Test abuses API validators', function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) await server.usersCommand.create({ username: username, password: password })
userToken = await server.loginCommand.getAccessToken({ username, password }) userToken = await server.loginCommand.getAccessToken({ username, password })
userToken2 = await generateUserAccessToken(server, 'user_2') userToken2 = await server.usersCommand.generateUserAndToken('user_2')
const res = await uploadVideo(server.url, server.accessToken, {}) const res = await uploadVideo(server.url, server.accessToken, {})
server.video = res.body.video server.video = res.body.video

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
makeDeleteRequest, makeDeleteRequest,
@ -34,7 +33,7 @@ describe('Test blocklist API validators', function () {
server = servers[0] server = servers[0]
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)

View File

@ -3,7 +3,6 @@
import 'mocha' import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
@ -24,7 +23,7 @@ describe('Test bulk API validators', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -5,7 +5,6 @@ import { omit } from 'lodash'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
@ -206,7 +205,7 @@ describe('Test config API validators', function () {
username: 'user1', username: 'user1',
password: 'password' password: 'password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
@ -26,7 +25,7 @@ describe('Test custom pages validators', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
@ -30,7 +29,7 @@ describe('Test debug API validators', function () {
username: 'user1', username: 'user1',
password: 'my super password' password: 'my super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeDeleteRequest, makeGetRequest, makeDeleteRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
@ -40,7 +39,7 @@ describe('Test server follows API validators', function () {
password: 'password' password: 'password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
@ -35,7 +34,7 @@ describe('Test jobs API validators', function () {
username: 'user1', username: 'user1',
password: 'my super password' password: 'my super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -2,14 +2,11 @@
import 'mocha' import 'mocha'
import { omit } from 'lodash' import { omit } from 'lodash'
import { VideoCreateResult, VideoPrivacy } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
LiveCommand, LiveCommand,
makePostBodyRequest, makePostBodyRequest,
makeUploadRequest, makeUploadRequest,
@ -18,7 +15,8 @@ import {
setAccessTokensToServers, setAccessTokensToServers,
stopFfmpeg, stopFfmpeg,
uploadVideoAndGetId uploadVideoAndGetId
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { VideoCreateResult, VideoPrivacy } from '@shared/models'
describe('Test video lives API validator', function () { describe('Test video lives API validator', function () {
const path = '/api/v1/videos/live' const path = '/api/v1/videos/live'
@ -51,12 +49,12 @@ describe('Test video lives API validator', function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{ {
const res = await getMyUserInformation(server.url, server.accessToken) const { videoChannels } = await server.usersCommand.getMyInfo()
channelId = res.body.videoChannels[0].id channelId = videoChannels[0].id
} }
{ {
@ -147,11 +145,11 @@ describe('Test video lives API validator', function () {
username: 'fake', username: 'fake',
password: 'fake_password' password: 'fake_password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user) const accessTokenUser = await server.loginCommand.getAccessToken(user)
const res = await getMyUserInformation(server.url, accessTokenUser) const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const customChannelId = res.body.videoChannels[0].id const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId } const fields = { ...baseCorrectParams, channelId: customChannelId }

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers setAccessTokensToServers
@ -30,7 +29,7 @@ describe('Test logs API validators', function () {
username: 'user1', username: 'user1',
password: 'my super password' password: 'my super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -7,7 +7,6 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
@ -43,7 +42,7 @@ describe('Test server plugins API validators', function () {
password: 'password' password: 'password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
{ {

View File

@ -8,7 +8,6 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo, getVideo,
@ -43,7 +42,7 @@ describe('Test server redundancy API validators', function () {
password: 'password' password: 'password'
} }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user) userAccessToken = await servers[0].loginCommand.getAccessToken(user)
videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id

View File

@ -3,17 +3,14 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils' import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' import { VideoImportState, VideoPrivacy } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
ImportsCommand, ImportsCommand,
registerUser,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
updateUser,
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
@ -31,15 +28,10 @@ describe('Test upload quota', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
const res = await getMyUserInformation(server.url, server.accessToken) const user = await server.usersCommand.getMyInfo()
rootId = (res.body as MyUser).id rootId = user.id
await updateUser({ await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
url: server.url,
userId: rootId,
accessToken: server.accessToken,
videoQuota: 42
})
}) })
describe('When having a video quota', function () { describe('When having a video quota', function () {
@ -48,7 +40,7 @@ describe('Test upload quota', function () {
this.timeout(30000) this.timeout(30000)
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await registerUser(server.url, user.username, user.password) await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user) const userAccessToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' } const videoAttributes = { fixture: 'video_short2.webm' }
@ -63,7 +55,7 @@ describe('Test upload quota', function () {
this.timeout(30000) this.timeout(30000)
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
await registerUser(server.url, user.username, user.password) await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user) const userAccessToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' } const videoAttributes = { fixture: 'video_short2.webm' }
@ -103,12 +95,7 @@ describe('Test upload quota', function () {
describe('When having a daily video quota', function () { describe('When having a daily video quota', function () {
it('Should fail with a user having too many videos daily', async function () { it('Should fail with a user having too many videos daily', async function () {
await updateUser({ await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
url: server.url,
userId: rootId,
accessToken: server.accessToken,
videoQuotaDaily: 42
})
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
@ -117,10 +104,8 @@ describe('Test upload quota', function () {
describe('When having an absolute and daily video quota', function () { describe('When having an absolute and daily video quota', function () {
it('Should fail if exceeding total quota', async function () { it('Should fail if exceeding total quota', async function () {
await updateUser({ await server.usersCommand.update({
url: server.url,
userId: rootId, userId: rootId,
accessToken: server.accessToken,
videoQuota: 42, videoQuota: 42,
videoQuotaDaily: 1024 * 1024 * 1024 videoQuotaDaily: 1024 * 1024 * 1024
}) })
@ -130,10 +115,8 @@ describe('Test upload quota', function () {
}) })
it('Should fail if exceeding daily quota', async function () { it('Should fail if exceeding daily quota', async function () {
await updateUser({ await server.usersCommand.update({
url: server.url,
userId: rootId, userId: rootId,
accessToken: server.accessToken,
videoQuota: 1024 * 1024 * 1024, videoQuota: 1024 * 1024 * 1024,
videoQuotaDaily: 42 videoQuotaDaily: 42
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
@ -39,7 +38,7 @@ describe('Test user subscriptions API validators', function () {
username: 'user1', username: 'user1',
password: 'my super password' password: 'my super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })

View File

@ -2,32 +2,22 @@
import 'mocha' import 'mocha'
import { omit } from 'lodash' import { omit } from 'lodash'
import { User, UserRole, VideoCreateResult } from '../../../../shared' import { UserRole, VideoCreateResult } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
blockUser,
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
createUser,
deleteMe,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
getMyUserVideoRating,
getUserScopedTokens,
getUsersList,
killallServers, killallServers,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
makeUploadRequest, makeUploadRequest,
registerUser,
removeUser,
renewUserScopedTokens,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
unblockUser, uploadVideo,
uploadVideo UsersCommand
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
import { import {
@ -45,8 +35,8 @@ describe('Test users API validators', function () {
let video: VideoCreateResult let video: VideoCreateResult
let server: ServerInfo let server: ServerInfo
let serverWithRegistrationDisabled: ServerInfo let serverWithRegistrationDisabled: ServerInfo
let userAccessToken = '' let userToken = ''
let moderatorAccessToken = '' let moderatorToken = ''
let emailPort: number let emailPort: number
let overrideConfig: Object let overrideConfig: Object
@ -73,52 +63,20 @@ describe('Test users API validators', function () {
} }
{ {
const user = { const user = { username: 'user1' }
username: 'user1', await server.usersCommand.create({ ...user })
password: 'my super password' userToken = await server.loginCommand.getAccessToken(user)
}
const videoQuota = 42000000
await createUser({
url: server.url,
accessToken: server.accessToken,
username: user.username,
password: user.password,
videoQuota: videoQuota
})
userAccessToken = await server.loginCommand.getAccessToken(user)
} }
{ {
const moderator = { const moderator = { username: 'moderator1' }
username: 'moderator1', await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
password: 'super password' moderatorToken = await server.loginCommand.getAccessToken(moderator)
}
await createUser({
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
role: UserRole.MODERATOR
})
moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
} }
{ {
const moderator = { const moderator = { username: 'moderator2' }
username: 'moderator2', await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
password: 'super password'
}
await createUser({
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
role: UserRole.MODERATOR
})
} }
{ {
@ -127,12 +85,10 @@ describe('Test users API validators', function () {
} }
{ {
const res = await getUsersList(server.url, server.accessToken) const { data } = await server.usersCommand.list()
const users: User[] = res.body.data userId = data.find(u => u.username === 'user1').id
rootId = data.find(u => u.username === 'root').id
userId = users.find(u => u.username === 'user1').id moderatorId = data.find(u => u.username === 'moderator2').id
rootId = users.find(u => u.username === 'root').id
moderatorId = users.find(u => u.username === 'moderator2').id
} }
}) })
@ -161,7 +117,7 @@ describe('Test users API validators', function () {
await makeGetRequest({ await makeGetRequest({
url: server.url, url: server.url,
path, path,
token: userAccessToken, token: userToken,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
}) })
}) })
@ -359,7 +315,7 @@ describe('Test users API validators', function () {
await makePostBodyRequest({ await makePostBodyRequest({
url: server.url, url: server.url,
path, path,
token: moderatorAccessToken, token: moderatorToken,
fields, fields,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
}) })
@ -372,7 +328,7 @@ describe('Test users API validators', function () {
await makePostBodyRequest({ await makePostBodyRequest({
url: server.url, url: server.url,
path, path,
token: moderatorAccessToken, token: moderatorToken,
fields, fields,
statusCodeExpected: HttpStatusCode.OK_200 statusCodeExpected: HttpStatusCode.OK_200
}) })
@ -389,11 +345,8 @@ describe('Test users API validators', function () {
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
const user = { const user = { username: 'user1' }
username: 'user1', userToken = await server.loginCommand.getAccessToken(user)
password: 'my super password'
}
userAccessToken = await server.loginCommand.getAccessToken(user)
const fields = { const fields = {
username: 'user3', username: 'user3',
@ -401,11 +354,12 @@ describe('Test users API validators', function () {
password: 'my super password', password: 'my super password',
videoQuota: 42000000 videoQuota: 42000000
} }
await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
}) })
}) })
describe('When updating my account', function () { describe('When updating my account', function () {
it('Should fail with an invalid email attribute', async function () { it('Should fail with an invalid email attribute', async function () {
const fields = { const fields = {
email: 'blabla' email: 'blabla'
@ -416,29 +370,29 @@ describe('Test users API validators', function () {
it('Should fail with a too small password', async function () { it('Should fail with a too small password', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'bla' password: 'bla'
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with a too long password', async function () { it('Should fail with a too long password', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'super'.repeat(61) password: 'super'.repeat(61)
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail without the current password', async function () { it('Should fail without the current password', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'super'.repeat(61) password: 'super'.repeat(61)
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid current password', async function () { it('Should fail with an invalid current password', async function () {
@ -450,7 +404,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + 'me', path: path + 'me',
token: userAccessToken, token: userToken,
fields, fields,
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
}) })
@ -461,7 +415,7 @@ describe('Test users API validators', function () {
nsfwPolicy: 'hello' nsfwPolicy: 'hello'
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid autoPlayVideo attribute', async function () { it('Should fail with an invalid autoPlayVideo attribute', async function () {
@ -469,7 +423,7 @@ describe('Test users API validators', function () {
autoPlayVideo: -1 autoPlayVideo: -1
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid autoPlayNextVideo attribute', async function () { it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
@ -477,7 +431,7 @@ describe('Test users API validators', function () {
autoPlayNextVideo: -1 autoPlayNextVideo: -1
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid videosHistoryEnabled attribute', async function () { it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
@ -485,12 +439,12 @@ describe('Test users API validators', function () {
videosHistoryEnabled: -1 videosHistoryEnabled: -1
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an non authenticated user', async function () { it('Should fail with an non authenticated user', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'my super password' password: 'my super password'
} }
@ -508,7 +462,7 @@ describe('Test users API validators', function () {
description: 'super'.repeat(201) description: 'super'.repeat(201)
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid videoLanguages attribute', async function () { it('Should fail with an invalid videoLanguages attribute', async function () {
@ -517,7 +471,7 @@ describe('Test users API validators', function () {
videoLanguages: 'toto' videoLanguages: 'toto'
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
} }
{ {
@ -530,18 +484,18 @@ describe('Test users API validators', function () {
videoLanguages: languages videoLanguages: languages
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
} }
}) })
it('Should fail with an invalid theme', async function () { it('Should fail with an invalid theme', async function () {
const fields = { theme: 'invalid' } const fields = { theme: 'invalid' }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an unknown theme', async function () { it('Should fail with an unknown theme', async function () {
const fields = { theme: 'peertube-theme-unknown' } const fields = { theme: 'peertube-theme-unknown' }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
@ -549,7 +503,7 @@ describe('Test users API validators', function () {
noInstanceConfigWarningModal: -1 noInstanceConfigWarningModal: -1
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should fail with an invalid noWelcomeModal attribute', async function () { it('Should fail with an invalid noWelcomeModal attribute', async function () {
@ -557,12 +511,12 @@ describe('Test users API validators', function () {
noWelcomeModal: -1 noWelcomeModal: -1
} }
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}) })
it('Should succeed to change password with the correct params', async function () { it('Should succeed to change password with the correct params', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'my super password', password: 'my super password',
nsfwPolicy: 'blur', nsfwPolicy: 'blur',
autoPlayVideo: false, autoPlayVideo: false,
@ -575,7 +529,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + 'me', path: path + 'me',
token: userAccessToken, token: userToken,
fields, fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
}) })
@ -590,7 +544,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + 'me', path: path + 'me',
token: userAccessToken, token: userToken,
fields, fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
}) })
@ -647,28 +601,28 @@ describe('Test users API validators', function () {
describe('When managing my scoped tokens', function () { describe('When managing my scoped tokens', function () {
it('Should fail to get my scoped tokens with an non authenticated user', async function () { it('Should fail to get my scoped tokens with an non authenticated user', async function () {
await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail to get my scoped tokens with a bad token', async function () { it('Should fail to get my scoped tokens with a bad token', async function () {
await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should succeed to get my scoped tokens', async function () { it('Should succeed to get my scoped tokens', async function () {
await getUserScopedTokens(server.url, server.accessToken) await server.usersCommand.getMyScopedTokens()
}) })
it('Should fail to renew my scoped tokens with an non authenticated user', async function () { it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail to renew my scoped tokens with a bad token', async function () { it('Should fail to renew my scoped tokens with a bad token', async function () {
await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should succeed to renew my scoped tokens', async function () { it('Should succeed to renew my scoped tokens', async function () {
await renewUserScopedTokens(server.url, server.accessToken) await server.usersCommand.renewMyScopedTokens()
}) })
}) })
@ -684,7 +638,7 @@ describe('Test users API validators', function () {
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should succeed with the correct params', async function () { it('Should succeed with the correct params', async function () {
@ -728,7 +682,7 @@ describe('Test users API validators', function () {
it('Should fail with a too small password', async function () { it('Should fail with a too small password', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'bla' password: 'bla'
} }
@ -737,7 +691,7 @@ describe('Test users API validators', function () {
it('Should fail with a too long password', async function () { it('Should fail with a too long password', async function () {
const fields = { const fields = {
currentPassword: 'my super password', currentPassword: 'password',
password: 'super'.repeat(61) password: 'super'.repeat(61)
} }
@ -780,7 +734,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + moderatorId, path: path + moderatorId,
token: moderatorAccessToken, token: moderatorToken,
fields, fields,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
}) })
@ -794,7 +748,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + userId, path: path + userId,
token: moderatorAccessToken, token: moderatorToken,
fields, fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
}) })
@ -820,31 +774,37 @@ describe('Test users API validators', function () {
describe('When getting my information', function () { describe('When getting my information', function () {
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should success with the correct parameters', async function () { it('Should success with the correct parameters', async function () {
await getMyUserInformation(server.url, userAccessToken) await server.usersCommand.getMyInfo({ token: userToken })
}) })
}) })
describe('When getting my video rating', function () { describe('When getting my video rating', function () {
let command: UsersCommand
before(function () {
command = server.usersCommand
})
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail with an incorrect video uuid', async function () { it('Should fail with an incorrect video uuid', async function () {
await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should fail with an unknown video', async function () { it('Should fail with an unknown video', async function () {
await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await getMyUserVideoRating(server.url, server.accessToken, video.id) await command.getMyRating({ videoId: video.id })
await getMyUserVideoRating(server.url, server.accessToken, video.uuid) await command.getMyRating({ videoId: video.uuid })
await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) await command.getMyRating({ videoId: video.shortUUID })
}) })
}) })
@ -852,15 +812,15 @@ describe('Test users API validators', function () {
const path = '/api/v1/accounts/user1/ratings' const path = '/api/v1/accounts/user1/ratings'
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await checkBadStartPagination(server.url, path, userAccessToken) await checkBadStartPagination(server.url, path, userToken)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await checkBadCountPagination(server.url, path, userAccessToken) await checkBadCountPagination(server.url, path, userToken)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await checkBadSortPagination(server.url, path, userAccessToken) await checkBadSortPagination(server.url, path, userToken)
}) })
it('Should fail with a unauthenticated user', async function () { it('Should fail with a unauthenticated user', async function () {
@ -875,57 +835,70 @@ describe('Test users API validators', function () {
await makeGetRequest({ await makeGetRequest({
url: server.url, url: server.url,
path, path,
token: userAccessToken, token: userToken,
query: { rating: 'toto ' }, query: { rating: 'toto ' },
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
}) })
}) })
it('Should succeed with the correct params', async function () { it('Should succeed with the correct params', async function () {
await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 })
}) })
}) })
describe('When blocking/unblocking/removing user', function () { describe('When blocking/unblocking/removing user', function () {
it('Should fail with an incorrect id', async function () { it('Should fail with an incorrect id', async function () {
await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) await server.usersCommand.remove(options)
await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should fail with the root user', async function () { it('Should fail with the root user', async function () {
await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) await server.usersCommand.remove(options)
await server.usersCommand.banUser(options)
await server.usersCommand.unbanUser(options)
}) })
it('Should return 404 with a non existing id', async function () { it('Should return 404 with a non existing id', async function () {
await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) await server.usersCommand.remove(options)
await server.usersCommand.banUser(options)
await server.usersCommand.unbanUser(options)
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) await server.usersCommand.remove(options)
await server.usersCommand.banUser(options)
await server.usersCommand.unbanUser(options)
}) })
it('Should fail on a moderator with a moderator', async function () { it('Should fail on a moderator with a moderator', async function () {
await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) await server.usersCommand.remove(options)
await server.usersCommand.banUser(options)
await server.usersCommand.unbanUser(options)
}) })
it('Should succeed on a user with a moderator', async function () { it('Should succeed on a user with a moderator', async function () {
await blockUser(server.url, userId, moderatorAccessToken) const options = { userId, token: moderatorToken }
await unblockUser(server.url, userId, moderatorAccessToken)
await server.usersCommand.banUser(options)
await server.usersCommand.unbanUser(options)
}) })
}) })
describe('When deleting our account', function () { describe('When deleting our account', function () {
it('Should fail with with the root account', async function () { it('Should fail with with the root account', async function () {
await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
}) })
@ -1087,7 +1060,7 @@ describe('Test users API validators', function () {
describe('When registering multiple users on a server with users limit', function () { describe('When registering multiple users on a server with users limit', function () {
it('Should fail when after 3 registrations', async function () { it('Should fail when after 3 registrations', async function () {
await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
}) })

View File

@ -9,7 +9,6 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo, getVideo,
@ -44,14 +43,14 @@ describe('Test video blacklist API validators', function () {
{ {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) await servers[0].usersCommand.create({ username: username, password: password })
userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password }) userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password })
} }
{ {
const username = 'user2' const username = 'user2'
const password = 'my super password' const password = 'my super password'
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) await servers[0].usersCommand.create({ username: username, password: password })
userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password }) userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password })
} }

View File

@ -5,7 +5,6 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
@ -42,7 +41,7 @@ describe('Test video captions API validator', function () {
username: 'user1', username: 'user1',
password: 'my super password' password: 'my super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
} }
}) })

View File

@ -11,7 +11,6 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
@ -45,7 +44,7 @@ describe('Test video channels API validator', function () {
} }
{ {
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
accessTokenUser = await server.loginCommand.getAccessToken(user) accessTokenUser = await server.loginCommand.getAccessToken(user)
} }

View File

@ -8,7 +8,6 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
@ -53,13 +52,13 @@ describe('Test video comments API validator', function () {
{ {
const user = { username: 'user1', password: 'my super password' } const user = { username: 'user1', password: 'my super password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
} }
{ {
const user = { username: 'user2', password: 'my super password' } const user = { username: 'user2', password: 'my super password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken2 = await server.loginCommand.getAccessToken(user) userAccessToken2 = await server.loginCommand.getAccessToken(user)
} }
}) })

View File

@ -9,9 +9,7 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
ImportsCommand, ImportsCommand,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
@ -38,12 +36,12 @@ describe('Test video imports API validator', function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{ {
const res = await getMyUserInformation(server.url, server.accessToken) const { videoChannels } = await server.usersCommand.getMyInfo()
channelId = res.body.videoChannels[0].id channelId = videoChannels[0].id
} }
}) })
@ -164,11 +162,11 @@ describe('Test video imports API validator', function () {
username: 'fake', username: 'fake',
password: 'fake_password' password: 'fake_password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user) const accessTokenUser = await server.loginCommand.getAccessToken(user)
const res = await getMyUserInformation(server.url, accessTokenUser) const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const customChannelId = res.body.videoChannels[0].id const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId } const fields = { ...baseCorrectParams, channelId: customChannelId }

View File

@ -17,7 +17,6 @@ import {
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
generateUserAccessToken,
makeGetRequest, makeGetRequest,
PlaylistsCommand, PlaylistsCommand,
ServerInfo, ServerInfo,
@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
userAccessToken = await generateUserAccessToken(server, 'user1') userAccessToken = await server.usersCommand.generateUserAndToken('user1')
videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
command = server.playlistsCommand command = server.playlistsCommand

View File

@ -3,7 +3,6 @@
import 'mocha' import 'mocha'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
@ -50,21 +49,12 @@ describe('Test video filters validators', function () {
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
const user = { username: 'user1', password: 'my super password' } const user = { username: 'user1', password: 'my super password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
const moderator = { username: 'moderator', password: 'my super password' } const moderator = { username: 'moderator', password: 'my super password' }
await createUser( await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
{
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
videoQuota: undefined,
videoQuotaDaily: undefined,
role: UserRole.MODERATOR
}
)
moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
}) })

View File

@ -10,9 +10,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
import { import {
checkUploadVideoParam, checkUploadVideoParam,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
getVideo, getVideo,
getVideosList, getVideosList,
makeDeleteRequest, makeDeleteRequest,
@ -53,14 +51,14 @@ describe('Test videos API validator', function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{ {
const res = await getMyUserInformation(server.url, server.accessToken) const body = await server.usersCommand.getMyInfo()
channelId = res.body.videoChannels[0].id channelId = body.videoChannels[0].id
channelName = res.body.videoChannels[0].name channelName = body.videoChannels[0].name
accountName = res.body.account.name + '@' + res.body.account.host accountName = body.account.name + '@' + body.account.host
} }
}) })
@ -283,11 +281,11 @@ describe('Test videos API validator', function () {
username: 'fake' + randomInt(0, 1500), username: 'fake' + randomInt(0, 1500),
password: 'fake_password' password: 'fake_password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user) const accessTokenUser = await server.loginCommand.getAccessToken(user)
const res = await getMyUserInformation(server.url, accessTokenUser) const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const customChannelId = res.body.videoChannels[0].id const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId } const fields = { ...baseCorrectParams, channelId: customChannelId }
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches

View File

@ -9,12 +9,10 @@ import {
ConfigCommand, ConfigCommand,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateUser,
getVideo, getVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
updateUser,
wait, wait,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
@ -58,9 +56,7 @@ describe('Test live constraints', function () {
} }
function updateQuota (options: { total: number, daily: number }) { function updateQuota (options: { total: number, daily: number }) {
return updateUser({ return servers[0].usersCommand.update({
url: servers[0].url,
accessToken: servers[0].accessToken,
userId, userId,
videoQuota: options.total, videoQuota: options.total,
videoQuotaDaily: options.daily videoQuotaDaily: options.daily
@ -89,7 +85,7 @@ describe('Test live constraints', function () {
}) })
{ {
const res = await generateUser(servers[0], 'user1') const res = await servers[0].usersCommand.generate('user1')
userId = res.userId userId = res.userId
userChannelId = res.userChannelId userChannelId = res.userChannelId
userAccessToken = res.token userAccessToken = res.token

View File

@ -5,13 +5,10 @@ import * as chai from 'chai'
import { import {
AbusesCommand, AbusesCommand,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateUserAccessToken,
getVideoIdFromUUID, getVideoIdFromUUID,
getVideosList, getVideosList,
removeUser,
removeVideo, removeVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
@ -278,7 +275,7 @@ describe('Test abuses', function () {
// register a second user to have two reporters/reportees // register a second user to have two reporters/reportees
const user = { username: 'user2', password: 'password' } const user = { username: 'user2', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) await servers[0].usersCommand.create({ ...user })
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
// upload a third video via this user // upload a third video via this user
@ -604,9 +601,9 @@ describe('Test abuses', function () {
before(async function () { before(async function () {
this.timeout(50000) this.timeout(50000)
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
const token = await generateUserAccessToken(servers[1], 'user_2') const token = await servers[1].usersCommand.generateUserAndToken('user_2')
await uploadVideo(servers[1].url, token, { name: 'super video' }) await uploadVideo(servers[1].url, token, { name: 'super video' })
await waitJobs(servers) await waitJobs(servers)
@ -708,7 +705,7 @@ describe('Test abuses', function () {
this.timeout(10000) this.timeout(10000)
const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
await removeUser(servers[1].url, account.userId, servers[1].accessToken) await servers[1].usersCommand.remove({ userId: account.userId })
await waitJobs(servers) await waitJobs(servers)
@ -765,7 +762,7 @@ describe('Test abuses', function () {
let userAccessToken: string let userAccessToken: string
before(async function () { before(async function () {
userAccessToken = await generateUserAccessToken(servers[0], 'user_42') userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42')
await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
@ -836,7 +833,7 @@ describe('Test abuses', function () {
let abuseMessageModerationId: number let abuseMessageModerationId: number
before(async function () { before(async function () {
userToken = await generateUserAccessToken(servers[0], 'user_43') userToken = await servers[0].usersCommand.generateUserAndToken('user_43')
const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
abuseId = body.abuse.id abuseId = body.abuse.id

View File

@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
ServerInfo, ServerInfo,
@ -76,9 +75,7 @@ describe('Test blocklist', function () {
{ {
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ await servers[0].usersCommand.create({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: user.username, username: user.username,
password: user.password, password: user.password,
videoQuota: -1, videoQuota: -1,
@ -91,14 +88,14 @@ describe('Test blocklist', function () {
{ {
const user = { username: 'user2', password: 'password' } const user = { username: 'user2', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[0].loginCommand.getAccessToken(user) userToken2 = await servers[0].loginCommand.getAccessToken(user)
} }
{ {
const user = { username: 'user3', password: 'password' } const user = { username: 'user3', password: 'password' }
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
remoteUserToken = await servers[1].loginCommand.getAccessToken(user) remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
} }

View File

@ -6,7 +6,6 @@ import {
BlocklistCommand, BlocklistCommand,
cleanupTests, cleanupTests,
CommentsCommand, CommentsCommand,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList, getVideosList,
@ -91,7 +90,7 @@ describe('Test blocklist', function () {
{ {
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken1 = await servers[0].loginCommand.getAccessToken(user) userToken1 = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@ -99,14 +98,14 @@ describe('Test blocklist', function () {
{ {
const user = { username: 'moderator', password: 'password' } const user = { username: 'moderator', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userModeratorToken = await servers[0].loginCommand.getAccessToken(user) userModeratorToken = await servers[0].loginCommand.getAccessToken(user)
} }
{ {
const user = { username: 'user2', password: 'password' } const user = { username: 'user2', password: 'password' }
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[1].loginCommand.getAccessToken(user) userToken2 = await servers[1].loginCommand.getAccessToken(user)
await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })

View File

@ -6,10 +6,8 @@ import { orderBy } from 'lodash'
import { import {
BlacklistCommand, BlacklistCommand,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyUserInformation,
getMyVideos, getMyVideos,
getVideosList, getVideosList,
ImportsCommand, ImportsCommand,
@ -21,7 +19,7 @@ import {
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -356,9 +354,7 @@ describe('Test video blacklist', function () {
{ {
const user = { username: 'user_without_flag', password: 'password' } const user = { username: 'user_without_flag', password: 'password' }
await createUser({ await servers[0].usersCommand.create({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: user.username, username: user.username,
adminFlags: UserAdminFlag.NONE, adminFlags: UserAdminFlag.NONE,
password: user.password, password: user.password,
@ -367,16 +363,13 @@ describe('Test video blacklist', function () {
userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) userWithoutFlag = await servers[0].loginCommand.getAccessToken(user)
const res = await getMyUserInformation(servers[0].url, userWithoutFlag) const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag })
const body: User = res.body channelOfUserWithoutFlag = videoChannels[0].id
channelOfUserWithoutFlag = body.videoChannels[0].id
} }
{ {
const user = { username: 'user_with_flag', password: 'password' } const user = { username: 'user_with_flag', password: 'password' }
await createUser({ await servers[0].usersCommand.create({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: user.username, username: user.username,
adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
password: user.password, password: user.password,

View File

@ -10,7 +10,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
updateMyUser,
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -193,17 +192,8 @@ describe('Test comments notifications', function () {
token: userToken token: userToken
} }
await updateMyUser({ await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
url: servers[0].url, await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
accessToken: servers[0].accessToken,
displayName: 'super root name'
})
await updateMyUser({
url: servers[1].url,
accessToken: servers[1].accessToken,
displayName: 'super root 2 name'
})
}) })
it('Should not send a new mention comment notification if I mention the video owner', async function () { it('Should not send a new mention comment notification if I mention the video owner', async function () {

View File

@ -17,13 +17,10 @@ import {
checkVideoAutoBlacklistForModerators, checkVideoAutoBlacklistForModerators,
checkVideoIsPublished, checkVideoIsPublished,
cleanupTests, cleanupTests,
createUser,
generateUserAccessToken,
getVideoIdFromUUID, getVideoIdFromUUID,
MockInstancesIndex, MockInstancesIndex,
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
registerUser,
ServerInfo, ServerInfo,
uploadVideo, uploadVideo,
wait, wait,
@ -139,8 +136,8 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const username = 'user' + new Date().getTime() const username = 'user' + new Date().getTime()
const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) const { account } = await servers[0].usersCommand.create({ username, password: 'donald' })
const accountId = resUser.body.user.account.id const accountId = account.id
await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) await servers[0].abusesCommand.report({ accountId, reason: 'super reason' })
@ -152,7 +149,7 @@ describe('Test moderation notifications', function () {
this.timeout(20000) this.timeout(20000)
const username = 'user' + new Date().getTime() const username = 'user' + new Date().getTime()
const tmpToken = await generateUserAccessToken(servers[0], username) const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) await uploadVideo(servers[0].url, tmpToken, { name: 'super video' })
await waitJobs(servers) await waitJobs(servers)
@ -339,7 +336,7 @@ describe('Test moderation notifications', function () {
it('Should send a notification only to moderators when a user registers on the instance', async function () { it('Should send a notification only to moderators when a user registers on the instance', async function () {
this.timeout(10000) this.timeout(10000)
await registerUser(servers[0].url, 'user_45', 'password') await servers[0].usersCommand.register({ username: 'user_45' })
await waitJobs(servers) await waitJobs(servers)

View File

@ -7,14 +7,13 @@ import {
checkNewVideoFromSubscription, checkNewVideoFromSubscription,
cleanupTests, cleanupTests,
getAllNotificationsSettings, getAllNotificationsSettings,
getMyUserInformation,
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
uploadRandomVideo, uploadRandomVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' import { UserNotification, UserNotificationSettingValue } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -109,15 +108,14 @@ describe('Test notifications API', function () {
}) })
{ {
const res = await getMyUserInformation(server.url, userToken) const info = await server.usersCommand.getMyInfo({ token: userToken })
const info = res.body as User
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
} }
const { name, uuid } = await uploadRandomVideo(server) const { name, uuid } = await uploadRandomVideo(server)
const check = { web: true, mail: true } const check = { web: true, mail: true }
await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
}) })
it('Should only have web notifications', async function () { it('Should only have web notifications', async function () {
@ -129,8 +127,7 @@ describe('Test notifications API', function () {
}) })
{ {
const res = await getMyUserInformation(server.url, userToken) const info = await server.usersCommand.getMyInfo({ token: userToken })
const info = res.body as User
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
} }
@ -138,12 +135,12 @@ describe('Test notifications API', function () {
{ {
const check = { mail: true, web: false } const check = { mail: true, web: false }
await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
} }
{ {
const check = { mail: false, web: true } const check = { mail: false, web: true }
await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
} }
}) })
@ -156,8 +153,7 @@ describe('Test notifications API', function () {
}) })
{ {
const res = await getMyUserInformation(server.url, userToken) const info = await server.usersCommand.getMyInfo({ token: userToken })
const info = res.body as User
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
} }
@ -165,12 +161,12 @@ describe('Test notifications API', function () {
{ {
const check = { mail: false, web: true } const check = { mail: false, web: true }
await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
} }
{ {
const check = { mail: true, web: false } const check = { mail: true, web: false }
await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
} }
}) })
@ -186,8 +182,7 @@ describe('Test notifications API', function () {
}) })
{ {
const res = await getMyUserInformation(server.url, userToken) const info = await server.usersCommand.getMyInfo({ token: userToken })
const info = res.body as User
expect(info.notificationSettings.newVideoFromSubscription).to.equal( expect(info.notificationSettings.newVideoFromSubscription).to.equal(
UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
) )

View File

@ -14,7 +14,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
ServerInfo, ServerInfo,
updateMyUser,
updateVideo, updateVideo,
uploadRandomVideoOnServers, uploadRandomVideoOnServers,
wait, wait,
@ -384,23 +383,14 @@ describe('Test user notifications', function () {
token: userAccessToken token: userAccessToken
} }
await updateMyUser({ await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
url: servers[0].url,
accessToken: servers[0].accessToken,
displayName: 'super root name'
})
await updateMyUser({ await servers[0].usersCommand.updateMe({
url: servers[0].url, token: userAccessToken,
accessToken: userAccessToken,
displayName: myUserName displayName: myUserName
}) })
await updateMyUser({ await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
url: servers[1].url,
accessToken: servers[1].accessToken,
displayName: 'super root 2 name'
})
await servers[0].channelsCommand.update({ await servers[0].channelsCommand.update({
token: userAccessToken, token: userAccessToken,

View File

@ -4,13 +4,11 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideoChannelVideos, getVideoChannelVideos,
SearchCommand, SearchCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateMyUser,
updateVideo, updateVideo,
uploadVideo, uploadVideo,
wait, wait,
@ -35,7 +33,7 @@ describe('Test ActivityPub video channels search', function () {
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
{ {
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' }) await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' })
const channel = { const channel = {
name: 'channel1_server1', name: 'channel1_server1',
displayName: 'Channel 1 server 1' displayName: 'Channel 1 server 1'
@ -45,7 +43,7 @@ describe('Test ActivityPub video channels search', function () {
{ {
const user = { username: 'user1_server2', password: 'password' } const user = { username: 'user1_server2', password: 'password' }
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
userServer2Token = await servers[1].loginCommand.getAccessToken(user) userServer2Token = await servers[1].loginCommand.getAccessToken(user)
const channel = { const channel = {
@ -171,7 +169,7 @@ describe('Test ActivityPub video channels search', function () {
channelName: 'channel1_server2', channelName: 'channel1_server2',
attributes: { displayName: 'channel updated' } attributes: { displayName: 'channel updated' }
}) })
await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' })
await waitJobs(servers) await waitJobs(servers)
// Expire video channel // Expire video channel

View File

@ -2,7 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { VideoChannel } from '@shared/models' import { VideoChannel } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -19,7 +19,7 @@ describe('Test channels search', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
{ {
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) await server.usersCommand.create({ username: 'user1', password: 'password' })
const channel = { const channel = {
name: 'squall_channel', name: 'squall_channel',
displayName: 'Squall channel' displayName: 'Squall channel'

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { import {
BulkCommand, BulkCommand,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList, getVideosList,
@ -38,21 +37,21 @@ describe('Test bulk actions', function () {
{ {
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
user1Token = await servers[0].loginCommand.getAccessToken(user) user1Token = await servers[0].loginCommand.getAccessToken(user)
} }
{ {
const user = { username: 'user2', password: 'password' } const user = { username: 'user2', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
user2Token = await servers[0].loginCommand.getAccessToken(user) user2Token = await servers[0].loginCommand.getAccessToken(user)
} }
{ {
const user = { username: 'user3', password: 'password' } const user = { username: 'user3', password: 'password' }
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
user3Token = await servers[1].loginCommand.getAccessToken(user) user3Token = await servers[1].loginCommand.getAccessToken(user)
} }

View File

@ -9,7 +9,6 @@ import {
killallServers, killallServers,
makeGetRequest, makeGetRequest,
parallelTests, parallelTests,
registerUser,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
@ -225,9 +224,9 @@ describe('Test config', function () {
this.timeout(5000) this.timeout(5000)
await Promise.all([ await Promise.all([
registerUser(server.url, 'user1', 'super password'), server.usersCommand.register({ username: 'user1' }),
registerUser(server.url, 'user2', 'super password'), server.usersCommand.register({ username: 'user2' }),
registerUser(server.url, 'user3', 'super password') server.usersCommand.register({ username: 'user3' })
]) ])
const data = await server.configCommand.getConfig() const data = await server.configCommand.getConfig()

View File

@ -2,23 +2,16 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '@shared/core-utils'
import { import {
askResetPassword,
askSendVerifyEmail,
blockUser,
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
resetPassword, MockSmtpServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
unblockUser,
uploadVideo, uploadVideo,
verifyEmail waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
const expect = chai.expect const expect = chai.expect
@ -58,8 +51,8 @@ describe('Test emails', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
{ {
const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) const created = await server.usersCommand.create({ username: user.username, password: user.password })
userId = res.body.user.id userId = created.id
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
} }
@ -87,7 +80,7 @@ describe('Test emails', function () {
it('Should ask to reset the password', async function () { it('Should ask to reset the password', async function () {
this.timeout(10000) this.timeout(10000)
await askResetPassword(server.url, 'user_1@example.com') await server.usersCommand.askResetPassword({ email: 'user_1@example.com' })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(1) expect(emails).to.have.lengthOf(1)
@ -113,15 +106,25 @@ describe('Test emails', function () {
}) })
it('Should not reset the password with an invalid verification string', async function () { it('Should not reset the password with an invalid verification string', async function () {
await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', HttpStatusCode.FORBIDDEN_403) await server.usersCommand.resetPassword({
userId,
verificationString: verificationString + 'b',
password: 'super_password2',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
}) })
it('Should reset the password', async function () { it('Should reset the password', async function () {
await resetPassword(server.url, userId, verificationString, 'super_password2') await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' })
}) })
it('Should not reset the password with the same verification string', async function () { it('Should not reset the password with the same verification string', async function () {
await resetPassword(server.url, userId, verificationString, 'super_password3', HttpStatusCode.FORBIDDEN_403) await server.usersCommand.resetPassword({
userId,
verificationString,
password: 'super_password3',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
}) })
it('Should login with this new password', async function () { it('Should login with this new password', async function () {
@ -132,15 +135,11 @@ describe('Test emails', function () {
}) })
describe('When creating a user without password', function () { describe('When creating a user without password', function () {
it('Should send a create password email', async function () { it('Should send a create password email', async function () {
this.timeout(10000) this.timeout(10000)
await createUser({ await server.usersCommand.create({ username: 'create_password', password: '' })
url: server.url,
accessToken: server.accessToken,
username: 'create_password',
password: ''
})
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(2) expect(emails).to.have.lengthOf(2)
@ -166,11 +165,20 @@ describe('Test emails', function () {
}) })
it('Should not reset the password with an invalid verification string', async function () { it('Should not reset the password with an invalid verification string', async function () {
await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', HttpStatusCode.FORBIDDEN_403) await server.usersCommand.resetPassword({
userId: userId2,
verificationString: verificationString2 + 'c',
password: 'newly_created_password',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
}) })
it('Should reset the password', async function () { it('Should reset the password', async function () {
await resetPassword(server.url, userId2, verificationString2, 'newly_created_password') await server.usersCommand.resetPassword({
userId: userId2,
verificationString: verificationString2,
password: 'newly_created_password'
})
}) })
it('Should login with this new password', async function () { it('Should login with this new password', async function () {
@ -207,7 +215,7 @@ describe('Test emails', function () {
this.timeout(10000) this.timeout(10000)
const reason = 'my super bad reason' const reason = 'my super bad reason'
await blockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204, reason) await server.usersCommand.banUser({ userId, reason })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(4) expect(emails).to.have.lengthOf(4)
@ -225,7 +233,7 @@ describe('Test emails', function () {
it('Should send the notification email when unblocking a user', async function () { it('Should send the notification email when unblocking a user', async function () {
this.timeout(10000) this.timeout(10000)
await unblockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204) await server.usersCommand.unbanUser({ userId })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(5) expect(emails).to.have.lengthOf(5)
@ -288,7 +296,7 @@ describe('Test emails', function () {
it('Should ask to send the verification email', async function () { it('Should ask to send the verification email', async function () {
this.timeout(10000) this.timeout(10000)
await askSendVerifyEmail(server.url, 'user_1@example.com') await server.usersCommand.askSendVerifyEmail({ email: 'user_1@example.com' })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(8) expect(emails).to.have.lengthOf(8)
@ -314,11 +322,16 @@ describe('Test emails', function () {
}) })
it('Should not verify the email with an invalid verification string', async function () { it('Should not verify the email with an invalid verification string', async function () {
await verifyEmail(server.url, userId, verificationString + 'b', false, HttpStatusCode.FORBIDDEN_403) await server.usersCommand.verifyEmail({
userId,
verificationString: verificationString + 'b',
isPendingEmail: false,
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
}) })
it('Should verify the email', async function () { it('Should verify the email', async function () {
await verifyEmail(server.url, userId, verificationString) await server.usersCommand.verifyEmail({ userId, verificationString })
}) })
}) })

View File

@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos, getAccountVideos,
@ -47,7 +46,7 @@ describe('Test follow constraints', function () {
username: 'user1', username: 'user1',
password: 'super_password' password: 'super_password'
} }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user) userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
completeVideoCheck, completeVideoCheck,
createUser,
dateIsValid, dateIsValid,
expectAccountFollows, expectAccountFollows,
flushAndRunMultipleServers, flushAndRunMultipleServers,
@ -327,9 +326,7 @@ describe('Test follows', function () {
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
{ {
const user = { username: 'captain', password: 'password' } const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password })
const userAccessToken = await servers[2].loginCommand.getAccessToken(user)
const resVideos = await getVideosList(servers[2].url) const resVideos = await getVideosList(servers[2].url)
video4 = resVideos.body.data.find(v => v.name === 'server3-4') video4 = resVideos.body.data.find(v => v.name === 'server3-4')

View File

@ -30,7 +30,7 @@ describe('Test jobs', function () {
}) })
it('Should create some jobs', async function () { it('Should create some jobs', async function () {
this.timeout(60000) this.timeout(120000)
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })

View File

@ -6,17 +6,15 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
killallServers, killallServers,
PluginsCommand, PluginsCommand,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testHelloWorldRegisteredSettings, testHelloWorldRegisteredSettings,
updateMyUser,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { PluginType, User } from '@shared/models' import { PluginType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -120,14 +118,10 @@ describe('Test plugins', function () {
}) })
it('Should update my default theme', async function () { it('Should update my default theme', async function () {
await updateMyUser({ await server.usersCommand.updateMe({ theme: 'background-red' })
url: server.url,
accessToken: server.accessToken,
theme: 'background-red'
})
const res = await getMyUserInformation(server.url, server.accessToken) const user = await server.usersCommand.getMyInfo()
expect((res.body as User).theme).to.equal('background-red') expect(user.theme).to.equal('background-red')
}) })
it('Should list plugins and themes', async function () { it('Should list plugins and themes', async function () {
@ -311,8 +305,8 @@ describe('Test plugins', function () {
}) })
it('Should have updated the user theme', async function () { it('Should have updated the user theme', async function () {
const res = await getMyUserInformation(server.url, server.accessToken) const user = await server.usersCommand.getMyInfo()
expect((res.body as User).theme).to.equal('instance-default') expect(user.theme).to.equal('instance-default')
}) })
it('Should not install a broken plugin', async function () { it('Should not install a broken plugin', async function () {

View File

@ -6,7 +6,7 @@ import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getVideo, getVideo,
registerUser, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo, uploadVideo,
viewVideo, viewVideo,
@ -14,8 +14,8 @@ import {
} from '@shared/extra-utils' } from '@shared/extra-utils'
describe('Test application behind a reverse proxy', function () { describe('Test application behind a reverse proxy', function () {
let server = null let server: ServerInfo
let videoId let videoId: number
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
@ -102,22 +102,22 @@ describe('Test application behind a reverse proxy', function () {
const user = { username: 'root', password: 'fail' } const user = { username: 'root', password: 'fail' }
for (let i = 0; i < 19; i++) { for (let i = 0; i < 19; i++) {
await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
} }
await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
}) })
it('Should rate limit signup', async function () { it('Should rate limit signup', async function () {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
try { try {
await registerUser(server.url, 'test' + i, 'password') await server.usersCommand.register({ username: 'test' + i })
} catch { } catch {
// empty // empty
} }
} }
await registerUser(server.url, 'test42', 'password', HttpStatusCode.TOO_MANY_REQUESTS_429) await server.usersCommand.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
}) })
it('Should not rate limit failed signup', async function () { it('Should not rate limit failed signup', async function () {
@ -126,10 +126,10 @@ describe('Test application behind a reverse proxy', function () {
await wait(7000) await wait(7000)
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
await registerUser(server.url, 'test' + i, 'password', HttpStatusCode.CONFLICT_409) await server.usersCommand.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 })
} }
await registerUser(server.url, 'test43', 'password', HttpStatusCode.NO_CONTENT_204) await server.usersCommand.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
ServerInfo, ServerInfo,
@ -35,7 +34,7 @@ describe('Test stats (excluding redundancy)', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
const videoUUID = resVideo.body.video.uuid const videoUUID = resVideo.body.video.uuid

View File

@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList, getVideosList,
@ -39,7 +38,7 @@ describe('Test users subscriptions', function () {
{ {
for (const server of servers) { for (const server of servers) {
const user = { username: 'user' + server.serverNumber, password: 'password' } const user = { username: 'user' + server.serverNumber, password: 'password' }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
const accessToken = await server.loginCommand.getAccessToken(user) const accessToken = await server.loginCommand.getAccessToken(user)
users.push({ accessToken }) users.push({ accessToken })

View File

@ -7,17 +7,12 @@ import {
checkTmpIsEmpty, checkTmpIsEmpty,
checkVideoFilesWereRemoved, checkVideoFilesWereRemoved,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos, getAccountVideos,
getMyUserInformation,
removeUser,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
updateMyAvatar,
updateMyUser,
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -56,13 +51,8 @@ describe('Test users with multiple servers', function () {
username: 'user1', username: 'user1',
password: 'password' password: 'password'
} }
const res = await createUser({ const created = await servers[0].usersCommand.create(user)
url: servers[0].url, userId = created.id
accessToken: servers[0].accessToken,
username: user.username,
password: user.password
})
userId = res.body.user.id
userAccessToken = await servers[0].loginCommand.getAccessToken(user) userAccessToken = await servers[0].loginCommand.getAccessToken(user)
} }
@ -77,15 +67,9 @@ describe('Test users with multiple servers', function () {
it('Should be able to update my display name', async function () { it('Should be able to update my display name', async function () {
this.timeout(10000) this.timeout(10000)
await updateMyUser({ await servers[0].usersCommand.updateMe({ displayName: 'my super display name' })
url: servers[0].url,
accessToken: servers[0].accessToken,
displayName: 'my super display name'
})
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
user = res.body
user = await servers[0].usersCommand.getMyInfo()
expect(user.account.displayName).to.equal('my super display name') expect(user.account.displayName).to.equal('my super display name')
await waitJobs(servers) await waitJobs(servers)
@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () {
it('Should be able to update my description', async function () { it('Should be able to update my description', async function () {
this.timeout(10_000) this.timeout(10_000)
await updateMyUser({ await servers[0].usersCommand.updateMe({ description: 'my super description updated' })
url: servers[0].url,
accessToken: servers[0].accessToken,
description: 'my super description updated'
})
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) user = await servers[0].usersCommand.getMyInfo()
user = res.body
expect(user.account.displayName).to.equal('my super display name') expect(user.account.displayName).to.equal('my super display name')
expect(user.account.description).to.equal('my super description updated') expect(user.account.description).to.equal('my super description updated')
@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () {
const fixture = 'avatar2.png' const fixture = 'avatar2.png'
await updateMyAvatar({ await servers[0].usersCommand.updateMyAvatar({ fixture })
url: servers[0].url,
accessToken: servers[0].accessToken,
fixture
})
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
user = res.body
user = await servers[0].usersCommand.getMyInfo()
userAvatarFilename = user.account.avatar.path userAvatarFilename = user.account.avatar.path
await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
@ -202,7 +175,7 @@ describe('Test users with multiple servers', function () {
expect(videoChannelDeleted).not.to.be.undefined expect(videoChannelDeleted).not.to.be.undefined
} }
await removeUser(servers[0].url, userId, servers[0].accessToken) await servers[0].usersCommand.remove({ userId })
await waitJobs(servers) await waitJobs(servers)

View File

@ -3,20 +3,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
cleanupTests,
flushAndRunServer,
getMyUserInformation,
getUserInformation,
MockSmtpServer,
registerUser,
ServerInfo,
setAccessTokensToServers,
updateMyUser,
verifyEmail,
waitJobs
} from '@shared/extra-utils'
import { User } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -65,7 +52,7 @@ describe('Test users account verification', function () {
} }
}) })
await registerUser(server.url, user1.username, user1.password) await server.usersCommand.register(user1)
await waitJobs(server) await waitJobs(server)
expectedEmailsLength++ expectedEmailsLength++
@ -84,8 +71,8 @@ describe('Test users account verification', function () {
userId = parseInt(userIdMatches[1], 10) userId = parseInt(userIdMatches[1], 10)
const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) const body = await server.usersCommand.get({ userId })
expect(resUserInfo.body.emailVerified).to.be.false expect(body.emailVerified).to.be.false
}) })
it('Should not allow login for user with unverified email', async function () { it('Should not allow login for user with unverified email', async function () {
@ -94,13 +81,13 @@ describe('Test users account verification', function () {
}) })
it('Should verify the user via email and allow login', async function () { it('Should verify the user via email and allow login', async function () {
await verifyEmail(server.url, userId, verificationString) await server.usersCommand.verifyEmail({ userId, verificationString })
const body = await server.loginCommand.login({ user: user1 }) const body = await server.loginCommand.login({ user: user1 })
userAccessToken = body.access_token userAccessToken = body.access_token
const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) const user = await server.usersCommand.get({ userId })
expect(resUserVerified.body.emailVerified).to.be.true expect(user.emailVerified).to.be.true
}) })
it('Should be able to change the user email', async function () { it('Should be able to change the user email', async function () {
@ -109,9 +96,8 @@ describe('Test users account verification', function () {
let updateVerificationString: string let updateVerificationString: string
{ {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: userAccessToken,
accessToken: userAccessToken,
email: 'updated@example.com', email: 'updated@example.com',
currentPassword: user1.password currentPassword: user1.password
}) })
@ -127,19 +113,15 @@ describe('Test users account verification', function () {
} }
{ {
const res = await getMyUserInformation(server.url, userAccessToken) const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
const me: User = res.body
expect(me.email).to.equal('user_1@example.com') expect(me.email).to.equal('user_1@example.com')
expect(me.pendingEmail).to.equal('updated@example.com') expect(me.pendingEmail).to.equal('updated@example.com')
} }
{ {
await verifyEmail(server.url, userId, updateVerificationString, true) await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true })
const res = await getMyUserInformation(server.url, userAccessToken)
const me: User = res.body
const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
expect(me.email).to.equal('updated@example.com') expect(me.email).to.equal('updated@example.com')
expect(me.pendingEmail).to.be.null expect(me.pendingEmail).to.be.null
} }
@ -157,15 +139,15 @@ describe('Test users account verification', function () {
} }
}) })
await registerUser(server.url, user2.username, user2.password) await server.usersCommand.register(user2)
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(expectedEmailsLength) expect(emails).to.have.lengthOf(expectedEmailsLength)
const accessToken = await server.loginCommand.getAccessToken(user2) const accessToken = await server.loginCommand.getAccessToken(user2)
const resMyUserInfo = await getMyUserInformation(server.url, accessToken) const user = await server.usersCommand.getMyInfo({ token: accessToken })
expect(resMyUserInfo.body.emailVerified).to.be.null expect(user.emailVerified).to.be.null
}) })
it('Should allow login for user with unverified email when setting later enabled', async function () { it('Should allow login for user with unverified email when setting later enabled', async function () {

View File

@ -4,37 +4,22 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
blockUser,
cleanupTests, cleanupTests,
createUser,
deleteMe,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
getMyUserVideoQuotaUsed,
getMyUserVideoRating,
getMyVideos, getMyVideos,
getUserInformation,
getUsersList,
getUsersListPaginationAndSort,
getVideosList, getVideosList,
killallServers, killallServers,
makePutBodyRequest, makePutBodyRequest,
rateVideo, rateVideo,
registerUserWithChannel,
removeUser,
removeVideo, removeVideo,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
unblockUser,
updateMyAvatar,
updateMyUser,
updateUser,
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -174,8 +159,7 @@ describe('Test users', function () {
it('Should retrieve a video rating', async function () { it('Should retrieve a video rating', async function () {
await rateVideo(server.url, accessToken, videoId, 'like') await rateVideo(server.url, accessToken, videoId, 'like')
const res = await getMyUserVideoRating(server.url, accessToken, videoId) const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId })
const rating = res.body
expect(rating.videoId).to.equal(videoId) expect(rating.videoId).to.equal(videoId)
expect(rating.rating).to.equal('like') expect(rating.rating).to.equal('like')
@ -222,7 +206,7 @@ describe('Test users', function () {
}) })
it('Should not be able to get the user information', async function () { it('Should not be able to get the user information', async function () {
await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should not be able to upload a video', async function () { it('Should not be able to upload a video', async function () {
@ -252,7 +236,7 @@ describe('Test users', function () {
}) })
it('Should be able to get my user information again', async function () { it('Should be able to get my user information again', async function () {
await getMyUserInformation(server.url, server.accessToken) await server.usersCommand.getMyInfo()
}) })
it('Should have an expired access token', async function () { it('Should have an expired access token', async function () {
@ -264,7 +248,7 @@ describe('Test users', function () {
await killallServers([ server ]) await killallServers([ server ])
await reRunServer(server) await reRunServer(server)
await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should not be able to refresh an access token with an expired refresh token', async function () { it('Should not be able to refresh an access token with an expired refresh token', async function () {
@ -286,21 +270,14 @@ describe('Test users', function () {
}) })
it('Should be able to get my user information again', async function () { it('Should be able to get my user information again', async function () {
await getMyUserInformation(server.url, server.accessToken) await server.usersCommand.getMyInfo()
}) })
}) })
describe('Creating a user', function () { describe('Creating a user', function () {
it('Should be able to create a new user', async function () { it('Should be able to create a new user', async function () {
await createUser({ await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
url: server.url,
accessToken: accessToken,
username: user.username,
password: user.password,
videoQuota: 2 * 1024 * 1024,
adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
})
}) })
it('Should be able to login with this user', async function () { it('Should be able to login with this user', async function () {
@ -308,11 +285,9 @@ describe('Test users', function () {
}) })
it('Should be able to get user information', async function () { it('Should be able to get user information', async function () {
const res1 = await getMyUserInformation(server.url, accessTokenUser) const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const userMe: MyUser = res1.body
const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
const userGet: User = res2.body
for (const user of [ userMe, userGet ]) { for (const user of [ userMe, userGet ]) {
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
@ -356,15 +331,11 @@ describe('Test users', function () {
}) })
it('Should have video quota updated', async function () { it('Should have video quota updated', async function () {
const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
const data = res.body expect(quota.videoQuotaUsed).to.equal(218910)
expect(data.videoQuotaUsed).to.equal(218910) const { data } = await server.usersCommand.list()
const tmpUser = data.find(u => u.username === user.username)
const resUsers = await getUsersList(server.url, server.accessToken)
const users: User[] = resUsers.body.data
const tmpUser = users.find(u => u.username === user.username)
expect(tmpUser.videoQuotaUsed).to.equal(218910) expect(tmpUser.videoQuotaUsed).to.equal(218910)
}) })
@ -421,9 +392,7 @@ describe('Test users', function () {
} }
{ {
const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
const data = res.body
expect(data.videoQuotaUsed).to.be.greaterThan(220000) expect(data.videoQuotaUsed).to.be.greaterThan(220000)
} }
}) })
@ -432,21 +401,18 @@ describe('Test users', function () {
describe('Users listing', function () { describe('Users listing', function () {
it('Should list all the users', async function () { it('Should list all the users', async function () {
const res = await getUsersList(server.url, server.accessToken) const { data, total } = await server.usersCommand.list()
const result = res.body
const total = result.total
const users = result.data
expect(total).to.equal(2) expect(total).to.equal(2)
expect(users).to.be.an('array') expect(data).to.be.an('array')
expect(users.length).to.equal(2) expect(data.length).to.equal(2)
const user = users[0] const user = data[0]
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com') expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display') expect(user.nsfwPolicy).to.equal('display')
const rootUser = users[1] const rootUser = data[1]
expect(rootUser.username).to.equal('root') expect(rootUser.username).to.equal('root')
expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(user.nsfwPolicy).to.equal('display') expect(user.nsfwPolicy).to.equal('display')
@ -458,16 +424,12 @@ describe('Test users', function () {
}) })
it('Should list only the first user by username asc', async function () { it('Should list only the first user by username asc', async function () {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' })
const result = res.body
const total = result.total
const users = result.data
expect(total).to.equal(2) expect(total).to.equal(2)
expect(users.length).to.equal(1) expect(data.length).to.equal(1)
const user = users[0] const user = data[0]
expect(user.username).to.equal('root') expect(user.username).to.equal('root')
expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(user.roleLabel).to.equal('Administrator') expect(user.roleLabel).to.equal('Administrator')
@ -475,84 +437,66 @@ describe('Test users', function () {
}) })
it('Should list only the first user by username desc', async function () { it('Should list only the first user by username desc', async function () {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' })
const result = res.body
const total = result.total
const users = result.data
expect(total).to.equal(2) expect(total).to.equal(2)
expect(users.length).to.equal(1) expect(data.length).to.equal(1)
const user = users[0] const user = data[0]
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com') expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display') expect(user.nsfwPolicy).to.equal('display')
}) })
it('Should list only the second user by createdAt desc', async function () { it('Should list only the second user by createdAt desc', async function () {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' })
const result = res.body
const total = result.total
const users = result.data
expect(total).to.equal(2) expect(total).to.equal(2)
expect(users.length).to.equal(1)
const user = users[0] expect(data.length).to.equal(1)
const user = data[0]
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com') expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display') expect(user.nsfwPolicy).to.equal('display')
}) })
it('Should list all the users by createdAt asc', async function () { it('Should list all the users by createdAt asc', async function () {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' })
const result = res.body
const total = result.total
const users = result.data
expect(total).to.equal(2) expect(total).to.equal(2)
expect(users.length).to.equal(2) expect(data.length).to.equal(2)
expect(users[0].username).to.equal('root') expect(data[0].username).to.equal('root')
expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(users[0].nsfwPolicy).to.equal('display') expect(data[0].nsfwPolicy).to.equal('display')
expect(users[1].username).to.equal('user_1') expect(data[1].username).to.equal('user_1')
expect(users[1].email).to.equal('user_1@example.com') expect(data[1].email).to.equal('user_1@example.com')
expect(users[1].nsfwPolicy).to.equal('display') expect(data[1].nsfwPolicy).to.equal('display')
}) })
it('Should search user by username', async function () { it('Should search user by username', async function () {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
const users = res.body.data as User[] expect(total).to.equal(1)
expect(data.length).to.equal(1)
expect(res.body.total).to.equal(1) expect(data[0].username).to.equal('root')
expect(users.length).to.equal(1)
expect(users[0].username).to.equal('root')
}) })
it('Should search user by email', async function () { it('Should search user by email', async function () {
{ {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
const users = res.body.data as User[] expect(total).to.equal(1)
expect(data.length).to.equal(1)
expect(res.body.total).to.equal(1) expect(data[0].username).to.equal('user_1')
expect(users.length).to.equal(1) expect(data[0].email).to.equal('user_1@example.com')
expect(users[0].username).to.equal('user_1')
expect(users[0].email).to.equal('user_1@example.com')
} }
{ {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
const users = res.body.data as User[] expect(total).to.equal(2)
expect(data.length).to.equal(2)
expect(res.body.total).to.equal(2) expect(data[0].username).to.equal('root')
expect(users.length).to.equal(2) expect(data[1].username).to.equal('user_1')
expect(users[0].username).to.equal('root')
expect(users[1].username).to.equal('user_1')
} }
}) })
}) })
@ -560,9 +504,8 @@ describe('Test users', function () {
describe('Update my account', function () { describe('Update my account', function () {
it('Should update my password', async function () { it('Should update my password', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
currentPassword: 'super password', currentPassword: 'super password',
password: 'new password' password: 'new password'
}) })
@ -572,15 +515,12 @@ describe('Test users', function () {
}) })
it('Should be able to change the NSFW display attribute', async function () { it('Should be able to change the NSFW display attribute', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
nsfwPolicy: 'do_not_list' nsfwPolicy: 'do_not_list'
}) })
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const user = res.body
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com') expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -591,42 +531,33 @@ describe('Test users', function () {
}) })
it('Should be able to change the autoPlayVideo attribute', async function () { it('Should be able to change the autoPlayVideo attribute', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
autoPlayVideo: false autoPlayVideo: false
}) })
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const user = res.body
expect(user.autoPlayVideo).to.be.false expect(user.autoPlayVideo).to.be.false
}) })
it('Should be able to change the autoPlayNextVideo attribute', async function () { it('Should be able to change the autoPlayNextVideo attribute', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
autoPlayNextVideo: true autoPlayNextVideo: true
}) })
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const user = res.body
expect(user.autoPlayNextVideo).to.be.true expect(user.autoPlayNextVideo).to.be.true
}) })
it('Should be able to change the email attribute', async function () { it('Should be able to change the email attribute', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
currentPassword: 'new password', currentPassword: 'new password',
email: 'updated@example.com' email: 'updated@example.com'
}) })
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const user = res.body
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -639,15 +570,9 @@ describe('Test users', function () {
it('Should be able to update my avatar with a gif', async function () { it('Should be able to update my avatar with a gif', async function () {
const fixture = 'avatar.gif' const fixture = 'avatar.gif'
await updateMyAvatar({ await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
url: server.url,
accessToken: accessTokenUser,
fixture
})
const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
}) })
@ -655,29 +580,17 @@ describe('Test users', function () {
for (const extension of [ '.png', '.gif' ]) { for (const extension of [ '.png', '.gif' ]) {
const fixture = 'avatar' + extension const fixture = 'avatar' + extension
await updateMyAvatar({ await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
url: server.url,
accessToken: accessTokenUser,
fixture
})
const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
} }
}) })
it('Should be able to update my display name', async function () { it('Should be able to update my display name', async function () {
await updateMyUser({ await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' })
url: server.url,
accessToken: accessTokenUser,
displayName: 'new display name'
})
const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -688,15 +601,9 @@ describe('Test users', function () {
}) })
it('Should be able to update my description', async function () { it('Should be able to update my description', async function () {
await updateMyUser({ await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' })
url: server.url,
accessToken: accessTokenUser,
description: 'my super description updated'
})
const res = await getMyUserInformation(server.url, accessTokenUser)
const user: User = res.body
const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com') expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.nsfwPolicy).to.equal('do_not_list')
@ -710,30 +617,21 @@ describe('Test users', function () {
it('Should be able to update my theme', async function () { it('Should be able to update my theme', async function () {
for (const theme of [ 'background-red', 'default', 'instance-default' ]) { for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
await updateMyUser({ await server.usersCommand.updateMe({ token: accessTokenUser, theme })
url: server.url,
accessToken: accessTokenUser,
theme
})
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const body: User = res.body expect(user.theme).to.equal(theme)
expect(body.theme).to.equal(theme)
} }
}) })
it('Should be able to update my modal preferences', async function () { it('Should be able to update my modal preferences', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: accessTokenUser,
accessToken: accessTokenUser,
noInstanceConfigWarningModal: true, noInstanceConfigWarningModal: true,
noWelcomeModal: true noWelcomeModal: true
}) })
const res = await getMyUserInformation(server.url, accessTokenUser) const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
const user: User = res.body
expect(user.noWelcomeModal).to.be.true expect(user.noWelcomeModal).to.be.true
expect(user.noInstanceConfigWarningModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true
}) })
@ -741,10 +639,9 @@ describe('Test users', function () {
describe('Updating another user', function () { describe('Updating another user', function () {
it('Should be able to update another user', async function () { it('Should be able to update another user', async function () {
await updateUser({ await server.usersCommand.update({
url: server.url,
userId, userId,
accessToken, token: accessToken,
email: 'updated2@example.com', email: 'updated2@example.com',
emailVerified: true, emailVerified: true,
videoQuota: 42, videoQuota: 42,
@ -753,8 +650,7 @@ describe('Test users', function () {
pluginAuth: 'toto' pluginAuth: 'toto'
}) })
const res = await getUserInformation(server.url, accessToken, userId) const user = await server.usersCommand.get({ token: accessToken, userId })
const user = res.body as User
expect(user.username).to.equal('user_1') expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated2@example.com') expect(user.email).to.equal('updated2@example.com')
@ -768,28 +664,22 @@ describe('Test users', function () {
}) })
it('Should reset the auth plugin', async function () { it('Should reset the auth plugin', async function () {
await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null })
const res = await getUserInformation(server.url, accessToken, userId) const user = await server.usersCommand.get({ token: accessToken, userId })
const user = res.body as User
expect(user.pluginAuth).to.be.null expect(user.pluginAuth).to.be.null
}) })
it('Should have removed the user token', async function () { it('Should have removed the user token', async function () {
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
accessTokenUser = await server.loginCommand.getAccessToken(user) accessTokenUser = await server.loginCommand.getAccessToken(user)
}) })
it('Should be able to update another user password', async function () { it('Should be able to update another user password', async function () {
await updateUser({ await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' })
url: server.url,
userId,
accessToken,
password: 'password updated'
})
await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
@ -806,7 +696,7 @@ describe('Test users', function () {
describe('Remove a user', function () { describe('Remove a user', function () {
it('Should be able to remove this user', async function () { it('Should be able to remove this user', async function () {
await removeUser(server.url, userId, accessToken) await server.usersCommand.remove({ userId, token: accessToken })
}) })
it('Should not be able to login with this user', async function () { it('Should not be able to login with this user', async function () {
@ -830,7 +720,7 @@ describe('Test users', function () {
const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
await registerUserWithChannel({ url: server.url, user, channel }) await server.usersCommand.register({ ...user, channel })
}) })
it('Should be able to login with this registered user', async function () { it('Should be able to login with this registered user', async function () {
@ -843,16 +733,12 @@ describe('Test users', function () {
}) })
it('Should have the correct display name', async function () { it('Should have the correct display name', async function () {
const res = await getMyUserInformation(server.url, user15AccessToken) const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
const user: User = res.body
expect(user.account.displayName).to.equal('super user 15') expect(user.account.displayName).to.equal('super user 15')
}) })
it('Should have the correct video quota', async function () { it('Should have the correct video quota', async function () {
const res = await getMyUserInformation(server.url, user15AccessToken) const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
const user = res.body
expect(user.videoQuota).to.equal(5 * 1024 * 1024) expect(user.videoQuota).to.equal(5 * 1024 * 1024)
}) })
@ -864,15 +750,15 @@ describe('Test users', function () {
it('Should remove me', async function () { it('Should remove me', async function () {
{ {
const res = await getUsersList(server.url, server.accessToken) const { data } = await server.usersCommand.list()
expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
} }
await deleteMe(server.url, user15AccessToken) await server.usersCommand.deleteMe({ token: user15AccessToken })
{ {
const res = await getUsersList(server.url, server.accessToken) const { data } = await server.usersCommand.list()
expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined expect(data.find(u => u.username === 'user_15')).to.be.undefined
} }
}) })
}) })
@ -886,49 +772,40 @@ describe('Test users', function () {
} }
it('Should block a user', async function () { it('Should block a user', async function () {
const resUser = await createUser({ const user = await server.usersCommand.create({ ...user16 })
url: server.url, user16Id = user.id
accessToken: server.accessToken,
username: user16.username,
password: user16.password
})
user16Id = resUser.body.user.id
user16AccessToken = await server.loginCommand.getAccessToken(user16) user16AccessToken = await server.loginCommand.getAccessToken(user16)
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
await blockUser(server.url, user16Id, server.accessToken) await server.usersCommand.banUser({ userId: user16Id })
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should search user by banned status', async function () { it('Should search user by banned status', async function () {
{ {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
const users = res.body.data as User[] expect(total).to.equal(1)
expect(data.length).to.equal(1)
expect(res.body.total).to.equal(1) expect(data[0].username).to.equal(user16.username)
expect(users.length).to.equal(1)
expect(users[0].username).to.equal(user16.username)
} }
{ {
const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
const users = res.body.data as User[] expect(total).to.equal(1)
expect(data.length).to.equal(1)
expect(res.body.total).to.equal(1) expect(data[0].username).to.not.equal(user16.username)
expect(users.length).to.equal(1)
expect(users[0].username).to.not.equal(user16.username)
} }
}) })
it('Should unblock a user', async function () { it('Should unblock a user', async function () {
await unblockUser(server.url, user16Id, server.accessToken) await server.usersCommand.unbanUser({ userId: user16Id })
user16AccessToken = await server.loginCommand.getAccessToken(user16) user16AccessToken = await server.loginCommand.getAccessToken(user16)
await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
}) })
}) })
@ -941,19 +818,12 @@ describe('Test users', function () {
username: 'user_17', username: 'user_17',
password: 'my super password' password: 'my super password'
} }
const resUser = await createUser({ const created = await server.usersCommand.create({ ...user17 })
url: server.url,
accessToken: server.accessToken,
username: user17.username,
password: user17.password
})
user17Id = resUser.body.user.id user17Id = created.id
user17AccessToken = await server.loginCommand.getAccessToken(user17) user17AccessToken = await server.loginCommand.getAccessToken(user17)
const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
const user: User = res.body
expect(user.videosCount).to.equal(0) expect(user.videosCount).to.equal(0)
expect(user.videoCommentsCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0)
expect(user.abusesCount).to.equal(0) expect(user.abusesCount).to.equal(0)
@ -969,9 +839,7 @@ describe('Test users', function () {
const res1 = await getVideosList(server.url) const res1 = await getVideosList(server.url)
videoId = res1.body.data.find(video => video.name === videoAttributes.name).id videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
const user: User = res2.body
expect(user.videosCount).to.equal(1) expect(user.videosCount).to.equal(1)
}) })
@ -979,9 +847,7 @@ describe('Test users', function () {
const text = 'super comment' const text = 'super comment'
await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text })
const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
const user: User = res.body
expect(user.videoCommentsCount).to.equal(1) expect(user.videoCommentsCount).to.equal(1)
}) })
@ -992,17 +858,13 @@ describe('Test users', function () {
const body1 = await server.abusesCommand.getAdminList() const body1 = await server.abusesCommand.getAdminList()
const abuseId = body1.data[0].id const abuseId = body1.data[0].id
const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true })
const user2: User = res2.body
expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCount).to.equal(1) // number of incriminations
expect(user2.abusesCreatedCount).to.equal(1) // number of reports created expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true })
const user3: User = res3.body
expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
}) })
}) })

View File

@ -10,7 +10,6 @@ import {
checkVideoFilesWereRemoved, checkVideoFilesWereRemoved,
cleanupTests, cleanupTests,
completeVideoCheck, completeVideoCheck,
createUser,
dateIsValid, dateIsValid,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
@ -153,7 +152,7 @@ describe('Test multiple servers', function () {
username: 'user1', username: 'user1',
password: 'super_password' password: 'super_password'
} }
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) await servers[1].usersCommand.create({ username: user.username, password: user.password })
const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
const videoAttributes = { const videoAttributes = {

View File

@ -9,15 +9,13 @@ import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
prepareResumableUpload, prepareResumableUpload,
sendResumableChunks, sendResumableChunks,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel
updateUser
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { MyUser, VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -109,15 +107,10 @@ describe('Test resumable upload', function () {
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ]) await setDefaultVideoChannel([ server ])
const res = await getMyUserInformation(server.url, server.accessToken) const body = await server.usersCommand.getMyInfo()
rootId = (res.body as MyUser).id rootId = body.id
await updateUser({ await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 })
url: server.url,
userId: rootId,
accessToken: server.accessToken,
videoQuota: 10_000_000
})
}) })
describe('Directory cleaning', function () { describe('Directory cleaning', function () {

View File

@ -6,11 +6,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
import { import {
ChangeOwnershipCommand, ChangeOwnershipCommand,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
getVideo, getVideo,
getVideosList, getVideosList,
ServerInfo, ServerInfo,
@ -19,21 +17,15 @@ import {
uploadVideo uploadVideo
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { User } from '../../../../shared/models/users'
import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
describe('Test video change ownership - nominal', function () { describe('Test video change ownership - nominal', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
const firstUser = {
username: 'first', const firstUser = 'first'
password: 'My great password' const secondUser = 'second'
}
const secondUser = {
username: 'second',
password: 'My other password'
}
let firstUserToken = '' let firstUserToken = ''
let firstUserChannelId: number let firstUserChannelId: number
@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () {
} }
}) })
const videoQuota = 42000000 firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser)
await createUser({ secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser)
url: servers[0].url,
accessToken: servers[0].accessToken,
username: firstUser.username,
password: firstUser.password,
videoQuota: videoQuota
})
await createUser({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: secondUser.username,
password: secondUser.password,
videoQuota: videoQuota
})
firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser)
secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser)
{ {
const res = await getMyUserInformation(servers[0].url, firstUserToken) const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken })
const firstUserInformation: User = res.body firstUserChannelId = videoChannels[0].id
firstUserChannelId = firstUserInformation.videoChannels[0].id
} }
{ {
const res = await getMyUserInformation(servers[0].url, secondUserToken) const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken })
const secondUserInformation: User = res.body secondUserChannelId = videoChannels[0].id
secondUserChannelId = secondUserInformation.videoChannels[0].id
} }
{ {
@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () {
it('Should send a request to change ownership of a video', async function () { it('Should send a request to change ownership of a video', async function () {
this.timeout(15000) this.timeout(15000)
await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
}) })
it('Should only return a request to change ownership for the second user', async function () { it('Should only return a request to change ownership for the second user', async function () {
@ -166,7 +140,7 @@ describe('Test video change ownership - nominal', function () {
it('Should accept the same change ownership request without crashing', async function () { it('Should accept the same change ownership request without crashing', async function () {
this.timeout(10000) this.timeout(10000)
await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
}) })
it('Should not create multiple change ownership requests while one is waiting', async function () { it('Should not create multiple change ownership requests while one is waiting', async function () {
@ -194,7 +168,7 @@ describe('Test video change ownership - nominal', function () {
it('Should send a new request to change ownership of a video', async function () { it('Should send a new request to change ownership of a video', async function () {
this.timeout(15000) this.timeout(15000)
await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
}) })
it('Should return two requests to change ownership for the second user', async function () { it('Should return two requests to change ownership for the second user', async function () {
@ -251,7 +225,7 @@ describe('Test video change ownership - nominal', function () {
it('Should send a request to change ownership of a live', async function () { it('Should send a request to change ownership of a live', async function () {
this.timeout(15000) this.timeout(15000)
await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
const body = await command.list({ token: secondUserToken }) const body = await command.list({ token: secondUserToken })
@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () {
describe('Test video change ownership - quota too small', function () { describe('Test video change ownership - quota too small', function () {
let server: ServerInfo let server: ServerInfo
const firstUser = { const firstUser = 'first'
username: 'first', const secondUser = 'second'
password: 'My great password'
}
const secondUser = {
username: 'second',
password: 'My other password'
}
let firstUserToken = '' let firstUserToken = ''
let secondUserToken = '' let secondUserToken = ''
let lastRequestId: number let lastRequestId: number
@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () {
server = await flushAndRunServer(1) server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const videoQuota = 42000000 await server.usersCommand.create({ username: secondUser, videoQuota: 10 })
const limitedVideoQuota = 10
await createUser({
url: server.url,
accessToken: server.accessToken,
username: firstUser.username,
password: firstUser.password,
videoQuota: videoQuota
})
await createUser({
url: server.url,
accessToken: server.accessToken,
username: secondUser.username,
password: secondUser.password,
videoQuota: limitedVideoQuota
})
firstUserToken = await server.loginCommand.getAccessToken(firstUser) firstUserToken = await server.usersCommand.generateUserAndToken(firstUser)
secondUserToken = await server.loginCommand.getAccessToken(secondUser) secondUserToken = await server.loginCommand.getAccessToken(secondUser)
// Upload some videos on the server // Upload some videos on the server
@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () {
it('Should send a request to change ownership of a video', async function () { it('Should send a request to change ownership of a video', async function () {
this.timeout(15000) this.timeout(15000)
await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser })
}) })
it('Should only return a request to change ownership for the second user', async function () { it('Should only return a request to change ownership for the second user', async function () {
@ -371,9 +325,8 @@ describe('Test video change ownership - quota too small', function () {
it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
this.timeout(10000) this.timeout(10000)
const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken })
const secondUserInformation: User = secondUserInformationResponse.body const channelId = videoChannels[0].id
const channelId = secondUserInformation.videoChannels[0].id
await server.changeOwnershipCommand.accept({ await server.changeOwnershipCommand.accept({
token: secondUserToken, token: secondUserToken,

View File

@ -6,21 +6,22 @@ import { basename } from 'path'
import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideo, getVideo,
getVideoChannelVideos, getVideoChannelVideos,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
testFileExistsOrNot, testFileExistsOrNot,
testImage, testImage,
updateVideo, updateVideo,
uploadVideo, uploadVideo,
wait viewVideo,
} from '../../../../shared/extra-utils' wait,
import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' waitJobs
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' } from '@shared/extra-utils'
import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' import { User, Video, VideoChannel, VideoDetails } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -85,8 +86,7 @@ describe('Test video channels', function () {
}) })
it('Should have two video channels when getting my information', async () => { it('Should have two video channels when getting my information', async () => {
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) userInfo = await servers[0].usersCommand.getMyInfo()
userInfo = res.body
expect(userInfo.videoChannels).to.be.an('array') expect(userInfo.videoChannels).to.be.an('array')
expect(userInfo.videoChannels).to.have.lengthOf(2) expect(userInfo.videoChannels).to.have.lengthOf(2)
@ -389,11 +389,11 @@ describe('Test video channels', function () {
} }
{ {
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) await servers[0].usersCommand.create({ username: 'toto', password: 'password' })
const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' })
const res = await getMyUserInformation(servers[0].url, accessToken) const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken })
const videoChannel = res.body.videoChannels[0] const videoChannel = videoChannels[0]
expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
} }
}) })

View File

@ -5,13 +5,11 @@ import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
CommentsCommand, CommentsCommand,
createUser,
dateIsValid, dateIsValid,
flushAndRunServer, flushAndRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
testImage, testImage,
updateMyAvatar,
uploadVideo uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -39,19 +37,9 @@ describe('Test video comments', function () {
videoUUID = res.body.video.uuid videoUUID = res.body.video.uuid
videoId = res.body.video.id videoId = res.body.video.id
await updateMyAvatar({ await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
url: server.url,
accessToken: server.accessToken,
fixture: 'avatar.png'
})
await createUser({ userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1')
url: server.url,
accessToken: server.accessToken,
username: 'user1',
password: 'password'
})
userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password')
command = server.commentsCommand command = server.commentsCommand
}) })

View File

@ -7,7 +7,6 @@ import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getMyUserInformation,
getMyVideos, getMyVideos,
getVideo, getVideo,
getVideosList, getVideosList,
@ -97,13 +96,13 @@ describe('Test video imports', function () {
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
{ {
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) const { videoChannels } = await servers[0].usersCommand.getMyInfo()
channelIdServer1 = res.body.videoChannels[0].id channelIdServer1 = videoChannels[0].id
} }
{ {
const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) const { videoChannels } = await servers[1].usersCommand.getMyInfo()
channelIdServer2 = res.body.videoChannels[0].id channelIdServer2 = videoChannels[0].id
} }
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])

View File

@ -4,20 +4,17 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getAccountVideos, getAccountVideos,
getMyUserInformation,
getMyVideos, getMyVideos,
getVideoChannelVideos, getVideoChannelVideos,
getVideosList, getVideosList,
getVideosListWithToken, getVideosListWithToken,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateMyUser,
uploadVideo uploadVideo
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -32,8 +29,7 @@ describe('Test video NSFW policy', function () {
let customConfig: CustomConfig let customConfig: CustomConfig
async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
const res = await getMyUserInformation(server.url, server.accessToken) const user = await server.usersCommand.getMyInfo()
const user: User = res.body
const videoChannelName = user.videoChannels[0].name const videoChannelName = user.videoChannels[0].name
const accountName = user.account.name + '@' + user.account.host const accountName = user.account.name + '@' + user.account.host
const hasQuery = Object.keys(query).length !== 0 const hasQuery = Object.keys(query).length !== 0
@ -148,13 +144,11 @@ describe('Test video NSFW policy', function () {
it('Should create a user having the default nsfw policy', async function () { it('Should create a user having the default nsfw policy', async function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password })
const res = await getMyUserInformation(server.url, userAccessToken) const user = await server.usersCommand.getMyInfo({ token: userAccessToken })
const user = res.body
expect(user.nsfwPolicy).to.equal('blur') expect(user.nsfwPolicy).to.equal('blur')
}) })
@ -173,11 +167,7 @@ describe('Test video NSFW policy', function () {
}) })
it('Should display NSFW videos with display user NSFW policy', async function () { it('Should display NSFW videos with display user NSFW policy', async function () {
await updateMyUser({ await server.usersCommand.updateMe({ nsfwPolicy: 'display' })
url: server.url,
accessToken: server.accessToken,
nsfwPolicy: 'display'
})
for (const body of await getVideosFunctions(server.accessToken)) { for (const body of await getVideosFunctions(server.accessToken)) {
expect(body.total).to.equal(2) expect(body.total).to.equal(2)
@ -190,11 +180,7 @@ describe('Test video NSFW policy', function () {
}) })
it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
await updateMyUser({ await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' })
url: server.url,
accessToken: server.accessToken,
nsfwPolicy: 'do_not_list'
})
for (const body of await getVideosFunctions(server.accessToken)) { for (const body of await getVideosFunctions(server.accessToken)) {
expect(body.total).to.equal(1) expect(body.total).to.equal(1)

View File

@ -6,13 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
checkPlaylistFilesWereRemoved, checkPlaylistFilesWereRemoved,
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateUserAccessToken,
getMyUserInformation,
PlaylistsCommand, PlaylistsCommand,
removeUser,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
@ -24,7 +20,6 @@ import {
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { import {
User,
VideoPlaylist, VideoPlaylist,
VideoPlaylistCreateResult, VideoPlaylistCreateResult,
VideoPlaylistElementType, VideoPlaylistElementType,
@ -113,15 +108,7 @@ describe('Test video playlists', function () {
nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id
{ userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1')
await createUser({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: 'user1',
password: 'password'
})
userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password')
}
await waitJobs(servers) await waitJobs(servers)
}) })
@ -165,7 +152,7 @@ describe('Test video playlists', function () {
}) })
it('Should get private playlist for a classic user', async function () { it('Should get private playlist for a classic user', async function () {
const token = await generateUserAccessToken(servers[0], 'toto') const token = await servers[0].usersCommand.generateUserAndToken('toto')
const body = await commands[0].listByAccount({ token, handle: 'toto' }) const body = await commands[0].listByAccount({ token, handle: 'toto' })
@ -1118,19 +1105,10 @@ describe('Test video playlists', function () {
it('Should delete an account and delete its playlists', async function () { it('Should delete an account and delete its playlists', async function () {
this.timeout(30000) this.timeout(30000)
const user = { username: 'user_1', password: 'password' } const { userId, token } = await servers[0].usersCommand.generate('user_1')
const res = await createUser({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: user.username,
password: user.password
})
const userId = res.body.user.id const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token })
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userChannel = videoChannels[0]
const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
const userChannel = (resChannel.body as User).videoChannels[0]
await commands[0].create({ await commands[0].create({
attributes: { attributes: {
@ -1152,7 +1130,7 @@ describe('Test video playlists', function () {
} }
} }
await removeUser(servers[0].url, userId, servers[0].accessToken) await servers[0].usersCommand.remove({ userId })
await waitJobs(servers) await waitJobs(servers)
{ {

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunServer, flushAndRunServer,
getMyVideos, getMyVideos,
@ -125,7 +124,7 @@ describe('Test video privacy', function () {
username: 'hello', username: 'hello',
password: 'super password' password: 'super password'
} }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) await servers[0].usersCommand.create({ username: user.username, password: user.password })
anotherUserToken = await servers[0].loginCommand.getAccessToken(user) anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403)

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
makeGetRequest, makeGetRequest,
@ -60,17 +59,7 @@ describe('Test videos filter', function () {
for (const server of servers) { for (const server of servers) {
const moderator = { username: 'moderator', password: 'my super password' } const moderator = { username: 'moderator', password: 'my super password' }
await createUser( await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
{
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
videoQuota: undefined,
videoQuotaDaily: undefined,
role: UserRole.MODERATOR
}
)
server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getVideosListWithToken, getVideosListWithToken,
getVideoWithToken, getVideoWithToken,
@ -14,7 +13,6 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateMyUser,
uploadVideo, uploadVideo,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
@ -59,7 +57,7 @@ describe('Test videos history', function () {
username: 'user_1', username: 'user_1',
password: 'super password' password: 'super password'
} }
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user) userAccessToken = await server.loginCommand.getAccessToken(user)
}) })
@ -174,9 +172,7 @@ describe('Test videos history', function () {
}) })
it('Should disable videos history', async function () { it('Should disable videos history', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url,
accessToken: server.accessToken,
videosHistoryEnabled: false videosHistoryEnabled: false
}) })
@ -184,9 +180,7 @@ describe('Test videos history', function () {
}) })
it('Should re-enable videos history', async function () { it('Should re-enable videos history', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url,
accessToken: server.accessToken,
videosHistoryEnabled: true videosHistoryEnabled: true
}) })

View File

@ -2,15 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils'
cleanupTests,
flushAndRunServer,
generateUserAccessToken,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
wait
} from '@shared/extra-utils'
import { VideosOverview } from '@shared/models' import { VideosOverview } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -112,7 +104,7 @@ describe('Test a videos overview', function () {
}) })
it('Should hide muted accounts', async function () { it('Should hide muted accounts', async function () {
const token = await generateUserAccessToken(server, 'choco') const token = await server.usersCommand.generateUserAndToken('choco')
await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })

View File

@ -8,11 +8,9 @@ import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
CLICommand, CLICommand,
createUser,
doubleFollow, doubleFollow,
flushAndRunServer, flushAndRunServer,
getLocalIdByUUID, getLocalIdByUUID,
getMyUserInformation,
getVideo, getVideo,
getVideosList, getVideosList,
ImportsCommand, ImportsCommand,
@ -38,7 +36,7 @@ describe('Test CLI wrapper', function () {
server = await flushAndRunServer(1) server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' }) await server.usersCommand.create({ username: 'user_1', password: 'super_password' })
userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' }) userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
@ -56,8 +54,8 @@ describe('Test CLI wrapper', function () {
const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`) const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
const token = stdout.trim() const token = stdout.trim()
const res = await getMyUserInformation(server.url, token) const body = await server.usersCommand.getMyInfo({ token })
expect(res.body.username).to.equal('user_1') expect(body.username).to.equal('user_1')
}) })
it('Should display no selected instance', async function () { it('Should display no selected instance', async function () {

View File

@ -16,7 +16,6 @@ import {
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
updateMyAvatar,
uploadVideo, uploadVideo,
wait, wait,
waitJobs waitJobs
@ -73,7 +72,7 @@ describe('Test prune storage scripts', function () {
await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
await updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' }) await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
await server.playlistsCommand.create({ await server.playlistsCommand.create({
attributes: { attributes: {

View File

@ -1,5 +1,5 @@
import 'mocha' import 'mocha'
import { cleanupTests, CLICommand, createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils' import { cleanupTests, CLICommand, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils'
describe('Test reset password scripts', function () { describe('Test reset password scripts', function () {
let server: ServerInfo let server: ServerInfo
@ -9,7 +9,7 @@ describe('Test reset password scripts', function () {
server = await flushAndRunServer(1) server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' }) await server.usersCommand.create({ username: 'user_1', password: 'super password' })
}) })
it('Should change the user password from CLI', async function () { it('Should change the user password from CLI', async function () {

View File

@ -4,7 +4,6 @@ import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
getVideo, getVideo,
getVideosList, getVideosList,
@ -41,7 +40,7 @@ describe('Test update host scripts', function () {
await uploadVideo(server.url, server.accessToken, videoAttributes) await uploadVideo(server.url, server.accessToken, videoAttributes)
// Create a user // Create a user
await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' }) await server.usersCommand.create({ username: 'toto', password: 'coucou' })
// Create channel // Create channel
const videoChannel = { const videoChannel = {

View File

@ -15,7 +15,6 @@ import {
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
updateMyUser,
uploadVideo, uploadVideo,
waitJobs waitJobs
} from '../../shared/extra-utils' } from '../../shared/extra-utils'
@ -96,7 +95,7 @@ describe('Test a client controllers', function () {
// Account // Account
await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' }) await servers[0].usersCommand.updateMe({ description: 'my account description' })
account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` }) account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })

View File

@ -3,9 +3,7 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { User } from '@shared/models/users/user.model' import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo } from '../../../shared/extra-utils'
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
describe('Official plugin auth-ldap', function () { describe('Official plugin auth-ldap', function () {
let server: ServerInfo let server: ServerInfo
@ -71,9 +69,7 @@ describe('Official plugin auth-ldap', function () {
}) })
it('Should login get my profile', async function () { it('Should login get my profile', async function () {
const res = await getMyUserInformation(server.url, accessToken) const body = await server.usersCommand.getMyInfo({ token: accessToken })
const body: User = res.body
expect(body.username).to.equal('fry') expect(body.username).to.equal('fry')
expect(body.email).to.equal('fry@planetexpress.com') expect(body.email).to.equal('fry@planetexpress.com')
@ -85,7 +81,7 @@ describe('Official plugin auth-ldap', function () {
}) })
it('Should not be able to login if the user is banned', async function () { it('Should not be able to login if the user is banned', async function () {
await blockUser(server.url, userId, server.accessToken) await server.usersCommand.banUser({ userId })
await server.loginCommand.login({ await server.loginCommand.login({
user: { username: 'fry@planetexpress.com', password: 'fry' }, user: { username: 'fry@planetexpress.com', password: 'fry' },
@ -94,7 +90,7 @@ describe('Official plugin auth-ldap', function () {
}) })
it('Should be able to login if the user is unbanned', async function () { it('Should be able to login if the user is unbanned', async function () {
await unblockUser(server.url, userId, server.accessToken) await server.usersCommand.unbanUser({ userId })
await server.loginCommand.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } }) await server.loginCommand.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
}) })

View File

@ -6,21 +6,16 @@ import * as xmlParser from 'fast-xml-parser'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
getUserScopedTokens,
renewUserScopedTokens,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo, uploadVideo,
uploadVideoAndGetId, uploadVideoAndGetId,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
import { ScopedToken } from '@shared/models/users/user-scoped-token'
chai.use(require('chai-xml')) chai.use(require('chai-xml'))
chai.use(require('chai-json-schema')) chai.use(require('chai-json-schema'))
@ -54,24 +49,21 @@ describe('Test syndication feeds', () => {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
{ {
const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) const user = await servers[0].usersCommand.getMyInfo()
const user: User = res.body
rootAccountId = user.account.id rootAccountId = user.account.id
rootChannelId = user.videoChannels[0].id rootChannelId = user.videoChannels[0].id
} }
{ {
const attr = { username: 'john', password: 'password' } const attr = { username: 'john', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(attr) userAccessToken = await servers[0].loginCommand.getAccessToken(attr)
const res = await getMyUserInformation(servers[0].url, userAccessToken) const user = await servers[0].usersCommand.getMyInfo({ token: userAccessToken })
const user: User = res.body
userAccountId = user.account.id userAccountId = user.account.id
userChannelId = user.videoChannels[0].id userChannelId = user.videoChannels[0].id
const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
const token: ScopedToken = res2.body
userFeedToken = token.feedToken userFeedToken = token.feedToken
} }
@ -299,18 +291,16 @@ describe('Test syndication feeds', () => {
it('Should list no videos for a user with no videos and no subscriptions', async function () { it('Should list no videos for a user with no videos and no subscriptions', async function () {
const attr = { username: 'feeduser', password: 'password' } const attr = { username: 'feeduser', password: 'password' }
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
const feeduserAccessToken = await servers[0].loginCommand.getAccessToken(attr) const feeduserAccessToken = await servers[0].loginCommand.getAccessToken(attr)
{ {
const res = await getMyUserInformation(servers[0].url, feeduserAccessToken) const user = await servers[0].usersCommand.getMyInfo({ token: feeduserAccessToken })
const user: User = res.body
feeduserAccountId = user.account.id feeduserAccountId = user.account.id
} }
{ {
const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken) const token = await servers[0].usersCommand.getMyScopedTokens({ token: feeduserAccessToken })
const token: ScopedToken = res.body
feeduserFeedToken = token.feedToken feeduserFeedToken = token.feedToken
} }
@ -381,15 +371,14 @@ describe('Test syndication feeds', () => {
}) })
it('Should renew the token, and so have an invalid old token', async function () { it('Should renew the token, and so have an invalid old token', async function () {
await renewUserScopedTokens(servers[0].url, userAccessToken) await servers[0].usersCommand.renewMyScopedTokens({ token: userAccessToken })
const query = { accountId: userAccountId, token: userFeedToken, version: 3 } const query = { accountId: userAccountId, token: userFeedToken, version: 3 }
await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should succeed with the new token', async function () { it('Should succeed with the new token', async function () {
const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
const token: ScopedToken = res2.body
userFeedToken = token.feedToken userFeedToken = token.feedToken
const query = { accountId: userAccountId, token: userFeedToken, version: 4 } const query = { accountId: userAccountId, token: userFeedToken, version: 4 }

View File

@ -5,7 +5,6 @@ import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
flushAndRunServer, flushAndRunServer,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
@ -173,8 +172,8 @@ describe('Test misc endpoints', function () {
await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } }) await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } }) await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) await server.usersCommand.create({ username: 'user1', password: 'password' })
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' }) await server.usersCommand.create({ username: 'user2', password: 'password' })
const res = await makeGetRequest({ const res = await makeGetRequest({
url: server.url, url: server.url,

View File

@ -1,28 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
import {
blockUser,
createUser,
PluginsCommand,
registerUser,
removeUser,
setAccessTokensToServers,
setDefaultVideoChannel,
unblockUser,
updateUser,
updateVideo,
uploadVideo,
viewVideo
} from '../../../shared/extra-utils'
import { import {
cleanupTests, cleanupTests,
flushAndRunMultipleServers, flushAndRunMultipleServers,
killallServers, killallServers,
PluginsCommand,
reRunServer, reRunServer,
ServerInfo ServerInfo,
} from '../../../shared/extra-utils/server/servers' setAccessTokensToServers,
setDefaultVideoChannel,
updateVideo,
uploadVideo,
viewVideo
} from '@shared/extra-utils'
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
describe('Test plugin action hooks', function () { describe('Test plugin action hooks', function () {
let servers: ServerInfo[] let servers: ServerInfo[]
@ -119,19 +111,14 @@ describe('Test plugin action hooks', function () {
let userId: number let userId: number
it('Should run action:api.user.registered', async function () { it('Should run action:api.user.registered', async function () {
await registerUser(servers[0].url, 'registered_user', 'super_password') await servers[0].usersCommand.register({ username: 'registered_user' })
await checkHook('action:api.user.registered') await checkHook('action:api.user.registered')
}) })
it('Should run action:api.user.created', async function () { it('Should run action:api.user.created', async function () {
const res = await createUser({ const user = await servers[0].usersCommand.create({ username: 'created_user' })
url: servers[0].url, userId = user.id
accessToken: servers[0].accessToken,
username: 'created_user',
password: 'super_password'
})
userId = res.body.user.id
await checkHook('action:api.user.created') await checkHook('action:api.user.created')
}) })
@ -143,25 +130,25 @@ describe('Test plugin action hooks', function () {
}) })
it('Should run action:api.user.blocked', async function () { it('Should run action:api.user.blocked', async function () {
await blockUser(servers[0].url, userId, servers[0].accessToken) await servers[0].usersCommand.banUser({ userId })
await checkHook('action:api.user.blocked') await checkHook('action:api.user.blocked')
}) })
it('Should run action:api.user.unblocked', async function () { it('Should run action:api.user.unblocked', async function () {
await unblockUser(servers[0].url, userId, servers[0].accessToken) await servers[0].usersCommand.unbanUser({ userId })
await checkHook('action:api.user.unblocked') await checkHook('action:api.user.unblocked')
}) })
it('Should run action:api.user.updated', async function () { it('Should run action:api.user.updated', async function () {
await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) await servers[0].usersCommand.update({ userId, videoQuota: 50 })
await checkHook('action:api.user.updated') await checkHook('action:api.user.updated')
}) })
it('Should run action:api.user.deleted', async function () { it('Should run action:api.user.deleted', async function () {
await removeUser(servers[0].url, userId, servers[0].accessToken) await servers[0].usersCommand.remove({ userId })
await checkHook('action:api.user.deleted') await checkHook('action:api.user.deleted')
}) })

View File

@ -5,17 +5,14 @@ import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createUser,
decodeQueryString, decodeQueryString,
flushAndRunServer, flushAndRunServer,
getMyUserInformation,
PluginsCommand, PluginsCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateMyUser,
wait wait
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, UserRole } from '@shared/models' import { UserRole } from '@shared/models'
async function loginExternal (options: { async function loginExternal (options: {
server: ServerInfo server: ServerInfo
@ -149,9 +146,7 @@ describe('Test external auth plugins', function () {
} }
{ {
const res = await getMyUserInformation(server.url, cyanAccessToken) const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
const body: User = res.body
expect(body.username).to.equal('cyan') expect(body.username).to.equal('cyan')
expect(body.account.displayName).to.equal('cyan') expect(body.account.displayName).to.equal('cyan')
expect(body.email).to.equal('cyan@example.com') expect(body.email).to.equal('cyan@example.com')
@ -173,9 +168,7 @@ describe('Test external auth plugins', function () {
} }
{ {
const res = await getMyUserInformation(server.url, kefkaAccessToken) const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken })
const body: User = res.body
expect(body.username).to.equal('kefka') expect(body.username).to.equal('kefka')
expect(body.account.displayName).to.equal('Kefka Palazzo') expect(body.account.displayName).to.equal('Kefka Palazzo')
expect(body.email).to.equal('kefka@example.com') expect(body.email).to.equal('kefka@example.com')
@ -189,9 +182,8 @@ describe('Test external auth plugins', function () {
cyanAccessToken = resRefresh.body.access_token cyanAccessToken = resRefresh.body.access_token
cyanRefreshToken = resRefresh.body.refresh_token cyanRefreshToken = resRefresh.body.refresh_token
const res = await getMyUserInformation(server.url, cyanAccessToken) const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
const user: User = res.body expect(body.username).to.equal('cyan')
expect(user.username).to.equal('cyan')
} }
{ {
@ -200,16 +192,13 @@ describe('Test external auth plugins', function () {
}) })
it('Should update Cyan profile', async function () { it('Should update Cyan profile', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: cyanAccessToken,
accessToken: cyanAccessToken,
displayName: 'Cyan Garamonde', displayName: 'Cyan Garamonde',
description: 'Retainer to the king of Doma' description: 'Retainer to the king of Doma'
}) })
const res = await getMyUserInformation(server.url, cyanAccessToken) const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
const body: User = res.body
expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.displayName).to.equal('Cyan Garamonde')
expect(body.account.description).to.equal('Retainer to the king of Doma') expect(body.account.description).to.equal('Retainer to the king of Doma')
}) })
@ -221,7 +210,7 @@ describe('Test external auth plugins', function () {
it('Should have logged out Cyan', async function () { it('Should have logged out Cyan', async function () {
await server.serversCommand.waitUntilLog('On logout cyan') await server.serversCommand.waitUntilLog('On logout cyan')
await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should login Cyan and keep the old existing profile', async function () { it('Should login Cyan and keep the old existing profile', async function () {
@ -239,9 +228,7 @@ describe('Test external auth plugins', function () {
cyanAccessToken = res.access_token cyanAccessToken = res.access_token
} }
const res = await getMyUserInformation(server.url, cyanAccessToken) const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
const body: User = res.body
expect(body.username).to.equal('cyan') expect(body.username).to.equal('cyan')
expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.displayName).to.equal('Cyan Garamonde')
expect(body.account.description).to.equal('Retainer to the king of Doma') expect(body.account.description).to.equal('Retainer to the king of Doma')
@ -249,12 +236,11 @@ describe('Test external auth plugins', function () {
}) })
it('Should not update an external auth email', async function () { it('Should not update an external auth email', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: cyanAccessToken,
accessToken: cyanAccessToken,
email: 'toto@example.com', email: 'toto@example.com',
currentPassword: 'toto', currentPassword: 'toto',
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 expectedStatus: HttpStatusCode.BAD_REQUEST_400
}) })
}) })
@ -263,7 +249,7 @@ describe('Test external auth plugins', function () {
await wait(5000) await wait(5000)
await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401) await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should unregister external-auth-2 and do not login existing Kefka', async function () { it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@ -334,12 +320,7 @@ describe('Test external auth plugins', function () {
}) })
it('Should not login an existing user', async function () { it('Should not login an existing user', async function () {
await createUser({ await server.usersCommand.create({ username: 'existing_user', password: 'super_password' })
url: server.url,
accessToken: server.accessToken,
username: 'existing_user',
password: 'super_password'
})
await loginExternal({ await loginExternal({
server, server,

View File

@ -17,7 +17,6 @@ import {
ImportsCommand, ImportsCommand,
makeRawRequest, makeRawRequest,
PluginsCommand, PluginsCommand,
registerUser,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
@ -335,11 +334,15 @@ describe('Test plugin filter hooks', function () {
}) })
it('Should allow a signup', async function () { it('Should allow a signup', async function () {
await registerUser(servers[0].url, 'john', 'password') await servers[0].usersCommand.register({ username: 'john', password: 'password' })
}) })
it('Should not allow a signup', async function () { it('Should not allow a signup', async function () {
const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) const res = await servers[0].usersCommand.register({
username: 'jma',
password: 'password',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
expect(res.body.error).to.equal('No jma') expect(res.body.error).to.equal('No jma')
}) })

View File

@ -3,18 +3,8 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
cleanupTests, import { UserRole } from '@shared/models'
flushAndRunServer,
getMyUserInformation,
getUsersList,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
updateMyUser,
wait
} from '@shared/extra-utils'
import { User, UserRole } from '@shared/models'
describe('Test id and pass auth plugins', function () { describe('Test id and pass auth plugins', function () {
let server: ServerInfo let server: ServerInfo
@ -55,9 +45,8 @@ describe('Test id and pass auth plugins', function () {
it('Should login Spyro, create the user and use the token', async function () { it('Should login Spyro, create the user and use the token', async function () {
const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' })
const res = await getMyUserInformation(server.url, accessToken) const body = await server.usersCommand.getMyInfo({ token: accessToken })
const body: User = res.body
expect(body.username).to.equal('spyro') expect(body.username).to.equal('spyro')
expect(body.account.displayName).to.equal('Spyro the Dragon') expect(body.account.displayName).to.equal('Spyro the Dragon')
expect(body.role).to.equal(UserRole.USER) expect(body.role).to.equal(UserRole.USER)
@ -71,9 +60,8 @@ describe('Test id and pass auth plugins', function () {
} }
{ {
const res = await getMyUserInformation(server.url, crashAccessToken) const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
const body: User = res.body
expect(body.username).to.equal('crash') expect(body.username).to.equal('crash')
expect(body.account.displayName).to.equal('Crash Bandicoot') expect(body.account.displayName).to.equal('Crash Bandicoot')
expect(body.role).to.equal(UserRole.MODERATOR) expect(body.role).to.equal(UserRole.MODERATOR)
@ -88,9 +76,8 @@ describe('Test id and pass auth plugins', function () {
} }
{ {
const res = await getMyUserInformation(server.url, lagunaAccessToken) const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken })
const body: User = res.body
expect(body.username).to.equal('laguna') expect(body.username).to.equal('laguna')
expect(body.account.displayName).to.equal('laguna') expect(body.account.displayName).to.equal('laguna')
expect(body.role).to.equal(UserRole.USER) expect(body.role).to.equal(UserRole.USER)
@ -103,9 +90,8 @@ describe('Test id and pass auth plugins', function () {
crashAccessToken = resRefresh.body.access_token crashAccessToken = resRefresh.body.access_token
crashRefreshToken = resRefresh.body.refresh_token crashRefreshToken = resRefresh.body.refresh_token
const res = await getMyUserInformation(server.url, crashAccessToken) const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
const user: User = res.body expect(body.username).to.equal('crash')
expect(user.username).to.equal('crash')
} }
{ {
@ -114,16 +100,14 @@ describe('Test id and pass auth plugins', function () {
}) })
it('Should update Crash profile', async function () { it('Should update Crash profile', async function () {
await updateMyUser({ await server.usersCommand.updateMe({
url: server.url, token: crashAccessToken,
accessToken: crashAccessToken,
displayName: 'Beautiful Crash', displayName: 'Beautiful Crash',
description: 'Mutant eastern barred bandicoot' description: 'Mutant eastern barred bandicoot'
}) })
const res = await getMyUserInformation(server.url, crashAccessToken) const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
const body: User = res.body
expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.displayName).to.equal('Beautiful Crash')
expect(body.account.description).to.equal('Mutant eastern barred bandicoot') expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
}) })
@ -135,15 +119,14 @@ describe('Test id and pass auth plugins', function () {
it('Should have logged out Crash', async function () { it('Should have logged out Crash', async function () {
await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') await server.serversCommand.waitUntilLog('On logout for auth 1 - 2')
await getMyUserInformation(server.url, crashAccessToken, 401) await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should login Crash and keep the old existing profile', async function () { it('Should login Crash and keep the old existing profile', async function () {
crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' })
const res = await getMyUserInformation(server.url, crashAccessToken) const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
const body: User = res.body
expect(body.username).to.equal('crash') expect(body.username).to.equal('crash')
expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.displayName).to.equal('Beautiful Crash')
expect(body.account.description).to.equal('Mutant eastern barred bandicoot') expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
@ -155,7 +138,7 @@ describe('Test id and pass auth plugins', function () {
await wait(5000) await wait(5000)
await getMyUserInformation(server.url, lagunaAccessToken, 401) await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should reject an invalid username, email, role or display name', async function () { it('Should reject an invalid username, email, role or display name', async function () {
@ -215,13 +198,11 @@ describe('Test id and pass auth plugins', function () {
}) })
it('Should display plugin auth information in users list', async function () { it('Should display plugin auth information in users list', async function () {
const res = await getUsersList(server.url, server.accessToken) const { data } = await server.usersCommand.list()
const users: User[] = res.body.data const root = data.find(u => u.username === 'root')
const crash = data.find(u => u.username === 'crash')
const root = users.find(u => u.username === 'root') const laguna = data.find(u => u.username === 'laguna')
const crash = users.find(u => u.username === 'crash')
const laguna = users.find(u => u.username === 'laguna')
expect(root.pluginAuth).to.be.null expect(root.pluginAuth).to.be.null
expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one')

View File

@ -3,8 +3,7 @@ import { Netrc } from 'netrc-parser'
import { join } from 'path' import { join } from 'path'
import { createLogger, format, transports } from 'winston' import { createLogger, format, transports } from 'winston'
import { assignCommands, ServerInfo } from '@shared/extra-utils' import { assignCommands, ServerInfo } from '@shared/extra-utils'
import { getMyUserInformation } from '@shared/extra-utils/users/users' import { UserRole } from '@shared/models'
import { User, UserRole } from '@shared/models'
import { VideoPrivacy } from '../../shared/models/videos' import { VideoPrivacy } from '../../shared/models/videos'
import { getAppNumber, isTestInstance, root } from '../helpers/core-utils' import { getAppNumber, isTestInstance, root } from '../helpers/core-utils'
@ -16,16 +15,15 @@ const config = require('application-config')(configName)
const version = require('../../../package.json').version const version = require('../../../package.json').version
async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) { async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) {
const accessToken = await server.loginCommand.getAccessToken(username, password) const token = await server.loginCommand.getAccessToken(username, password)
const resMe = await getMyUserInformation(server.url, accessToken) const me = await server.usersCommand.getMyUserInformation({ token })
const me: User = resMe.body
if (me.role !== UserRole.ADMINISTRATOR) { if (me.role !== UserRole.ADMINISTRATOR) {
console.error('You must be an administrator.') console.error('You must be an administrator.')
process.exit(-1) process.exit(-1)
} }
return accessToken return token
} }
interface Settings { interface Settings {

View File

@ -16,7 +16,7 @@ import { AbusesCommand } from '../moderation'
import { OverviewsCommand } from '../overviews' import { OverviewsCommand } from '../overviews'
import { SearchCommand } from '../search' import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket' import { SocketIOCommand } from '../socket'
import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand } from '../users' import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users'
import { import {
BlacklistCommand, BlacklistCommand,
CaptionsCommand, CaptionsCommand,
@ -127,6 +127,7 @@ interface ServerInfo {
notificationsCommand?: NotificationsCommand notificationsCommand?: NotificationsCommand
serversCommand?: ServersCommand serversCommand?: ServersCommand
loginCommand?: LoginCommand loginCommand?: LoginCommand
usersCommand?: UsersCommand
} }
function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
@ -359,6 +360,7 @@ function assignCommands (server: ServerInfo) {
server.notificationsCommand = new NotificationsCommand(server) server.notificationsCommand = new NotificationsCommand(server)
server.serversCommand = new ServersCommand(server) server.serversCommand = new ServersCommand(server)
server.loginCommand = new LoginCommand(server) server.loginCommand = new LoginCommand(server)
server.usersCommand = new UsersCommand(server)
} }
async function reRunServer (server: ServerInfo, configOverride?: any) { async function reRunServer (server: ServerInfo, configOverride?: any) {

View File

@ -6,4 +6,5 @@ export * from './login-command'
export * from './notifications' export * from './notifications'
export * from './notifications-command' export * from './notifications-command'
export * from './subscriptions-command' export * from './subscriptions-command'
export * from './users-command'
export * from './users' export * from './users'

View File

@ -7,7 +7,7 @@ export class LoginCommand extends AbstractCommand {
login (options: OverrideCommandOptions & { login (options: OverrideCommandOptions & {
client?: { id?: string, secret?: string } client?: { id?: string, secret?: string }
user?: { username: string, password: string } user?: { username: string, password?: string }
} = {}) { } = {}) {
const { client = this.server.client, user = this.server.user } = options const { client = this.server.client, user = this.server.user } = options
const path = '/api/v1/users/token' const path = '/api/v1/users/token'
@ -16,7 +16,7 @@ export class LoginCommand extends AbstractCommand {
client_id: client.id, client_id: client.id,
client_secret: client.secret, client_secret: client.secret,
username: user.username, username: user.username,
password: user.password, password: user.password ?? 'password',
response_type: 'code', response_type: 'code',
grant_type: 'password', grant_type: 'password',
scope: 'upload' scope: 'upload'
@ -33,10 +33,10 @@ export class LoginCommand extends AbstractCommand {
})) }))
} }
getAccessToken (arg1?: { username: string, password: string }): Promise<string> getAccessToken (arg1?: { username: string, password?: string }): Promise<string>
getAccessToken (arg1: string, password: string): Promise<string> getAccessToken (arg1: string, password?: string): Promise<string>
async getAccessToken (arg1?: { username: string, password: string } | string, password?: string) { async getAccessToken (arg1?: { username: string, password?: string } | string, password?: string) {
let user: { username: string, password: string } let user: { username: string, password?: string }
if (!arg1) user = this.server.user if (!arg1) user = this.server.user
else if (typeof arg1 === 'object') user = arg1 else if (typeof arg1 === 'object') user = arg1

View File

@ -8,7 +8,6 @@ import { MockSmtpServer } from '../mock-servers/mock-email'
import { doubleFollow } from '../server/follows' import { doubleFollow } from '../server/follows'
import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
import { setAccessTokensToServers } from './login' import { setAccessTokensToServers } from './login'
import { createUser, getMyUserInformation } from './users'
function getAllNotificationsSettings (): UserNotificationSetting { function getAllNotificationsSettings (): UserNotificationSetting {
return { return {
@ -651,17 +650,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
} }
const user = { const user = { username: 'user_1', password: 'super password' }
username: 'user_1', await servers[0].usersCommand.create({ ...user, videoQuota: 10 * 1000 * 1000 })
password: 'super password'
}
await createUser({
url: servers[0].url,
accessToken: servers[0].accessToken,
username: user.username,
password: user.password,
videoQuota: 10 * 1000 * 1000
})
const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() }) await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
@ -685,8 +675,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
socket.on('new-notification', n => adminNotificationsServer2.push(n)) socket.on('new-notification', n => adminNotificationsServer2.push(n))
} }
const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) const { videoChannels } = await servers[0].usersCommand.getMyInfo()
const channelId = resChannel.body.videoChannels[0].id const channelId = videoChannels[0].id
return { return {
userNotifications, userNotifications,

View File

@ -0,0 +1,414 @@
import { omit, pick } from 'lodash'
import { HttpStatusCode } from '@shared/core-utils'
import {
MyUser,
ResultList,
User,
UserAdminFlag,
UserCreateResult,
UserRole,
UserUpdate,
UserUpdateMe,
UserVideoQuota,
UserVideoRate
} from '@shared/models'
import { ScopedToken } from '@shared/models/users/user-scoped-token'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class UsersCommand extends AbstractCommand {
askResetPassword (options: OverrideCommandOptions & {
email: string
}) {
const { email } = options
const path = '/api/v1/users/ask-reset-password'
return this.postBodyRequest({
...options,
path,
fields: { email },
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
resetPassword (options: OverrideCommandOptions & {
userId: number
verificationString: string
password: string
}) {
const { userId, verificationString, password } = options
const path = '/api/v1/users/' + userId + '/reset-password'
return this.postBodyRequest({
...options,
path,
fields: { password, verificationString },
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
// ---------------------------------------------------------------------------
askSendVerifyEmail (options: OverrideCommandOptions & {
email: string
}) {
const { email } = options
const path = '/api/v1/users/ask-send-verify-email'
return this.postBodyRequest({
...options,
path,
fields: { email },
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
verifyEmail (options: OverrideCommandOptions & {
userId: number
verificationString: string
isPendingEmail?: boolean // default false
}) {
const { userId, verificationString, isPendingEmail = false } = options
const path = '/api/v1/users/' + userId + '/verify-email'
return this.postBodyRequest({
...options,
path,
fields: {
verificationString,
isPendingEmail
},
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
// ---------------------------------------------------------------------------
banUser (options: OverrideCommandOptions & {
userId: number
reason?: string
}) {
const { userId, reason } = options
const path = '/api/v1/users' + '/' + userId + '/block'
return this.postBodyRequest({
...options,
path,
fields: { reason },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
unbanUser (options: OverrideCommandOptions & {
userId: number
}) {
const { userId } = options
const path = '/api/v1/users' + '/' + userId + '/unblock'
return this.postBodyRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
// ---------------------------------------------------------------------------
getMyScopedTokens (options: OverrideCommandOptions = {}) {
const path = '/api/v1/users/scoped-tokens'
return this.getRequestBody<ScopedToken>({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
renewMyScopedTokens (options: OverrideCommandOptions = {}) {
const path = '/api/v1/users/scoped-tokens'
return this.postBodyRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
// ---------------------------------------------------------------------------
create (options: OverrideCommandOptions & {
username: string
password?: string
videoQuota?: number
videoQuotaDaily?: number
role?: UserRole
adminFlags?: UserAdminFlag
}) {
const {
username,
adminFlags,
password = 'password',
videoQuota = 42000000,
videoQuotaDaily = -1,
role = UserRole.USER
} = options
const path = '/api/v1/users'
return unwrapBody<{ user: UserCreateResult }>(this.postBodyRequest({
...options,
path,
fields: {
username,
password,
role,
adminFlags,
email: username + '@example.com',
videoQuota,
videoQuotaDaily
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})).then(res => res.user)
}
async generate (username: string) {
const password = 'password'
const user = await this.create({ username, password })
const token = await this.server.loginCommand.getAccessToken({ username, password })
const me = await this.getMyInfo({ token })
return {
token,
userId: user.id,
userChannelId: me.videoChannels[0].id
}
}
async generateUserAndToken (username: string) {
const password = 'password'
await this.create({ username, password })
return this.server.loginCommand.getAccessToken({ username, password })
}
register (options: OverrideCommandOptions & {
username: string
password?: string
displayName?: string
channel?: {
name: string
displayName: string
}
}) {
const { username, password = 'password', displayName, channel } = options
const path = '/api/v1/users/register'
return this.postBodyRequest({
...options,
path,
fields: {
username,
password,
email: username + '@example.com',
displayName,
channel
},
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
// ---------------------------------------------------------------------------
getMyInfo (options: OverrideCommandOptions = {}) {
const path = '/api/v1/users/me'
return this.getRequestBody<MyUser>({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
getMyQuotaUsed (options: OverrideCommandOptions = {}) {
const path = '/api/v1/users/me/video-quota-used'
return this.getRequestBody<UserVideoQuota>({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
getMyRating (options: OverrideCommandOptions & {
videoId: number | string
}) {
const { videoId } = options
const path = '/api/v1/users/me/videos/' + videoId + '/rating'
return this.getRequestBody<UserVideoRate>({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
deleteMe (options: OverrideCommandOptions = {}) {
const path = '/api/v1/users/me'
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
updateMe (options: OverrideCommandOptions & UserUpdateMe) {
const path = '/api/v1/users/me'
const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
return this.putBodyRequest({
...options,
path,
fields: toSend,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
updateMyAvatar (options: OverrideCommandOptions & {
fixture: string
}) {
const { fixture } = options
const path = '/api/v1/users/me/avatar/pick'
return this.updateImageRequest({
...options,
path,
fixture,
fieldname: 'avatarfile',
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
// ---------------------------------------------------------------------------
get (options: OverrideCommandOptions & {
userId: number
withStats?: boolean // default false
}) {
const { userId, withStats } = options
const path = '/api/v1/users/' + userId
return this.getRequestBody<User>({
...options,
path,
query: { withStats },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
list (options: OverrideCommandOptions & {
start?: number
count?: number
sort?: string
search?: string
blocked?: boolean
} = {}) {
const path = '/api/v1/users'
return this.getRequestBody<ResultList<User>>({
...options,
path,
query: pick(options, [ 'start', 'count', 'sort', 'search', 'blocked' ]),
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
remove (options: OverrideCommandOptions & {
userId: number
}) {
const { userId } = options
const path = '/api/v1/users/' + userId
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
update (options: OverrideCommandOptions & {
userId: number
email?: string
emailVerified?: boolean
videoQuota?: number
videoQuotaDaily?: number
password?: string
adminFlags?: UserAdminFlag
pluginAuth?: string
role?: UserRole
}) {
const path = '/api/v1/users/' + options.userId
const toSend: UserUpdate = {}
if (options.password !== undefined && options.password !== null) toSend.password = options.password
if (options.email !== undefined && options.email !== null) toSend.email = options.email
if (options.emailVerified !== undefined && options.emailVerified !== null) toSend.emailVerified = options.emailVerified
if (options.videoQuota !== undefined && options.videoQuota !== null) toSend.videoQuota = options.videoQuota
if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend.videoQuotaDaily = options.videoQuotaDaily
if (options.role !== undefined && options.role !== null) toSend.role = options.role
if (options.adminFlags !== undefined && options.adminFlags !== null) toSend.adminFlags = options.adminFlags
if (options.pluginAuth !== undefined) toSend.pluginAuth = options.pluginAuth
return this.putBodyRequest({
...options,
path,
fields: toSend,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
}

View File

@ -1,118 +1,8 @@
import { omit } from 'lodash'
import * as request from 'supertest' import * as request from 'supertest'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
import { UserUpdateMe } from '../../models/users'
import { UserAdminFlag } from '../../models/users/user-flag.model'
import { UserRegister } from '../../models/users/user-register.model'
import { UserRole } from '../../models/users/user-role'
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests'
import { ServerInfo } from '../server/servers'
function createUser (parameters: { // FIXME: delete once videos does not use it anymore
url: string function xxxgetMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
accessToken: string
username: string
password: string
videoQuota?: number
videoQuotaDaily?: number
role?: UserRole
adminFlags?: UserAdminFlag
specialStatus?: number
}) {
const {
url,
accessToken,
username,
adminFlags,
password = 'password',
videoQuota = 1000000,
videoQuotaDaily = -1,
role = UserRole.USER,
specialStatus = HttpStatusCode.OK_200
} = parameters
const path = '/api/v1/users'
const body = {
username,
password,
role,
adminFlags,
email: username + '@example.com',
videoQuota,
videoQuotaDaily
}
return request(url)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.send(body)
.expect(specialStatus)
}
async function generateUser (server: ServerInfo, username: string) {
const password = 'my super password'
const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
const token = await server.loginCommand.getAccessToken({ username, password })
const resMe = await getMyUserInformation(server.url, token)
return {
token,
userId: resCreate.body.user.id,
userChannelId: resMe.body.videoChannels[0].id
}
}
async function generateUserAccessToken (server: ServerInfo, username: string) {
const password = 'my super password'
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
return server.loginCommand.getAccessToken({ username, password })
}
function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/users/register'
const body = {
username,
password,
email: username + '@example.com'
}
return request(url)
.post(path)
.set('Accept', 'application/json')
.send(body)
.expect(specialStatus)
}
function registerUserWithChannel (options: {
url: string
user: { username: string, password: string, displayName?: string }
channel: { name: string, displayName: string }
}) {
const path = '/api/v1/users/register'
const body: UserRegister = {
username: options.user.username,
password: options.user.password,
email: options.user.username + '@example.com',
channel: options.channel
}
if (options.user.displayName) {
Object.assign(body, { displayName: options.user.displayName })
}
return makePostBodyRequest({
url: options.url,
path,
fields: body,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
}
function getMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
const path = '/api/v1/users/me' const path = '/api/v1/users/me'
return request(url) return request(url)
@ -123,292 +13,8 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus =
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
} }
function getUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
const path = '/api/v1/users/scoped-tokens'
return makeGetRequest({
url,
path,
token,
statusCodeExpected
})
}
function renewUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
const path = '/api/v1/users/scoped-tokens'
return makePostBodyRequest({
url,
path,
token,
statusCodeExpected
})
}
function deleteMe (url: string, accessToken: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/users/me'
return request(url)
.delete(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(specialStatus)
}
function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
const path = '/api/v1/users/me/video-quota-used'
return request(url)
.get(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(specialStatus)
.expect('Content-Type', /json/)
}
function getUserInformation (url: string, accessToken: string, userId: number, withStats = false) {
const path = '/api/v1/users/' + userId
return request(url)
.get(path)
.query({ withStats })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(HttpStatusCode.OK_200)
.expect('Content-Type', /json/)
}
function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = HttpStatusCode.OK_200) {
const path = '/api/v1/users/me/videos/' + videoId + '/rating'
return request(url)
.get(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(specialStatus)
.expect('Content-Type', /json/)
}
function getUsersList (url: string, accessToken: string) {
const path = '/api/v1/users'
return request(url)
.get(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(HttpStatusCode.OK_200)
.expect('Content-Type', /json/)
}
function getUsersListPaginationAndSort (
url: string,
accessToken: string,
start: number,
count: number,
sort: string,
search?: string,
blocked?: boolean
) {
const path = '/api/v1/users'
const query = {
start,
count,
sort,
search,
blocked
}
return request(url)
.get(path)
.query(query)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(HttpStatusCode.OK_200)
.expect('Content-Type', /json/)
}
function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/users'
return request(url)
.delete(path + '/' + userId)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
}
function blockUser (
url: string,
userId: number | string,
accessToken: string,
expectedStatus = HttpStatusCode.NO_CONTENT_204,
reason?: string
) {
const path = '/api/v1/users'
let body: any
if (reason) body = { reason }
return request(url)
.post(path + '/' + userId + '/block')
.send(body)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
}
function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/users'
return request(url)
.post(path + '/' + userId + '/unblock')
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
}
function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: HttpStatusCode } & UserUpdateMe) {
const path = '/api/v1/users/me'
const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
return makePutBodyRequest({
url: options.url,
path,
token: options.accessToken,
fields: toSend,
statusCodeExpected: options.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
})
}
function updateMyAvatar (options: {
url: string
accessToken: string
fixture: string
}) {
const path = '/api/v1/users/me/avatar/pick'
return updateImageRequest({ ...options, path, fieldname: 'avatarfile' })
}
function updateUser (options: {
url: string
userId: number
accessToken: string
email?: string
emailVerified?: boolean
videoQuota?: number
videoQuotaDaily?: number
password?: string
adminFlags?: UserAdminFlag
pluginAuth?: string
role?: UserRole
}) {
const path = '/api/v1/users/' + options.userId
const toSend = {}
if (options.password !== undefined && options.password !== null) toSend['password'] = options.password
if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
if (options.emailVerified !== undefined && options.emailVerified !== null) toSend['emailVerified'] = options.emailVerified
if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags
if (options.pluginAuth !== undefined) toSend['pluginAuth'] = options.pluginAuth
return makePutBodyRequest({
url: options.url,
path,
token: options.accessToken,
fields: toSend,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
}
function askResetPassword (url: string, email: string) {
const path = '/api/v1/users/ask-reset-password'
return makePostBodyRequest({
url,
path,
fields: { email },
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
}
function resetPassword (
url: string,
userId: number,
verificationString: string,
password: string,
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
) {
const path = '/api/v1/users/' + userId + '/reset-password'
return makePostBodyRequest({
url,
path,
fields: { password, verificationString },
statusCodeExpected
})
}
function askSendVerifyEmail (url: string, email: string) {
const path = '/api/v1/users/ask-send-verify-email'
return makePostBodyRequest({
url,
path,
fields: { email },
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
}
function verifyEmail (
url: string,
userId: number,
verificationString: string,
isPendingEmail = false,
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
) {
const path = '/api/v1/users/' + userId + '/verify-email'
return makePostBodyRequest({
url,
path,
fields: {
verificationString,
isPendingEmail
},
statusCodeExpected
})
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
createUser, xxxgetMyUserInformation
registerUser,
getMyUserInformation,
getMyUserVideoRating,
deleteMe,
registerUserWithChannel,
getMyUserVideoQuotaUsed,
getUsersList,
getUsersListPaginationAndSort,
removeUser,
updateUser,
updateMyUser,
getUserInformation,
blockUser,
unblockUser,
askResetPassword,
resetPassword,
renewUserScopedTokens,
updateMyAvatar,
generateUser,
askSendVerifyEmail,
generateUserAccessToken,
verifyEmail,
getUserScopedTokens
} }

View File

@ -1,13 +1,11 @@
import { User } from '../../models/users/user.model'
import { ServerInfo } from '../server/servers' import { ServerInfo } from '../server/servers'
import { getMyUserInformation } from '../users/users'
function setDefaultVideoChannel (servers: ServerInfo[]) { function setDefaultVideoChannel (servers: ServerInfo[]) {
const tasks: Promise<any>[] = [] const tasks: Promise<any>[] = []
for (const server of servers) { for (const server of servers) {
const p = getMyUserInformation(server.url, server.accessToken) const p = server.usersCommand.getMyInfo()
.then(res => { server.videoChannel = (res.body as User).videoChannels[0] }) .then(user => { server.videoChannel = user.videoChannels[0] })
tasks.push(p) tasks.push(p)
} }

View File

@ -17,7 +17,7 @@ import { buildAbsoluteFixturePath, dateIsValid, testImage, wait, webtorrentAdd }
import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests' import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'
import { waitJobs } from '../server/jobs' import { waitJobs } from '../server/jobs'
import { ServerInfo } from '../server/servers' import { ServerInfo } from '../server/servers'
import { getMyUserInformation } from '../users/users' import { xxxgetMyUserInformation } from '../users'
loadLanguages() loadLanguages()
@ -339,7 +339,7 @@ async function uploadVideo (
let defaultChannelId = '1' let defaultChannelId = '1'
try { try {
const res = await getMyUserInformation(url, accessToken) const res = await xxxgetMyUserInformation(url, accessToken)
defaultChannelId = res.body.videoChannels[0].id defaultChannelId = res.body.videoChannels[0].id
} catch (e) { /* empty */ } } catch (e) { /* empty */ }

View File

@ -1,3 +1,4 @@
export * from './user-create-result.model'
export * from './user-create.model' export * from './user-create.model'
export * from './user-flag.model' export * from './user-flag.model'
export * from './user-login.model' export * from './user-login.model'

View File

@ -0,0 +1,7 @@
export interface UserCreateResult {
id: number
account: {
id: number
}
}