iceshrimp-161sh/packages/backend/test/ff-visibility.ts

284 lines
5.9 KiB
TypeScript
Raw Normal View History

2023-04-07 03:56:46 +02:00
process.env.NODE_ENV = "test";
2023-04-07 03:56:46 +02:00
import * as assert from "assert";
import * as childProcess from "child_process";
import {
async,
signup,
request,
post,
react,
connectStream,
startServer,
shutdownServer,
simpleGet,
} from "./utils.js";
2023-04-07 03:56:46 +02:00
describe("FF visibility", () => {
let p: childProcess.ChildProcess;
let alice: any;
let bob: any;
let carol: any;
before(async () => {
p = await startServer();
2023-04-07 03:56:46 +02:00
alice = await signup({ username: "alice" });
bob = await signup({ username: "bob" });
carol = await signup({ username: "carol" });
});
after(async () => {
await shutdownServer(p);
});
2023-04-07 03:56:46 +02:00
it("ffVisibility が public なユーザーのフォロー/フォロワーを誰でも見れる", async(async () => {
await request(
"/i/update",
{
ffVisibility: "public",
},
alice,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
bob,
);
const followersRes = await request(
"/users/followers",
{
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);
}));
2023-04-07 03:56:46 +02:00
it("ffVisibility が followers なユーザーのフォロー/フォロワーを自分で見れる", async(async () => {
await request(
"/i/update",
{
ffVisibility: "followers",
},
alice,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
alice,
);
const followersRes = await request(
"/users/followers",
{
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);
}));
2023-04-07 03:56:46 +02:00
it("ffVisibility が followers なユーザーのフォロー/フォロワーを非フォロワーが見れない", async(async () => {
await request(
"/i/update",
{
ffVisibility: "followers",
},
alice,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
bob,
);
const followersRes = await request(
"/users/followers",
{
userId: alice.id,
},
bob,
);
assert.strictEqual(followingRes.status, 400);
assert.strictEqual(followersRes.status, 400);
}));
2023-04-07 03:56:46 +02:00
it("ffVisibility が followers なユーザーのフォロー/フォロワーをフォロワーが見れる", async(async () => {
await request(
"/i/update",
{
ffVisibility: "followers",
},
alice,
);
2023-04-07 03:56:46 +02:00
await request(
"/following/create",
{
userId: alice.id,
},
bob,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
bob,
);
const followersRes = await request(
"/users/followers",
{
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);
}));
2023-04-07 03:56:46 +02:00
it("ffVisibility が private なユーザーのフォロー/フォロワーを自分で見れる", async(async () => {
await request(
"/i/update",
{
ffVisibility: "private",
},
alice,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
alice,
);
const followersRes = await request(
"/users/followers",
{
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);
}));
2023-04-07 03:56:46 +02:00
it("ffVisibility が private なユーザーのフォロー/フォロワーを他人が見れない", async(async () => {
await request(
"/i/update",
{
ffVisibility: "private",
},
alice,
);
2023-04-07 03:56:46 +02:00
const followingRes = await request(
"/users/following",
{
userId: alice.id,
},
bob,
);
const followersRes = await request(
"/users/followers",
{
userId: alice.id,
},
bob,
);
assert.strictEqual(followingRes.status, 400);
assert.strictEqual(followersRes.status, 400);
}));
2023-04-07 03:56:46 +02:00
describe("AP", () => {
it("ffVisibility が public 以外ならばAPからは取得できない", async(async () => {
{
2023-04-07 03:56:46 +02:00
await request(
"/i/update",
{
ffVisibility: "public",
},
alice,
);
2023-04-07 03:56:46 +02:00
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-04-07 03:56:46 +02:00
await request(
"/i/update",
{
ffVisibility: "followers",
},
alice,
);
2023-04-07 03:56:46 +02:00
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);
}
{
2023-04-07 03:56:46 +02:00
await request(
"/i/update",
{
ffVisibility: "private",
},
alice,
);
2023-04-07 03:56:46 +02:00
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);
}
}));
});
});