yumechi-no-kuni/packages/backend/test-federation/test/drive.test.ts

176 lines
6.1 KiB
TypeScript
Raw Normal View History

test(backend): add federation test (#14582) * test(backend): add federation test * fix(ci): install pnpm * fix(ci): cd * fix(ci): build entire project * fix(ci): skip frontend build * fix(ci): pull submodule when checkout * chore: show log for debugging * Revert "chore: show log for debugging" This reverts commit a930964b8d6ba550c23bce1e7fb45d92eab49ef9. * fix(ci): build entire project * chore: omit unused globals * refactor: use strictEqual and simplify some asserts * test: follow requests * refactor: add resolveRemoteNote function * refactor: refine resolveRemoteUser function * refactor: cache admin credentials * refactor: simplify assertion with excluded fields * refactor: use assert * test: note * chore: labeler detect federation * test: blocking * test: move * fix: use appropriate TLD * chore: shorter purge interval * fix(ci): change TLD * refactor: delete trivial comment * test(user): isCat * chore: use jest * chore: omit logs * chore: add memo * fix(ci): omit unnecessary build * test: pinning Note * fix: build daemon in container * style: indent * test(streaming): timeline * chore: rename * fix: delete role after test * refactor: resolve users by uri * fix: delete antenna after test * test: api timeline * test: Note deletion * refactor: sleep function * test: notification * style: indent * refactor: type-safe host * docs: update description * refactor: resolve function params * fix(block): wrong test name * fix: invalid type * fix: longer timeout for fire testing * test(timeline): hashtag * test(note): vote delivery * fix: wrong description * fix: hashtag channel param type * refactor: wrap basic cases * test(timeline): add homeTimeline tests * fix(timeline): correct wrong case and description * test(notification): add tests for Note * refactor(user): wrap profile consistency with describe * chore(note): add issue link * test(timeline): add test * test(user): suspension * test: emoji * refactor: fetch admin first * perf: faster tests * test(drive): sensitive flag * test(emoji): add tests * chore: ignore .config/docker.env * chore: hard-coded tester IP address * test(emoji): custom emoji are surrounded by zero width space * refactor: client and username as property * test(notification): mute * fix(notification): correct description * test(block): mention * refactor(emoji): addCustomEmoji function * fix: typo * test(note): add reaction tests * test(timeline): Note deletion * fix: unnecessary ts-expect-error * refactor: unnecessary fetch mocking * chore: add TODO comments * test(user): deletion * chore: enable --frozen-lockfile * fix(ci): copying configs * docs: update CONTRIBUTING.md * docs: fix typo * chore: set default sleep duration * fix(notification): omit flaky tests * fix(notification): correct type * test(notification): add api endpoint tests * chore: remove redundant mute test * refactor: use param client * fix: start timer after trigger * refactor: remove unnecessary any * chore: shorter timeout for checking if fired * fix(block): remove outdated comment * refactor: shorten remote user variable name * refactor(block): use existing function * refactor: file upload * docs: update description * test(user): ffVisibility * fix: `/api/signin` -> `/api/signin-flow` * test: abuse report * refactor: use existing type * refactor: extract duplicate configs to template file * fix: typo * fix: avoid conflict * refactor: change container dependency * perf: start misskey parallelly * fix: remove dependency * chore(backend): add typecheck * test: add check for #14728 * chore: enable eslint check * perf: don't start linked services when test * test(note): remote note deletion for moderation * chore: define config template * chore: write setup script * refactor: omit unnecessary conditional * refactor: clarify scope * refactor: omit type assertion * refactor: omit logs * style * refactor: redundant promise * refactor: unnecessary imports * refactor: use readable error code * refactor: cache set in signin function * refactor: optimize import
2024-10-14 23:37:00 -05:00
import assert, { strictEqual } from 'node:assert';
import * as Misskey from 'misskey-js';
import { createAccount, deepStrictEqualWithExcludedFields, fetchAdmin, type LoginUser, resolveRemoteNote, resolveRemoteUser, sleep, uploadFile } from './utils.js';
const bAdmin = await fetchAdmin('b.test');
describe('Drive', () => {
describe('Upload image in a.test and resolve from b.test', () => {
let uploader: LoginUser;
beforeAll(async () => {
uploader = await createAccount('a.test');
});
let image: Misskey.entities.DriveFile, imageInB: Misskey.entities.DriveFile;
describe('Upload', () => {
beforeAll(async () => {
image = await uploadFile('a.test', uploader);
const noteWithImage = (await uploader.client.request('notes/create', { fileIds: [image.id] })).createdNote;
const noteInB = await resolveRemoteNote('a.test', noteWithImage.id, bAdmin);
assert(noteInB.files != null);
strictEqual(noteInB.files.length, 1);
imageInB = noteInB.files[0];
});
test('Check consistency of DriveFile', () => {
// console.log(`a.test: ${JSON.stringify(image, null, '\t')}`);
// console.log(`b.test: ${JSON.stringify(imageInB, null, '\t')}`);
deepStrictEqualWithExcludedFields(image, imageInB, [
'id',
'createdAt',
'size',
'url',
'thumbnailUrl',
'userId',
]);
});
});
let updatedImage: Misskey.entities.DriveFile, updatedImageInB: Misskey.entities.DriveFile;
describe('Update', () => {
beforeAll(async () => {
updatedImage = await uploader.client.request('drive/files/update', {
fileId: image.id,
name: 'updated_192.jpg',
isSensitive: true,
});
updatedImageInB = await bAdmin.client.request('drive/files/show', {
fileId: imageInB.id,
});
});
test('Check consistency', () => {
// console.log(`a.test: ${JSON.stringify(updatedImage, null, '\t')}`);
// console.log(`b.test: ${JSON.stringify(updatedImageInB, null, '\t')}`);
// FIXME: not updated with `drive/files/update`
strictEqual(updatedImage.isSensitive, true);
strictEqual(updatedImage.name, 'updated_192.jpg');
strictEqual(updatedImageInB.isSensitive, false);
strictEqual(updatedImageInB.name, '192.jpg');
});
});
let reupdatedImageInB: Misskey.entities.DriveFile;
describe('Re-update with attaching to Note', () => {
beforeAll(async () => {
const noteWithUpdatedImage = (await uploader.client.request('notes/create', { fileIds: [updatedImage.id] })).createdNote;
const noteWithUpdatedImageInB = await resolveRemoteNote('a.test', noteWithUpdatedImage.id, bAdmin);
assert(noteWithUpdatedImageInB.files != null);
strictEqual(noteWithUpdatedImageInB.files.length, 1);
reupdatedImageInB = noteWithUpdatedImageInB.files[0];
});
test('Check consistency', () => {
// console.log(`b.test: ${JSON.stringify(reupdatedImageInB, null, '\t')}`);
// `isSensitive` is updated
strictEqual(reupdatedImageInB.isSensitive, true);
// FIXME: but `name` is not updated
strictEqual(reupdatedImageInB.name, '192.jpg');
});
});
});
describe('Sensitive flag', () => {
describe('isSensitive is federated in delivering to followers', () => {
let alice: LoginUser, bob: LoginUser;
let bobInA: Misskey.entities.UserDetailedNotMe, aliceInB: Misskey.entities.UserDetailedNotMe;
beforeAll(async () => {
[alice, bob] = await Promise.all([
createAccount('a.test'),
createAccount('b.test'),
]);
[bobInA, aliceInB] = await Promise.all([
resolveRemoteUser('b.test', bob.id, alice),
resolveRemoteUser('a.test', alice.id, bob),
]);
await bob.client.request('following/create', { userId: aliceInB.id });
await sleep();
});
test('Alice uploads sensitive image and it is shown as sensitive from Bob', async () => {
const file = await uploadFile('a.test', alice);
await alice.client.request('drive/files/update', { fileId: file.id, isSensitive: true });
await alice.client.request('notes/create', { text: 'sensitive', fileIds: [file.id] });
await sleep();
const notes = await bob.client.request('notes/timeline', {});
strictEqual(notes.length, 1);
const noteInB = notes[0];
assert(noteInB.files != null);
strictEqual(noteInB.files.length, 1);
strictEqual(noteInB.files[0].isSensitive, true);
});
});
describe('isSensitive is federated in resolving', () => {
let alice: LoginUser, bob: LoginUser;
beforeAll(async () => {
[alice, bob] = await Promise.all([
createAccount('a.test'),
createAccount('b.test'),
]);
});
test('Alice uploads sensitive image and it is shown as sensitive from Bob', async () => {
const file = await uploadFile('a.test', alice);
await alice.client.request('drive/files/update', { fileId: file.id, isSensitive: true });
const note = (await alice.client.request('notes/create', { text: 'sensitive', fileIds: [file.id] })).createdNote;
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
assert(noteInB.files != null);
strictEqual(noteInB.files.length, 1);
strictEqual(noteInB.files[0].isSensitive, true);
});
});
/** @see https://github.com/misskey-dev/misskey/issues/12208 */
describe('isSensitive is federated in replying', () => {
let alice: LoginUser, bob: LoginUser;
beforeAll(async () => {
[alice, bob] = await Promise.all([
createAccount('a.test'),
createAccount('b.test'),
]);
});
test('Alice uploads sensitive image and it is shown as sensitive from Bob', async () => {
const bobNote = (await bob.client.request('notes/create', { text: 'I\'m Bob' })).createdNote;
const file = await uploadFile('a.test', alice);
await alice.client.request('drive/files/update', { fileId: file.id, isSensitive: true });
const bobNoteInA = await resolveRemoteNote('b.test', bobNote.id, alice);
const note = (await alice.client.request('notes/create', { text: 'sensitive', fileIds: [file.id], replyId: bobNoteInA.id })).createdNote;
await sleep();
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
assert(noteInB.files != null);
strictEqual(noteInB.files.length, 1);
strictEqual(noteInB.files[0].isSensitive, true);
});
});
});
});