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

@ -0,0 +1,5 @@
# mod_http_peertubelivechat_test
This module is a custom module that allows Peertube to test communication with Prosody.
This module is part of peertube-plugin-livechat, and is under the same LICENSE.

View File

@ -0,0 +1,43 @@
local json = require "util.json";
module:depends"http";
function check_auth(routes)
local function check_request_auth(event)
local apikey = module:get_option_string("peertubelivechat_test_apikey", "")
if apikey == "" then
return false, 500;
end
if event.request.headers.authorization ~= "Bearer " .. apikey then
return false, 401;
end
return true;
end
for route, handler in pairs(routes) do
routes[route] = function (event, ...)
local permit, code = check_request_auth(event);
if not permit then
return code;
end
return handler(event, ...);
end;
end
return routes;
end
local function test_peertube_prosody(event)
local request, response = event.request, event.response;
local json_response = {
ok = true;
}
event.response.headers["Content-Type"] = "application/json";
return json.encode(json_response);
end
module:provides("http", {
route = check_auth {
["GET /test-peertube-prosody"] = test_peertube_prosody;
-- ["GET /test-prosody-peertube"] = test_prosody_peertube;
};
});