2021-11-07 09:04:32 +00:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
|
|
|
import * as childProcess from 'child_process';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { async, signup, request, post, react, connectStream, startServer, shutdownServer, simpleGet } from './utils.js';
|
2021-11-07 09:04:32 +00:00
|
|
|
|
2023-05-31 10:42:13 +00:00
|
|
|
describe('FF visibility', function() {
|
|
|
|
this.timeout(20*60*1000);
|
|
|
|
|
2021-11-07 09:04:32 +00:00
|
|
|
let p: childProcess.ChildProcess;
|
|
|
|
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
2023-05-07 21:35:29 +00:00
|
|
|
let follower: any;
|
2021-11-07 09:04:32 +00:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2023-05-07 21:35:29 +00:00
|
|
|
follower = await signup({ username: 'follower' });
|
|
|
|
|
|
|
|
await request('/following/create', { userId: alice.id }, follower);
|
2021-11-07 09:04:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
|
|
|
});
|
|
|
|
|
2023-05-07 21:35:29 +00:00
|
|
|
const visible = (user) => {
|
|
|
|
return async () => {
|
|
|
|
const followingRes = await request('/users/following', {
|
|
|
|
userId: alice.id,
|
|
|
|
}, user);
|
|
|
|
const followersRes = await request('/users/followers', {
|
|
|
|
userId: alice.id,
|
|
|
|
}, user);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.ok(Array.isArray(followingRes.body));
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
assert.ok(Array.isArray(followersRes.body));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const hidden = (user) => {
|
|
|
|
return async () => {
|
|
|
|
const followingRes = await request('/users/following', {
|
|
|
|
userId: alice.id,
|
|
|
|
}, user);
|
|
|
|
const followersRes = await request('/users/followers', {
|
|
|
|
userId: alice.id,
|
|
|
|
}, user);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('public visibility', () => {
|
|
|
|
before(async () => {
|
|
|
|
await request('/i/update', {
|
|
|
|
ffVisibility: 'public',
|
|
|
|
}, alice);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows followers and following to self', visible(alice));
|
|
|
|
it('shows followers and following to a follower', visible(follower));
|
|
|
|
it('shows followers and following to a non-follower', visible(bob));
|
|
|
|
it('shows followers and following when unauthenticated', visible(null));
|
|
|
|
|
|
|
|
it('provides followers in ActivityPub representation', async () => {
|
|
|
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json');
|
|
|
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json');
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('followers visibility', () => {
|
|
|
|
before(async () => {
|
|
|
|
await request('/i/update', {
|
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows followers and following to self', visible(alice));
|
|
|
|
it('shows followers and following to a follower', visible(follower));
|
|
|
|
it('hides followers and following from a non-follower', hidden(bob));
|
|
|
|
it('hides followers and following when unauthenticated', hidden(null));
|
|
|
|
|
|
|
|
it('hides followers from ActivityPub representation', async () => {
|
|
|
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
|
|
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('private visibility', () => {
|
|
|
|
before(async () => {
|
|
|
|
await request('/i/update', {
|
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows followers and following to self', visible(alice));
|
|
|
|
it('hides followers and following from a follower', hidden(follower));
|
|
|
|
it('hides followers and following from a non-follower', hidden(bob));
|
|
|
|
it('hides followers and following when unauthenticated', hidden(null));
|
|
|
|
|
|
|
|
it('hides followers from ActivityPub representation', async () => {
|
|
|
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
|
|
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json').catch(res => ({ status: res.statusCode }));
|
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
});
|
2021-11-07 09:04:32 +00:00
|
|
|
});
|
|
|
|
});
|