2023-04-07 01:56:46 +00:00
|
|
|
process.env.NODE_ENV = "test";
|
2021-07-10 14:14:57 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
import * as assert from "assert";
|
|
|
|
import rndstr from "rndstr";
|
|
|
|
import { initDb } from "../src/db/postgre.js";
|
|
|
|
import { initTestDb } from "./utils.js";
|
2021-07-10 14:14:57 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("ActivityPub", () => {
|
2021-07-10 14:14:57 +00:00
|
|
|
before(async () => {
|
2022-06-04 05:25:30 +00:00
|
|
|
//await initTestDb();
|
|
|
|
await initDb();
|
2021-07-10 14:14:57 +00:00
|
|
|
});
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("Parse minimum object", () => {
|
|
|
|
const host = "https://host1.test";
|
|
|
|
const preferredUsername = `${rndstr("A-Z", 4)}${rndstr("a-z", 4)}`;
|
2021-07-10 14:14:57 +00:00
|
|
|
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
|
|
|
|
|
|
|
const actor = {
|
2023-04-07 01:56:46 +00:00
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
2021-07-10 14:14:57 +00:00
|
|
|
id: actorId,
|
2023-04-07 01:56:46 +00:00
|
|
|
type: "Person",
|
2021-07-10 14:14:57 +00:00
|
|
|
preferredUsername,
|
|
|
|
inbox: `${actorId}/inbox`,
|
|
|
|
outbox: `${actorId}/outbox`,
|
|
|
|
};
|
|
|
|
|
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
id: `${host}/users/${rndstr("0-9a-z", 8)}`,
|
|
|
|
type: "Note",
|
2021-07-10 14:14:57 +00:00
|
|
|
attributedTo: actor.id,
|
2023-04-07 01:56:46 +00:00
|
|
|
to: "https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
content: "あ",
|
2021-07-10 14:14:57 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Minimum Actor", async () => {
|
|
|
|
const { MockResolver } = await import("./misc/mock-resolver.js");
|
|
|
|
const { createPerson } = await import(
|
|
|
|
"../src/remote/activitypub/models/person.js"
|
|
|
|
);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
|
|
|
const resolver = new MockResolver();
|
|
|
|
resolver._register(actor.id, actor);
|
|
|
|
|
|
|
|
const user = await createPerson(actor.id, resolver);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(user.uri, actor.id);
|
|
|
|
assert.deepStrictEqual(user.username, actor.preferredUsername);
|
|
|
|
assert.deepStrictEqual(user.inbox, actor.inbox);
|
|
|
|
});
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Minimum Note", async () => {
|
|
|
|
const { MockResolver } = await import("./misc/mock-resolver.js");
|
|
|
|
const { createNote } = await import(
|
|
|
|
"../src/remote/activitypub/models/note.js"
|
|
|
|
);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
|
|
|
const resolver = new MockResolver();
|
|
|
|
resolver._register(actor.id, actor);
|
|
|
|
resolver._register(post.id, post);
|
|
|
|
|
|
|
|
const note = await createNote(post.id, resolver, true);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(note?.uri, post.id);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.deepStrictEqual(note.visibility, "public");
|
2022-05-21 13:21:41 +00:00
|
|
|
assert.deepStrictEqual(note.text, post.content);
|
2021-07-10 14:14:57 +00:00
|
|
|
});
|
|
|
|
});
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("Truncate long name", () => {
|
|
|
|
const host = "https://host1.test";
|
|
|
|
const preferredUsername = `${rndstr("A-Z", 4)}${rndstr("a-z", 4)}`;
|
2021-08-17 08:25:19 +00:00
|
|
|
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const name = rndstr("0-9a-z", 129);
|
2021-08-17 08:25:19 +00:00
|
|
|
|
|
|
|
const actor = {
|
2023-04-07 01:56:46 +00:00
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
2021-08-17 08:25:19 +00:00
|
|
|
id: actorId,
|
2023-04-07 01:56:46 +00:00
|
|
|
type: "Person",
|
2021-08-17 08:25:19 +00:00
|
|
|
preferredUsername,
|
|
|
|
name,
|
|
|
|
inbox: `${actorId}/inbox`,
|
|
|
|
outbox: `${actorId}/outbox`,
|
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("Actor", async () => {
|
|
|
|
const { MockResolver } = await import("./misc/mock-resolver.js");
|
|
|
|
const { createPerson } = await import(
|
|
|
|
"../src/remote/activitypub/models/person.js"
|
|
|
|
);
|
2021-08-17 08:25:19 +00:00
|
|
|
|
|
|
|
const resolver = new MockResolver();
|
|
|
|
resolver._register(actor.id, actor);
|
|
|
|
|
|
|
|
const user = await createPerson(actor.id, resolver);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(user.name, actor.name.substr(0, 128));
|
|
|
|
});
|
|
|
|
});
|
2021-07-10 14:14:57 +00:00
|
|
|
});
|