2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-07-10 14:14:57 +00:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-02-19 06:27:14 +00:00
|
|
|
import { Test } from '@nestjs/testing';
|
|
|
|
import { jest } from '@jest/globals';
|
|
|
|
|
2023-07-15 11:12:20 +00:00
|
|
|
import { ApImageService } from '@/core/activitypub/models/ApImageService.js';
|
2023-02-19 06:27:14 +00:00
|
|
|
import { ApNoteService } from '@/core/activitypub/models/ApNoteService.js';
|
|
|
|
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
|
2023-03-12 03:11:37 +00:00
|
|
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
2024-05-01 07:33:58 +00:00
|
|
|
import { JsonLdService } from '@/core/activitypub/JsonLdService.js';
|
|
|
|
import { CONTEXT } from '@/core/activitypub/misc/contexts.js';
|
2023-02-19 06:27:14 +00:00
|
|
|
import { GlobalModule } from '@/GlobalModule.js';
|
|
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
|
|
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
|
|
|
import { LoggerService } from '@/core/LoggerService.js';
|
2024-04-28 01:53:33 +00:00
|
|
|
import type { IActor, IApDocument, ICollection, IObject, IPost } from '@/core/activitypub/type.js';
|
2024-08-09 03:10:51 +00:00
|
|
|
import { MiMeta, MiNote, UserProfilesRepository } from '@/models/_.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-06-25 02:04:33 +00:00
|
|
|
import { secureRndstr } from '@/misc/secure-rndstr.js';
|
2023-07-15 11:12:20 +00:00
|
|
|
import { DownloadService } from '@/core/DownloadService.js';
|
2023-09-20 02:33:36 +00:00
|
|
|
import type { MiRemoteUser } from '@/models/User.js';
|
2023-10-16 03:58:17 +00:00
|
|
|
import { genAidx } from '@/misc/id/aidx.js';
|
2023-06-25 02:04:33 +00:00
|
|
|
import { MockResolver } from '../misc/mock-resolver.js';
|
2021-07-10 14:14:57 +00:00
|
|
|
|
2023-02-19 08:49:18 +00:00
|
|
|
const host = 'https://host1.test';
|
|
|
|
|
2023-07-08 23:59:44 +00:00
|
|
|
type NonTransientIActor = IActor & { id: string };
|
|
|
|
type NonTransientIPost = IPost & { id: string };
|
|
|
|
|
|
|
|
function createRandomActor({ actorHost = host } = {}): NonTransientIActor {
|
2023-06-25 02:04:33 +00:00
|
|
|
const preferredUsername = secureRndstr(8);
|
2023-07-08 23:59:44 +00:00
|
|
|
const actorId = `${actorHost}/users/${preferredUsername.toLowerCase()}`;
|
2023-02-19 08:49:18 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: actorId,
|
|
|
|
type: 'Person',
|
|
|
|
preferredUsername,
|
|
|
|
inbox: `${actorId}/inbox`,
|
|
|
|
outbox: `${actorId}/outbox`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-08 23:59:44 +00:00
|
|
|
function createRandomNote(actor: NonTransientIActor): NonTransientIPost {
|
|
|
|
const id = secureRndstr(8);
|
|
|
|
const noteId = `${new URL(actor.id).origin}/notes/${id}`;
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: noteId,
|
|
|
|
type: 'Note',
|
|
|
|
attributedTo: actor.id,
|
|
|
|
content: 'test test foo',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRandomNotes(actor: NonTransientIActor, length: number): NonTransientIPost[] {
|
|
|
|
return new Array(length).fill(null).map(() => createRandomNote(actor));
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRandomFeaturedCollection(actor: NonTransientIActor, length: number): ICollection {
|
|
|
|
const items = createRandomNotes(actor, length);
|
|
|
|
|
|
|
|
return {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
type: 'Collection',
|
|
|
|
id: actor.outbox as string,
|
|
|
|
totalItems: items.length,
|
|
|
|
items,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-15 11:12:20 +00:00
|
|
|
async function createRandomRemoteUser(
|
|
|
|
resolver: MockResolver,
|
|
|
|
personService: ApPersonService,
|
2023-09-05 08:02:14 +00:00
|
|
|
): Promise<MiRemoteUser> {
|
2023-07-15 11:12:20 +00:00
|
|
|
const actor = createRandomActor();
|
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
|
|
|
|
return await personService.createPerson(actor.id, resolver);
|
|
|
|
}
|
|
|
|
|
2021-07-10 14:14:57 +00:00
|
|
|
describe('ActivityPub', () => {
|
2024-08-09 03:10:51 +00:00
|
|
|
let userProfilesRepository: UserProfilesRepository;
|
2023-07-15 11:12:20 +00:00
|
|
|
let imageService: ApImageService;
|
2023-02-19 06:27:14 +00:00
|
|
|
let noteService: ApNoteService;
|
|
|
|
let personService: ApPersonService;
|
2023-03-12 03:11:37 +00:00
|
|
|
let rendererService: ApRendererService;
|
2024-05-01 07:33:58 +00:00
|
|
|
let jsonLdService: JsonLdService;
|
2023-02-19 06:27:14 +00:00
|
|
|
let resolver: MockResolver;
|
|
|
|
|
2023-07-15 11:12:20 +00:00
|
|
|
const metaInitial = {
|
|
|
|
cacheRemoteFiles: true,
|
|
|
|
cacheRemoteSensitiveFiles: true,
|
2023-10-23 06:17:25 +00:00
|
|
|
enableFanoutTimeline: true,
|
2023-11-16 01:20:57 +00:00
|
|
|
enableFanoutTimelineDbFallback: true,
|
2023-10-04 05:45:46 +00:00
|
|
|
perUserHomeTimelineCacheMax: 100,
|
2023-10-04 06:29:09 +00:00
|
|
|
perLocalUserUserTimelineCacheMax: 100,
|
|
|
|
perRemoteUserUserTimelineCacheMax: 100,
|
2023-07-15 11:12:20 +00:00
|
|
|
blockedHosts: [] as string[],
|
|
|
|
sensitiveWords: [] as string[],
|
2024-02-12 19:54:01 +00:00
|
|
|
prohibitedWords: [] as string[],
|
2023-09-05 08:02:14 +00:00
|
|
|
} as MiMeta;
|
2024-09-22 03:53:13 +00:00
|
|
|
const meta = { ...metaInitial };
|
|
|
|
|
|
|
|
function updateMeta(newMeta: Partial<MiMeta>): void {
|
|
|
|
for (const key in meta) {
|
|
|
|
delete (meta as any)[key];
|
|
|
|
}
|
|
|
|
Object.assign(meta, newMeta);
|
|
|
|
}
|
2023-07-15 11:12:20 +00:00
|
|
|
|
2023-07-08 23:59:44 +00:00
|
|
|
beforeAll(async () => {
|
2023-02-19 06:27:14 +00:00
|
|
|
const app = await Test.createTestingModule({
|
|
|
|
imports: [GlobalModule, CoreModule],
|
2023-07-15 11:12:20 +00:00
|
|
|
})
|
|
|
|
.overrideProvider(DownloadService).useValue({
|
|
|
|
async downloadUrl(): Promise<{ filename: string }> {
|
|
|
|
return {
|
|
|
|
filename: 'dummy.tmp',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})
|
2024-09-22 03:53:13 +00:00
|
|
|
.overrideProvider(DI.meta).useFactory({ factory: () => meta })
|
|
|
|
.compile();
|
2023-02-19 06:27:14 +00:00
|
|
|
|
|
|
|
await app.init();
|
|
|
|
app.enableShutdownHooks();
|
|
|
|
|
2024-08-09 03:10:51 +00:00
|
|
|
userProfilesRepository = app.get(DI.userProfilesRepository);
|
|
|
|
|
2023-02-19 06:27:14 +00:00
|
|
|
noteService = app.get<ApNoteService>(ApNoteService);
|
|
|
|
personService = app.get<ApPersonService>(ApPersonService);
|
2023-03-12 03:11:37 +00:00
|
|
|
rendererService = app.get<ApRendererService>(ApRendererService);
|
2023-07-15 11:12:20 +00:00
|
|
|
imageService = app.get<ApImageService>(ApImageService);
|
2024-05-01 07:33:58 +00:00
|
|
|
jsonLdService = app.get<JsonLdService>(JsonLdService);
|
2023-02-19 06:27:14 +00:00
|
|
|
resolver = new MockResolver(await app.resolve<LoggerService>(LoggerService));
|
|
|
|
|
|
|
|
// Prevent ApPersonService from fetching instance, as it causes Jest import-after-test error
|
|
|
|
const federatedInstanceService = app.get<FederatedInstanceService>(FederatedInstanceService);
|
2023-07-08 23:59:44 +00:00
|
|
|
jest.spyOn(federatedInstanceService, 'fetch').mockImplementation(() => new Promise(() => { }));
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
resolver.clear();
|
2023-02-19 06:27:14 +00:00
|
|
|
});
|
|
|
|
|
2021-07-10 14:14:57 +00:00
|
|
|
describe('Parse minimum object', () => {
|
2023-02-19 08:49:18 +00:00
|
|
|
const actor = createRandomActor();
|
2021-07-10 14:14:57 +00:00
|
|
|
|
|
|
|
const post = {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
2023-06-25 02:04:33 +00:00
|
|
|
id: `${host}/users/${secureRndstr(8)}`,
|
2021-07-10 14:14:57 +00:00
|
|
|
type: 'Note',
|
|
|
|
attributedTo: actor.id,
|
|
|
|
to: 'https://www.w3.org/ns/activitystreams#Public',
|
|
|
|
content: 'あ',
|
|
|
|
};
|
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('Minimum Actor', async () => {
|
2023-07-08 23:59:44 +00:00
|
|
|
resolver.register(actor.id, actor);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
2023-02-19 06:27:14 +00:00
|
|
|
const user = await personService.createPerson(actor.id, resolver);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
|
|
|
assert.deepStrictEqual(user.uri, actor.id);
|
|
|
|
assert.deepStrictEqual(user.username, actor.preferredUsername);
|
|
|
|
assert.deepStrictEqual(user.inbox, actor.inbox);
|
|
|
|
});
|
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('Minimum Note', async () => {
|
2023-07-08 23:59:44 +00:00
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
resolver.register(post.id, post);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
2024-11-21 03:10:02 +00:00
|
|
|
const note = await noteService.createNote(post.id, undefined, resolver, true);
|
2021-07-10 14:14:57 +00:00
|
|
|
|
|
|
|
assert.deepStrictEqual(note?.uri, post.id);
|
2022-05-21 13:21:41 +00:00
|
|
|
assert.deepStrictEqual(note.visibility, 'public');
|
|
|
|
assert.deepStrictEqual(note.text, post.content);
|
2021-07-10 14:14:57 +00:00
|
|
|
});
|
|
|
|
});
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-02-19 08:49:18 +00:00
|
|
|
describe('Name field', () => {
|
|
|
|
test('Truncate long name', async () => {
|
|
|
|
const actor = {
|
|
|
|
...createRandomActor(),
|
2023-06-25 02:04:33 +00:00
|
|
|
name: secureRndstr(129),
|
2023-02-19 08:49:18 +00:00
|
|
|
};
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-07-08 23:59:44 +00:00
|
|
|
resolver.register(actor.id, actor);
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-02-19 08:49:18 +00:00
|
|
|
const user = await personService.createPerson(actor.id, resolver);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(user.name, actor.name.slice(0, 128));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Normalize empty name', async () => {
|
|
|
|
const actor = {
|
|
|
|
...createRandomActor(),
|
|
|
|
name: '',
|
|
|
|
};
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-07-08 23:59:44 +00:00
|
|
|
resolver.register(actor.id, actor);
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-02-19 06:27:14 +00:00
|
|
|
const user = await personService.createPerson(actor.id, resolver);
|
2021-08-17 08:25:19 +00:00
|
|
|
|
2023-02-19 08:49:18 +00:00
|
|
|
assert.strictEqual(user.name, null);
|
2021-08-17 08:25:19 +00:00
|
|
|
});
|
|
|
|
});
|
2023-03-12 03:11:37 +00:00
|
|
|
|
2024-08-09 03:10:51 +00:00
|
|
|
describe('Collection visibility', () => {
|
|
|
|
test('Public following/followers', async () => {
|
|
|
|
const actor = createRandomActor();
|
|
|
|
actor.following = {
|
|
|
|
id: `${actor.id}/following`,
|
|
|
|
type: 'OrderedCollection',
|
|
|
|
totalItems: 0,
|
|
|
|
first: `${actor.id}/following?page=1`,
|
|
|
|
};
|
|
|
|
actor.followers = `${actor.id}/followers`;
|
|
|
|
|
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
resolver.register(actor.followers, {
|
|
|
|
id: actor.followers,
|
|
|
|
type: 'OrderedCollection',
|
|
|
|
totalItems: 0,
|
|
|
|
first: `${actor.followers}?page=1`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const user = await personService.createPerson(actor.id, resolver);
|
|
|
|
const userProfile = await userProfilesRepository.findOneByOrFail({ userId: user.id });
|
|
|
|
|
|
|
|
assert.deepStrictEqual(userProfile.followingVisibility, 'public');
|
|
|
|
assert.deepStrictEqual(userProfile.followersVisibility, 'public');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Private following/followers', async () => {
|
|
|
|
const actor = createRandomActor();
|
|
|
|
actor.following = {
|
|
|
|
id: `${actor.id}/following`,
|
|
|
|
type: 'OrderedCollection',
|
|
|
|
totalItems: 0,
|
|
|
|
// first: …
|
|
|
|
};
|
|
|
|
actor.followers = `${actor.id}/followers`;
|
|
|
|
|
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
//resolver.register(actor.followers, { … });
|
|
|
|
|
|
|
|
const user = await personService.createPerson(actor.id, resolver);
|
|
|
|
const userProfile = await userProfilesRepository.findOneByOrFail({ userId: user.id });
|
|
|
|
|
|
|
|
assert.deepStrictEqual(userProfile.followingVisibility, 'private');
|
|
|
|
assert.deepStrictEqual(userProfile.followersVisibility, 'private');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-12 03:11:37 +00:00
|
|
|
describe('Renderer', () => {
|
|
|
|
test('Render an announce with visibility: followers', () => {
|
2024-02-17 03:41:19 +00:00
|
|
|
rendererService.renderAnnounce('https://example.com/notes/00example', {
|
2023-10-16 03:58:17 +00:00
|
|
|
id: genAidx(Date.now()),
|
2023-03-12 03:11:37 +00:00
|
|
|
visibility: 'followers',
|
2023-09-05 08:02:14 +00:00
|
|
|
} as MiNote);
|
2023-03-12 03:11:37 +00:00
|
|
|
});
|
|
|
|
});
|
2023-07-08 23:59:44 +00:00
|
|
|
|
|
|
|
describe('Featured', () => {
|
|
|
|
test('Fetch featured notes from IActor', async () => {
|
|
|
|
const actor = createRandomActor();
|
|
|
|
actor.featured = `${actor.id}/collections/featured`;
|
|
|
|
|
|
|
|
const featured = createRandomFeaturedCollection(actor, 5);
|
|
|
|
|
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
resolver.register(actor.featured, featured);
|
|
|
|
|
|
|
|
await personService.createPerson(actor.id, resolver);
|
|
|
|
|
|
|
|
// All notes in `featured` are same-origin, no need to fetch notes again
|
|
|
|
assert.deepStrictEqual(resolver.remoteGetTrials(), [actor.id, actor.featured]);
|
|
|
|
|
|
|
|
// Created notes without resolving anything
|
|
|
|
for (const item of featured.items as IPost[]) {
|
|
|
|
const note = await noteService.fetchNote(item);
|
|
|
|
assert.ok(note);
|
|
|
|
assert.strictEqual(note.text, 'test test foo');
|
|
|
|
assert.strictEqual(note.uri, item.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Fetch featured notes from IActor pointing to another remote server', async () => {
|
|
|
|
const actor1 = createRandomActor();
|
|
|
|
actor1.featured = `${actor1.id}/collections/featured`;
|
|
|
|
const actor2 = createRandomActor({ actorHost: 'https://host2.test' });
|
|
|
|
|
|
|
|
const actor2Note = createRandomNote(actor2);
|
|
|
|
const featured = createRandomFeaturedCollection(actor1, 0);
|
|
|
|
(featured.items as IPost[]).push({
|
|
|
|
...actor2Note,
|
|
|
|
content: 'test test bar', // fraud!
|
|
|
|
});
|
|
|
|
|
|
|
|
resolver.register(actor1.id, actor1);
|
|
|
|
resolver.register(actor1.featured, featured);
|
|
|
|
resolver.register(actor2.id, actor2);
|
|
|
|
resolver.register(actor2Note.id, actor2Note);
|
|
|
|
|
|
|
|
await personService.createPerson(actor1.id, resolver);
|
|
|
|
|
|
|
|
// actor2Note is from a different server and needs to be fetched again
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
resolver.remoteGetTrials(),
|
|
|
|
[actor1.id, actor1.featured, actor2Note.id, actor2.id],
|
|
|
|
);
|
|
|
|
|
|
|
|
const note = await noteService.fetchNote(actor2Note.id);
|
|
|
|
assert.ok(note);
|
|
|
|
|
|
|
|
// Reflects the original content instead of the fraud
|
|
|
|
assert.strictEqual(note.text, 'test test foo');
|
|
|
|
assert.strictEqual(note.uri, actor2Note.id);
|
|
|
|
});
|
2023-08-08 04:26:03 +00:00
|
|
|
|
|
|
|
test('Fetch a note that is a featured note of the attributed actor', async () => {
|
|
|
|
const actor = createRandomActor();
|
|
|
|
actor.featured = `${actor.id}/collections/featured`;
|
|
|
|
|
|
|
|
const featured = createRandomFeaturedCollection(actor, 5);
|
|
|
|
const firstNote = (featured.items as NonTransientIPost[])[0];
|
|
|
|
|
|
|
|
resolver.register(actor.id, actor);
|
|
|
|
resolver.register(actor.featured, featured);
|
|
|
|
resolver.register(firstNote.id, firstNote);
|
|
|
|
|
2024-11-21 03:10:02 +00:00
|
|
|
const note = await noteService.createNote(firstNote.id as string, undefined, resolver);
|
2023-08-08 04:26:03 +00:00
|
|
|
assert.strictEqual(note?.uri, firstNote.id);
|
|
|
|
});
|
2023-07-08 23:59:44 +00:00
|
|
|
});
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
describe('Images', () => {
|
|
|
|
test('Create images', async () => {
|
|
|
|
const imageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/foo.png',
|
|
|
|
name: '',
|
|
|
|
};
|
|
|
|
const driveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
imageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(driveFile && !driveFile.isLink);
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
const sensitiveImageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/bar.png',
|
|
|
|
name: '',
|
|
|
|
sensitive: true,
|
|
|
|
};
|
|
|
|
const sensitiveDriveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
sensitiveImageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(sensitiveDriveFile && !sensitiveDriveFile.isLink);
|
2023-07-15 11:12:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('cacheRemoteFiles=false disables caching', async () => {
|
2024-09-22 03:53:13 +00:00
|
|
|
updateMeta({ ...metaInitial, cacheRemoteFiles: false });
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
const imageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/foo.png',
|
|
|
|
name: '',
|
|
|
|
};
|
|
|
|
const driveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
imageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(driveFile && driveFile.isLink);
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
const sensitiveImageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/bar.png',
|
|
|
|
name: '',
|
|
|
|
sensitive: true,
|
|
|
|
};
|
|
|
|
const sensitiveDriveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
sensitiveImageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(sensitiveDriveFile && sensitiveDriveFile.isLink);
|
2023-07-15 11:12:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('cacheRemoteSensitiveFiles=false only affects sensitive files', async () => {
|
2024-09-22 03:53:13 +00:00
|
|
|
updateMeta({ ...metaInitial, cacheRemoteSensitiveFiles: false });
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
const imageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/foo.png',
|
|
|
|
name: '',
|
|
|
|
};
|
|
|
|
const driveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
imageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(driveFile && !driveFile.isLink);
|
2023-07-15 11:12:20 +00:00
|
|
|
|
|
|
|
const sensitiveImageObject: IApDocument = {
|
|
|
|
type: 'Document',
|
|
|
|
mediaType: 'image/png',
|
|
|
|
url: 'http://host1.test/bar.png',
|
|
|
|
name: '',
|
|
|
|
sensitive: true,
|
|
|
|
};
|
|
|
|
const sensitiveDriveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
sensitiveImageObject,
|
|
|
|
);
|
2024-04-28 01:53:33 +00:00
|
|
|
assert.ok(sensitiveDriveFile && sensitiveDriveFile.isLink);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Link is not an attachment files', async () => {
|
|
|
|
const linkObject: IObject = {
|
|
|
|
type: 'Link',
|
|
|
|
href: 'https://example.com/',
|
|
|
|
};
|
|
|
|
const driveFile = await imageService.createImage(
|
|
|
|
await createRandomRemoteUser(resolver, personService),
|
|
|
|
linkObject,
|
|
|
|
);
|
|
|
|
assert.strictEqual(driveFile, null);
|
2023-07-15 11:12:20 +00:00
|
|
|
});
|
|
|
|
});
|
2024-05-01 07:33:58 +00:00
|
|
|
|
|
|
|
describe('JSON-LD', () =>{
|
|
|
|
test('Compaction', async () => {
|
|
|
|
const jsonLd = jsonLdService.use();
|
|
|
|
|
|
|
|
const object = {
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
{
|
|
|
|
_misskey_quote: 'https://misskey-hub.net/ns#_misskey_quote',
|
|
|
|
unknown: 'https://example.org/ns#unknown',
|
|
|
|
undefined: null,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
id: 'https://example.com/notes/42',
|
|
|
|
type: 'Note',
|
|
|
|
attributedTo: 'https://example.com/users/1',
|
|
|
|
to: ['https://www.w3.org/ns/activitystreams#Public'],
|
|
|
|
content: 'test test foo',
|
|
|
|
_misskey_quote: 'https://example.com/notes/1',
|
|
|
|
unknown: 'test test bar',
|
|
|
|
undefined: 'test test baz',
|
|
|
|
};
|
|
|
|
const compacted = await jsonLd.compact(object);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(compacted, {
|
|
|
|
'@context': CONTEXT,
|
|
|
|
id: 'https://example.com/notes/42',
|
|
|
|
type: 'Note',
|
|
|
|
attributedTo: 'https://example.com/users/1',
|
|
|
|
to: 'as:Public',
|
|
|
|
content: 'test test foo',
|
|
|
|
_misskey_quote: 'https://example.com/notes/1',
|
|
|
|
'https://example.org/ns#unknown': 'test test bar',
|
|
|
|
// undefined: 'test test baz',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-07-10 14:14:57 +00:00
|
|
|
});
|