2023-07-27 14:31:52 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-11-07 18:04:32 +09:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-03-03 11:13:12 +09:00
|
|
|
import { signup, api, startServer, simpleGet } from '../utils.js';
|
|
|
|
import type { INestApplicationContext } from '@nestjs/common';
|
2023-06-25 08:34:18 +09:00
|
|
|
import type * as misskey from 'misskey-js';
|
2021-11-07 18:04:32 +09:00
|
|
|
|
|
|
|
describe('FF visibility', () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
let app: INestApplicationContext;
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-06-25 08:34:18 +09:00
|
|
|
let alice: misskey.entities.MeSignup;
|
|
|
|
let bob: misskey.entities.MeSignup;
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
beforeAll(async () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
app = await startServer();
|
2021-11-07 18:04:32 +09:00
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2023-03-03 11:13:12 +09:00
|
|
|
}, 1000 * 60 * 2);
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
afterAll(async () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
await app.close();
|
2021-11-07 18:04:32 +09:00
|
|
|
});
|
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が public なユーザーのフォロー/フォロワーを誰でも見れる', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'public',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09: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-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーを自分で見れる', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09: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-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーを非フォロワーが見れない', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 400);
|
|
|
|
assert.strictEqual(followersRes.status, 400);
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が followers なユーザーのフォロー/フォロワーをフォロワーが見れる', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/following/create', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09: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-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が private なユーザーのフォロー/フォロワーを自分で見れる', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09: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-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が private なユーザーのフォロー/フォロワーを他人が見れない', async () => {
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const followingRes = await api('/users/following', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
2023-03-03 11:13:12 +09:00
|
|
|
const followersRes = await api('/users/followers', {
|
2021-11-07 18:04:32 +09:00
|
|
|
userId: alice.id,
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(followingRes.status, 400);
|
|
|
|
assert.strictEqual(followersRes.status, 400);
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
|
|
|
|
describe('AP', () => {
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ffVisibility が public 以外ならばAPからは取得できない', async () => {
|
2021-11-07 18:04:32 +09:00
|
|
|
{
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09: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-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09: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 18:04:32 +09:00
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
}
|
|
|
|
{
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/update', {
|
2021-11-07 18:04:32 +09:00
|
|
|
ffVisibility: 'private',
|
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 11:13:12 +09: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 18:04:32 +09:00
|
|
|
assert.strictEqual(followingRes.status, 403);
|
|
|
|
assert.strictEqual(followersRes.status, 403);
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-11-07 18:04:32 +09:00
|
|
|
});
|
|
|
|
});
|