diff options
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r-- | shared/extra-utils/server/clients.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/server/contact-form.ts | 10 | ||||
-rw-r--r-- | shared/extra-utils/server/follows.ts | 26 | ||||
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 22 | ||||
-rw-r--r-- | shared/extra-utils/server/plugins.ts | 72 | ||||
-rw-r--r-- | shared/extra-utils/server/redundancy.ts | 70 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 27 |
7 files changed, 147 insertions, 84 deletions
diff --git a/shared/extra-utils/server/clients.ts b/shared/extra-utils/server/clients.ts index 273aac747..dc631e823 100644 --- a/shared/extra-utils/server/clients.ts +++ b/shared/extra-utils/server/clients.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import * as urlUtil from 'url' | 2 | import { URL } from 'url' |
3 | 3 | ||
4 | function getClient (url: string) { | 4 | function getClient (url: string) { |
5 | const path = '/api/v1/oauth-clients/local' | 5 | const path = '/api/v1/oauth-clients/local' |
6 | 6 | ||
7 | return request(url) | 7 | return request(url) |
8 | .get(path) | 8 | .get(path) |
9 | .set('Host', urlUtil.parse(url).host) | 9 | .set('Host', new URL(url).host) |
10 | .set('Accept', 'application/json') | 10 | .set('Accept', 'application/json') |
11 | .expect(200) | 11 | .expect(200) |
12 | .expect('Content-Type', /json/) | 12 | .expect('Content-Type', /json/) |
diff --git a/shared/extra-utils/server/contact-form.ts b/shared/extra-utils/server/contact-form.ts index e002e03dd..d50f83241 100644 --- a/shared/extra-utils/server/contact-form.ts +++ b/shared/extra-utils/server/contact-form.ts | |||
@@ -2,11 +2,11 @@ import * as request from 'supertest' | |||
2 | import { ContactForm } from '../../models/server' | 2 | import { ContactForm } from '../../models/server' |
3 | 3 | ||
4 | function sendContactForm (options: { | 4 | function sendContactForm (options: { |
5 | url: string, | 5 | url: string |
6 | fromEmail: string, | 6 | fromEmail: string |
7 | fromName: string, | 7 | fromName: string |
8 | subject: string, | 8 | subject: string |
9 | body: string, | 9 | body: string |
10 | expectedStatus?: number | 10 | expectedStatus?: number |
11 | }) { | 11 | }) { |
12 | const path = '/api/v1/server/contact' | 12 | const path = '/api/v1/server/contact' |
diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 3f7729c20..006d59199 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts | |||
@@ -5,12 +5,12 @@ import { makePostBodyRequest } from '../requests/requests' | |||
5 | import { ActivityPubActorType, FollowState } from '@shared/models' | 5 | import { ActivityPubActorType, FollowState } from '@shared/models' |
6 | 6 | ||
7 | function getFollowersListPaginationAndSort (options: { | 7 | function getFollowersListPaginationAndSort (options: { |
8 | url: string, | 8 | url: string |
9 | start: number, | 9 | start: number |
10 | count: number, | 10 | count: number |
11 | sort: string, | 11 | sort: string |
12 | search?: string, | 12 | search?: string |
13 | actorType?: ActivityPubActorType, | 13 | actorType?: ActivityPubActorType |
14 | state?: FollowState | 14 | state?: FollowState |
15 | }) { | 15 | }) { |
16 | const { url, start, count, sort, search, state, actorType } = options | 16 | const { url, start, count, sort, search, state, actorType } = options |
@@ -56,12 +56,12 @@ function rejectFollower (url: string, token: string, follower: string, statusCod | |||
56 | } | 56 | } |
57 | 57 | ||
58 | function getFollowingListPaginationAndSort (options: { | 58 | function getFollowingListPaginationAndSort (options: { |
59 | url: string, | 59 | url: string |
60 | start: number, | 60 | start: number |
61 | count: number, | 61 | count: number |
62 | sort: string, | 62 | sort: string |
63 | search?: string, | 63 | search?: string |
64 | actorType?: ActivityPubActorType, | 64 | actorType?: ActivityPubActorType |
65 | state?: FollowState | 65 | state?: FollowState |
66 | }) { | 66 | }) { |
67 | const { url, start, count, sort, search, state, actorType } = options | 67 | const { url, start, count, sort, search, state, actorType } = options |
@@ -92,7 +92,7 @@ function follow (follower: string, following: string[], accessToken: string, exp | |||
92 | .post(path) | 92 | .post(path) |
93 | .set('Accept', 'application/json') | 93 | .set('Accept', 'application/json') |
94 | .set('Authorization', 'Bearer ' + accessToken) | 94 | .set('Authorization', 'Bearer ' + accessToken) |
95 | .send({ 'hosts': followingHosts }) | 95 | .send({ hosts: followingHosts }) |
96 | .expect(expectedStatus) | 96 | .expect(expectedStatus) |
97 | } | 97 | } |
98 | 98 | ||
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 56fe5fa2a..d984b3d1e 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -8,20 +8,20 @@ function getJobsList (url: string, accessToken: string, state: JobState) { | |||
8 | const path = '/api/v1/jobs/' + state | 8 | const path = '/api/v1/jobs/' + state |
9 | 9 | ||
10 | return request(url) | 10 | return request(url) |
11 | .get(path) | 11 | .get(path) |
12 | .set('Accept', 'application/json') | 12 | .set('Accept', 'application/json') |
13 | .set('Authorization', 'Bearer ' + accessToken) | 13 | .set('Authorization', 'Bearer ' + accessToken) |
14 | .expect(200) | 14 | .expect(200) |
15 | .expect('Content-Type', /json/) | 15 | .expect('Content-Type', /json/) |
16 | } | 16 | } |
17 | 17 | ||
18 | function getJobsListPaginationAndSort (options: { | 18 | function getJobsListPaginationAndSort (options: { |
19 | url: string, | 19 | url: string |
20 | accessToken: string, | 20 | accessToken: string |
21 | state: JobState, | 21 | state: JobState |
22 | start: number, | 22 | start: number |
23 | count: number, | 23 | count: number |
24 | sort: string, | 24 | sort: string |
25 | jobType?: JobType | 25 | jobType?: JobType |
26 | }) { | 26 | }) { |
27 | const { url, accessToken, state, start, count, sort, jobType } = options | 27 | const { url, accessToken, state, start, count, sort, jobType } = options |
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index 5c0d1e511..2d02d823d 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -7,13 +7,13 @@ import { root } from '../miscs/miscs' | |||
7 | import { join } from 'path' | 7 | import { join } from 'path' |
8 | 8 | ||
9 | function listPlugins (parameters: { | 9 | function listPlugins (parameters: { |
10 | url: string, | 10 | url: string |
11 | accessToken: string, | 11 | accessToken: string |
12 | start?: number, | 12 | start?: number |
13 | count?: number, | 13 | count?: number |
14 | sort?: string, | 14 | sort?: string |
15 | pluginType?: PluginType, | 15 | pluginType?: PluginType |
16 | uninstalled?: boolean, | 16 | uninstalled?: boolean |
17 | expectedStatus?: number | 17 | expectedStatus?: number |
18 | }) { | 18 | }) { |
19 | const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters | 19 | const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters |
@@ -35,13 +35,13 @@ function listPlugins (parameters: { | |||
35 | } | 35 | } |
36 | 36 | ||
37 | function listAvailablePlugins (parameters: { | 37 | function listAvailablePlugins (parameters: { |
38 | url: string, | 38 | url: string |
39 | accessToken: string, | 39 | accessToken: string |
40 | start?: number, | 40 | start?: number |
41 | count?: number, | 41 | count?: number |
42 | sort?: string, | 42 | sort?: string |
43 | pluginType?: PluginType, | 43 | pluginType?: PluginType |
44 | currentPeerTubeEngine?: string, | 44 | currentPeerTubeEngine?: string |
45 | search?: string | 45 | search?: string |
46 | expectedStatus?: number | 46 | expectedStatus?: number |
47 | }) { | 47 | }) { |
@@ -67,9 +67,9 @@ function listAvailablePlugins (parameters: { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | function getPlugin (parameters: { | 69 | function getPlugin (parameters: { |
70 | url: string, | 70 | url: string |
71 | accessToken: string, | 71 | accessToken: string |
72 | npmName: string, | 72 | npmName: string |
73 | expectedStatus?: number | 73 | expectedStatus?: number |
74 | }) { | 74 | }) { |
75 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | 75 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters |
@@ -84,10 +84,10 @@ function getPlugin (parameters: { | |||
84 | } | 84 | } |
85 | 85 | ||
86 | function updatePluginSettings (parameters: { | 86 | function updatePluginSettings (parameters: { |
87 | url: string, | 87 | url: string |
88 | accessToken: string, | 88 | accessToken: string |
89 | npmName: string, | 89 | npmName: string |
90 | settings: any, | 90 | settings: any |
91 | expectedStatus?: number | 91 | expectedStatus?: number |
92 | }) { | 92 | }) { |
93 | const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters | 93 | const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters |
@@ -103,9 +103,9 @@ function updatePluginSettings (parameters: { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | function getPluginRegisteredSettings (parameters: { | 105 | function getPluginRegisteredSettings (parameters: { |
106 | url: string, | 106 | url: string |
107 | accessToken: string, | 107 | accessToken: string |
108 | npmName: string, | 108 | npmName: string |
109 | expectedStatus?: number | 109 | expectedStatus?: number |
110 | }) { | 110 | }) { |
111 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | 111 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters |
@@ -120,8 +120,8 @@ function getPluginRegisteredSettings (parameters: { | |||
120 | } | 120 | } |
121 | 121 | ||
122 | function getPublicSettings (parameters: { | 122 | function getPublicSettings (parameters: { |
123 | url: string, | 123 | url: string |
124 | npmName: string, | 124 | npmName: string |
125 | expectedStatus?: number | 125 | expectedStatus?: number |
126 | }) { | 126 | }) { |
127 | const { url, npmName, expectedStatus = 200 } = parameters | 127 | const { url, npmName, expectedStatus = 200 } = parameters |
@@ -135,8 +135,8 @@ function getPublicSettings (parameters: { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | function getPluginTranslations (parameters: { | 137 | function getPluginTranslations (parameters: { |
138 | url: string, | 138 | url: string |
139 | locale: string, | 139 | locale: string |
140 | expectedStatus?: number | 140 | expectedStatus?: number |
141 | }) { | 141 | }) { |
142 | const { url, locale, expectedStatus = 200 } = parameters | 142 | const { url, locale, expectedStatus = 200 } = parameters |
@@ -150,9 +150,9 @@ function getPluginTranslations (parameters: { | |||
150 | } | 150 | } |
151 | 151 | ||
152 | function installPlugin (parameters: { | 152 | function installPlugin (parameters: { |
153 | url: string, | 153 | url: string |
154 | accessToken: string, | 154 | accessToken: string |
155 | path?: string, | 155 | path?: string |
156 | npmName?: string | 156 | npmName?: string |
157 | expectedStatus?: number | 157 | expectedStatus?: number |
158 | }) { | 158 | }) { |
@@ -169,9 +169,9 @@ function installPlugin (parameters: { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | function updatePlugin (parameters: { | 171 | function updatePlugin (parameters: { |
172 | url: string, | 172 | url: string |
173 | accessToken: string, | 173 | accessToken: string |
174 | path?: string, | 174 | path?: string |
175 | npmName?: string | 175 | npmName?: string |
176 | expectedStatus?: number | 176 | expectedStatus?: number |
177 | }) { | 177 | }) { |
@@ -188,8 +188,8 @@ function updatePlugin (parameters: { | |||
188 | } | 188 | } |
189 | 189 | ||
190 | function uninstallPlugin (parameters: { | 190 | function uninstallPlugin (parameters: { |
191 | url: string, | 191 | url: string |
192 | accessToken: string, | 192 | accessToken: string |
193 | npmName: string | 193 | npmName: string |
194 | expectedStatus?: number | 194 | expectedStatus?: number |
195 | }) { | 195 | }) { |
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts index c39ff2c8b..08467e4c0 100644 --- a/shared/extra-utils/server/redundancy.ts +++ b/shared/extra-utils/server/redundancy.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { makePutBodyRequest } from '../requests/requests' | 1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
2 | import { VideoRedundanciesTarget } from '@shared/models' | ||
2 | 3 | ||
3 | async function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { | 4 | function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { |
4 | const path = '/api/v1/server/redundancy/' + host | 5 | const path = '/api/v1/server/redundancy/' + host |
5 | 6 | ||
6 | return makePutBodyRequest({ | 7 | return makePutBodyRequest({ |
@@ -12,6 +13,69 @@ async function updateRedundancy (url: string, accessToken: string, host: string, | |||
12 | }) | 13 | }) |
13 | } | 14 | } |
14 | 15 | ||
16 | function listVideoRedundancies (options: { | ||
17 | url: string | ||
18 | accessToken: string | ||
19 | target: VideoRedundanciesTarget | ||
20 | start?: number | ||
21 | count?: number | ||
22 | sort?: string | ||
23 | statusCodeExpected?: number | ||
24 | }) { | ||
25 | const path = '/api/v1/server/redundancy/videos' | ||
26 | |||
27 | const { url, accessToken, target, statusCodeExpected, start, count, sort } = options | ||
28 | |||
29 | return makeGetRequest({ | ||
30 | url, | ||
31 | token: accessToken, | ||
32 | path, | ||
33 | query: { | ||
34 | start: start ?? 0, | ||
35 | count: count ?? 5, | ||
36 | sort: sort ?? 'name', | ||
37 | target | ||
38 | }, | ||
39 | statusCodeExpected: statusCodeExpected || 200 | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | function addVideoRedundancy (options: { | ||
44 | url: string | ||
45 | accessToken: string | ||
46 | videoId: number | ||
47 | }) { | ||
48 | const path = '/api/v1/server/redundancy/videos' | ||
49 | const { url, accessToken, videoId } = options | ||
50 | |||
51 | return makePostBodyRequest({ | ||
52 | url, | ||
53 | token: accessToken, | ||
54 | path, | ||
55 | fields: { videoId }, | ||
56 | statusCodeExpected: 204 | ||
57 | }) | ||
58 | } | ||
59 | |||
60 | function removeVideoRedundancy (options: { | ||
61 | url: string | ||
62 | accessToken: string | ||
63 | redundancyId: number | ||
64 | }) { | ||
65 | const { url, accessToken, redundancyId } = options | ||
66 | const path = '/api/v1/server/redundancy/videos/' + redundancyId | ||
67 | |||
68 | return makeDeleteRequest({ | ||
69 | url, | ||
70 | token: accessToken, | ||
71 | path, | ||
72 | statusCodeExpected: 204 | ||
73 | }) | ||
74 | } | ||
75 | |||
15 | export { | 76 | export { |
16 | updateRedundancy | 77 | updateRedundancy, |
78 | listVideoRedundancies, | ||
79 | addVideoRedundancy, | ||
80 | removeVideoRedundancy | ||
17 | } | 81 | } |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index a0720d778..a0f0ce9c9 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -1,16 +1,15 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ |
2 | 2 | ||
3 | import { ChildProcess, exec, fork } from 'child_process' | 3 | import { ChildProcess, exec, fork } from 'child_process' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { root, wait } from '../miscs/miscs' | 5 | import { root, wait } from '../miscs/miscs' |
6 | import { copy, pathExists, readdir, readFile, remove } from 'fs-extra' | 6 | import { copy, pathExists, readdir, readFile, remove } from 'fs-extra' |
7 | import { existsSync } from 'fs' | ||
8 | import { expect } from 'chai' | 7 | import { expect } from 'chai' |
9 | import { VideoChannel } from '../../models/videos' | 8 | import { VideoChannel } from '../../models/videos' |
10 | import { randomInt } from '../../core-utils/miscs/miscs' | 9 | import { randomInt } from '../../core-utils/miscs/miscs' |
11 | 10 | ||
12 | interface ServerInfo { | 11 | interface ServerInfo { |
13 | app: ChildProcess, | 12 | app: ChildProcess |
14 | url: string | 13 | url: string |
15 | host: string | 14 | host: string |
16 | 15 | ||
@@ -20,13 +19,13 @@ interface ServerInfo { | |||
20 | serverNumber: number | 19 | serverNumber: number |
21 | 20 | ||
22 | client: { | 21 | client: { |
23 | id: string, | 22 | id: string |
24 | secret: string | 23 | secret: string |
25 | } | 24 | } |
26 | 25 | ||
27 | user: { | 26 | user: { |
28 | username: string, | 27 | username: string |
29 | password: string, | 28 | password: string |
30 | email?: string | 29 | email?: string |
31 | } | 30 | } |
32 | 31 | ||
@@ -57,7 +56,7 @@ function parallelTests () { | |||
57 | } | 56 | } |
58 | 57 | ||
59 | function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { | 58 | function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { |
60 | let apps = [] | 59 | const apps = [] |
61 | let i = 0 | 60 | let i = 0 |
62 | 61 | ||
63 | return new Promise<ServerInfo[]>(res => { | 62 | return new Promise<ServerInfo[]>(res => { |
@@ -203,20 +202,20 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
203 | 202 | ||
204 | // Capture things if we want to | 203 | // Capture things if we want to |
205 | for (const key of Object.keys(regexps)) { | 204 | for (const key of Object.keys(regexps)) { |
206 | const regexp = regexps[ key ] | 205 | const regexp = regexps[key] |
207 | const matches = data.toString().match(regexp) | 206 | const matches = data.toString().match(regexp) |
208 | if (matches !== null) { | 207 | if (matches !== null) { |
209 | if (key === 'client_id') server.client.id = matches[ 1 ] | 208 | if (key === 'client_id') server.client.id = matches[1] |
210 | else if (key === 'client_secret') server.client.secret = matches[ 1 ] | 209 | else if (key === 'client_secret') server.client.secret = matches[1] |
211 | else if (key === 'user_username') server.user.username = matches[ 1 ] | 210 | else if (key === 'user_username') server.user.username = matches[1] |
212 | else if (key === 'user_password') server.user.password = matches[ 1 ] | 211 | else if (key === 'user_password') server.user.password = matches[1] |
213 | } | 212 | } |
214 | } | 213 | } |
215 | 214 | ||
216 | // Check if all required sentences are here | 215 | // Check if all required sentences are here |
217 | for (const key of Object.keys(serverRunString)) { | 216 | for (const key of Object.keys(serverRunString)) { |
218 | if (data.toString().indexOf(key) !== -1) serverRunString[ key ] = true | 217 | if (data.toString().indexOf(key) !== -1) serverRunString[key] = true |
219 | if (serverRunString[ key ] === false) dontContinue = true | 218 | if (serverRunString[key] === false) dontContinue = true |
220 | } | 219 | } |
221 | 220 | ||
222 | // If no, there is maybe one thing not already initialized (client/user credentials generation...) | 221 | // If no, there is maybe one thing not already initialized (client/user credentials generation...) |