2022-11-30 02:50:00 +03:00
|
|
|
var request = require('supertest');
|
2022-12-11 08:10:10 +03:00
|
|
|
const parseJson = require('parse-json');
|
2022-11-30 02:50:00 +03:00
|
|
|
const jsonfile = require('jsonfile');
|
|
|
|
const Ajv = require('ajv-draft-04');
|
2022-12-08 21:07:54 +03:00
|
|
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
2022-11-30 02:49:08 +03:00
|
|
|
|
|
|
|
request = request('http://127.0.0.1:8080');
|
|
|
|
|
|
|
|
var ajv = new Ajv();
|
|
|
|
var nodeInfoSchema = jsonfile.readFileSync('schema/nodeinfo_2.0.json');
|
|
|
|
|
2023-12-10 03:31:50 +03:00
|
|
|
const serverName = 'owncast.server.test';
|
|
|
|
const serverURL = 'http://' + serverName;
|
|
|
|
const fediUsername = 'streamer';
|
2022-12-08 03:26:06 +03:00
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('disable federation', async () => {
|
|
|
|
await sendAdminRequest('config/federation/enable', false);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/webfinger when federation is disabled', async () => {
|
|
|
|
await request.get('/.well-known/webfinger').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/host-meta when federation is disabled', async () => {
|
|
|
|
await request.get('/.well-known/host-meta').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/nodeinfo when federation is disabled', async () => {
|
|
|
|
await request.get('/.well-known/nodeinfo').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/x-nodeinfo2 when federation is disabled', async () => {
|
|
|
|
await request.get('/.well-known/x-nodeinfo2').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /nodeinfo/2.0 when federation is disabled', async () => {
|
|
|
|
await request.get('/nodeinfo/2.0').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /api/v1/instance when federation is disabled', async () => {
|
|
|
|
await request.get('/api/v1/instance').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /federation/user/ when federation is disabled', async () => {
|
|
|
|
await request.get('/federation/user/').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /federation/ when federation is disabled', async () => {
|
|
|
|
await request.get('/federation/').expect(405);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('set required parameters and enable federation', async () => {
|
|
|
|
await sendAdminRequest('config/serverurl', serverURL);
|
|
|
|
await sendAdminRequest('config/federation/username', fediUsername);
|
|
|
|
await sendAdminRequest('config/federation/enable', true);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/webfinger when federation is enabled', async () => {
|
2022-12-08 03:26:06 +03:00
|
|
|
const resNoResource = request.get('/.well-known/webfinger').expect(400);
|
2023-12-10 03:31:50 +03:00
|
|
|
const resBadResource = request
|
|
|
|
.get('/.well-known/webfinger?resource=' + fediUsername + '@' + serverName)
|
|
|
|
.expect(400);
|
|
|
|
const resBadResource2 = request
|
|
|
|
.get(
|
|
|
|
'/.well-known/webfinger?resource=notacct:' +
|
|
|
|
fediUsername +
|
|
|
|
'@' +
|
|
|
|
serverName
|
|
|
|
)
|
|
|
|
.expect(400);
|
|
|
|
const resBadServer = request
|
|
|
|
.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:' +
|
|
|
|
fediUsername +
|
|
|
|
'@not' +
|
|
|
|
serverName
|
|
|
|
)
|
|
|
|
.expect(404);
|
|
|
|
const resBadUser = request
|
|
|
|
.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:not' +
|
|
|
|
fediUsername +
|
|
|
|
'@' +
|
|
|
|
serverName
|
|
|
|
)
|
|
|
|
.expect(404);
|
|
|
|
const resNoAccept = request
|
|
|
|
.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:' + fediUsername + '@' + serverName
|
|
|
|
)
|
|
|
|
.expect(200)
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2023-12-10 03:31:50 +03:00
|
|
|
const resWithAccept = request
|
|
|
|
.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:' + fediUsername + '@' + serverName
|
|
|
|
)
|
|
|
|
.expect(200)
|
2022-12-11 08:10:10 +03:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/host-meta when federation is enabled', async () => {
|
|
|
|
request
|
2023-12-10 03:31:50 +03:00
|
|
|
.get('/.well-known/host-meta')
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /xml/);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/nodeinfo when federation is enabled', async () => {
|
|
|
|
await request
|
2023-12-10 03:31:50 +03:00
|
|
|
.get('/.well-known/nodeinfo')
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /.well-known/x-nodeinfo2 when federation is enabled', async () => {
|
|
|
|
await request
|
2023-12-10 03:31:50 +03:00
|
|
|
.get('/.well-known/x-nodeinfo2')
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /nodeinfo/2.0 when federation is enabled', async () => {
|
|
|
|
await request
|
2022-11-30 02:50:00 +03:00
|
|
|
.get('/nodeinfo/2.0')
|
|
|
|
.expect(200)
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect('Content-Type', /json/)
|
2022-11-30 02:50:00 +03:00
|
|
|
.then((res) => {
|
2022-12-11 08:10:10 +03:00
|
|
|
parseJson(res.text);
|
2022-11-30 02:50:00 +03:00
|
|
|
expect(ajv.validate(nodeInfoSchema, res.body)).toBe(true);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /api/v1/instance when federation is enabled', async () => {
|
|
|
|
await request
|
2023-12-10 03:31:50 +03:00
|
|
|
.get('/api/v1/instance')
|
2022-12-11 08:10:10 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /federation/user/ when federation is enabled', async () => {
|
2023-12-10 03:31:50 +03:00
|
|
|
const resNoAccept = request.get('/federation/user/').expect(307);
|
|
|
|
const resWithAccept = request
|
|
|
|
.get('/federation/user/')
|
2022-12-11 08:10:10 +03:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(404);
|
2023-12-10 03:31:50 +03:00
|
|
|
const resWithAcceptWrongUsername = request
|
|
|
|
.get('/federation/user/not' + fediUsername)
|
2022-12-11 08:10:10 +03:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(404);
|
2023-12-10 03:31:50 +03:00
|
|
|
const resWithAcceptUsername = request
|
|
|
|
.get('/federation/user/' + fediUsername)
|
2022-12-11 08:10:10 +03:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.then((res) => {
|
|
|
|
parseJson(res.text);
|
|
|
|
});
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|
|
|
|
|
2024-08-22 00:44:09 +03:00
|
|
|
test('verify responses of /federation/ when federation is enabled', async () => {
|
2023-12-10 03:31:50 +03:00
|
|
|
const resNoAccept = request.get('/federation/').expect(307);
|
|
|
|
const resWithAccept = request
|
|
|
|
.get('/federation/')
|
2022-12-11 08:10:10 +03:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(404);
|
2022-11-30 02:49:08 +03:00
|
|
|
});
|