aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/requests/requests.ts8
-rw-r--r--shared/extra-utils/server/plugins.ts24
-rw-r--r--shared/extra-utils/users/login.ts23
3 files changed, 53 insertions, 2 deletions
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts
index 61167f212..0e9d67f0b 100644
--- a/shared/extra-utils/requests/requests.ts
+++ b/shared/extra-utils/requests/requests.ts
@@ -4,6 +4,7 @@ import * as request from 'supertest'
4import { buildAbsoluteFixturePath, root } from '../miscs/miscs' 4import { buildAbsoluteFixturePath, root } from '../miscs/miscs'
5import { isAbsolute, join } from 'path' 5import { isAbsolute, join } from 'path'
6import { URL } from 'url' 6import { URL } from 'url'
7import { decode } from 'querystring'
7 8
8function get4KFileUrl () { 9function get4KFileUrl () {
9 return 'https://download.cpy.re/peertube/4k_file.txt' 10 return 'https://download.cpy.re/peertube/4k_file.txt'
@@ -23,6 +24,7 @@ function makeGetRequest (options: {
23 statusCodeExpected?: number 24 statusCodeExpected?: number
24 contentType?: string 25 contentType?: string
25 range?: string 26 range?: string
27 redirects?: number
26}) { 28}) {
27 if (!options.statusCodeExpected) options.statusCodeExpected = 400 29 if (!options.statusCodeExpected) options.statusCodeExpected = 400
28 if (options.contentType === undefined) options.contentType = 'application/json' 30 if (options.contentType === undefined) options.contentType = 'application/json'
@@ -33,6 +35,7 @@ function makeGetRequest (options: {
33 if (options.token) req.set('Authorization', 'Bearer ' + options.token) 35 if (options.token) req.set('Authorization', 'Bearer ' + options.token)
34 if (options.query) req.query(options.query) 36 if (options.query) req.query(options.query)
35 if (options.range) req.set('Range', options.range) 37 if (options.range) req.set('Range', options.range)
38 if (options.redirects) req.redirects(options.redirects)
36 39
37 return req.expect(options.statusCodeExpected) 40 return req.expect(options.statusCodeExpected)
38} 41}
@@ -171,12 +174,17 @@ function updateAvatarRequest (options: {
171 }) 174 })
172} 175}
173 176
177function decodeQueryString (path: string) {
178 return decode(path.split('?')[1])
179}
180
174// --------------------------------------------------------------------------- 181// ---------------------------------------------------------------------------
175 182
176export { 183export {
177 get4KFileUrl, 184 get4KFileUrl,
178 makeHTMLRequest, 185 makeHTMLRequest,
179 makeGetRequest, 186 makeGetRequest,
187 decodeQueryString,
180 makeUploadRequest, 188 makeUploadRequest,
181 makePostBodyRequest, 189 makePostBodyRequest,
182 makePutBodyRequest, 190 makePutBodyRequest,
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts
index 2d02d823d..b6b5e3958 100644
--- a/shared/extra-utils/server/plugins.ts
+++ b/shared/extra-utils/server/plugins.ts
@@ -235,6 +235,27 @@ function getPluginTestPath (suffix = '') {
235 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) 235 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
236} 236}
237 237
238function getExternalAuth (options: {
239 url: string
240 npmName: string
241 npmVersion: string
242 authName: string
243 query?: any
244 statusCodeExpected?: number
245}) {
246 const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options
247
248 const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName
249
250 return makeGetRequest({
251 url,
252 path,
253 query,
254 statusCodeExpected: statusCodeExpected || 200,
255 redirects: 0
256 })
257}
258
238export { 259export {
239 listPlugins, 260 listPlugins,
240 listAvailablePlugins, 261 listAvailablePlugins,
@@ -250,5 +271,6 @@ export {
250 updatePluginPackageJSON, 271 updatePluginPackageJSON,
251 getPluginPackageJSON, 272 getPluginPackageJSON,
252 getPluginTestPath, 273 getPluginTestPath,
253 getPublicSettings 274 getPublicSettings,
275 getExternalAuth
254} 276}
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts
index b12b51b8c..275bb0826 100644
--- a/shared/extra-utils/users/login.ts
+++ b/shared/extra-utils/users/login.ts
@@ -95,6 +95,26 @@ function setAccessTokensToServers (servers: ServerInfo[]) {
95 return Promise.all(tasks) 95 return Promise.all(tasks)
96} 96}
97 97
98function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = 200) {
99 const path = '/api/v1/users/token'
100
101 const body = {
102 client_id: server.client.id,
103 client_secret: server.client.secret,
104 username: username,
105 response_type: 'code',
106 grant_type: 'password',
107 scope: 'upload',
108 externalAuthToken
109 }
110
111 return request(server.url)
112 .post(path)
113 .type('form')
114 .send(body)
115 .expect(expectedStatus)
116}
117
98// --------------------------------------------------------------------------- 118// ---------------------------------------------------------------------------
99 119
100export { 120export {
@@ -107,5 +127,6 @@ export {
107 setAccessTokensToServers, 127 setAccessTokensToServers,
108 Server, 128 Server,
109 Client, 129 Client,
110 User 130 User,
131 loginUsingExternalToken
111} 132}