diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-05-29 12:41:27 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-29 12:41:27 +0900 |
| commit | e4b7a1f4e14a35055bb67dc198614f04f69e2ff9 (patch) | |
| tree | aeba520f07212ed065b91efe5d63317b2ad59c27 /packages/backend/test/unit/server | |
| parent | Bump version to 2025.5.1-beta.3 (diff) | |
| download | misskey-e4b7a1f4e14a35055bb67dc198614f04f69e2ff9.tar.gz misskey-e4b7a1f4e14a35055bb67dc198614f04f69e2ff9.tar.bz2 misskey-e4b7a1f4e14a35055bb67dc198614f04f69e2ff9.zip | |
fix tests
* test
* Update activitypub.ts
* Update activitypub.ts
* Update create.ts
* Update create.ts
* Update endpoints.ts
Diffstat (limited to 'packages/backend/test/unit/server')
| -rw-r--r-- | packages/backend/test/unit/server/api/drive/files/create.ts | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/packages/backend/test/unit/server/api/drive/files/create.ts b/packages/backend/test/unit/server/api/drive/files/create.ts index 723e399430..e86b818ca5 100644 --- a/packages/backend/test/unit/server/api/drive/files/create.ts +++ b/packages/backend/test/unit/server/api/drive/files/create.ts @@ -17,6 +17,8 @@ import { ServerModule } from '@/server/ServerModule.js'; import { ServerService } from '@/server/ServerService.js'; import { IdService } from '@/core/IdService.js'; +// TODO: uploadableFileTypes で許可されていないファイルが弾かれるかのテスト + describe('/drive/files/create', () => { let module: TestingModule; let server: FastifyInstance; @@ -25,6 +27,8 @@ describe('/drive/files/create', () => { let root: MiUser; let role_tinyAttachment: MiRole; + let role_imageOnly: MiRole; + let role_allowAllTypes: MiRole; let folder: MiDriveFolder; @@ -64,11 +68,35 @@ describe('/drive/files/create', () => { }); roleService = module.get<RoleService>(RoleService); - role_tinyAttachment = await roleService.create({ + role_imageOnly = await roleService.create({ name: 'test-role001', description: 'Test role001 description', target: 'manual', policies: { + uploadableFileTypes: { + useDefault: false, + priority: 1, + value: ['image/png'], + }, + }, + }); + role_allowAllTypes = await roleService.create({ + name: 'test-role002', + description: 'Test role002 description', + target: 'manual', + policies: { + uploadableFileTypes: { + useDefault: false, + priority: 1, + value: ['*/*'], + }, + }, + }); + role_tinyAttachment = await roleService.create({ + name: 'test-role003', + description: 'Test role003 description', + target: 'manual', + policies: { maxFileSizeMb: { useDefault: false, priority: 1, @@ -82,6 +110,10 @@ describe('/drive/files/create', () => { beforeEach(async () => { await roleService.unassign(root.id, role_tinyAttachment.id).catch(() => { }); + await roleService.unassign(root.id, role_imageOnly.id).catch(() => { + }); + await roleService.unassign(root.id, role_allowAllTypes.id).catch(() => { + }); }); afterAll(async () => { @@ -110,7 +142,9 @@ describe('/drive/files/create', () => { .field('i', root.token ?? ''); } - test('200 ok', async () => { + test('200 ok (all types allowed)', async () => { + await roleService.assign(root.id, role_allowAllTypes.id); + const name = randomString(); const comment = randomString(); const result = await postFile({ @@ -127,7 +161,24 @@ describe('/drive/files/create', () => { expect(result.body.folderId).toBe(folder.id); }); - test('200 ok(with role)', async () => { + test('400 when not allowed type', async () => { + await roleService.assign(root.id, role_imageOnly.id); + + const name = randomString(); + const comment = randomString(); + const result = await postFile({ + name: name, + comment: comment, + isSensitive: true, + force: true, + fileContent: Buffer.from('a'.repeat(10)), + }); + expect(result.statusCode).toBe(400); + expect(result.body.error.code).toBe('UNALLOWED_FILE_TYPE'); + }); + + test('200 ok (with size limited role)', async () => { + await roleService.assign(root.id, role_allowAllTypes.id); await roleService.assign(root.id, role_tinyAttachment.id); const name = randomString(); @@ -147,6 +198,7 @@ describe('/drive/files/create', () => { }); test('413 too large', async () => { + await roleService.assign(root.id, role_allowAllTypes.id); await roleService.assign(root.id, role_tinyAttachment.id); const name = randomString(); |