Verified Commit 254d3579 authored by Chocobozzz's avatar Chocobozzz
Browse files

Use an object to represent a server

parent 89d241a7
import * as autocannon from 'autocannon'
import { writeJson } from 'fs-extra'
import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths()
let server: ServerInfo
let server: PeerTubeServer
let video: Video
let threadId: number
......@@ -188,7 +188,7 @@ function runBenchmark (options: {
}
async function prepare () {
server = await flushAndRunServer(1, {
server = await createSingleServer(1, {
rates_limit: {
api: {
max: 5_000_000
......
......@@ -5,8 +5,8 @@ import * as chai from 'chai'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
createMultipleServers,
PeerTubeServer,
setAccessTokensToServers,
wait,
waitJobs
......@@ -15,7 +15,7 @@ import {
const expect = chai.expect
describe('Test AP cleaner', function () {
let servers: ServerInfo[] = []
let servers: PeerTubeServer[] = []
let videoUUID1: string
let videoUUID2: string
let videoUUID3: string
......@@ -30,7 +30,7 @@ describe('Test AP cleaner', function () {
videos: { cleanup_remote_interactions: true }
}
}
servers = await flushAndRunMultipleServers(3, config)
servers = await createMultipleServers(3, config)
// Get the access tokens
await setAccessTokensToServers(servers)
......
......@@ -6,9 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
createMultipleServers,
makeActivityPubGetRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel
} from '@shared/extra-utils'
......@@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
describe('Test activitypub', function () {
let servers: ServerInfo[] = []
let servers: PeerTubeServer[] = []
let video: { id: number, uuid: string, shortUUID: string }
let playlist: { id: number, uuid: string, shortUUID: string }
......@@ -62,7 +62,7 @@ describe('Test activitypub', function () {
before(async function () {
this.timeout(30000)
servers = await flushAndRunMultipleServers(2)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers)
......
......@@ -2,19 +2,19 @@
import 'mocha'
import * as chai from 'chai'
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
describe('Test ActivityPub fetcher', function () {
let servers: ServerInfo[]
let servers: PeerTubeServer[]
// ---------------------------------------------------------------
before(async function () {
this.timeout(60000)
servers = await flushAndRunMultipleServers(3)
servers = await createMultipleServers(3)
// Get the access tokens
await setAccessTokensToServers(servers)
......
......@@ -5,10 +5,9 @@ import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
createMultipleServers,
killallServers,
reRunServer,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
wait,
......@@ -17,7 +16,7 @@ import {
import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test AP refresher', function () {
let servers: ServerInfo[] = []
let servers: PeerTubeServer[] = []
let videoUUID1: string
let videoUUID2: string
let videoUUID3: string
......@@ -27,7 +26,7 @@ describe('Test AP refresher', function () {
before(async function () {
this.timeout(60000)
servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
servers = await createMultipleServers(2, { transcoding: { enabled: false } })
// Get the access tokens
await setAccessTokensToServers(servers)
......@@ -95,7 +94,7 @@ describe('Test AP refresher', function () {
// The refresh should fail
await waitJobs([ servers[0] ])
await reRunServer(servers[1])
await servers[1].run()
await servers[0].videos.get({ id: videoUUID3 })
})
......
......@@ -7,10 +7,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
import {
buildAbsoluteFixturePath,
cleanupTests,
flushAndRunMultipleServers,
createMultipleServers,
killallServers,
reRunServer,
ServerInfo,
PeerTubeServer,
wait
} from '../../../../shared/extra-utils'
import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
......@@ -20,7 +19,7 @@ import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activi
const expect = chai.expect
function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) {
function setKeysOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, publicKey: string, privateKey: string) {
const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
return Promise.all([
......@@ -29,7 +28,7 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey:
])
}
function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) {
function setUpdatedAtOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, updatedAt: string) {
const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
return Promise.all([
......@@ -38,7 +37,7 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat
])
}
function getAnnounceWithoutContext (server: ServerInfo) {
function getAnnounceWithoutContext (server: PeerTubeServer) {
const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
const result: typeof json = {}
......@@ -54,7 +53,7 @@ function getAnnounceWithoutContext (server: ServerInfo) {
}
describe('Test ActivityPub security', function () {
let servers: ServerInfo[]
let servers: PeerTubeServer[]
let url: string
const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
......@@ -72,7 +71,7 @@ describe('Test ActivityPub security', function () {
before(async function () {
this.timeout(60000)
servers = await flushAndRunMultipleServers(3)
servers = await createMultipleServers(3)
url = servers[0].url + '/inbox'
......@@ -172,7 +171,7 @@ describe('Test ActivityPub security', function () {
// Invalid peertube actor cache
await killallServers([ servers[1] ])
await reRunServer(servers[1])
await servers[1].run()
const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
const headers = buildGlobalHeaders(body)
......
......@@ -9,10 +9,10 @@ import {
checkBadStartPagination,
cleanupTests,
doubleFollow,
flushAndRunServer,
createSingleServer,
makeGetRequest,
makePostBodyRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@shared/extra-utils'
......@@ -21,7 +21,7 @@ import { AbuseCreate, AbuseState } from '@shared/models'
describe('Test abuses API validators', function () {
const basePath = '/api/v1/abuses/'
let server: ServerInfo
let server: PeerTubeServer
let userToken = ''
let userToken2 = ''
......@@ -35,7 +35,7 @@ describe('Test abuses API validators', function () {
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......@@ -404,12 +404,12 @@ describe('Test abuses API validators', function () {
describe('When trying to manage messages of a remote abuse', function () {
let remoteAbuseId: number
let anotherServer: ServerInfo
let anotherServer: PeerTubeServer
before(async function () {
this.timeout(50000)
anotherServer = await flushAndRunServer(2)
anotherServer = await createSingleServer(2)
await setAccessTokensToServers([ anotherServer ])
await doubleFollow(anotherServer, server)
......
......@@ -7,20 +7,20 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
ServerInfo
createSingleServer,
PeerTubeServer
} from '@shared/extra-utils'
describe('Test accounts API validators', function () {
const path = '/api/v1/accounts/'
let server: ServerInfo
let server: PeerTubeServer
// ---------------------------------------------------------------
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
})
describe('When listing accounts', function () {
......
......@@ -5,11 +5,11 @@ import 'mocha'
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
createMultipleServers,
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import {
......@@ -20,14 +20,14 @@ import {
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test blocklist API validators', function () {
let servers: ServerInfo[]
let server: ServerInfo
let servers: PeerTubeServer[]
let server: PeerTubeServer
let userAccessToken: string
before(async function () {
this.timeout(60000)
servers = await flushAndRunMultipleServers(2)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
server = servers[0]
......
......@@ -3,15 +3,15 @@
import 'mocha'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test bulk API validators', function () {
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken: string
// ---------------------------------------------------------------
......@@ -19,7 +19,7 @@ describe('Test bulk API validators', function () {
before(async function () {
this.timeout(120000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' }
......
......@@ -5,18 +5,18 @@ import { omit } from 'lodash'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
flushAndRunServer,
createSingleServer,
makeDeleteRequest,
makeGetRequest,
makePutBodyRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers
} from '@shared/extra-utils'
import { CustomConfig } from '@shared/models'
describe('Test config API validators', function () {
const path = '/api/v1/config/custom'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken: string
const updateParams: CustomConfig = {
instance: {
......@@ -197,7 +197,7 @@ describe('Test config API validators', function () {
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......
......@@ -2,11 +2,11 @@
import 'mocha'
import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils'
import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils'
import { ContactFormCommand } from '@shared/extra-utils/server'
describe('Test contact form API validators', function () {
let server: ServerInfo
let server: PeerTubeServer
const emails: object[] = []
const defaultBody = {
fromName: 'super name',
......@@ -25,7 +25,7 @@ describe('Test contact form API validators', function () {
emailPort = await MockSmtpServer.Instance.collectEmails(emails)
// Email is disabled
server = await flushAndRunServer(1)
server = await createSingleServer(1)
command = server.contactForm
})
......@@ -39,7 +39,7 @@ describe('Test contact form API validators', function () {
await killallServers([ server ])
// Contact form is disabled
await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
await server.run({ smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
})
......@@ -49,7 +49,7 @@ describe('Test contact form API validators', function () {
await killallServers([ server ])
// Email & contact form enabled
await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
await server.run({ smtp: { hostname: 'localhost', port: emailPort } })
await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
......
......@@ -4,8 +4,8 @@ import 'mocha'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests'
......@@ -13,7 +13,7 @@ import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-uti
describe('Test custom pages validators', function () {
const path = '/api/v1/custom-pages/homepage/instance'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken: string
// ---------------------------------------------------------------
......@@ -21,7 +21,7 @@ describe('Test custom pages validators', function () {
before(async function () {
this.timeout(120000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' }
......
......@@ -4,8 +4,8 @@ import 'mocha'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
......@@ -13,7 +13,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
describe('Test debug API validators', function () {
const path = '/api/v1/server/debug'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken = ''
// ---------------------------------------------------------------
......@@ -21,7 +21,7 @@ describe('Test debug API validators', function () {
before(async function () {
this.timeout(120000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......
......@@ -4,10 +4,10 @@ import 'mocha'
import {
cleanupTests,
flushAndRunServer,
createSingleServer,
makeDeleteRequest, makeGetRequest,
makePostBodyRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import {
......@@ -18,14 +18,14 @@ import {
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test server follows API validators', function () {
let server: ServerInfo
let server: PeerTubeServer
// ---------------------------------------------------------------
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
})
......
......@@ -4,8 +4,8 @@ import 'mocha'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import {
......@@ -18,7 +18,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
describe('Test jobs API validators', function () {
const path = '/api/v1/jobs/failed'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken = ''
// ---------------------------------------------------------------
......@@ -26,7 +26,7 @@ describe('Test jobs API validators', function () {
before(async function () {
this.timeout(120000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......
......@@ -6,12 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
cleanupTests,
flushAndRunServer,
createSingleServer,
LiveCommand,
makePostBodyRequest,
makeUploadRequest,
sendRTMPStream,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers,
stopFfmpeg
} from '@shared/extra-utils'
......@@ -19,7 +19,7 @@ import { VideoCreateResult, VideoPrivacy } from '@shared/models'
describe('Test video lives API validator', function () {
const path = '/api/v1/videos/live'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken = ''
let channelId: number
let video: VideoCreateResult
......@@ -31,7 +31,7 @@ describe('Test video lives API validator', function () {
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......
......@@ -4,8 +4,8 @@ import 'mocha'
import {
cleanupTests,
flushAndRunServer,
ServerInfo,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers
} from '../../../../shared/extra-utils'
import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
......@@ -13,7 +13,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
describe('Test logs API validators', function () {
const path = '/api/v1/server/logs'
let server: ServerInfo
let server: PeerTubeServer
let userAccessToken = ''
// ---------------------------------------------------------------
......@@ -21,7 +21,7 @@ describe('Test logs API validators', function () {
before(async function () {
this.timeout(120000)
server = await flushAndRunServer(1)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
......
......@@ -7,17 +7,17 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
createSingleServer,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
ServerInfo,
PeerTubeServer,
setAccessTokensToServers
} from '@shared/extra-utils'
import { PeerTubePlugin, PluginType } from '@shared/models'
describe('Test server plugins API validators', function () {