fix: broken call to request lib, tests

This commit is contained in:
Julian Lam
2023-12-21 14:38:16 -05:00
parent 00bda0688d
commit 8d79617044
4 changed files with 36 additions and 118 deletions

View File

@@ -1876,59 +1876,34 @@ describe('Controllers', () => {
});
it('should error if resource parameter is missing', async () => {
const response = await requestAsync(`${nconf.get('url')}/.well-known/webfinger`, {
json: true,
simple: false,
resolveWithFullResponse: true,
});
const { response } = await request.get(`${nconf.get('url')}/.well-known/webfinger`);
assert.strictEqual(response.statusCode, 400);
});
it('should error if resource parameter is malformed', async () => {
const response = await requestAsync(`${nconf.get('url')}/.well-known/webfinger?resource=foobar`, {
json: true,
simple: false,
resolveWithFullResponse: true,
});
const { response } = await request.get(`${nconf.get('url')}/.well-known/webfinger?resource=foobar`);
assert.strictEqual(response.statusCode, 400);
});
it('should deny access if view:users privilege is not enabled for guests', async () => {
await privileges.global.rescind(['groups:view:users'], 'guests');
const response = await requestAsync(`${nconf.get('url')}/.well-known/webfinger?resource=acct:${username}@${nconf.get('url_parsed').host}`, {
json: true,
simple: false,
resolveWithFullResponse: true,
});
const { response } = await request.get(`${nconf.get('url')}/.well-known/webfinger?resource=acct:${username}@${nconf.get('url_parsed').host}`);
assert.strictEqual(response.statusCode, 403);
await privileges.global.give(['groups:view:users'], 'guests');
});
it('should respond appropriately if the user requested does not exist locally', async () => {
const response = await requestAsync(`${nconf.get('url')}/.well-known/webfinger?resource=acct:foobar@${nconf.get('url_parsed').host}`, {
json: true,
simple: false,
resolveWithFullResponse: true,
});
const { response } = await request.get(`${nconf.get('url')}/.well-known/webfinger?resource=acct:foobar@${nconf.get('url_parsed').host}`);
assert.strictEqual(response.statusCode, 404);
});
it('should return a valid webfinger response if the user exists', async () => {
const response = await requestAsync(`${nconf.get('url')}/.well-known/webfinger?resource=acct:${username}@${nconf.get('url_parsed').host}`, {
json: true,
simple: false,
resolveWithFullResponse: true,
});
const { response, body } = await request.get(`${nconf.get('url')}/.well-known/webfinger?resource=acct:${username}@${nconf.get('url_parsed').host}`);
assert.strictEqual(response.statusCode, 200);
assert(['subject', 'aliases', 'links'].every(prop => response.body.hasOwnProperty(prop)));
assert(response.body.subject, `acct:${username}@${nconf.get('url_parsed').host}`);
assert(['subject', 'aliases', 'links'].every(prop => body.hasOwnProperty(prop)));
assert(body.subject, `acct:${username}@${nconf.get('url_parsed').host}`);
});
});
});