From 5abb9fbbd12e7097e348d6a38622d364b1fa47ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jan 2019 15:39:51 +0100 Subject: Add ability to unfederate a local video (on blacklist) --- shared/utils/server/servers.ts | 4 ++++ shared/utils/videos/video-blacklist.ts | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'shared/utils') diff --git a/shared/utils/server/servers.ts b/shared/utils/server/servers.ts index 568385a41..1e9c83c72 100644 --- a/shared/utils/server/servers.ts +++ b/shared/utils/server/servers.ts @@ -145,8 +145,12 @@ function runServer (serverNumber: number, configOverride?: Object, args = []) { if (dontContinue === true) return server.app.stdout.removeListener('data', onStdout) + + process.on('exit', () => process.kill(server.app.pid)) + res(server) }) + }) } diff --git a/shared/utils/videos/video-blacklist.ts b/shared/utils/videos/video-blacklist.ts index 2c176fde0..f2ae0ed26 100644 --- a/shared/utils/videos/video-blacklist.ts +++ b/shared/utils/videos/video-blacklist.ts @@ -1,11 +1,18 @@ import * as request from 'supertest' -function addVideoToBlacklist (url: string, token: string, videoId: number | string, reason?: string, specialStatus = 204) { +function addVideoToBlacklist ( + url: string, + token: string, + videoId: number | string, + reason?: string, + unfederate?: boolean, + specialStatus = 204 +) { const path = '/api/v1/videos/' + videoId + '/blacklist' return request(url) .post(path) - .send({ reason }) + .send({ reason, unfederate }) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + token) .expect(specialStatus) -- cgit v1.2.3 From dc094603cd9eccce3243a6b6ccec3416491f59d2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 17 Jan 2019 11:23:40 +0100 Subject: Fix tests --- shared/utils/server/servers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'shared/utils') diff --git a/shared/utils/server/servers.ts b/shared/utils/server/servers.ts index 1e9c83c72..cb57e0a69 100644 --- a/shared/utils/server/servers.ts +++ b/shared/utils/server/servers.ts @@ -146,7 +146,11 @@ function runServer (serverNumber: number, configOverride?: Object, args = []) { server.app.stdout.removeListener('data', onStdout) - process.on('exit', () => process.kill(server.app.pid)) + process.on('exit', () => { + try { + process.kill(server.app.pid) + } catch { /* empty */ } + }) res(server) }) -- cgit v1.2.3 From 38967f7b73cec6f6198c72d62f8d64bb88e6951c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 21 Jan 2019 13:52:46 +0100 Subject: Add server host in notification account field --- shared/utils/users/user-notifications.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'shared/utils') diff --git a/shared/utils/users/user-notifications.ts b/shared/utils/users/user-notifications.ts index bcbe29fc7..b85d5d2f1 100644 --- a/shared/utils/users/user-notifications.ts +++ b/shared/utils/users/user-notifications.ts @@ -146,6 +146,7 @@ function checkVideo (video: any, videoName?: string, videoUUID?: string) { function checkActor (actor: any) { expect(actor.displayName).to.be.a('string') expect(actor.displayName).to.not.be.empty + expect(actor.host).to.not.be.undefined } function checkComment (comment: any, commentId: number, threadId: number) { -- cgit v1.2.3 From ebff55d8d6747d0627f135ab668f43e0d6125a37 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 21 Jan 2019 15:58:07 +0100 Subject: Fix tests --- shared/utils/users/user-notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/utils') diff --git a/shared/utils/users/user-notifications.ts b/shared/utils/users/user-notifications.ts index b85d5d2f1..c8ed7df30 100644 --- a/shared/utils/users/user-notifications.ts +++ b/shared/utils/users/user-notifications.ts @@ -274,8 +274,8 @@ async function checkNewActorFollow ( checkActor(notification.actorFollow.follower) expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName) expect(notification.actorFollow.follower.name).to.equal(followerName) + expect(notification.actorFollow.follower.host).to.not.be.undefined - checkActor(notification.actorFollow.following) expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName) expect(notification.actorFollow.following.type).to.equal(followType) } else { -- cgit v1.2.3 From 092092969633bbcf6d4891a083ea497a7d5c3154 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 29 Jan 2019 08:37:25 +0100 Subject: Add hls support on server --- shared/utils/index.ts | 2 ++ shared/utils/requests/requests.ts | 13 ++++++++++--- shared/utils/server/config.ts | 3 +++ shared/utils/server/servers.ts | 7 ++++++- shared/utils/videos/video-playlists.ts | 21 +++++++++++++++++++++ shared/utils/videos/videos.ts | 13 +++++++++++-- 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 shared/utils/videos/video-playlists.ts (limited to 'shared/utils') diff --git a/shared/utils/index.ts b/shared/utils/index.ts index e08bbfd2a..156901372 100644 --- a/shared/utils/index.ts +++ b/shared/utils/index.ts @@ -17,6 +17,8 @@ export * from './users/users' export * from './videos/video-abuses' export * from './videos/video-blacklist' export * from './videos/video-channels' +export * from './videos/video-comments' +export * from './videos/video-playlists' export * from './videos/videos' export * from './videos/video-change-ownership' export * from './feeds/feeds' diff --git a/shared/utils/requests/requests.ts b/shared/utils/requests/requests.ts index 77e9f6164..fc687c701 100644 --- a/shared/utils/requests/requests.ts +++ b/shared/utils/requests/requests.ts @@ -1,10 +1,17 @@ import * as request from 'supertest' import { buildAbsoluteFixturePath, root } from '../miscs/miscs' import { isAbsolute, join } from 'path' +import { parse } from 'url' + +function makeRawRequest (url: string, statusCodeExpected?: number) { + const { host, protocol, pathname } = parse(url) + + return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected }) +} function makeGetRequest (options: { url: string, - path: string, + path?: string, query?: any, token?: string, statusCodeExpected?: number, @@ -13,8 +20,7 @@ function makeGetRequest (options: { if (!options.statusCodeExpected) options.statusCodeExpected = 400 if (options.contentType === undefined) options.contentType = 'application/json' - const req = request(options.url) - .get(options.path) + const req = request(options.url).get(options.path) if (options.contentType) req.set('Accept', options.contentType) if (options.token) req.set('Authorization', 'Bearer ' + options.token) @@ -164,5 +170,6 @@ export { makePostBodyRequest, makePutBodyRequest, makeDeleteRequest, + makeRawRequest, updateAvatarRequest } diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts index 0c5512bab..29c24cff9 100644 --- a/shared/utils/server/config.ts +++ b/shared/utils/server/config.ts @@ -97,6 +97,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { '480p': true, '720p': false, '1080p': false + }, + hls: { + enabled: false } }, import: { diff --git a/shared/utils/server/servers.ts b/shared/utils/server/servers.ts index cb57e0a69..bde7dd5c2 100644 --- a/shared/utils/server/servers.ts +++ b/shared/utils/server/servers.ts @@ -166,9 +166,13 @@ async function reRunServer (server: ServerInfo, configOverride?: any) { } async function checkTmpIsEmpty (server: ServerInfo) { + return checkDirectoryIsEmpty(server, 'tmp') +} + +async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { const testDirectory = 'test' + server.serverNumber - const directoryPath = join(root(), testDirectory, 'tmp') + const directoryPath = join(root(), testDirectory, directory) const directoryExists = existsSync(directoryPath) expect(directoryExists).to.be.true @@ -199,6 +203,7 @@ async function waitUntilLog (server: ServerInfo, str: string, count = 1) { // --------------------------------------------------------------------------- export { + checkDirectoryIsEmpty, checkTmpIsEmpty, ServerInfo, flushAndRunMultipleServers, diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts new file mode 100644 index 000000000..9a0710ca6 --- /dev/null +++ b/shared/utils/videos/video-playlists.ts @@ -0,0 +1,21 @@ +import { makeRawRequest } from '../requests/requests' + +function getPlaylist (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +function getSegment (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +function getSegmentSha256 (url: string, statusCodeExpected = 200) { + return makeRawRequest(url, statusCodeExpected) +} + +// --------------------------------------------------------------------------- + +export { + getPlaylist, + getSegment, + getSegmentSha256 +} diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts index 0cf6e7c4f..b5b33e038 100644 --- a/shared/utils/videos/videos.ts +++ b/shared/utils/videos/videos.ts @@ -271,7 +271,16 @@ function removeVideo (url: string, token: string, id: number | string, expectedS async function checkVideoFilesWereRemoved ( videoUUID: string, serverNumber: number, - directories = [ 'redundancy', 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ] + directories = [ + 'redundancy', + 'videos', + 'thumbnails', + 'torrents', + 'previews', + 'captions', + join('playlists', 'hls'), + join('redundancy', 'hls') + ] ) { const testDirectory = 'test' + serverNumber @@ -279,7 +288,7 @@ async function checkVideoFilesWereRemoved ( const directoryPath = join(root(), testDirectory, directory) const directoryExists = existsSync(directoryPath) - expect(directoryExists).to.be.true + if (!directoryExists) continue const files = await readdir(directoryPath) for (const file of files) { -- cgit v1.2.3 From 4c280004ce62bf11ddb091854c28f1e1d54a54d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Feb 2019 15:08:19 +0100 Subject: Use a single file instead of segments for HLS --- shared/utils/requests/requests.ts | 8 +++++--- shared/utils/videos/video-playlists.ts | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'shared/utils') diff --git a/shared/utils/requests/requests.ts b/shared/utils/requests/requests.ts index fc687c701..6b59e24fc 100644 --- a/shared/utils/requests/requests.ts +++ b/shared/utils/requests/requests.ts @@ -3,10 +3,10 @@ import { buildAbsoluteFixturePath, root } from '../miscs/miscs' import { isAbsolute, join } from 'path' import { parse } from 'url' -function makeRawRequest (url: string, statusCodeExpected?: number) { +function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) { const { host, protocol, pathname } = parse(url) - return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected }) + return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) } function makeGetRequest (options: { @@ -15,7 +15,8 @@ function makeGetRequest (options: { query?: any, token?: string, statusCodeExpected?: number, - contentType?: string + contentType?: string, + range?: string }) { if (!options.statusCodeExpected) options.statusCodeExpected = 400 if (options.contentType === undefined) options.contentType = 'application/json' @@ -25,6 +26,7 @@ function makeGetRequest (options: { if (options.contentType) req.set('Accept', options.contentType) if (options.token) req.set('Authorization', 'Bearer ' + options.token) if (options.query) req.query(options.query) + if (options.range) req.set('Range', options.range) return req.expect(options.statusCodeExpected) } diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts index 9a0710ca6..eb25011cb 100644 --- a/shared/utils/videos/video-playlists.ts +++ b/shared/utils/videos/video-playlists.ts @@ -1,21 +1,51 @@ import { makeRawRequest } from '../requests/requests' +import { sha256 } from '../../../server/helpers/core-utils' +import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' +import { expect } from 'chai' function getPlaylist (url: string, statusCodeExpected = 200) { return makeRawRequest(url, statusCodeExpected) } -function getSegment (url: string, statusCodeExpected = 200) { - return makeRawRequest(url, statusCodeExpected) +function getSegment (url: string, statusCodeExpected = 200, range?: string) { + return makeRawRequest(url, statusCodeExpected, range) } function getSegmentSha256 (url: string, statusCodeExpected = 200) { return makeRawRequest(url, statusCodeExpected) } +async function checkSegmentHash ( + baseUrlPlaylist: string, + baseUrlSegment: string, + videoUUID: string, + resolution: number, + hlsPlaylist: VideoStreamingPlaylist +) { + const res = await getPlaylist(`${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8`) + const playlist = res.text + + const videoName = `${videoUUID}-${resolution}-fragmented.mp4` + + const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) + + const length = parseInt(matches[1], 10) + const offset = parseInt(matches[2], 10) + const range = `${offset}-${offset + length - 1}` + + const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) + + const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) + + const sha256Server = resSha.body[ videoName ][range] + expect(sha256(res2.body)).to.equal(sha256Server) +} + // --------------------------------------------------------------------------- export { getPlaylist, getSegment, - getSegmentSha256 + getSegmentSha256, + checkSegmentHash } -- cgit v1.2.3 From b426edd4854adc6e65844d8c54b8998e792b5778 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 11 Feb 2019 09:30:29 +0100 Subject: Cleanup reset user password by admin And add some tests --- shared/utils/users/users.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'shared/utils') diff --git a/shared/utils/users/users.ts b/shared/utils/users/users.ts index 61a7e3757..7191b263e 100644 --- a/shared/utils/users/users.ts +++ b/shared/utils/users/users.ts @@ -213,11 +213,13 @@ function updateUser (options: { emailVerified?: boolean, videoQuota?: number, videoQuotaDaily?: number, + password?: 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 -- cgit v1.2.3