Diagnostic tool: testing API communication between Peertube and Prosody.

This commit is contained in:
John Livingston
2021-06-22 10:26:45 +02:00
parent 350a9fa833
commit 7279761c66
8 changed files with 323 additions and 9 deletions

View File

@ -1,8 +1,11 @@
import { getProsodyConfig, getWorkingDir } from '../prosody/config'
import { getProsodyAbout, testProsodyCorrectlyRunning } from '../prosody/ctl'
import { newResult, TestResult } from './utils'
import { getAPIKey } from '../apikey'
import * as fs from 'fs'
const got = require('got')
export async function diagProsody (test: string, options: RegisterServerOptions): Promise<TestResult> {
const result = newResult(test)
result.label = 'Builtin Prosody and ConverseJS'
@ -17,11 +20,13 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
// FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here?
// Testing the prosody config file.
let prosodyPort: string
try {
const wantedConfig = await getProsodyConfig(options)
const filePath = wantedConfig.paths.config
result.messages.push(`Prosody will run on port '${wantedConfig.port}'`)
prosodyPort = wantedConfig.port
result.messages.push(`Prosody modules path will be '${wantedConfig.paths.modules}'`)
@ -87,6 +92,27 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
}
}
try {
const apiUrl = `http://localhost:${prosodyPort}/peertubelivechat_test/test-peertube-prosody`
const testResult = await got(apiUrl, {
method: 'GET',
headers: {
authorization: 'Bearer ' + await getAPIKey(options)
},
responseType: 'json',
resolveBodyOnly: true
})
if (testResult.ok === true) {
result.messages.push('API Peertube -> Prosody is OK')
} else {
result.messages.push('API Peertube -> Prosody is KO. Response was: ' + JSON.stringify(testResult))
return result
}
} catch (error) {
result.messages.push('Error when calling Prosody test api (test-peertube-prosody): ' + (error as string))
return result
}
result.ok = true
return result
}

View File

@ -96,6 +96,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
// TODO: add a settings to choose?
config.useDefaultPersistent()
config.useTestModule(apikey)
let logLevel: ProsodyLogLevel | undefined
if (logger.level && (typeof logger.level === 'string')) {
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {

View File

@ -236,6 +236,11 @@ class ProsodyConfigContent {
this.muc.set('muc_room_default_persistent', true)
}
useTestModule (apikey: string): void {
this.global.add('modules_enabled', 'http_peertubelivechat_test')
this.global.set('peertubelivechat_test_apikey', apikey)
}
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
let log = ''
log += 'log = {\n'