Verified Commit 6c5065a0 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce server commands

parent 0d8ecb75
......@@ -2,11 +2,10 @@
import 'mocha'
import { expect } from 'chai'
import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs'
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
import { cloneDeep } from 'lodash'
import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/extra-utils'
import { buildSignedActivity } from '../../../helpers/activitypub'
import { buildAbsoluteFixturePath } from '@shared/extra-utils'
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
describe('Test activity pub helpers', function () {
describe('When checking the Linked Signature', function () {
......
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { omit } from 'lodash'
import 'mocha'
import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
import { omit } from 'lodash'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
createUser,
flushAndRunServer,
immutableAssign,
makeDeleteRequest,
makeGetRequest,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
userLogin
} from '../../../../shared/extra-utils'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
} from '@shared/extra-utils'
import { CustomConfig } from '@shared/models'
describe('Test config API validators', function () {
const path = '/api/v1/config/custom'
......@@ -265,11 +263,13 @@ describe('Test config API validators', function () {
})
it('Should fail with a bad default NSFW policy', async function () {
const newUpdateParams = immutableAssign(updateParams, {
const newUpdateParams = {
...updateParams,
instance: {
defaultNSFWPolicy: 'hello'
}
})
}
await makePutBodyRequest({
url: server.url,
......@@ -282,13 +282,15 @@ describe('Test config API validators', function () {
it('Should fail if email disabled and signup requires email verification', async function () {
// opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
const newUpdateParams = immutableAssign(updateParams, {
const newUpdateParams = {
...updateParams,
signup: {
enabled: true,
limit: 5,
requiresEmailVerification: true
}
})
}
await makePutBodyRequest({
url: server.url,
......@@ -300,7 +302,9 @@ describe('Test config API validators', function () {
})
it('Should fail with a disabled webtorrent & hls transcoding', async function () {
const newUpdateParams = immutableAssign(updateParams, {
const newUpdateParams = {
...updateParams,
transcoding: {
hls: {
enabled: false
......@@ -309,7 +313,7 @@ describe('Test config API validators', function () {
enabled: false
}
}
})
}
await makePutBodyRequest({
url: server.url,
......
......@@ -10,7 +10,6 @@ import {
createUser,
flushAndRunServer,
getMyUserInformation,
immutableAssign,
LiveCommand,
makePostBodyRequest,
makeUploadRequest,
......@@ -97,37 +96,37 @@ describe('Test video lives API validator', function () {
})
it('Should fail with a long name', async function () {
const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a bad category', async function () {
const fields = immutableAssign(baseCorrectParams, { category: 125 })
const fields = { ...baseCorrectParams, category: 125 }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a bad licence', async function () {
const fields = immutableAssign(baseCorrectParams, { licence: 125 })
const fields = { ...baseCorrectParams, licence: 125 }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a bad language', async function () {
const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a long description', async function () {
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a long support text', async function () {
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -139,7 +138,7 @@ describe('Test video lives API validator', function () {
})
it('Should fail with a bad channel', async function () {
const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
const fields = { ...baseCorrectParams, channelId: 545454 }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -155,25 +154,25 @@ describe('Test video lives API validator', function () {
const res = await getMyUserInformation(server.url, accessTokenUser)
const customChannelId = res.body.videoChannels[0].id
const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
const fields = { ...baseCorrectParams, channelId: customChannelId }
await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
})
it('Should fail with too many tags', async function () {
const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a tag length too low', async function () {
const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a tag length too big', async function () {
const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -215,7 +214,7 @@ describe('Test video lives API validator', function () {
})
it('Should fail with save replay and permanent live set to true', async function () {
const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true })
const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -253,7 +252,7 @@ describe('Test video lives API validator', function () {
})
it('Should forbid to save replay if not enabled by the admin', async function () {
const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
const fields = { ...baseCorrectParams, saveReplay: true }
await server.configCommand.updateCustomSubConfig({
newConfig: {
......@@ -274,7 +273,7 @@ describe('Test video lives API validator', function () {
})
it('Should allow to save replay if enabled by the admin', async function () {
const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
const fields = { ...baseCorrectParams, saveReplay: true }
await server.configCommand.updateCustomSubConfig({
newConfig: {
......
......@@ -9,7 +9,6 @@ import {
cleanupTests,
createUser,
flushAndRunServer,
immutableAssign,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
......@@ -200,7 +199,7 @@ describe('Test server plugins API validators', function () {
})
it('Should fail with an invalid plugin type', async function () {
const query = immutableAssign(baseQuery, { pluginType: 5 })
const query = { ...baseQuery, pluginType: 5 }
await makeGetRequest({
url: server.url,
......@@ -211,7 +210,7 @@ describe('Test server plugins API validators', function () {
})
it('Should fail with an invalid current peertube engine', async function () {
const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' })
const query = { ...baseQuery, currentPeerTubeEngine: '1.0' }
await makeGetRequest({
url: server.url,
......@@ -271,7 +270,7 @@ describe('Test server plugins API validators', function () {
})
it('Should fail with an invalid plugin type', async function () {
const query = immutableAssign(baseQuery, { pluginType: 5 })
const query = { ...baseQuery, pluginType: 5 }
await makeGetRequest({
url: server.url,
......
......@@ -8,7 +8,6 @@ import {
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
immutableAssign,
makeGetRequest,
ServerInfo,
setAccessTokensToServers
......@@ -63,78 +62,78 @@ describe('Test videos API validator', function () {
})
it('Should fail with an invalid category', async function () {
const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
const customQuery2 = { ...query, categoryOneOf: 'a' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with a valid category', async function () {
const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
const customQuery2 = { ...query, categoryOneOf: 1 }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
})
it('Should fail with an invalid licence', async function () {
const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
const customQuery2 = { ...query, licenceOneOf: 'a' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with a valid licence', async function () {
const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
const customQuery2 = { ...query, licenceOneOf: 1 }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
})
it('Should succeed with a valid language', async function () {
const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
const customQuery2 = { ...query, languageOneOf: 'fr' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
})
it('Should succeed with valid tags', async function () {
const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
const customQuery2 = { ...query, tagsOneOf: 'tag1' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
const customQuery4 = { ...query, tagsAllOf: 'tag1' }
await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
})
it('Should fail with invalid durations', async function () {
const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
const customQuery1 = { ...query, durationMin: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
const customQuery2 = { ...query, durationMax: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with invalid dates', async function () {
const customQuery1 = immutableAssign(query, { startDate: 'hello' })
const customQuery1 = { ...query, startDate: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery2 = immutableAssign(query, { endDate: 'hello' })
const customQuery2 = { ...query, endDate: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
})
})
......@@ -201,41 +200,41 @@ describe('Test videos API validator', function () {
for (const path of paths) {
{
const customQuery = immutableAssign(query, { searchTarget: 'hello' })
const customQuery = { ...query, searchTarget: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
}
{
const customQuery = immutableAssign(query, { searchTarget: undefined })
const customQuery = { ...query, searchTarget: undefined }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
}
{
const customQuery = immutableAssign(query, { searchTarget: 'local' })
const customQuery = { ...query, searchTarget: 'local' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
}
{
const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
const customQuery = { ...query, searchTarget: 'search-index' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
}
await updateSearchIndex(server, true, true)
{
const customQuery = immutableAssign(query, { searchTarget: 'local' })
const customQuery = { ...query, searchTarget: 'local' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
}
{
const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
const customQuery = { ...query, searchTarget: 'search-index' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
}
await updateSearchIndex(server, true, false)
{
const customQuery = immutableAssign(query, { searchTarget: 'local' })
const customQuery = { ...query, searchTarget: 'local' }
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
}
......
......@@ -2,25 +2,21 @@
import 'mocha'
import { io } from 'socket.io-client'
import { HttpStatusCode } from '@shared/core-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
immutableAssign,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
wait
} from '../../../../shared/extra-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'
import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
} from '@shared/extra-utils'
import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models'
describe('Test user notifications API validators', function () {
let server: ServerInfo
......@@ -193,7 +189,7 @@ describe('Test user notifications API validators', function () {
it('Should fail with incorrect field values', async function () {
{
const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 })
const fields = { ...correctFields, newCommentOnMyVideo: 15 }
await makePutBodyRequest({
url: server.url,
......@@ -205,7 +201,7 @@ describe('Test user notifications API validators', function () {
}
{
const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' })
const fields = { ...correctFields, newCommentOnMyVideo: 'toto' }
await makePutBodyRequest({
url: server.url,
......
......@@ -15,7 +15,6 @@ import {
getMyUserVideoRating,
getUserScopedTokens,
getUsersList,
immutableAssign,
killallServers,
makeGetRequest,
makePostBodyRequest,
......@@ -181,25 +180,25 @@ describe('Test users API validators', function () {
}
it('Should fail with a too small username', async function () {
const fields = immutableAssign(baseCorrectParams, { username: '' })
const fields = { ...baseCorrectParams, username: '' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a too long username', async function () {
const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a not lowercase username', async function () {
const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
const fields = { ...baseCorrectParams, username: 'Toto' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with an incorrect username', async function () {
const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
const fields = { ...baseCorrectParams, username: 'my username' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -211,25 +210,25 @@ describe('Test users API validators', function () {
})
it('Should fail with an invalid email', async function () {
const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
const fields = { ...baseCorrectParams, email: 'test_example.com' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a too small password', async function () {
const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
const fields = { ...baseCorrectParams, password: 'bla' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with a too long password', async function () {
const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with empty password and no smtp configured', async function () {
const fields = immutableAssign(baseCorrectParams, { password: '' })
const fields = { ...baseCorrectParams, password: '' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -239,19 +238,23 @@ describe('Test users API validators', function () {
await killallServers([ server ])
const config = immutableAssign(overrideConfig, {
const config = {
...overrideConfig,
smtp: {
hostname: 'localhost',
port: emailPort
}
})
}
await reRunServer(server, config)
const fields = immutableAssign(baseCorrectParams, {
const fields = {
...baseCorrectParams,
password: '',
username: 'create_password',
email: 'create_password@example.com'
})
}
await makePostBodyRequest({
url: server.url,
......@@ -263,7 +266,7 @@ describe('Test users API validators', function () {
})
it('Should fail with invalid admin flags', async function () {
const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
const fields = { ...baseCorrectParams, adminFlags: 'toto' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
......@@ -279,7 +282,7 @@ describe('Test users API validators', function () {
})
it('Should fail if we add a user with the same username', async function () {
const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
const fields = { ...baseCorrectParams, username: 'user1' }
await makePostBodyRequest({
url: server.url,
......@@ -291,7 +294,7 @@ describe('Test users API validators', function () {
})
it('Should fail if we add a user with the same email', async function () {
const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
const fields = { ...baseCorrectParams, email: 'user1@example.com' }
await makePostBodyRequest({