2021-11-07 01:04:32 -08:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-03-02 18:13:12 -08:00
|
|
|
import { signup, api, startServer, simpleGet } from '../utils.js';
|
|
|
|
import type { INestApplicationContext } from '@nestjs/common';
|
2021-11-07 01:04:32 -08:00
|
|
|
|
|
|
|
describe('FF visibility', () => {
|
2023-03-12 04:57:01 -07:00
|
|
|
let app: INestApplicationContext;
|
2021-11-07 01:04:32 -08:00
|
|
|
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
|
2022-09-17 11:27:08 -07:00
|
|
|
beforeAll(async () => {
|
2023-03-12 04:57:01 -07:00
|
|
|
app = await startServer();
|
2021-11-07 01:04:32 -08:00
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2023-03-02 18:13:12 -08:00
|
|
|
}, 1000 * 60 * 2);
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2022-09-17 11:27:08 -07:00
|
|
|
afterAll(async () => {
|
2023-03-12 04:57:01 -07:00
|
|
|
await app.close();
|
2021-11-07 01:04:32 -08:00
|
|
|
});
|
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が public なユーザーのフォロー/フォロワーを誰でも見れる', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'public',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followersRes.body), true);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーを自分で見れる', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followersRes.body), true);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーを非フォロワーが見れない', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 400);
|
|
|
|
assert.strictEqual(followersRes.status, 400);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーをフォロワーが見れる', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/following/create', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followersRes.body), true);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が private なユーザーのフォロー/フォロワーを自分で見れる', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followingRes.body), true);
|
|
|
|
assert.strictEqual(followersRes.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(followersRes.body), true);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が private なユーザーのフォロー/フォロワーを他人が見れない', async () => {
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-02 18:13:12 -08:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 01:04:32 -08:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 400);
|
|
|
|
assert.strictEqual(followersRes.status, 400);
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
|
|
|
|
describe('AP', () => {
|
2023-02-02 01:18:25 -08:00
|
|
|
test('ffVisibility が public 以外ならばAPからは取得できない', async () => {
|
2021-11-07 01:04:32 -08:00
|
|
|
{
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'public',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
{
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json');
|
|
|
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json');
|
2021-11-07 01:04:32 -08:00
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
}
|
|
|
|
{
|
2023-03-02 18:13:12 -08:00
|
|
|
await api('/i/update', {
|
2021-11-07 01:04:32 -08:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 18:13:12 -08:00
|
|
|
const followingRes = await simpleGet(`/users/${alice.id}/following`, 'application/activity+json');
|
|
|
|
const followersRes = await simpleGet(`/users/${alice.id}/followers`, 'application/activity+json');
|
2021-11-07 01:04:32 -08:00
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
}
|
2022-09-17 11:27:08 -07:00
|
|
|
});
|
2021-11-07 01:04:32 -08:00
|
|
|
});
|
|
|
|
});
|