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