aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/initializers/checker.ts25
-rw-r--r--server/tests/cli/update-host.ts65
2 files changed, 86 insertions, 4 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts
index 6259c7b6c..d5402098f 100644
--- a/server/initializers/checker.ts
+++ b/server/initializers/checker.ts
@@ -3,6 +3,28 @@ import { promisify0 } from '../helpers/core-utils'
3import { UserModel } from '../models/account/user' 3import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application' 4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { parse } from 'url'
7import { CONFIG } from './constants'
8import { logger } from '../helpers/logger'
9import { getServerActor } from '../helpers/utils'
10
11async function checkActivityPubUrls () {
12 const actor = await getServerActor()
13
14 const parsed = parse(actor.url)
15 if (CONFIG.WEBSERVER.HOST !== parsed.host) {
16 const NODE_ENV = config.util.getEnv('NODE_ENV')
17 const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR')
18
19 logger.warn(
20 'It seems PeerTube was started (and created some data) with another domain name. ' +
21 'This means you will not be able to federate! ' +
22 'Please use %s %s npm run update-host to fix this.',
23 NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '',
24 NODE_ENV ? `NODE_ENV=${NODE_ENV}` : ''
25 )
26 }
27}
6 28
7// Some checks on configuration files 29// Some checks on configuration files
8// Return an error message, or null if everything is okay 30// Return an error message, or null if everything is okay
@@ -95,5 +117,6 @@ export {
95 checkMissedConfig, 117 checkMissedConfig,
96 clientsExist, 118 clientsExist,
97 usersExist, 119 usersExist,
98 applicationExist 120 applicationExist,
121 checkActivityPubUrls
99} 122}
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index d0c6d2042..968b7bd7f 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -3,20 +3,26 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos' 5import { VideoDetails } from '../../../shared/models/videos'
6import { waitJobs } from '../utils/server/jobs'
7import { addVideoCommentThread } from '../utils/videos/video-comments'
6import { 8import {
9 addVideoChannel,
10 createUser,
7 execCLI, 11 execCLI,
8 flushTests, 12 flushTests,
9 getEnvCli, 13 getEnvCli,
10 getVideo, 14 getVideo,
15 getVideoChannelsList,
11 getVideosList, 16 getVideosList,
12 killallServers, 17 killallServers,
18 makeActivityPubGetRequest,
13 parseTorrentVideo, 19 parseTorrentVideo,
14 runServer, 20 runServer,
15 ServerInfo, 21 ServerInfo,
16 setAccessTokensToServers, 22 setAccessTokensToServers,
17 uploadVideo 23 uploadVideo
18} from '../utils' 24} from '../utils'
19import { waitJobs } from '../utils/server/jobs' 25import { getAccountsList } from '../utils/users/accounts'
20 26
21const expect = chai.expect 27const expect = chai.expect
22 28
@@ -39,13 +45,28 @@ describe('Test update host scripts', function () {
39 45
40 // Upload two videos for our needs 46 // Upload two videos for our needs
41 const videoAttributes = {} 47 const videoAttributes = {}
48 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
49 const video1UUID = resVideo1.body.video.uuid
42 await uploadVideo(server.url, server.accessToken, videoAttributes) 50 await uploadVideo(server.url, server.accessToken, videoAttributes)
43 await uploadVideo(server.url, server.accessToken, videoAttributes) 51
52 // Create a user
53 await createUser(server.url, server.accessToken, 'toto', 'coucou')
54
55 // Create channel
56 const videoChannel = {
57 displayName: 'second video channel',
58 description: 'super video channel description'
59 }
60 await addVideoChannel(server.url, server.accessToken, videoChannel)
61
62 // Create comments
63 const text = 'my super first comment'
64 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
44 65
45 await waitJobs(server) 66 await waitJobs(server)
46 }) 67 })
47 68
48 it('Should update torrent hosts', async function () { 69 it('Should run update host', async function () {
49 this.timeout(30000) 70 this.timeout(30000)
50 71
51 killallServers([ server ]) 72 killallServers([ server ])
@@ -54,6 +75,44 @@ describe('Test update host scripts', function () {
54 75
55 const env = getEnvCli(server) 76 const env = getEnvCli(server)
56 await execCLI(`${env} npm run update-host`) 77 await execCLI(`${env} npm run update-host`)
78 })
79
80 it('Should have updated videos url', async function () {
81 const res = await getVideosList(server.url)
82 expect(res.body.total).to.equal(2)
83
84 for (const video of res.body.data) {
85 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
86
87 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
88 }
89 })
90
91 it('Should have updated video channels url', async function () {
92 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
93 expect(res.body.total).to.equal(3)
94
95 for (const channel of res.body.data) {
96 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.uuid)
97
98 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.uuid)
99 }
100 })
101
102 it('Should have update accounts url', async function () {
103 const res = await getAccountsList(server.url)
104 expect(res.body.total).to.equal(3)
105
106 for (const account of res.body.data) {
107 const usernameWithDomain = account.name
108 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
109
110 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
111 }
112 })
113
114 it('Should update torrent hosts', async function () {
115 this.timeout(30000)
57 116
58 const res = await getVideosList(server.url) 117 const res = await getVideosList(server.url)
59 const videos = res.body.data 118 const videos = res.body.data