2022-11-30 00:50:00 +01:00
|
|
|
var request = require('supertest');
|
|
|
|
const jsonfile = require('jsonfile');
|
|
|
|
const Ajv = require('ajv-draft-04');
|
2022-12-08 19:07:54 +01:00
|
|
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
2022-11-30 00:49:08 +01:00
|
|
|
|
|
|
|
request = request('http://127.0.0.1:8080');
|
|
|
|
|
|
|
|
var ajv = new Ajv();
|
|
|
|
var nodeInfoSchema = jsonfile.readFileSync('schema/nodeinfo_2.0.json');
|
|
|
|
|
2022-12-08 01:26:06 +01:00
|
|
|
const serverURL = 'owncast.server.test'
|
|
|
|
const fediUsername = 'streamer'
|
|
|
|
|
2022-11-30 00:49:08 +01:00
|
|
|
test('disable federation', async (done) => {
|
2022-12-08 19:07:54 +01:00
|
|
|
const res = await sendAdminRequest('config/federation/enable', false);
|
2022-11-30 00:50:00 +01:00
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/webfinger when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/webfinger').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/host-meta when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/host-meta').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/nodeinfo when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/nodeinfo').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/x-nodeinfo2 when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/x-nodeinfo2').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /nodeinfo/2.0 when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/nodeinfo/2.0').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /api/v1/instance when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/api/v1/instance').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /federation/user/ when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/federation/user/').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /federation/ when federation is disabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/federation/').expect(405);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
2022-12-08 01:26:06 +01:00
|
|
|
test('set required parameters and enable federation', async (done) => {
|
2022-12-08 19:07:54 +01:00
|
|
|
const res1 = await sendAdminRequest(
|
|
|
|
'config/serverurl',
|
2022-12-08 01:26:06 +01:00
|
|
|
serverURL
|
|
|
|
);
|
2022-12-08 19:07:54 +01:00
|
|
|
const res2 = await sendAdminRequest(
|
|
|
|
'config/federation/username',
|
2022-12-08 01:26:06 +01:00
|
|
|
fediUsername
|
|
|
|
);
|
2022-12-08 19:07:54 +01:00
|
|
|
const res3 = await sendAdminRequest('config/federation/enable', true);
|
2022-11-30 00:50:00 +01:00
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/webfinger when federation is enabled', async (done) => {
|
2022-12-08 01:26:06 +01:00
|
|
|
const resNoResource = request.get('/.well-known/webfinger').expect(400);
|
|
|
|
const resBadResource = request.get(
|
|
|
|
'/.well-known/webfinger?resource=' + fediUsername + '@' + serverURL
|
|
|
|
).expect(400);
|
|
|
|
const resBadServer = request.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:' + fediUsername + '@not.my.server.lol'
|
|
|
|
).expect(404);
|
|
|
|
const resBadUser = request.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:not' + fediUsername + '@' + serverURL
|
|
|
|
).expect(404);
|
|
|
|
const res = request.get(
|
|
|
|
'/.well-known/webfinger?resource=acct:' + fediUsername + '@' + serverURL
|
|
|
|
).expect(200);
|
2022-11-30 00:50:00 +01:00
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/host-meta when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/host-meta').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/nodeinfo when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/nodeinfo').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /.well-known/x-nodeinfo2 when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/.well-known/x-nodeinfo2').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /nodeinfo/2.0 when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request
|
|
|
|
.get('/nodeinfo/2.0')
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
expect(ajv.validate(nodeInfoSchema, res.body)).toBe(true);
|
|
|
|
done();
|
|
|
|
});
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /api/v1/instance when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/api/v1/instance').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /federation/user/ when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/federation/user/').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('verify responses of /federation/ when federation is enabled', async (done) => {
|
2022-11-30 00:50:00 +01:00
|
|
|
const res = request.get('/federation/').expect(200);
|
|
|
|
done();
|
2022-11-30 00:49:08 +01:00
|
|
|
});
|