sonamu 0.13.11 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +2 -1
- package/dist/api/code-converters.d.ts +5 -1
- package/dist/api/code-converters.d.ts.map +1 -1
- package/dist/api/code-converters.js +24 -7
- package/dist/api/config.d.ts +7 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +1 -1
- package/dist/api/decorators.d.ts +1 -0
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +1 -1
- package/dist/api/guards.d.ts +37 -0
- package/dist/api/guards.d.ts.map +1 -0
- package/dist/api/guards.js +96 -0
- package/dist/api/sonamu.d.ts +14 -1
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +121 -25
- package/dist/api/websocket-helpers.d.ts +6 -1
- package/dist/api/websocket-helpers.d.ts.map +1 -1
- package/dist/api/websocket-helpers.js +7 -4
- package/dist/auth/auth-entity-policy.d.ts +32 -0
- package/dist/auth/auth-entity-policy.d.ts.map +1 -0
- package/dist/auth/auth-entity-policy.js +44 -0
- package/dist/auth/auth-secret.d.ts +24 -0
- package/dist/auth/auth-secret.d.ts.map +1 -0
- package/dist/auth/auth-secret.js +46 -0
- package/dist/auth/base-url.d.ts +39 -0
- package/dist/auth/base-url.d.ts.map +1 -0
- package/dist/auth/base-url.js +84 -0
- package/dist/auth/better-auth-entities.js +20 -7
- package/dist/auth/better-auth-options.d.ts +15 -0
- package/dist/auth/better-auth-options.d.ts.map +1 -0
- package/dist/auth/better-auth-options.js +38 -0
- package/dist/auth/better-auth-request.d.ts +8 -1
- package/dist/auth/better-auth-request.d.ts.map +1 -1
- package/dist/auth/better-auth-request.js +26 -3
- package/dist/auth/plugins/entity-definitions/admin.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/admin.js +6 -1
- package/dist/auth/plugins/entity-definitions/anonymous.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/anonymous.js +2 -1
- package/dist/auth/plugins/entity-definitions/api-key.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/api-key.js +18 -2
- package/dist/auth/plugins/entity-definitions/audit-log.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/audit-log.js +27 -1
- package/dist/auth/plugins/entity-definitions/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/jwt.js +4 -2
- package/dist/auth/plugins/entity-definitions/organization.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/organization.js +15 -1
- package/dist/auth/plugins/entity-definitions/passkey.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/passkey.js +9 -1
- package/dist/auth/plugins/entity-definitions/phone-number.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/phone-number.js +2 -1
- package/dist/auth/plugins/entity-definitions/sso.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/sso.js +7 -3
- package/dist/auth/plugins/entity-definitions/two-factor.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/two-factor.js +8 -3
- package/dist/auth/verify-email-guard.d.ts +37 -0
- package/dist/auth/verify-email-guard.d.ts.map +1 -0
- package/dist/auth/verify-email-guard.js +48 -0
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +6 -2
- package/dist/bin/typecheck-web.js +1 -1
- package/dist/cache/decorator.d.ts +12 -0
- package/dist/cache/decorator.d.ts.map +1 -1
- package/dist/cache/decorator.js +86 -19
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +3 -3
- package/dist/cache/types.d.ts +16 -0
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/cli/plugin-loader.d.ts +17 -0
- package/dist/cli/plugin-loader.d.ts.map +1 -0
- package/dist/cli/plugin-loader.js +178 -0
- package/dist/cli/plugin.d.ts +65 -0
- package/dist/cli/plugin.d.ts.map +1 -0
- package/dist/cli/plugin.js +7 -0
- package/dist/code-formatting/oxfmt.js +1 -1
- package/dist/code-formatting/oxlint.js +1 -1
- package/dist/database/db.d.ts +35 -10
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +37 -4
- package/dist/database/puri.d.ts +8 -0
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +108 -171
- package/dist/database/puri.types.d.ts +2 -0
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +1 -1
- package/dist/database/sql-expression-brand.d.ts +10 -0
- package/dist/database/sql-expression-brand.d.ts.map +1 -0
- package/dist/database/sql-expression-brand.js +10 -0
- package/dist/dict/en.d.ts +1 -0
- package/dist/dict/en.d.ts.map +1 -1
- package/dist/dict/en.js +2 -1
- package/dist/dict/ko.d.ts +1 -0
- package/dist/dict/ko.d.ts.map +1 -1
- package/dist/dict/ko.js +2 -1
- package/dist/dict/sonamu-dictionary.d.ts +23 -1
- package/dist/dict/sonamu-dictionary.d.ts.map +1 -1
- package/dist/dict/sonamu-dictionary.js +187 -32
- package/dist/entity/entity-codegen-safety.d.ts +105 -0
- package/dist/entity/entity-codegen-safety.d.ts.map +1 -0
- package/dist/entity/entity-codegen-safety.js +70 -0
- package/dist/entity/entity-manager.d.ts +32 -0
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +21 -2
- package/dist/entity/entity.d.ts +5 -2
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +19 -8
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +31 -3
- package/dist/filter/utils.d.ts +2 -2
- package/dist/filter/utils.d.ts.map +1 -1
- package/dist/filter/utils.js +16 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/logger/configure.d.ts.map +1 -1
- package/dist/logger/configure.js +10 -3
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +177 -96
- package/dist/migration/migrator.d.ts +16 -0
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +28 -3
- package/dist/migration/slack-confirm.d.ts +6 -2
- package/dist/migration/slack-confirm.d.ts.map +1 -1
- package/dist/migration/slack-confirm.js +11 -9
- package/dist/ssr/errors.d.ts +13 -0
- package/dist/ssr/errors.d.ts.map +1 -0
- package/dist/ssr/errors.js +12 -0
- package/dist/ssr/index.d.ts +1 -0
- package/dist/ssr/index.d.ts.map +1 -1
- package/dist/ssr/index.js +5 -2
- package/dist/ssr/renderer.d.ts +6 -0
- package/dist/ssr/renderer.d.ts.map +1 -1
- package/dist/ssr/renderer.js +10 -1
- package/dist/storage/base-file.d.ts +6 -2
- package/dist/storage/base-file.d.ts.map +1 -1
- package/dist/storage/base-file.js +10 -5
- package/dist/storage/buffered-file.d.ts +1 -0
- package/dist/storage/buffered-file.d.ts.map +1 -1
- package/dist/storage/buffered-file.js +5 -2
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -2
- package/dist/storage/upload-safety.d.ts +47 -0
- package/dist/storage/upload-safety.d.ts.map +1 -0
- package/dist/storage/upload-safety.js +112 -0
- package/dist/stream/ws.d.ts +6 -0
- package/dist/stream/ws.d.ts.map +1 -1
- package/dist/stream/ws.js +52 -6
- package/dist/syncer/code-generator.d.ts +2 -0
- package/dist/syncer/code-generator.d.ts.map +1 -1
- package/dist/syncer/code-generator.js +21 -7
- package/dist/template/implementations/entity.template.d.ts.map +1 -1
- package/dist/template/implementations/entity.template.js +40 -35
- package/dist/template/implementations/generated.template.d.ts +10 -0
- package/dist/template/implementations/generated.template.d.ts.map +1 -1
- package/dist/template/implementations/generated.template.js +46 -7
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -1
- package/dist/template/implementations/generated_http.template.js +3 -1
- package/dist/template/implementations/init_types.template.d.ts.map +1 -1
- package/dist/template/implementations/init_types.template.js +3 -8
- package/dist/template/implementations/model.template.d.ts.map +1 -1
- package/dist/template/implementations/model.template.js +9 -2
- package/dist/template/implementations/sd.template.d.ts +0 -1
- package/dist/template/implementations/sd.template.d.ts.map +1 -1
- package/dist/template/implementations/sd.template.js +2 -5
- package/dist/template/implementations/view_form.template.d.ts.map +1 -1
- package/dist/template/implementations/view_form.template.js +8 -6
- package/dist/template/implementations/view_list.template.d.ts.map +1 -1
- package/dist/template/implementations/view_list.template.js +8 -4
- package/dist/testing/dev-test-routes.d.ts.map +1 -1
- package/dist/testing/dev-test-routes.js +7 -4
- package/dist/tooling/__tests__/helpers/sonamu-test-root.js +1 -1
- package/dist/tooling/cdd-service.js +1 -1
- package/dist/tooling/index.d.ts +1 -0
- package/dist/tooling/index.d.ts.map +1 -1
- package/dist/tooling/index.js +3 -1
- package/dist/tsdown.api.config.js +1 -1
- package/dist/types/types.d.ts +81 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +2 -1
- package/dist/ui/__tests__/ui-test-helpers.d.ts +10 -0
- package/dist/ui/__tests__/ui-test-helpers.d.ts.map +1 -0
- package/dist/ui/__tests__/ui-test-helpers.js +75 -0
- package/dist/ui/access-guard.d.ts +42 -0
- package/dist/ui/access-guard.d.ts.map +1 -0
- package/dist/ui/access-guard.js +94 -0
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +40 -95
- package/dist/ui/dev-host-guard.d.ts +28 -0
- package/dist/ui/dev-host-guard.d.ts.map +1 -0
- package/dist/ui/dev-host-guard.js +67 -0
- package/dist/ui/migrations-api.d.ts.map +1 -1
- package/dist/ui/migrations-api.js +72 -16
- package/dist/ui/open-vscode-api.d.ts +4 -0
- package/dist/ui/open-vscode-api.d.ts.map +1 -0
- package/dist/ui/open-vscode-api.js +65 -0
- package/dist/ui/scaffolding-api.d.ts +18 -0
- package/dist/ui/scaffolding-api.d.ts.map +1 -0
- package/dist/ui/scaffolding-api.js +111 -0
- package/dist/ui/ui-db-presets.d.ts +19 -0
- package/dist/ui/ui-db-presets.d.ts.map +1 -0
- package/dist/ui/ui-db-presets.js +34 -0
- package/dist/ui/ui-request-guard.d.ts +11 -0
- package/dist/ui/ui-request-guard.d.ts.map +1 -0
- package/dist/ui/ui-request-guard.js +38 -0
- package/dist/ui-web/assets/{index-QDMyy31K.js → index-BPqP-tug.js} +39 -39
- package/dist/ui-web/index.html +2 -1
- package/package.json +1 -1
- package/src/__tests__/env.test.ts +121 -2
- package/src/api/__tests__/code-converters.union.test.ts +97 -0
- package/src/api/__tests__/guards.test.ts +233 -0
- package/src/api/__tests__/sonamu.auth-secret.test.ts +77 -0
- package/src/api/__tests__/sonamu.dev-host-guard.test.ts +130 -0
- package/src/api/__tests__/sonamu.guards.test.ts +327 -0
- package/src/api/__tests__/sonamu.upload-limits.test.ts +156 -0
- package/src/api/__tests__/websocket-helpers.test.ts +101 -0
- package/src/api/caster.ts +7 -0
- package/src/api/code-converters.ts +44 -12
- package/src/api/config.ts +8 -0
- package/src/api/decorators.ts +1 -0
- package/src/api/guards.ts +130 -0
- package/src/api/sonamu.ts +195 -39
- package/src/api/websocket-helpers.ts +11 -6
- package/src/auth/__tests__/auth-entity-policy.test.ts +59 -0
- package/src/auth/__tests__/auth-secret.test.ts +133 -0
- package/src/auth/__tests__/base-url-host-poisoning.test.ts +193 -0
- package/src/auth/__tests__/base-url.test.ts +117 -0
- package/src/auth/__tests__/better-auth-options.test.ts +194 -0
- package/src/auth/__tests__/better-auth-request.test.ts +45 -0
- package/src/auth/__tests__/verify-email-guard.test.ts +228 -0
- package/src/auth/auth-entity-policy.ts +48 -0
- package/src/auth/auth-secret.ts +77 -0
- package/src/auth/base-url.ts +109 -0
- package/src/auth/better-auth-entities.ts +30 -30
- package/src/auth/better-auth-options.ts +39 -0
- package/src/auth/better-auth-request.ts +28 -1
- package/src/auth/plugins/entity-definitions/admin.ts +5 -0
- package/src/auth/plugins/entity-definitions/anonymous.ts +9 -1
- package/src/auth/plugins/entity-definitions/api-key.ts +53 -16
- package/src/auth/plugins/entity-definitions/audit-log.ts +122 -21
- package/src/auth/plugins/entity-definitions/jwt.ts +5 -4
- package/src/auth/plugins/entity-definitions/organization.ts +26 -6
- package/src/auth/plugins/entity-definitions/passkey.ts +8 -7
- package/src/auth/plugins/entity-definitions/phone-number.ts +1 -0
- package/src/auth/plugins/entity-definitions/sso.ts +20 -15
- package/src/auth/plugins/entity-definitions/two-factor.ts +21 -5
- package/src/auth/verify-email-guard.ts +82 -0
- package/src/bin/__tests__/build-web-command.test.ts +24 -0
- package/src/bin/build-config.ts +5 -0
- package/src/cache/decorator.ts +116 -21
- package/src/cache/index.ts +6 -1
- package/src/cache/types.ts +18 -0
- package/src/cli/plugin-loader.ts +238 -0
- package/src/cli/plugin.ts +82 -0
- package/src/database/__tests__/db.test.ts +64 -1
- package/src/database/__tests__/puri.test.ts +56 -0
- package/src/database/db.ts +56 -6
- package/src/database/puri.ts +135 -125
- package/src/database/puri.types.test-d.ts +12 -0
- package/src/database/puri.types.ts +3 -0
- package/src/database/sql-expression-brand.ts +9 -0
- package/src/dict/__tests__/sonamu-dictionary.test.ts +217 -0
- package/src/dict/en.ts +2 -0
- package/src/dict/ko.ts +2 -0
- package/src/dict/sonamu-dictionary.ts +298 -38
- package/src/entity/__tests__/entity-codegen-safety.test.ts +326 -0
- package/src/entity/entity-codegen-safety.ts +126 -0
- package/src/entity/entity-manager.ts +29 -1
- package/src/entity/entity.ts +26 -12
- package/src/env.ts +52 -1
- package/src/filter/utils.ts +19 -7
- package/src/index.ts +4 -3
- package/src/logger/__tests__/configure.test.ts +51 -1
- package/src/logger/configure.ts +14 -1
- package/src/migration/__tests__/code-generation.escape.test.ts +322 -0
- package/src/migration/__tests__/migrator.test.ts +76 -1
- package/src/migration/code-generation.ts +247 -117
- package/src/migration/migrator.ts +45 -4
- package/src/migration/slack-confirm.ts +19 -5
- package/src/ssr/__tests__/preload-guard.test.ts +274 -0
- package/src/ssr/errors.ts +11 -0
- package/src/ssr/index.ts +1 -0
- package/src/ssr/renderer.ts +12 -0
- package/src/storage/__tests__/upload-safety.test.ts +179 -0
- package/src/storage/base-file.ts +8 -4
- package/src/storage/buffered-file.ts +3 -1
- package/src/storage/index.ts +9 -0
- package/src/storage/upload-safety.ts +155 -0
- package/src/stream/__tests__/ws.test.ts +97 -0
- package/src/stream/ws.ts +67 -5
- package/src/syncer/__tests__/code-generator-path-containment.test.ts +105 -0
- package/src/syncer/code-generator.ts +34 -6
- package/src/template/__tests__/generated.template.search-text.test.ts +5 -1
- package/src/template/__tests__/model.template.auth-entity.test.ts +42 -0
- package/src/template/__tests__/save-params.template.test.ts +219 -0
- package/src/template/implementations/entity.template.ts +53 -48
- package/src/template/implementations/generated.template.ts +87 -12
- package/src/template/implementations/generated_http.template.ts +5 -0
- package/src/template/implementations/init_types.template.ts +4 -22
- package/src/template/implementations/model.template.ts +15 -1
- package/src/template/implementations/sd.template.ts +4 -5
- package/src/template/implementations/view_form.template.ts +13 -5
- package/src/template/implementations/view_list.template.ts +12 -3
- package/src/testing/__tests__/dev-test-routes.test.ts +99 -0
- package/src/testing/dev-test-routes.ts +7 -3
- package/src/tooling/__tests__/cli-plugins.contract.test.ts +273 -0
- package/src/tooling/index.ts +1 -0
- package/src/types/types.ts +22 -1
- package/src/ui/__tests__/access-guard.test.ts +217 -0
- package/src/ui/__tests__/dev-host-guard.test.ts +161 -0
- package/src/ui/__tests__/fixture-api.test.ts +92 -0
- package/src/ui/__tests__/migrations-api.test.ts +352 -0
- package/src/ui/__tests__/open-vscode.test.ts +151 -0
- package/src/ui/__tests__/scaffolding-api.test.ts +232 -0
- package/src/ui/__tests__/ui-process-routes.test.ts +166 -0
- package/src/ui/__tests__/ui-test-helpers.ts +71 -0
- package/src/ui/access-guard.ts +115 -0
- package/src/ui/api.ts +65 -198
- package/src/ui/dev-host-guard.ts +109 -0
- package/src/ui/migrations-api.ts +130 -24
- package/src/ui/open-vscode-api.ts +82 -0
- package/src/ui/scaffolding-api.ts +177 -0
- package/src/ui/ui-db-presets.ts +41 -0
- package/src/ui/ui-request-guard.ts +53 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import fastify, { type FastifyInstance, type RouteOptions } from "fastify";
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { setSDConfig } from "../../dict/sd";
|
|
5
|
+
import {
|
|
6
|
+
canServeSonamuUIToken,
|
|
7
|
+
getSonamuUIToken,
|
|
8
|
+
requireSonamuUIToken,
|
|
9
|
+
SONAMU_UI_TOKEN_HEADER,
|
|
10
|
+
} from "../access-guard";
|
|
11
|
+
import { sonamuUIApiPlugin } from "../api";
|
|
12
|
+
|
|
13
|
+
const HOST = "localhost:10280";
|
|
14
|
+
// 없는 엔티티라 가드를 통과해도 핸들러가 파일을 지우기 전에 실패합니다.
|
|
15
|
+
const MISSING_ENTITY_BODY = "entityId=Son618MissingEntity";
|
|
16
|
+
// 읽기 전용 라우트에 없는 규칙을 요청해 가드 통과 여부만 확인합니다.
|
|
17
|
+
const MISSING_RULE_BODY = { ruleKey: "son618-missing-rule" };
|
|
18
|
+
|
|
19
|
+
let server: FastifyInstance;
|
|
20
|
+
const uiRoutes: RouteOptions[] = [];
|
|
21
|
+
|
|
22
|
+
beforeAll(async () => {
|
|
23
|
+
setSDConfig({ defaultLocale: "ko", supportedLocales: ["ko"] });
|
|
24
|
+
server = fastify();
|
|
25
|
+
// 플러그인이 등록하는 모든 라우트의 최종 옵션을 모읍니다(같은 객체를 참조하므로 이후 수정도 반영됩니다).
|
|
26
|
+
server.addHook("onRoute", (routeOptions) => {
|
|
27
|
+
uiRoutes.push(routeOptions);
|
|
28
|
+
});
|
|
29
|
+
await server.register(import("@fastify/formbody"));
|
|
30
|
+
await server.register(import("@fastify/multipart"));
|
|
31
|
+
await server.register(sonamuUIApiPlugin);
|
|
32
|
+
await server.ready();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterAll(async () => {
|
|
36
|
+
await server.close();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function tokenHeaders(extra: Record<string, string> = {}) {
|
|
40
|
+
return { host: HOST, [SONAMU_UI_TOKEN_HEADER]: getSonamuUIToken(), ...extra };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("Sonamu UI API 접근 토큰", () => {
|
|
44
|
+
test("/sonamu-ui/api 아래 모든 라우트에 토큰 가드가 붙는다", () => {
|
|
45
|
+
const apiRoutes = uiRoutes.filter((route) => route.url.startsWith("/sonamu-ui/api/"));
|
|
46
|
+
// 가드 누락을 놓치지 않도록 라우트가 실제로 수집됐는지도 확인합니다.
|
|
47
|
+
expect(apiRoutes.length).toBeGreaterThan(50);
|
|
48
|
+
for (const route of apiRoutes) {
|
|
49
|
+
const hooks = [route.onRequest ?? []].flat();
|
|
50
|
+
expect(hooks[0], `${String(route.method)} ${route.url}`).toBe(requireSonamuUIToken);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("토큰 없는 GET·HEAD 요청은 401로 거부한다", async () => {
|
|
55
|
+
for (const method of ["GET", "HEAD"] as const) {
|
|
56
|
+
const res = await server.inject({
|
|
57
|
+
method,
|
|
58
|
+
url: "/sonamu-ui/api/sonamu/config",
|
|
59
|
+
headers: { host: HOST },
|
|
60
|
+
});
|
|
61
|
+
expect(res.statusCode, method).toBe(401);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("토큰 없는 form·no-cors·본문 없는 POST는 핸들러 전에 401로 거부한다", async () => {
|
|
66
|
+
const crossSite = { host: HOST, origin: "http://evil.example", "sec-fetch-site": "cross-site" };
|
|
67
|
+
const requests: { headers: Record<string, string>; payload?: string }[] = [
|
|
68
|
+
{
|
|
69
|
+
headers: { ...crossSite, "content-type": "application/x-www-form-urlencoded" },
|
|
70
|
+
payload: MISSING_ENTITY_BODY,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
headers: { ...crossSite, "content-type": "text/plain;charset=UTF-8" },
|
|
74
|
+
payload: '{"entityId":"Son618MissingEntity"}',
|
|
75
|
+
},
|
|
76
|
+
{ headers: crossSite },
|
|
77
|
+
];
|
|
78
|
+
for (const { headers, payload } of requests) {
|
|
79
|
+
const res = await server.inject({
|
|
80
|
+
method: "POST",
|
|
81
|
+
url: "/sonamu-ui/api/entity/del",
|
|
82
|
+
headers,
|
|
83
|
+
payload,
|
|
84
|
+
});
|
|
85
|
+
expect(res.statusCode, JSON.stringify(headers)).toBe(401);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("multipart 업로드도 토큰이 없으면 401로 거부한다", async () => {
|
|
90
|
+
const boundary = "----son618";
|
|
91
|
+
const res = await server.inject({
|
|
92
|
+
method: "POST",
|
|
93
|
+
url: "/sonamu-ui/api/i18n/import",
|
|
94
|
+
headers: { host: HOST, "content-type": `multipart/form-data; boundary=${boundary}` },
|
|
95
|
+
payload: `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="a.xlsx"\r\n\r\nx\r\n--${boundary}--\r\n`,
|
|
96
|
+
});
|
|
97
|
+
expect(res.statusCode).toBe(401);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("틀린 토큰은 401로 거부한다", async () => {
|
|
101
|
+
for (const token of ["", "wrong", `${getSonamuUIToken()}x`, getSonamuUIToken().slice(1)]) {
|
|
102
|
+
const res = await server.inject({
|
|
103
|
+
method: "GET",
|
|
104
|
+
url: "/sonamu-ui/api/sonamu/config",
|
|
105
|
+
headers: { host: HOST, [SONAMU_UI_TOKEN_HEADER]: token },
|
|
106
|
+
});
|
|
107
|
+
expect(res.statusCode, token).toBe(401);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("퍼센트 인코딩한 경로로도 토큰 검사를 우회할 수 없다", async () => {
|
|
112
|
+
const res = await server.inject({
|
|
113
|
+
method: "POST",
|
|
114
|
+
url: "/sonamu-ui/%61pi/entity/del",
|
|
115
|
+
headers: { host: HOST, "content-type": "application/x-www-form-urlencoded" },
|
|
116
|
+
payload: MISSING_ENTITY_BODY,
|
|
117
|
+
});
|
|
118
|
+
expect([401, 404]).toContain(res.statusCode);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("토큰이 있어도 다른 출처에서 온 요청은 403으로 거부한다", async () => {
|
|
122
|
+
const crossOriginHeaders: Record<string, string>[] = [
|
|
123
|
+
{ origin: "http://evil.example", "sec-fetch-site": "cross-site" },
|
|
124
|
+
// 같은 사이트의 다른 포트(localhost의 다른 개발 서버)도 다른 출처입니다.
|
|
125
|
+
{ origin: "http://localhost:3000", "sec-fetch-site": "same-site" },
|
|
126
|
+
// Sec-Fetch-Site를 보내지 않는 브라우저는 Origin과 Host를 비교합니다.
|
|
127
|
+
{ origin: "http://evil.example" },
|
|
128
|
+
{ origin: "null" },
|
|
129
|
+
];
|
|
130
|
+
for (const extra of crossOriginHeaders) {
|
|
131
|
+
const res = await server.inject({
|
|
132
|
+
method: "POST",
|
|
133
|
+
url: "/sonamu-ui/api/cdd/readRule",
|
|
134
|
+
headers: tokenHeaders({ "content-type": "application/json", ...extra }),
|
|
135
|
+
payload: JSON.stringify(MISSING_RULE_BODY),
|
|
136
|
+
});
|
|
137
|
+
expect(res.statusCode, JSON.stringify(extra)).toBe(403);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("동일 출처 Sonamu UI의 토큰 요청은 가드를 통과해 핸들러까지 도달한다", async () => {
|
|
142
|
+
const sameOriginHeaders: Record<string, string>[] = [
|
|
143
|
+
{ origin: `http://${HOST}`, "sec-fetch-site": "same-origin" },
|
|
144
|
+
// ui-web Vite 개발 프록시(changeOrigin)는 Host를 바꾸지만 브라우저는 동일 출처로 표시합니다.
|
|
145
|
+
{ origin: "http://localhost:65000", "sec-fetch-site": "same-origin" },
|
|
146
|
+
{ origin: `http://${HOST}` },
|
|
147
|
+
// 브라우저 밖 로컬 클라이언트
|
|
148
|
+
{},
|
|
149
|
+
];
|
|
150
|
+
for (const extra of sameOriginHeaders) {
|
|
151
|
+
const res = await server.inject({
|
|
152
|
+
method: "POST",
|
|
153
|
+
url: "/sonamu-ui/api/cdd/readRule",
|
|
154
|
+
headers: tokenHeaders({ "content-type": "application/json", ...extra }),
|
|
155
|
+
payload: JSON.stringify(MISSING_RULE_BODY),
|
|
156
|
+
});
|
|
157
|
+
// 없는 규칙 파일이라 핸들러에서 실패합니다. 가드가 막았다면 401·403입니다.
|
|
158
|
+
expect(res.statusCode, JSON.stringify(extra)).not.toBe(401);
|
|
159
|
+
expect(res.statusCode, JSON.stringify(extra)).not.toBe(403);
|
|
160
|
+
expect(res.statusCode, JSON.stringify(extra)).toBeGreaterThanOrEqual(400);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("index.html 접근 토큰 노출 범위", () => {
|
|
166
|
+
let app: FastifyInstance;
|
|
167
|
+
|
|
168
|
+
beforeAll(async () => {
|
|
169
|
+
app = fastify();
|
|
170
|
+
app.get("/index", async (request, reply) =>
|
|
171
|
+
canServeSonamuUIToken(request) ? "token" : reply.code(403).send(),
|
|
172
|
+
);
|
|
173
|
+
await app.ready();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
afterAll(async () => {
|
|
177
|
+
await app.close();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("동일 출처 요청과 다른 출처에서의 페이지 이동은 토큰이 담긴 HTML을 받는다", async () => {
|
|
181
|
+
const allowed: Record<string, string>[] = [
|
|
182
|
+
{},
|
|
183
|
+
{ "sec-fetch-site": "none", "sec-fetch-mode": "navigate" },
|
|
184
|
+
{ "sec-fetch-site": "same-origin", "sec-fetch-mode": "cors" },
|
|
185
|
+
// 다른 출처 링크로 이동하면 문서를 열 뿐, 링크를 건 페이지는 응답을 읽을 수 없습니다.
|
|
186
|
+
{ "sec-fetch-site": "cross-site", "sec-fetch-mode": "navigate" },
|
|
187
|
+
];
|
|
188
|
+
for (const extra of allowed) {
|
|
189
|
+
const res = await app.inject({
|
|
190
|
+
method: "GET",
|
|
191
|
+
url: "/index",
|
|
192
|
+
headers: { host: HOST, ...extra },
|
|
193
|
+
});
|
|
194
|
+
expect(res.statusCode, JSON.stringify(extra)).toBe(200);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("다른 출처의 fetch·XHR로 HTML을 읽으려는 요청은 403으로 거부한다", async () => {
|
|
199
|
+
const rejected: Record<string, string>[] = [
|
|
200
|
+
{ origin: "http://evil.example", "sec-fetch-site": "cross-site", "sec-fetch-mode": "cors" },
|
|
201
|
+
{
|
|
202
|
+
origin: "http://evil.example",
|
|
203
|
+
"sec-fetch-site": "cross-site",
|
|
204
|
+
"sec-fetch-mode": "no-cors",
|
|
205
|
+
},
|
|
206
|
+
{ origin: "http://evil.example" },
|
|
207
|
+
];
|
|
208
|
+
for (const extra of rejected) {
|
|
209
|
+
const res = await app.inject({
|
|
210
|
+
method: "GET",
|
|
211
|
+
url: "/index",
|
|
212
|
+
headers: { host: HOST, ...extra },
|
|
213
|
+
});
|
|
214
|
+
expect(res.statusCode, JSON.stringify(extra)).toBe(403);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import Fastify, { type FastifyInstance } from "fastify";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { setSDConfig } from "../../dict/sd";
|
|
5
|
+
import { type DevTestRouteManager } from "../../testing/dev-test-routes";
|
|
6
|
+
import { registerDevTestRoutes } from "../../testing/dev-test-routes";
|
|
7
|
+
import {
|
|
8
|
+
getConfiguredDevHostnames,
|
|
9
|
+
isAllowedDevHost,
|
|
10
|
+
registerDevHostGuard,
|
|
11
|
+
} from "../dev-host-guard";
|
|
12
|
+
|
|
13
|
+
describe("isAllowedDevHost", () => {
|
|
14
|
+
it.each([
|
|
15
|
+
"localhost",
|
|
16
|
+
"localhost:34900",
|
|
17
|
+
"LOCALHOST:34900",
|
|
18
|
+
"app.localhost:34900",
|
|
19
|
+
"127.0.0.1:34900",
|
|
20
|
+
"127.0.0.1",
|
|
21
|
+
"[::1]:34900",
|
|
22
|
+
"[::1]",
|
|
23
|
+
"192.168.0.10:34900",
|
|
24
|
+
])("DNS로 바꿔치기할 수 없는 호스트 %s 는 허용한다", (host) => {
|
|
25
|
+
expect(isAllowedDevHost(host)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it.each([
|
|
29
|
+
undefined,
|
|
30
|
+
"",
|
|
31
|
+
"attacker.example",
|
|
32
|
+
"attacker.example:34900",
|
|
33
|
+
"localhost.attacker.example:34900",
|
|
34
|
+
"attacker.example@localhost:34900",
|
|
35
|
+
"localhost/attacker.example",
|
|
36
|
+
"localhost:34900:1",
|
|
37
|
+
"[attacker.example]:34900",
|
|
38
|
+
"localhost evil",
|
|
39
|
+
])("공격자가 소유할 수 있거나 형식이 잘못된 Host %s 는 거부한다", (host) => {
|
|
40
|
+
expect(isAllowedDevHost(host)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("설정한 호스트 이름은 포트와 대소문자에 관계없이 허용한다", () => {
|
|
44
|
+
expect(isAllowedDevHost("Dev.Example.Test:34900", ["dev.example.test"])).toBe(true);
|
|
45
|
+
expect(isAllowedDevHost("other.example.test:34900", ["dev.example.test"])).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("getConfiguredDevHostnames", () => {
|
|
50
|
+
it("listen.host와 baseUrl의 호스트 이름을 모은다", () => {
|
|
51
|
+
expect(
|
|
52
|
+
getConfiguredDevHostnames({
|
|
53
|
+
listen: { port: 34900, host: "dev.example.test" },
|
|
54
|
+
baseUrl: "https://api.example.test:8443/base",
|
|
55
|
+
}),
|
|
56
|
+
).toEqual(["dev.example.test", "api.example.test"]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("IPv6 baseUrl은 대괄호를 벗기고, URL이 아닌 baseUrl은 무시한다", () => {
|
|
60
|
+
expect(getConfiguredDevHostnames({ baseUrl: "http://[::1]:34900" })).toEqual(["::1"]);
|
|
61
|
+
expect(getConfiguredDevHostnames({ baseUrl: "not a url" })).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 라우트가 의존하는 매니저 기능을 모두 제공하는 테스트 대역입니다.
|
|
66
|
+
const mockManager = {
|
|
67
|
+
start: vi.fn(),
|
|
68
|
+
run: vi.fn(),
|
|
69
|
+
getStatus: vi.fn(),
|
|
70
|
+
emitEvent: vi.fn(),
|
|
71
|
+
addEventListener: vi.fn(),
|
|
72
|
+
removeEventListener: vi.fn(),
|
|
73
|
+
shutdown: vi.fn(),
|
|
74
|
+
} satisfies DevTestRouteManager;
|
|
75
|
+
|
|
76
|
+
describe("registerDevHostGuard", () => {
|
|
77
|
+
let app: FastifyInstance;
|
|
78
|
+
|
|
79
|
+
beforeEach(async () => {
|
|
80
|
+
vi.clearAllMocks();
|
|
81
|
+
// 403 응답 메시지를 만드는 SD 사전이 동작하도록 i18n 설정을 채웁니다.
|
|
82
|
+
setSDConfig({ defaultLocale: "ko", supportedLocales: ["ko"] });
|
|
83
|
+
mockManager.start.mockResolvedValue(undefined);
|
|
84
|
+
mockManager.getStatus.mockReturnValue({ ready: true, running: false, lastRunAt: null });
|
|
85
|
+
app = Fastify();
|
|
86
|
+
registerDevHostGuard(app, {
|
|
87
|
+
configuredHostnames: ["dev.example.test"],
|
|
88
|
+
protectedPrefixes: ["/sonamu-ui", "/custom-test/"],
|
|
89
|
+
});
|
|
90
|
+
// Sonamu UI 플러그인처럼 prefix를 가진 하위 플러그인과 와일드카드 SPA 라우트를 흉내 냅니다.
|
|
91
|
+
await app.register(
|
|
92
|
+
async (scope) => {
|
|
93
|
+
scope.get("/api/sonamu/config", async () => ({ secret: "secret-config-value" }));
|
|
94
|
+
scope.get("*", async () => "spa");
|
|
95
|
+
},
|
|
96
|
+
{ prefix: "/sonamu-ui" },
|
|
97
|
+
);
|
|
98
|
+
await registerDevTestRoutes(
|
|
99
|
+
app,
|
|
100
|
+
{ enabled: true, routePrefix: "/custom-test" },
|
|
101
|
+
{ manager: mockManager, apiRootPath: "/tmp/fixture-api", sseAvailable: false },
|
|
102
|
+
);
|
|
103
|
+
app.get("/api/user/me", async () => ({ ok: true }));
|
|
104
|
+
app.get("/sonamu-uix", async () => "not-ui");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
afterEach(async () => {
|
|
108
|
+
await app.close();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it.each([
|
|
112
|
+
"/sonamu-ui/api/sonamu/config",
|
|
113
|
+
"/sonamu-ui/",
|
|
114
|
+
"/sonamu-ui/entities",
|
|
115
|
+
"/custom-test/status",
|
|
116
|
+
])("Host: attacker.example 로 온 UI·dev 라우트 %s 요청은 403으로 거부한다", async (url) => {
|
|
117
|
+
const response = await app.inject({
|
|
118
|
+
method: "GET",
|
|
119
|
+
url,
|
|
120
|
+
headers: { host: "attacker.example:34900" },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(response.statusCode).toBe(403);
|
|
124
|
+
expect(response.json()).toMatchObject({ issues: [] });
|
|
125
|
+
expect(response.body).not.toContain("secret-config-value");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("Host: attacker.example 로 온 dev 상태 변경 요청도 핸들러 전에 403으로 거부한다", async () => {
|
|
129
|
+
const response = await app.inject({
|
|
130
|
+
method: "POST",
|
|
131
|
+
url: "/custom-test/run",
|
|
132
|
+
headers: { host: "attacker.example:34900" },
|
|
133
|
+
payload: {},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(response.statusCode).toBe(403);
|
|
137
|
+
expect(mockManager.run).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it.each(["localhost:34900", "127.0.0.1:34900", "[::1]:34900", "dev.example.test:34900"])(
|
|
141
|
+
"허용된 Host %s 로 온 UI·dev 라우트 요청은 그대로 처리한다",
|
|
142
|
+
async (host) => {
|
|
143
|
+
const config = await app.inject({ url: "/sonamu-ui/api/sonamu/config", headers: { host } });
|
|
144
|
+
const status = await app.inject({ url: "/custom-test/status", headers: { host } });
|
|
145
|
+
|
|
146
|
+
expect(config.statusCode).toBe(200);
|
|
147
|
+
expect(status.statusCode).toBe(200);
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
it("보호 대상이 아닌 앱 라우트는 Host와 관계없이 처리한다", async () => {
|
|
152
|
+
const api = await app.inject({ url: "/api/user/me", headers: { host: "attacker.example" } });
|
|
153
|
+
const lookalike = await app.inject({
|
|
154
|
+
url: "/sonamu-uix",
|
|
155
|
+
headers: { host: "attacker.example" },
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(api.statusCode).toBe(200);
|
|
159
|
+
expect(lookalike.statusCode).toBe(200);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import Fastify from "fastify";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { FixtureManager } from "../../testing/fixture-manager";
|
|
5
|
+
import { getSonamuUIToken, SONAMU_UI_TOKEN_HEADER } from "../access-guard";
|
|
6
|
+
import { aiClient } from "../ai-client";
|
|
7
|
+
import { sonamuUIApiPlugin } from "../api";
|
|
8
|
+
import { createConfig, createDBConfig, setupSonamu } from "./ui-test-helpers";
|
|
9
|
+
|
|
10
|
+
// 실제 sonamuUIApiPlugin을 거치므로 SON-618 접근 토큰을 보내야 DB 프리셋 검증까지 도달합니다.
|
|
11
|
+
const UI_TOKEN_HEADERS = { [SONAMU_UI_TOKEN_HEADER]: getSonamuUIToken() };
|
|
12
|
+
|
|
13
|
+
describe("Sonamu UI fixture API의 DB 프리셋 제한", () => {
|
|
14
|
+
let app: ReturnType<typeof Fastify>;
|
|
15
|
+
let cleanup: () => Promise<void>;
|
|
16
|
+
const getFixturesSpy = vi.spyOn(FixtureManager, "getFixtures");
|
|
17
|
+
const insertFixturesSpy = vi.spyOn(FixtureManager, "insertFixtures");
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
({ cleanup } = await setupSonamu(createConfig(), createDBConfig()));
|
|
21
|
+
vi.spyOn(aiClient, "init").mockResolvedValue(undefined);
|
|
22
|
+
getFixturesSpy.mockResolvedValue([]);
|
|
23
|
+
insertFixturesSpy.mockResolvedValue([]);
|
|
24
|
+
app = Fastify();
|
|
25
|
+
await app.register(sonamuUIApiPlugin);
|
|
26
|
+
await app.ready();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await app.close();
|
|
31
|
+
await cleanup();
|
|
32
|
+
vi.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const search = { entityId: "User", field: "id", value: "1", searchType: "equals" };
|
|
36
|
+
|
|
37
|
+
it.each([
|
|
38
|
+
{ sourceDB: "production", targetDB: "test" },
|
|
39
|
+
{ sourceDB: "production_readonly", targetDB: "fixture" },
|
|
40
|
+
{ sourceDB: "development", targetDB: "staging" },
|
|
41
|
+
{ sourceDB: ["development"], targetDB: "test" },
|
|
42
|
+
])("조회 요청 %j 는 400으로 거부하고 DB에 접근하지 않는다", async (dbs) => {
|
|
43
|
+
const res = await app.inject({
|
|
44
|
+
method: "POST",
|
|
45
|
+
url: "/sonamu-ui/api/fixture",
|
|
46
|
+
headers: UI_TOKEN_HEADERS,
|
|
47
|
+
payload: { ...dbs, search },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(res.statusCode).toBe(400);
|
|
51
|
+
expect(getFixturesSpy).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("development에서 test로 조회하는 요청은 허용한다", async () => {
|
|
55
|
+
const res = await app.inject({
|
|
56
|
+
method: "POST",
|
|
57
|
+
url: "/sonamu-ui/api/fixture",
|
|
58
|
+
headers: UI_TOKEN_HEADERS,
|
|
59
|
+
payload: { sourceDB: "development", targetDB: "test", search },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(res.statusCode).toBe(200);
|
|
63
|
+
expect(getFixturesSpy).toHaveBeenCalledWith("development", "test", search, undefined);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it.each(["production", "staging", "development_old"])(
|
|
67
|
+
"저장 대상 db=%s 는 400으로 거부하고 쓰지 않는다",
|
|
68
|
+
async (db) => {
|
|
69
|
+
const res = await app.inject({
|
|
70
|
+
method: "POST",
|
|
71
|
+
url: "/sonamu-ui/api/fixture/import",
|
|
72
|
+
headers: UI_TOKEN_HEADERS,
|
|
73
|
+
payload: { db, fixtures: [] },
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(res.statusCode).toBe(400);
|
|
77
|
+
expect(insertFixturesSpy).not.toHaveBeenCalled();
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
it("fixture DB 저장 요청은 허용한다", async () => {
|
|
82
|
+
const res = await app.inject({
|
|
83
|
+
method: "POST",
|
|
84
|
+
url: "/sonamu-ui/api/fixture/import",
|
|
85
|
+
headers: UI_TOKEN_HEADERS,
|
|
86
|
+
payload: { db: "fixture", fixtures: [] },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(res.statusCode).toBe(200);
|
|
90
|
+
expect(insertFixturesSpy).toHaveBeenCalledWith("fixture", []);
|
|
91
|
+
});
|
|
92
|
+
});
|