Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Merge branch 'move-utils-to-shared' of https://github.com/buoyantair/PeerTube into buoyantair-move-utils-to-shared

Chocobozzz2a8c5d0af13f
diff --cc server/lib/activitypub/process/process-create.ts
index cd7ea01aa0,9a72cb899b..df05ee452d
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@@ -12,8 -12,9 +12,7 @@@ import { getOrCreateVideoAndAccountAndC
import { forwardVideoRelatedActivity } from '../send/utils'
import { Redis } from '../../redis'
import { createOrUpdateCacheFile } from '../cache-file'
-import { immutableAssign } from '../../../../shared/utils'
import { getVideoDislikeActivityPubUrl } from '../url'
--import { VideoModel } from '../../../models/video/video'
async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
const activityObject = activity.object
diff --cc server/tests/api/activitypub/client.ts
index ea0682634f,d45232c8d0..6d90d86437
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@@ -8,11 -6,12 +8,11 @@@ import
flushTests,
killallServers,
makeActivityPubGetRequest,
-- runServer,
ServerInfo,
- setAccessTokensToServers, uploadVideo
- } from '../../utils'
- setAccessTokensToServers
++ setAccessTokensToServers,
++ uploadVideo
+ } from '../../../../shared/utils'
-
const expect = chai.expect
describe('Test activitypub', function () {
diff --cc server/tests/api/activitypub/fetch.ts
index a42c606c6c,e84eb18bb3..03609c1a97
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@@ -11,12 -11,12 +11,13 @@@ import
killallServers,
ServerInfo,
setAccessTokensToServers,
++ setActorField,
++ setVideoField,
uploadVideo,
-- userLogin
- } from '../../utils'
++ userLogin,
++ waitJobs
+ } from '../../../../shared/utils'
import * as chai from 'chai'
--import { setActorField, setVideoField } from '../../utils/miscs/sql'
- import { waitJobs } from '../../utils/server/jobs'
-import { waitJobs } from '../../../../shared/utils/server/jobs'
import { Video } from '../../../../shared/models/videos'
const expect = chai.expect
diff --cc server/tests/api/activitypub/helpers.ts
index 51256a9222,4c42f3d67e..ac6e755c36
--- a/server/tests/api/activitypub/helpers.ts
+++ b/server/tests/api/activitypub/helpers.ts
@@@ -2,7 -2,7 +2,7 @@@
import 'mocha'
import { expect } from 'chai'
- import { buildRequestStub } from '../../utils'
-import { buildRequestStub } from '../../utils/miscs/stubs'
++import { buildRequestStub } from '../../../../shared/utils/miscs/stubs'
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
import { cloneDeep } from 'lodash'
import { buildSignedActivity } from '../../../helpers/activitypub'
diff --cc server/tests/api/activitypub/refresher.ts
index 67e04f79ea,0000000000..332ea7ed14
mode 100644,000000..100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@@ -1,84 -1,0 +1,93 @@@
+/* tslint:disable:no-unused-expression */
+
+import 'mocha'
- import { doubleFollow, getVideo, reRunServer } from '../../utils'
- import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../utils/index'
- import { waitJobs } from '../../utils/server/jobs'
- import { setVideoField } from '../../utils/miscs/sql'
++import {
++ doubleFollow,
++ flushAndRunMultipleServers,
++ getVideo,
++ killallServers,
++ reRunServer,
++ ServerInfo,
++ setAccessTokensToServers,
++ uploadVideo,
++ wait,
++ setVideoField,
++ waitJobs
++} from '../../../../shared/utils'
+
+describe('Test AP refresher', function () {
+ let servers: ServerInfo[] = []
+ let videoUUID1: string
+ let videoUUID2: string
+ let videoUUID3: string
+
+ before(async function () {
+ this.timeout(30000)
+
+ servers = await flushAndRunMultipleServers(2)
+
+ // Get the access tokens
+ await setAccessTokensToServers(servers)
+
+ {
+ const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
+ videoUUID1 = res.body.video.uuid
+ }
+
+ {
+ const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
+ videoUUID2 = res.body.video.uuid
+ }
+
+ {
+ const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video3' })
+ videoUUID3 = res.body.video.uuid
+ }
+
+ await doubleFollow(servers[0], servers[1])
+ })
+
+ it('Should remove a deleted remote video', async function () {
+ this.timeout(60000)
+
+ await wait(10000)
+
+ // Change UUID so the remote server returns a 404
+ await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
+
+ await getVideo(servers[0].url, videoUUID1)
+ await getVideo(servers[0].url, videoUUID2)
+
+ await waitJobs(servers)
+
+ await getVideo(servers[0].url, videoUUID1, 404)
+ await getVideo(servers[0].url, videoUUID2, 200)
+ })
+
+ it('Should not update a remote video if the remote instance is down', async function () {
+ this.timeout(60000)
+
+ killallServers([ servers[1] ])
+
+ await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
+
+ // Video will need a refresh
+ await wait(10000)
+
+ await getVideo(servers[0].url, videoUUID3)
+ // The refresh should fail
+ await waitJobs([ servers[0] ])
+
+ await reRunServer(servers[1])
+
+ // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
+ await getVideo(servers[0].url, videoUUID3)
+ await waitJobs(servers)
+
+ await getVideo(servers[0].url, videoUUID3, 200)
+ })
+
+ after(async function () {
+ killallServers(servers)
+ })
+})
diff --cc server/tests/api/activitypub/security.ts
index 7349749f1f,b71a61c8c0..342ae0fa13
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@@ -2,13 -2,18 +2,19 @@@
import 'mocha'
- import { flushAndRunMultipleServers, flushTests, killallServers, ServerInfo } from '../../utils'
+ import {
+ flushAndRunMultipleServers,
+ flushTests,
+ killallServers,
- ServerInfo
++ makeFollowRequest,
++ makePOSTAPRequest,
++ ServerInfo,
++ setActorField
+ } from '../../../../shared/utils'
import { HTTP_SIGNATURE } from '../../../initializers'
import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
import * as chai from 'chai'
--import { setActorField } from '../../utils/miscs/sql'
import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub'
--import { makeFollowRequest, makePOSTAPRequest } from '../../utils/requests/activitypub'
const expect = chai.expect
diff --cc server/tests/misc-endpoints.ts
index 4de47d6930,f948fdfd04..5f82719dac
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@@ -2,18 -2,7 +2,18 @@@
import 'mocha'
import * as chai from 'chai'
-import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo } from '../../shared/utils'
+import {
+ addVideoChannel,
+ createUser,
+ flushTests,
+ killallServers,
+ makeGetRequest,
+ runServer,
+ ServerInfo,
+ setAccessTokensToServers,
+ uploadVideo
- } from './utils'
++} from '../../shared/utils'
+import { VideoPrivacy } from '../../shared/models/videos'
const expect = chai.expect
diff --cc shared/utils/index.ts
index 8349631c96,897389824d..e08bbfd2a9
--- a/shared/utils/index.ts
+++ b/shared/utils/index.ts
@@@ -2,11 -2,10 +2,15 @@@ export * from './server/activitypub
export * from './cli/cli'
export * from './server/clients'
export * from './server/config'
++export * from './server/jobs'
export * from './users/login'
export * from './miscs/miscs'
+export * from './miscs/stubs'
++export * from './miscs/sql'
export * from './server/follows'
++export * from './requests/activitypub'
export * from './requests/requests'
++export * from './requests/check-api-params'
export * from './server/servers'
export * from './videos/services'
export * from './users/users'
diff --cc shared/utils/miscs/miscs.ts
index 589daa420d,589daa420d..91a93b631f
--- a/shared/utils/miscs/miscs.ts
+++ b/shared/utils/miscs/miscs.ts
@@@ -33,8 -33,8 +33,8 @@@ function webtorrentAdd (torrent: string
}
function root () {
-- // We are in server/tests/utils/miscs
-- return join(__dirname, '..', '..', '..', '..')
++ // We are in /shared/utils/miscs
++ return join(__dirname, '..', '..', '..')
}
async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
@@@ -44,7 -44,7 +44,7 @@@
const body = res.body
-- const data = await readFile(join(__dirname, '..', '..', 'fixtures', imageName + extension))
++ const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))
const minLength = body.length - ((20 * body.length) / 100)
const maxLength = body.length + ((20 * body.length) / 100)
@@@ -59,7 -59,7 +59,7 @@@ function buildAbsoluteFixturePath (path
if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path)
-- return join(__dirname, '..', '..', 'fixtures', path)
++ return join(root(), 'server', 'tests', 'fixtures', path)
}
async function generateHighBitrateVideo () {
diff --cc shared/utils/requests/activitypub.ts
index 96fee60a87,96fee60a87..e2348ace0d
--- a/shared/utils/requests/activitypub.ts
+++ b/shared/utils/requests/activitypub.ts
@@@ -1,7 -1,7 +1,7 @@@
--import { doRequest } from '../../../helpers/requests'
--import { HTTP_SIGNATURE } from '../../../initializers'
--import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
--import { activityPubContextify } from '../../../helpers/activitypub'
++import { doRequest } from '../../../server/helpers/requests'
++import { HTTP_SIGNATURE } from '../../../server/initializers'
++import { buildGlobalHeaders } from '../../../server/lib/job-queue/handlers/utils/activitypub-http-utils'
++import { activityPubContextify } from '../../../server/helpers/activitypub'
function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
const options = {
diff --cc shared/utils/requests/requests.ts
index 5796540f7c,5796540f7c..77e9f61645
--- a/shared/utils/requests/requests.ts
+++ b/shared/utils/requests/requests.ts
@@@ -1,5 -1,5 +1,5 @@@
import * as request from 'supertest'
--import { buildAbsoluteFixturePath } from '../miscs/miscs'
++import { buildAbsoluteFixturePath, root } from '../miscs/miscs'
import { isAbsolute, join } from 'path'
function makeGetRequest (options: {
@@@ -142,7 -142,7 +142,7 @@@ function updateAvatarRequest (options:
if (isAbsolute(options.fixture)) {
filePath = options.fixture
} else {
-- filePath = join(__dirname, '..', '..', 'fixtures', options.fixture)
++ filePath = join(root(), 'server', 'tests', 'fixtures', options.fixture)
}
return makeUploadRequest({
diff --cc shared/utils/server/servers.ts
index f358a21f13,f358a21f13..88d2b390cf
--- a/shared/utils/server/servers.ts
+++ b/shared/utils/server/servers.ts
@@@ -115,7 -115,7 +115,7 @@@ function runServer (serverNumber: numbe
}
return new Promise<ServerInfo>(res => {
-- server.app = fork(join(__dirname, '..', '..', '..', '..', 'dist', 'server.js'), args, options)
++ server.app = fork(join(root(), 'dist', 'server.js'), args, options)
server.app.stdout.on('data', function onStdout (data) {
let dontContinue = false
diff --cc shared/utils/videos/videos.ts
index d6c3e5dac0,1ab3e7c4be..f5fcc6a8ad
--- a/shared/utils/videos/videos.ts
+++ b/shared/utils/videos/videos.ts
@@@ -416,7 -417,7 +417,7 @@@ function rateVideo (url: string, access
function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
return new Promise<any>((res, rej) => {
const torrentName = videoUUID + '-' + resolution + '.torrent'
-- const torrentPath = join(__dirname, '..', '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName)
++ const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName)
readFile(torrentPath, (err, data) => {
if (err) return rej(err)