1
0
Fork 0
peertube/server/tests/api/check-params/config.ts

406 lines
9.3 KiB
TypeScript
Raw Normal View History

2020-01-31 10:56:52 -05:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
import { merge, omit } from 'lodash'
import { CustomConfig, HttpStatusCode } from '@shared/models'
import {
cleanupTests,
2021-07-16 03:47:51 -04:00
createSingleServer,
makeDeleteRequest,
makeGetRequest,
makePutBodyRequest,
2021-07-16 03:47:51 -04:00
PeerTubeServer,
2021-07-13 05:05:15 -04:00
setAccessTokensToServers
} from '@shared/server-commands'
describe('Test config API validators', function () {
const path = '/api/v1/config/custom'
2021-07-16 03:47:51 -04:00
let server: PeerTubeServer
let userAccessToken: string
const updateParams: CustomConfig = {
instance: {
name: 'PeerTube updated',
2018-03-15 09:31:08 -04:00
shortDescription: 'my short description',
description: 'my super description',
terms: 'my super terms',
2019-08-23 09:23:27 -04:00
codeOfConduct: 'my super coc',
2019-09-03 03:49:04 -04:00
creationReason: 'my super reason',
2019-08-23 09:23:27 -04:00
moderationInformation: 'my super moderation information',
administrator: 'Kuja',
maintenanceLifetime: 'forever',
businessModel: 'my super business model',
hardwareInformation: '2vCore 3GB RAM',
2019-08-23 09:23:27 -04:00
languages: [ 'en', 'es' ],
categories: [ 1, 2 ],
2019-02-20 09:36:43 -05:00
isNSFW: true,
defaultNSFWPolicy: 'blur',
defaultClientRoute: '/videos/recently-added',
customizations: {
javascript: 'alert("coucou")',
css: 'body { background-color: red; }'
}
},
2019-07-09 05:45:19 -04:00
theme: {
default: 'default'
},
services: {
twitter: {
username: '@MySuperUsername',
whitelisted: true
}
},
client: {
videos: {
miniature: {
preferAuthorDisplayName: false
}
},
menu: {
login: {
redirectOnSingleExternalAuth: false
}
}
},
cache: {
previews: {
size: 2
2018-07-12 13:02:00 -04:00
},
captions: {
size: 3
},
torrents: {
size: 4
}
},
signup: {
enabled: false,
limit: 5,
requiresEmailVerification: false,
minimumAge: 16
},
admin: {
email: 'superadmin1@example.com'
},
2019-01-09 09:14:29 -05:00
contactForm: {
enabled: false
},
user: {
videoQuota: 5242881,
videoQuotaDaily: 318742
},
videoChannels: {
maxPerUser: 20
},
transcoding: {
enabled: true,
2018-12-11 08:52:50 -05:00
allowAdditionalExtensions: true,
2019-05-16 10:55:34 -04:00
allowAudioFiles: true,
concurrency: 1,
threads: 1,
profile: 'vod_profile',
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': true,
'480p': true,
'720p': false,
2019-06-12 11:33:29 -04:00
'1080p': false,
'1440p': false,
2019-06-12 11:33:29 -04:00
'2160p': false
2019-01-29 02:37:25 -05:00
},
alwaysTranscodeOriginalResolution: false,
webtorrent: {
enabled: true
},
2019-01-29 02:37:25 -05:00
hls: {
enabled: false
}
2018-08-03 05:10:31 -04:00
},
live: {
enabled: true,
2020-09-25 10:19:35 -04:00
allowReplay: false,
2022-03-04 07:40:02 -05:00
latencySetting: {
enabled: false
},
2020-12-15 03:23:28 -05:00
maxDuration: 30,
2020-10-28 10:24:40 -04:00
maxInstanceLives: -1,
maxUserLives: 50,
2020-09-25 10:19:35 -04:00
transcoding: {
enabled: true,
threads: 4,
profile: 'live_profile',
resolutions: {
'144p': true,
'240p': true,
'360p': true,
'480p': true,
'720p': true,
'1080p': true,
'1440p': true,
'2160p': true
},
alwaysTranscodeOriginalResolution: false
}
},
2022-03-22 11:58:49 -04:00
videoStudio: {
2022-02-11 04:51:33 -05:00
enabled: true
},
2018-08-03 05:10:31 -04:00
import: {
videos: {
concurrency: 1,
2018-08-03 05:10:31 -04:00
http: {
enabled: false
2018-08-07 04:07:53 -04:00
},
torrent: {
enabled: false
2018-08-03 05:10:31 -04:00
}
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
},
videoChannelSynchronization: {
enabled: false,
maxPerUser: 10
2018-08-03 05:10:31 -04:00
}
},
2021-01-27 11:15:21 -05:00
trending: {
videos: {
algorithms: {
enabled: [ 'hot', 'most-viewed', 'most-liked' ],
2021-01-27 11:15:21 -05:00
default: 'most-viewed'
}
}
},
autoBlacklist: {
videos: {
ofUsers: {
enabled: false
}
}
2019-04-08 08:04:57 -04:00
},
followers: {
instance: {
enabled: false,
manualApproval: true
2019-04-08 08:04:57 -04:00
}
},
followings: {
instance: {
autoFollowBack: {
enabled: true
},
autoFollowIndex: {
enabled: true,
indexUrl: 'https://index.example.com'
}
}
2020-05-28 05:15:38 -04:00
},
broadcastMessage: {
enabled: true,
dismissable: true,
message: 'super message',
level: 'warning'
2020-05-29 10:16:24 -04:00
},
search: {
remoteUri: {
users: true,
anonymous: true
},
searchIndex: {
enabled: true,
url: 'https://search.joinpeertube.org',
disableLocalSearch: true,
isDefaultSearch: true
}
}
}
// ---------------------------------------------------------------
before(async function () {
2018-01-18 12:10:45 -05:00
this.timeout(30000)
2021-07-16 03:47:51 -04:00
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
const user = {
username: 'user1',
password: 'password'
}
2021-07-16 03:04:35 -04:00
await server.users.create({ username: user.username, password: user.password })
userAccessToken = await server.login.getAccessToken(user)
})
describe('When getting the configuration', function () {
it('Should fail without token', async function () {
await makeGetRequest({
url: server.url,
path,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail if the user is not an administrator', async function () {
await makeGetRequest({
url: server.url,
path,
token: userAccessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
})
describe('When updating the configuration', function () {
it('Should fail without token', async function () {
await makePutBodyRequest({
url: server.url,
path,
fields: updateParams,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail if the user is not an administrator', async function () {
await makePutBodyRequest({
url: server.url,
path,
fields: updateParams,
token: userAccessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
it('Should fail if it misses a key', async function () {
const newUpdateParams = omit(updateParams, 'admin.email')
await makePutBodyRequest({
url: server.url,
path,
fields: newUpdateParams,
token: server.accessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should fail with a bad default NSFW policy', async function () {
2021-07-13 03:43:59 -04:00
const newUpdateParams = {
...updateParams,
instance: {
defaultNSFWPolicy: 'hello'
}
2021-07-13 03:43:59 -04:00
}
await makePutBodyRequest({
url: server.url,
path,
fields: newUpdateParams,
token: server.accessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should fail if email disabled and signup requires email verification', async function () {
2019-04-24 09:10:37 -04:00
// opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
2021-07-13 03:43:59 -04:00
const newUpdateParams = {
...updateParams,
signup: {
enabled: true,
limit: 5,
requiresEmailVerification: true
}
2021-07-13 03:43:59 -04:00
}
await makePutBodyRequest({
url: server.url,
path,
fields: newUpdateParams,
token: server.accessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should fail with a disabled webtorrent & hls transcoding', async function () {
2021-07-13 03:43:59 -04:00
const newUpdateParams = {
...updateParams,
transcoding: {
hls: {
enabled: false
},
webtorrent: {
enabled: false
}
}
2021-07-13 03:43:59 -04:00
}
await makePutBodyRequest({
url: server.url,
path,
fields: newUpdateParams,
token: server.accessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
it('Should fail with a disabled http upload & enabled sync', async function () {
const newUpdateParams: CustomConfig = merge({}, updateParams, {
import: {
videos: {
http: { enabled: false }
},
videoChannelSynchronization: { enabled: true }
}
})
await makePutBodyRequest({
url: server.url,
path,
fields: newUpdateParams,
token: server.accessToken,
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should succeed with the correct parameters', async function () {
await makePutBodyRequest({
url: server.url,
path,
fields: updateParams,
token: server.accessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.OK_200
})
})
})
describe('When deleting the configuration', function () {
it('Should fail without token', async function () {
await makeDeleteRequest({
url: server.url,
path,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail if the user is not an administrator', async function () {
await makeDeleteRequest({
url: server.url,
path,
token: userAccessToken,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
})
2019-04-24 09:10:37 -04:00
after(async function () {
await cleanupTests([ server ])
})
})