From 5d08a6a74e83f2e4dfe2f3ba7f5a39371e1bc89e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Aug 2018 11:10:31 +0200 Subject: Add import http enabled configuration --- server/tests/api/check-params/config.ts | 7 + server/tests/api/check-params/index.ts | 1 + server/tests/api/check-params/video-imports.ts | 246 +++++++++++++++++++++++++ server/tests/api/server/config.ts | 9 + 4 files changed, 263 insertions(+) create mode 100644 server/tests/api/check-params/video-imports.ts (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 03855237f..2742e26de 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -60,6 +60,13 @@ describe('Test config API validators', function () { '720p': false, '1080p': false } + }, + import: { + videos: { + http: { + enabled: false + } + } } } diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 820dde889..03fdd5c4e 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts @@ -10,4 +10,5 @@ import './video-captions' import './video-channels' import './video-comments' import './videos' +import './video-imports' import './search' diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts new file mode 100644 index 000000000..7f58efb74 --- /dev/null +++ b/server/tests/api/check-params/video-imports.ts @@ -0,0 +1,246 @@ +/* tslint:disable:no-unused-expression */ + +import { omit } from 'lodash' +import 'mocha' +import { join } from 'path' +import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +import { + createUser, + flushTests, + getMyUserInformation, + immutableAssign, + killallServers, + makeGetRequest, + makePostBodyRequest, + makeUploadRequest, + runServer, + ServerInfo, + setAccessTokensToServers, + userLogin +} from '../../utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' + +describe('Test video imports API validator', function () { + const path = '/api/v1/videos/imports' + let server: ServerInfo + let userAccessToken = '' + let accountName: string + let channelId: number + let channelUUID: string + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(30000) + + await flushTests() + + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const username = 'user1' + const password = 'my super password' + await createUser(server.url, server.accessToken, username, password) + userAccessToken = await userLogin(server, { username, password }) + + { + const res = await getMyUserInformation(server.url, server.accessToken) + channelId = res.body.videoChannels[ 0 ].id + channelUUID = res.body.videoChannels[ 0 ].uuid + accountName = res.body.account.name + '@' + res.body.account.host + } + }) + + describe('When listing my video imports', function () { + const myPath = '/api/v1/users/me/videos/imports' + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, myPath, server.accessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, myPath, server.accessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, myPath, server.accessToken) + }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) + }) + }) + + describe('When adding a video import', function () { + let baseCorrectParams + + before(function () { + baseCorrectParams = { + targetUrl: 'https://youtu.be/msX3jv1XdvM', + name: 'my super name', + category: 5, + licence: 1, + language: 'pt', + nsfw: false, + commentsEnabled: true, + waitTranscoding: true, + description: 'my super description', + support: 'my super support text', + tags: [ 'tag1', 'tag2' ], + privacy: VideoPrivacy.PUBLIC, + channelId: channelId + } + }) + + it('Should fail with nothing', async function () { + const fields = {} + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with a long name', async function () { + const fields = immutableAssign(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 }) + + 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 }) + + 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) }) + + 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) }) + + 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(150) }) + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail without a channel', async function () { + const fields = omit(baseCorrectParams, 'channelId') + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with a bad channel', async function () { + const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with another user channel', async function () { + const user = { + username: 'fake', + password: 'fake_password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + + const accessTokenUser = await userLogin(server, user) + const res = await getMyUserInformation(server.url, accessTokenUser) + const customChannelId = res.body.videoChannels[0].id + + const fields = immutableAssign(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' ] }) + + 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' ] }) + + 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' ] }) + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail with an incorrect thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + + await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a big thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + } + + await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) + }) + + it('Should fail with an incorrect preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + + await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a big preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + } + + await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) + }) + + it('Should succeed with the correct parameters', async function () { + this.timeout(10000) + + const fields = baseCorrectParams + + { + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: 200 + }) + } + }) + + it('Should forbid importing') + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 1782a8623..b65061a5d 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -44,6 +44,7 @@ function checkInitialConfig (data: CustomConfig) { expect(data.transcoding.resolutions['480p']).to.be.true expect(data.transcoding.resolutions['720p']).to.be.true expect(data.transcoding.resolutions['1080p']).to.be.true + expect(data.import.videos.http.enabled).to.be.true } function checkUpdatedConfig (data: CustomConfig) { @@ -70,6 +71,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.transcoding.resolutions['480p']).to.be.true expect(data.transcoding.resolutions['720p']).to.be.false expect(data.transcoding.resolutions['1080p']).to.be.false + expect(data.import.videos.http.enabled).to.be.false } describe('Test config', function () { @@ -160,6 +162,13 @@ describe('Test config', function () { '720p': false, '1080p': false } + }, + import: { + videos: { + http: { + enabled: false + } + } } } await updateCustomConfig(server.url, server.accessToken, newCustomConfig) -- cgit v1.2.3