Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix backend testing #322

Open
wants to merge 1 commit into
base: taiyme
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/backend/test/e2e/2fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import * as crypto from 'node:crypto';
import cbor from 'cbor';
import * as OTPAuth from 'otpauth';
import { loadConfig } from '@/config.js';
import { api, signup } from '../utils.js';
import type {
AuthenticationResponseJSON,
Expand All @@ -19,10 +18,11 @@ import type {
PublicKeyCredentialRequestOptionsJSON,
RegistrationResponseJSON,
} from '@simplewebauthn/types';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';
import { loadConfig } from '@/config.js';

describe('2要素認証', () => {
let alice: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;

const config = loadConfig();
const password = 'test';
Expand Down Expand Up @@ -96,10 +96,10 @@ describe('2要素認証', () => {
password,
token: param.token,
name: param.keyName,
credential: <RegistrationResponseJSON>{
credential: {
id: param.credentialId.toString('base64url'),
rawId: param.credentialId.toString('base64url'),
response: <AuthenticatorAttestationResponseJSON>{
response: {
clientDataJSON: Buffer.from(JSON.stringify({
type: 'webauthn.create',
challenge: param.creationOptions.challenge,
Expand All @@ -111,10 +111,10 @@ describe('2要素認証', () => {
attStmt: {},
authData,
}).toString('base64url'),
},
} satisfies AuthenticatorAttestationResponseJSON,
clientExtensionResults: {},
type: 'public-key',
},
} satisfies RegistrationResponseJSON,
};
};

Expand All @@ -136,7 +136,7 @@ describe('2要素認証', () => {
keyName: string,
credentialId: Buffer,
requestOptions: PublicKeyCredentialRequestOptionsJSON,
}): misskey.entities.SigninFlowRequest => {
}): Misskey.entities.SigninFlowRequest => {
// AuthenticatorAssertionResponse.authenticatorData
// https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAssertionResponse/authenticatorData
const authenticatorData = Buffer.concat([
Expand All @@ -160,17 +160,17 @@ describe('2要素認証', () => {
return {
username,
password,
credential: <AuthenticationResponseJSON>{
credential: {
id: param.credentialId.toString('base64url'),
rawId: param.credentialId.toString('base64url'),
response: <AuthenticatorAssertionResponseJSON>{
response: {
clientDataJSON: clientDataJSONBuffer.toString('base64url'),
authenticatorData: authenticatorData.toString('base64url'),
signature: signature.toString('base64url'),
},
} satisfies AuthenticatorAssertionResponseJSON,
clientExtensionResults: {},
type: 'public-key',
},
} satisfies AuthenticationResponseJSON,
'g-recaptcha-response': null,
'hcaptcha-response': null,
};
Expand Down
30 changes: 15 additions & 15 deletions packages/backend/test/e2e/antennas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import * as assert from 'node:assert';
import {
api,
failedApiCall,
Expand All @@ -18,7 +17,8 @@ import {
uploadFile,
userList,
} from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';

const compareBy = <T extends { id: string }>(selector: (s: T) => string = (s: T): string => s.id) => (a: T, b: T): number => {
return selector(a).localeCompare(selector(b));
Expand All @@ -28,9 +28,9 @@ describe('アンテナ', () => {
// エンティティとしてのアンテナを主眼においたテストを記述する
// (Antennaを返すエンドポイント、Antennaエンティティを書き換えるエンドポイント、Antennaからノートを取得するエンドポイントをテストする)

type Antenna = misskey.entities.Antenna;
type User = misskey.entities.SignupResponse;
type Note = misskey.entities.Note;
type Antenna = Misskey.entities.Antenna;
type User = Misskey.entities.SignupResponse;
type Note = Misskey.entities.Note;

// アンテナを作成できる最小のパラメタ
const defaultParam = {
Expand All @@ -52,9 +52,9 @@ describe('アンテナ', () => {
let carol: User;

let alicePost: Note;
let aliceList: misskey.entities.UserList;
let bobFile: misskey.entities.DriveFile;
let bobList: misskey.entities.UserList;
let aliceList: Misskey.entities.UserList;
let bobFile: Misskey.entities.DriveFile;
let bobList: Misskey.entities.UserList;

let userNotExplorable: User;
let userLocking: User;
Expand Down Expand Up @@ -232,12 +232,12 @@ describe('アンテナ', () => {
await failedApiCall({
endpoint: 'antennas/create',
parameters: { ...defaultParam, keywords: [[]], excludeKeywords: [[]] },
user: alice
user: alice,
}, {
status: 400,
code: 'EMPTY_KEYWORD',
id: '53ee222e-1ddd-4f9a-92e5-9fb82ddb463a'
})
id: '53ee222e-1ddd-4f9a-92e5-9fb82ddb463a',
});
});
//#endregion
//#region 更新(antennas/update)
Expand Down Expand Up @@ -271,12 +271,12 @@ describe('アンテナ', () => {
await failedApiCall({
endpoint: 'antennas/update',
parameters: { ...defaultParam, antennaId: antenna.id, keywords: [[]], excludeKeywords: [[]] },
user: alice
user: alice,
}, {
status: 400,
code: 'EMPTY_KEYWORD',
id: '721aaff6-4e1b-4d88-8de6-877fae9f68c4'
})
id: '721aaff6-4e1b-4d88-8de6-877fae9f68c4',
});
});

//#endregion
Expand Down
44 changes: 22 additions & 22 deletions packages/backend/test/e2e/api-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { UserToken, api, post, signup } from '../utils.js';
import type * as misskey from 'misskey-js';
import * as assert from 'node:assert';
import { type UserToken, api, post, signup } from '../utils.js';
import type * as Misskey from 'misskey-js';

describe('API visibility', () => {
describe('Note visibility', () => {
//#region vars
/** ヒロイン */
let alice: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
/** フォロワー */
let follower: misskey.entities.SignupResponse;
let follower: Misskey.entities.SignupResponse;
/** 非フォロワー */
let other: misskey.entities.SignupResponse;
let other: Misskey.entities.SignupResponse;
/** 非フォロワーでもリプライやメンションをされた人 */
let target: misskey.entities.SignupResponse;
let target: Misskey.entities.SignupResponse;
/** specified mentionでmentionを飛ばされる人 */
let target2: misskey.entities.SignupResponse;
let target2: Misskey.entities.SignupResponse;

/** public-post */
let pub: misskey.entities.Note;
let pub: Misskey.entities.Note;
/** home-post */
let home: misskey.entities.Note;
let home: Misskey.entities.Note;
/** followers-post */
let fol: misskey.entities.Note;
let fol: Misskey.entities.Note;
/** specified-post */
let spe: misskey.entities.Note;
let spe: Misskey.entities.Note;

/** public-reply to target's post */
let pubR: misskey.entities.Note;
let pubR: Misskey.entities.Note;
/** home-reply to target's post */
let homeR: misskey.entities.Note;
let homeR: Misskey.entities.Note;
/** followers-reply to target's post */
let folR: misskey.entities.Note;
let folR: Misskey.entities.Note;
/** specified-reply to target's post */
let speR: misskey.entities.Note;
let speR: Misskey.entities.Note;

/** public-mention to target */
let pubM: misskey.entities.Note;
let pubM: Misskey.entities.Note;
/** home-mention to target */
let homeM: misskey.entities.Note;
let homeM: Misskey.entities.Note;
/** followers-mention to target */
let folM: misskey.entities.Note;
let folM: Misskey.entities.Note;
/** specified-mention to target */
let speM: misskey.entities.Note;
let speM: Misskey.entities.Note;

/** reply target post */
let tgt: misskey.entities.Note;
let tgt: Misskey.entities.Note;
//#endregion

const show = async (noteId: misskey.entities.Note['id'], by?: UserToken) => {
const show = async (noteId: Misskey.entities.Note['id'], by?: UserToken) => {
return await api('notes/show', {
noteId,
}, by);
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/test/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { IncomingMessage } from 'http';
import * as assert from 'node:assert';
import {
api,
connectStream,
Expand All @@ -18,11 +17,12 @@ import {
uploadFile,
waitFire,
} from '../utils.js';
import type * as misskey from 'misskey-js';
import type { IncomingMessage } from 'node:http';
import type * as Misskey from 'misskey-js';

describe('API', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/test/e2e/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import { api, castAsError, post, signup } from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';

describe('Block', () => {
// alice blocks bob
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let carol: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;
let carol: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Block', () => {
const carolNote = await post(carol, { text: 'hi' });

const res = await api('notes/local-timeline', {}, bob);
const body = res.body as misskey.entities.Note[];
const body = res.body as Misskey.entities.Note[];

assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/test/e2e/clips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { api, ApiRequest, failedApiCall, hiddenNote, post, signup, successfulApiCall } from '../utils.js';
import * as assert from 'node:assert';
import { type ApiRequest, api, failedApiCall, hiddenNote, post, signup, successfulApiCall } from '../utils.js';
import type * as Misskey from 'misskey-js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/test/e2e/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import { api, makeStreamCatcher, post, signup, uploadFile } from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';

describe('Drive', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand All @@ -23,7 +23,7 @@ describe('Drive', () => {

const marker = Math.random().toString();

const url = 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/192.jpg';
const url = 'https://raw.githubusercontent.com/taiyme/misskey/taiyme/packages/backend/test/resources/192.jpg';

const catcher = makeStreamCatcher(
alice,
Expand Down
20 changes: 10 additions & 10 deletions packages/backend/test/e2e/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
// node-fetch only supports it's own Blob yet
// https://github.com/node-fetch/node-fetch/pull/1664
import { Blob } from 'node-fetch';
import { MiUser } from '@/models/_.js';
import { api, castAsError, initTestDb, post, signup, simpleGet, uploadFile } from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';
import { MiUser } from '@/models/_.js';

describe('Endpoints', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let carol: misskey.entities.SignupResponse;
let dave: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;
let carol: Misskey.entities.SignupResponse;
let dave: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand Down Expand Up @@ -632,7 +632,7 @@ describe('Endpoints', () => {
for (const type of ['webp', 'avif']) {
const mediaType = `image/${type}`;

const getWebpublicType = async (user: misskey.entities.SignupResponse, fileId: string): Promise<string> => {
const getWebpublicType = async (user: Misskey.entities.SignupResponse, fileId: string): Promise<string> => {
// drive/files/create does not expose webpublicType directly, so get it by posting it
const res = await post(user, {
text: mediaType,
Expand Down Expand Up @@ -1064,7 +1064,7 @@ describe('Endpoints', () => {
userId: bob.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
assert.strictEqual((res2.body as unknown as { memo: string }).memo, memo);
});

test('自分に関するメモを更新できる', async () => {
Expand All @@ -1079,7 +1079,7 @@ describe('Endpoints', () => {
userId: alice.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
assert.strictEqual((res2.body as unknown as { memo: string }).memo, memo);
});

test('メモを削除できる', async () => {
Expand Down
Loading
Loading