@stackonward/cli 0.0.1 → 1.0.1
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/index.js +4588 -205
- package/dist/index.js.map +1 -1
- package/dist/resources/apple/.claude/docs/architecture-template.md +54 -0
- package/dist/resources/apple/.claude/docs/architecture.md +52 -0
- package/dist/resources/apple/.claude/docs/index.md +13 -0
- package/dist/resources/apple/.claude/docs/security-lifecycle.md +57 -0
- package/dist/resources/apple/.claude/docs/stack.md +93 -0
- package/dist/resources/apple/.claude/docs/verification.md +63 -0
- package/dist/resources/apple/AGENTS.md +397 -0
- package/dist/resources/apple/CLAUDE.md +397 -0
- package/dist/resources/apple/Gemfile +2 -0
- package/dist/resources/apple/Gemfile.lock +365 -0
- package/dist/resources/apple/_gitignore +14 -0
- package/dist/resources/apple/fastlane/Fastfile +123 -0
- package/dist/resources/components/nuxt/site-source/app/app.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/assets/css/site-shell.css +1035 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/brand/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/common/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationHeader.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationShell.vue +56 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationSidebar.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/BackToTop.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentArticlePage.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentListPage.vue +30 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/CookieConsent.vue +18 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingFooter.vue +52 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingHeader.vue +106 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingShell.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/SiteBrand.vue +10 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/StaticPage.vue +21 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ToastViewport.vue +25 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseButton.vue +86 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseGradientBorder.vue +59 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseModal.vue +131 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BasePopover.vue +150 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseText.vue +138 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutStatus.vue +112 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutSummary.vue +172 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/GoogleSignInButton.vue +113 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/InfiniteScroll.vue +123 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/YoutubeEmbed.vue +126 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useAnalytics.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useCheckout.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useConsent.ts +31 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useGoogleIdentity.ts +163 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useNavigation.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSeo.ts +33 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSiteShell.ts +58 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useToasts.ts +48 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/app.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/default.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/analytics.client.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/google-identity.client.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/theme/accordion.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/breadcrumb.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/button.ts +92 -0
- package/dist/resources/components/nuxt/site-source/app/theme/carousel.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/theme/checkbox.ts +12 -0
- package/dist/resources/components/nuxt/site-source/app/theme/index.ts +30 -0
- package/dist/resources/components/nuxt/site-source/app/theme/input.ts +47 -0
- package/dist/resources/components/nuxt/site-source/app/theme/modal.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/pagination.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/theme/select.ts +23 -0
- package/dist/resources/components/nuxt/site-source/app/theme/stepper.ts +10 -0
- package/dist/resources/components/nuxt/site-source/app/theme/toast.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/tooltip.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/types/site-shell.ts +85 -0
- package/dist/resources/components/react/ui/Button.tsx +73 -0
- package/dist/resources/components/react/ui/Input.tsx +44 -0
- package/dist/resources/components/registry.json +355 -0
- package/dist/resources/components/vue/feedback/Toast.vue +120 -0
- package/dist/resources/components/vue/feedback/useToast.ts +70 -0
- package/dist/resources/components/vue/media/FileUpload.vue +229 -0
- package/dist/resources/components/vue/media/VideoPlayer.vue +157 -0
- package/dist/resources/components/vue/ui/AppImage.vue +147 -0
- package/dist/resources/components/vue/ui/BottomSheet.vue +217 -0
- package/dist/resources/components/vue/ui/Button.vue +154 -0
- package/dist/resources/components/vue/ui/Card.vue +111 -0
- package/dist/resources/components/vue/ui/Input.vue +113 -0
- package/dist/resources/components/vue/ui/Modal.vue +193 -0
- package/dist/resources/components/vue/ui/ScrollArea.vue +163 -0
- package/dist/resources/components/vue/ui/Tooltip.vue +115 -0
- package/dist/resources/registry.json +158 -0
- package/dist/resources/snippets/node/cache.ts +116 -0
- package/dist/resources/snippets/node/date.ts +126 -0
- package/dist/resources/snippets/node/logger.ts +104 -0
- package/dist/resources/snippets/node/validation.ts +132 -0
- package/dist/resources/snippets/react/useDebounce.ts +90 -0
- package/dist/resources/snippets/registry.json +65 -0
- package/dist/resources/snippets/vue/useAsync.ts +96 -0
- package/dist/resources/snippets/vue/usePagination.ts +102 -0
- package/dist/resources/templates/base/.claude/docs/architecture-template.md +459 -0
- package/dist/resources/templates/base/.claude/docs/architecture.md +137 -0
- package/dist/resources/templates/base/.claude/docs/index.md +42 -0
- package/dist/resources/templates/base/.claude/docs/security-lifecycle.md +129 -0
- package/dist/resources/templates/base/.claude/docs/verification.md +121 -0
- package/dist/resources/templates/base/AGENTS.md +415 -0
- package/dist/resources/templates/base/CLAUDE.md +415 -0
- package/dist/resources/templates/go-backend/.claude/docs/api-design.md +486 -0
- package/dist/resources/templates/go-backend/.claude/docs/architecture-template.md +449 -0
- package/dist/resources/templates/go-backend/.claude/docs/check-list.md +155 -0
- package/dist/resources/templates/go-backend/.claude/docs/database.md +369 -0
- package/dist/resources/templates/go-backend/.claude/docs/e2e-standards.md +161 -0
- package/dist/resources/templates/go-backend/.claude/docs/error-handling.md +558 -0
- package/dist/resources/templates/go-backend/.claude/docs/event-runtime-boundary.md +124 -0
- package/dist/resources/templates/go-backend/.claude/docs/identifier-contract.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/index.md +22 -0
- package/dist/resources/templates/go-backend/.claude/docs/logging.md +314 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-onboarding-sop.md +917 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-quick-reference.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/module-standards.md +309 -0
- package/dist/resources/templates/go-backend/.claude/docs/openapi-contract.md +141 -0
- package/dist/resources/templates/go-backend/.claude/docs/payment-gateway-onboarding.md +283 -0
- package/dist/resources/templates/go-backend/.claude/docs/platform-boundary.md +191 -0
- package/dist/resources/templates/go-backend/.claude/docs/quality-gates.md +112 -0
- package/dist/resources/templates/go-backend/.dockerignore +6 -0
- package/dist/resources/templates/go-backend/.env.example +13 -0
- package/dist/resources/templates/go-backend/.gitattributes +2 -0
- package/dist/resources/templates/go-backend/AGENTS.md +1139 -0
- package/dist/resources/templates/go-backend/CLAUDE.md +1139 -0
- package/dist/resources/templates/go-backend/Dockerfile +14 -0
- package/dist/resources/templates/go-backend/Makefile +71 -0
- package/dist/resources/templates/go-backend/README.md +66 -0
- package/dist/resources/templates/go-backend/_gitignore +10 -0
- package/dist/resources/templates/go-backend/api/openapi/README.md +29 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/artifact-manifest.json +19 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/conformance-matrix.json +276 -0
- package/dist/resources/templates/go-backend/api/openapi/document.go +30 -0
- package/dist/resources/templates/go-backend/api/openapi/package.json +28 -0
- package/dist/resources/templates/go-backend/api/openapi/pnpm-lock.yaml +3052 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly-source.yaml +18 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly.yaml +8 -0
- package/dist/resources/templates/go-backend/api/openapi/sdk-generators.json +16 -0
- package/dist/resources/templates/go-backend/api/openapi/service-registry.json +39 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/breaking.mjs +416 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/build.mjs +103 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/conformance_coverage.mjs +111 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_compiler.mjs +62 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_policy.mjs +208 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/delegated_contract.mjs +302 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/deterministic_archive.mjs +69 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_example_privacy.mjs +93 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_projection.mjs +498 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_quality.mjs +346 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/git_artifact_history.mjs +188 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/manifest.mjs +170 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/overlay.mjs +98 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/project.mjs +549 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/route_contract.mjs +156 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/runtime_conformance.mjs +193 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/scalar_asset_localization.mjs +164 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/sdk_generator.mjs +229 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/semantic_version.mjs +64 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/service_contract_inputs.mjs +16 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/breaking.test.mjs +365 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/build.test.mjs +42 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/conformance_coverage.test.mjs +88 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/contract_policy.test.mjs +257 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/delegated_contract.test.mjs +205 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_example_privacy.test.mjs +51 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_projection.test.mjs +368 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_quality.test.mjs +151 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/git_artifact_history.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/head_policy.test.mjs +8 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/overlay.test.mjs +44 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/projection.test.mjs +270 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/redocly_documentation_rules.test.mjs +146 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/release_manifest.test.mjs +76 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/route_contract.test.mjs +119 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/runtime_conformance.test.mjs +75 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/scalar_asset_localization.test.mjs +50 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/sdk_generator.test.mjs +31 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/semantic_version.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/service_contract_inputs.test.mjs +27 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/resources.go +125 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime.go +102 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime_test.go +70 -0
- package/dist/resources/templates/go-backend/cmd/product-api/lifecycle_test.go +58 -0
- package/dist/resources/templates/go-backend/cmd/product-api/main.go +32 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire.go +13 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire_gen.go +94 -0
- package/dist/resources/templates/go-backend/cmd/worker/main.go +47 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire.go +14 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire_gen.go +111 -0
- package/dist/resources/templates/go-backend/configs/config.yaml +37 -0
- package/dist/resources/templates/go-backend/deployments/compose.yaml +71 -0
- package/dist/resources/templates/go-backend/docs/openapi-provenance.json +489 -0
- package/dist/resources/templates/go-backend/docs/runtime-provenance.json +175 -0
- package/dist/resources/templates/go-backend/docs/source-provenance.json +3568 -0
- package/dist/resources/templates/go-backend/docs/standards-provenance.json +1624 -0
- package/dist/resources/templates/go-backend/go.mod +256 -0
- package/dist/resources/templates/go-backend/go.sum +805 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical.go +370 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical_test.go +223 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/contracts.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/contentaccess/contentaccess.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/contracts/contact.go +85 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/identity.go +20 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/product.go +53 -0
- package/dist/resources/templates/go-backend/internal/common/enumdomain/payment.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/dto_admin.go +9 -0
- package/dist/resources/templates/go-backend/internal/common/enums/enum.go +1247 -0
- package/dist/resources/templates/go-backend/internal/common/enums/handler_admin.go +66 -0
- package/dist/resources/templates/go-backend/internal/common/enums/module.go +46 -0
- package/dist/resources/templates/go-backend/internal/common/enums/provider.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_audit.go +274 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_command_replay.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_config.go +27 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_locale.go +37 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_ops.go +14 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_outbox.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_rule_expression.go +63 -0
- package/dist/resources/templates/go-backend/internal/common/enums/registry.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin_test.go +38 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext_test.go +29 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_binding.go +26 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter.go +173 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter_test.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/authorization_details.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies.go +660 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/audience_token_source.go +166 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bootstrap_token_exchanger.go +183 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bound_service_token_signer.go +52 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger.go +189 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/product_scoped_service_token_signer.go +92 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/provider.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/request_signer.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver.go +69 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver_test.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope.go +95 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope_test.go +78 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/service_identity_test.go +387 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler_test.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale.go +145 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale_test.go +75 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref.go +54 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_auth.go +320 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_throttle.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth_test.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/client_context.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/cors.go +68 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/event_context.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/gateway_identity.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/helpers.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_route_permission.go +171 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth.go +151 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_identity.go +138 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_token_auth.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent.go +273 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent_test.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission_test.go +186 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/logging.go +191 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/metrics.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/middleware_test.go +1516 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context.go +160 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context_test.go +355 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/product_context.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/recovery.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/referral_attribution.go +178 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/requestid.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission.go +790 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission_test.go +440 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/service_credential_auth.go +67 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/tenant.go +148 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/throttle.go +310 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/money/currency.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/money/errors.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/money/format.go +123 -0
- package/dist/resources/templates/go-backend/internal/common/money/format_test.go +204 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway.go +144 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway_test.go +165 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/principal/context.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/principal/principal.go +49 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema.go +577 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema_test.go +47 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request.go +246 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/common/response/pagination.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/response/response.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/response/response_test.go +463 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast.go +141 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical.go +184 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder.go +555 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder_test.go +260 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/errors.go +55 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator.go +96 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator_test.go +220 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/fuzz_test.go +116 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/limits.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema.go +412 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema_test.go +164 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input.go +627 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input_test.go +245 -0
- package/dist/resources/templates/go-backend/internal/common/semver/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver_test.go +205 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier.go +33 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier_test.go +32 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator_test.go +396 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/prefix.go +247 -0
- package/dist/resources/templates/go-backend/internal/common/types/asset_url.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing.go +89 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/types/country.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/types/country_test.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/currency.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/types/identifiers.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/types/operator.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/types/tier.go +72 -0
- package/dist/resources/templates/go-backend/internal/common/types/types.go +411 -0
- package/dist/resources/templates/go-backend/internal/common/types/types_test.go +295 -0
- package/dist/resources/templates/go-backend/internal/common/utils/constants.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto_test.go +345 -0
- package/dist/resources/templates/go-backend/internal/common/utils/duration.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/utils/helpers.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json_test.go +76 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination_test.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer.go +107 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer_test.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/utils/slice.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake_test.go +316 -0
- package/dist/resources/templates/go-backend/internal/common/utils/string.go +16 -0
- package/dist/resources/templates/go-backend/internal/common/utils/timefmt.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator.go +136 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator_test.go +240 -0
- package/dist/resources/templates/go-backend/internal/common/youtubeapi/client.go +224 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator.go +78 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator_test.go +108 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.js +2385 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.metadata.json +10 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route.go +107 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route_test.go +200 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar.go +117 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy.go +91 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/audit/actor_resolver.go +36 -0
- package/dist/resources/templates/go-backend/internal/core/audit/constants.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context.go +119 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context_test.go +310 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto.go +468 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto_admin.go +172 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum.go +460 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum_test.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/audit/errors.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/handler.go +568 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener.go +319 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware.go +669 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware_test.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/audit/model.go +306 -0
- package/dist/resources/templates/go-backend/internal/core/audit/partition_job.go +316 -0
- package/dist/resources/templates/go-backend/internal/core/audit/ports.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/provider.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository.go +1007 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository_test.go +934 -0
- package/dist/resources/templates/go-backend/internal/core/audit/router.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service.go +770 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/core/audit/vo_admin.go +475 -0
- package/dist/resources/templates/go-backend/internal/core/cache/config.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key.go +41 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key_test.go +62 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1.go +153 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1_test.go +212 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager.go +278 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager_provider.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/cache/metrics.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace_test.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options.go +39 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options_test.go +96 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis.go +311 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer.go +31 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer_test.go +139 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight_test.go +211 -0
- package/dist/resources/templates/go-backend/internal/core/cache/warming.go +86 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock.go +66 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock_test.go +26 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock.go +283 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model_test.go +79 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/namespace.go +7 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence_test.go +185 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/provider.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/repository.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service.go +853 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_persistence_test.go +432 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_test.go +891 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/types.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/config/config.go +2069 -0
- package/dist/resources/templates/go-backend/internal/core/config/config_test.go +1122 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/contract_test.go +388 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/docs.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/verify.go +424 -0
- package/dist/resources/templates/go-backend/internal/core/config/enum.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata.go +717 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata_test.go +228 -0
- package/dist/resources/templates/go-backend/internal/core/config/product_admin_config_test.go +210 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm.go +111 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm_test.go +364 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/encryptor.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor.go +134 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor_test.go +118 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem_test.go +44 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider.go +130 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider_test.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/database/base_model.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/database/clickhouse.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/database/database.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/database/database_logger_test.go +95 -0
- package/dist/resources/templates/go-backend/internal/core/database/errors.go +25 -0
- package/dist/resources/templates/go-backend/internal/core/database/metrics_plugin.go +105 -0
- package/dist/resources/templates/go-backend/internal/core/database/pool_collector.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/database/read_replica.go +520 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction_test.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock.go +353 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock_test.go +106 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler.go +189 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler_test.go +515 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus.go +667 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus_test.go +792 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/noop.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/provider.go +20 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/publisher.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/redis.go +109 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing_test.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/model.go +19 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/service.go +88 -0
- package/dist/resources/templates/go-backend/internal/core/health/health.go +333 -0
- package/dist/resources/templates/go-backend/internal/core/health/health_test.go +27 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client.go +772 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client_test.go +287 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download.go +578 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download_test.go +374 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/jwk.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring.go +144 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring_test.go +128 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/registry.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger_test.go +194 -0
- package/dist/resources/templates/go-backend/internal/core/observability/metrics.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry.go +445 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry_privacy_test.go +175 -0
- package/dist/resources/templates/go-backend/internal/core/observability/tracing.go +187 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/persistence.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/provider.go +23 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay.go +1138 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_postgres_test.go +257 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_test.go +690 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler.go +164 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler_test.go +209 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer.go +249 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_postgres_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_test.go +123 -0
- package/dist/resources/templates/go-backend/internal/core/provider.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware_test.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue.go +288 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead.go +514 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead_test.go +984 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker_test.go +788 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry.go +318 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry_test.go +735 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/recorder.go +305 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context.go +124 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context_test.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler.go +1589 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler_control_test.go +808 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider.go +398 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider_test.go +89 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path.go +110 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path_test.go +301 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider.go +489 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/storage/storage.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation.go +225 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation_test.go +495 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/logger.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider_test.go +67 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/config.go +58 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/handler.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/hub.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/message.go +273 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/notifier.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/provider.go +33 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action.go +77 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action_test.go +238 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/condition.go +107 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/decision.go +256 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/enum.go +643 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/errors.go +102 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/principal_record.go +21 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/product_context.go +486 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource.go +215 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource_test.go +242 -0
- package/dist/resources/templates/go-backend/internal/products/README.md +5 -0
- package/dist/resources/templates/go-backend/internal/sharedevents/README.md +5 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.down.sql +13 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.up.sql +886 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error.go +327 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_code.go +65 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_test.go +41 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_type.go +14 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response.go +216 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response_test.go +216 -0
- package/dist/resources/templates/go-backend/scripts/check-openapi-clean-deletion.sh +54 -0
- package/dist/resources/templates/go-backend/scripts/test-migrations.sh +32 -0
- package/dist/resources/templates/go-backend/tests/infrastructure.sql +69 -0
- package/dist/resources/templates/mcp-server/.claude/docs/stack.md +338 -0
- package/dist/resources/templates/mcp-server/.editorconfig +13 -0
- package/dist/resources/templates/mcp-server/.env.example +8 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/bug_report.yml +104 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/feature_request.yml +54 -0
- package/dist/resources/templates/mcp-server/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/dist/resources/templates/mcp-server/.github/workflows/ci.yml +78 -0
- package/dist/resources/templates/mcp-server/.husky/commit-msg +1 -0
- package/dist/resources/templates/mcp-server/.husky/pre-commit +1 -0
- package/dist/resources/templates/mcp-server/.lintstagedrc.json +4 -0
- package/dist/resources/templates/mcp-server/.nvmrc +1 -0
- package/dist/resources/templates/mcp-server/.prettierrc +8 -0
- package/dist/resources/templates/mcp-server/CONTRIBUTING.md +184 -0
- package/dist/resources/templates/mcp-server/Dockerfile +23 -0
- package/dist/resources/templates/mcp-server/LICENSE +21 -0
- package/dist/resources/templates/mcp-server/README.md +123 -0
- package/dist/resources/templates/mcp-server/_gitignore +26 -0
- package/dist/resources/templates/mcp-server/commitlint.config.js +24 -0
- package/dist/resources/templates/mcp-server/eslint.config.js +30 -0
- package/dist/resources/templates/mcp-server/package.json +72 -0
- package/dist/resources/templates/mcp-server/src/index.ts +27 -0
- package/dist/resources/templates/mcp-server/src/resources.ts +33 -0
- package/dist/resources/templates/mcp-server/src/services/.gitkeep +0 -0
- package/dist/resources/templates/mcp-server/src/tools.ts +43 -0
- package/dist/resources/templates/mcp-server/src/types/index.ts +19 -0
- package/dist/resources/templates/mcp-server/src/utils/index.ts +31 -0
- package/dist/resources/templates/mcp-server/tsconfig.json +22 -0
- package/dist/resources/templates/mcp-server/tsup.config.ts +14 -0
- package/dist/resources/templates/mcp-server/vitest.config.ts +15 -0
- package/dist/resources/templates/nuxt/.claude/docs/stack.md +666 -0
- package/dist/resources/templates/nuxt/.editorconfig +15 -0
- package/dist/resources/templates/nuxt/.env.example +22 -0
- package/dist/resources/templates/nuxt/.github/workflows/ci.yml +34 -0
- package/dist/resources/templates/nuxt/.husky/commit-msg +1 -0
- package/dist/resources/templates/nuxt/.husky/pre-commit +1 -0
- package/dist/resources/templates/nuxt/.nvmrc +1 -0
- package/dist/resources/templates/nuxt/.prettierignore +9 -0
- package/dist/resources/templates/nuxt/.prettierrc +1 -0
- package/dist/resources/templates/nuxt/README.md +23 -0
- package/dist/resources/templates/nuxt/_gitignore +7 -0
- package/dist/resources/templates/nuxt/app/app.config.ts +105 -0
- package/dist/resources/templates/nuxt/app/i18n/locales/en.json +5 -0
- package/dist/resources/templates/nuxt/app/pages/app/index.vue +224 -0
- package/dist/resources/templates/nuxt/app/pages/authors/[slug].vue +37 -0
- package/dist/resources/templates/nuxt/app/pages/blog/[slug].vue +55 -0
- package/dist/resources/templates/nuxt/app/pages/blog/category/[category].vue +38 -0
- package/dist/resources/templates/nuxt/app/pages/blog/index.vue +46 -0
- package/dist/resources/templates/nuxt/app/pages/index.vue +626 -0
- package/dist/resources/templates/nuxt/app/pages/legal/privacy.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/legal/terms.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/ui/index.vue +397 -0
- package/dist/resources/templates/nuxt/commitlint.config.mjs +1 -0
- package/dist/resources/templates/nuxt/eslint.config.mjs +4 -0
- package/dist/resources/templates/nuxt/lint-staged.config.mjs +8 -0
- package/dist/resources/templates/nuxt/nuxt.config.ts +71 -0
- package/dist/resources/templates/nuxt/package.json +67 -0
- package/dist/resources/templates/nuxt/public/apple-touch-icon.png +0 -0
- package/dist/resources/templates/nuxt/public/favicon.ico +0 -0
- package/dist/resources/templates/nuxt/public/favicon.svg +5 -0
- package/dist/resources/templates/nuxt/public/icon-16x16.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-192x192.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-32x32.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-512x512.png +0 -0
- package/dist/resources/templates/nuxt/public/logo.svg +6 -0
- package/dist/resources/templates/nuxt/public/media/hero-product-gallery.png +0 -0
- package/dist/resources/templates/nuxt/server/api/content/sitemap-urls.get.ts +12 -0
- package/dist/resources/templates/nuxt/server/api/preview.get.ts +9 -0
- package/dist/resources/templates/nuxt/stylelint.config.mjs +3 -0
- package/dist/resources/templates/nuxt/test/e2e/rendering.test.ts +13 -0
- package/dist/resources/templates/nuxt/tsconfig.json +3 -0
- package/dist/resources/templates/nuxt/vitest.config.ts +8 -0
- package/package.json +8 -5
|
@@ -0,0 +1,1122 @@
|
|
|
1
|
+
package config
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
"time"
|
|
7
|
+
|
|
8
|
+
"github.com/spf13/viper"
|
|
9
|
+
"github.com/stretchr/testify/assert"
|
|
10
|
+
"github.com/stretchr/testify/require"
|
|
11
|
+
|
|
12
|
+
"{{module}}/internal/common/serviceidentity"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const testIdentityPhoneHashKey = "0123456789abcdef0123456789abcdef"
|
|
16
|
+
const testIdentityOAuthStateSigningSecret = "oauth-state-signing-secret-32-bytes-minimum"
|
|
17
|
+
const testBootstrapCredentialRef = "vault://kv/onex/prod/iam/platform-api-bootstrap-credential"
|
|
18
|
+
const testServiceTokenPrivateKeyPath = "/run/secrets/iam-service-token-private.pem"
|
|
19
|
+
const testServiceTokenPublicKeyDirectory = "/run/secrets/iam-service-token-public"
|
|
20
|
+
|
|
21
|
+
func TestValidateFeatureFlagConfig(t *testing.T) {
|
|
22
|
+
valid := FeatureFlagConfig{
|
|
23
|
+
FreshnessTTL: 30 * time.Second,
|
|
24
|
+
MaximumStaleAge: 15 * time.Minute,
|
|
25
|
+
CacheTTL: 30 * time.Minute,
|
|
26
|
+
}
|
|
27
|
+
require.NoError(t, validateFeatureFlagConfig(valid))
|
|
28
|
+
|
|
29
|
+
invalid := []FeatureFlagConfig{
|
|
30
|
+
{FreshnessTTL: 0, MaximumStaleAge: time.Minute, CacheTTL: time.Minute},
|
|
31
|
+
{FreshnessTTL: time.Minute, MaximumStaleAge: 30 * time.Second, CacheTTL: time.Minute},
|
|
32
|
+
{FreshnessTTL: time.Second, MaximumStaleAge: time.Minute, CacheTTL: 30 * time.Second},
|
|
33
|
+
}
|
|
34
|
+
for _, candidate := range invalid {
|
|
35
|
+
require.Error(t, validateFeatureFlagConfig(candidate))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// TestConfigIsDevelopment 验证 IsDevelopment() 对各环境值的行为
|
|
40
|
+
func TestConfigIsDevelopment(t *testing.T) {
|
|
41
|
+
t.Run("returns true for development", func(t *testing.T) {
|
|
42
|
+
cfg := &Config{App: AppConfig{Env: "development"}}
|
|
43
|
+
assert.True(t, cfg.IsDevelopment())
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
t.Run("returns false for production", func(t *testing.T) {
|
|
47
|
+
cfg := &Config{App: AppConfig{Env: "production"}}
|
|
48
|
+
assert.False(t, cfg.IsDevelopment())
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
t.Run("returns false for staging", func(t *testing.T) {
|
|
52
|
+
cfg := &Config{App: AppConfig{Env: "staging"}}
|
|
53
|
+
assert.False(t, cfg.IsDevelopment())
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
t.Run("returns false for local", func(t *testing.T) {
|
|
57
|
+
// "local" は "development" と等しくないため false を返す
|
|
58
|
+
cfg := &Config{App: AppConfig{Env: "local"}}
|
|
59
|
+
assert.False(t, cfg.IsDevelopment())
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
t.Run("returns false for empty string", func(t *testing.T) {
|
|
63
|
+
cfg := &Config{App: AppConfig{Env: ""}}
|
|
64
|
+
assert.False(t, cfg.IsDevelopment())
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// TestConfigIsProduction 验证 IsProduction() 对各环境值的行为
|
|
69
|
+
func TestConfigIsProduction(t *testing.T) {
|
|
70
|
+
t.Run("returns true for production", func(t *testing.T) {
|
|
71
|
+
cfg := &Config{App: AppConfig{Env: "production"}}
|
|
72
|
+
assert.True(t, cfg.IsProduction())
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
t.Run("returns false for development", func(t *testing.T) {
|
|
76
|
+
cfg := &Config{App: AppConfig{Env: "development"}}
|
|
77
|
+
assert.False(t, cfg.IsProduction())
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
t.Run("returns false for local", func(t *testing.T) {
|
|
81
|
+
cfg := &Config{App: AppConfig{Env: "local"}}
|
|
82
|
+
assert.False(t, cfg.IsProduction())
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
t.Run("returns false for staging", func(t *testing.T) {
|
|
86
|
+
cfg := &Config{App: AppConfig{Env: "staging"}}
|
|
87
|
+
assert.False(t, cfg.IsProduction())
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
t.Run("returns false for empty string", func(t *testing.T) {
|
|
91
|
+
cfg := &Config{App: AppConfig{Env: ""}}
|
|
92
|
+
assert.False(t, cfg.IsProduction())
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// TestConfigStructDefaults 验证 setDefaults 写入的默认值与源码一致
|
|
97
|
+
// 不依赖文件系统,直接构造 viper 实例并调用包内 setDefaults 函数
|
|
98
|
+
func TestConfigStructDefaults(t *testing.T) {
|
|
99
|
+
v := viper.New()
|
|
100
|
+
setDefaults(v)
|
|
101
|
+
|
|
102
|
+
t.Run("app defaults", func(t *testing.T) {
|
|
103
|
+
assert.Equal(t, "ai-chat-platform", v.GetString("app.name"))
|
|
104
|
+
assert.Equal(t, 3000, v.GetInt("app.port"))
|
|
105
|
+
assert.Equal(t, "0.0.0.0", v.GetString("app.host"))
|
|
106
|
+
assert.Equal(t, "development", v.GetString("app.env"))
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
t.Run("database defaults", func(t *testing.T) {
|
|
110
|
+
assert.Equal(t, "localhost", v.GetString("database.host"))
|
|
111
|
+
assert.Equal(t, 5432, v.GetInt("database.port"))
|
|
112
|
+
assert.Equal(t, "postgres", v.GetString("database.username"))
|
|
113
|
+
assert.Equal(t, "", v.GetString("database.password"))
|
|
114
|
+
assert.Equal(t, "ai_chat_platform", v.GetString("database.name"))
|
|
115
|
+
assert.False(t, v.GetBool("database.ssl"))
|
|
116
|
+
assert.False(t, v.GetBool("database.logging"))
|
|
117
|
+
assert.Equal(t, 25, v.GetInt("database.max_open_conns"))
|
|
118
|
+
assert.Equal(t, 10, v.GetInt("database.max_idle_conns"))
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
t.Run("redis defaults", func(t *testing.T) {
|
|
122
|
+
assert.Equal(t, "localhost", v.GetString("redis.host"))
|
|
123
|
+
assert.Equal(t, 6379, v.GetInt("redis.port"))
|
|
124
|
+
assert.Equal(t, "", v.GetString("redis.password"))
|
|
125
|
+
assert.Equal(t, 0, v.GetInt("redis.db"))
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
t.Run("identity access token defaults", func(t *testing.T) {
|
|
129
|
+
assert.Equal(t, "http://localhost:3002", v.GetString("identity.access_token.issuer"))
|
|
130
|
+
assert.Equal(t, "onex-local-2026-07", v.GetString("identity.access_token.signing_key_id"))
|
|
131
|
+
assert.Equal(t, "", v.GetString("identity.access_token.private_key_path"))
|
|
132
|
+
var cfg Config
|
|
133
|
+
require.NoError(t, v.Unmarshal(&cfg))
|
|
134
|
+
assert.Len(t, cfg.Identity.Clients, 1)
|
|
135
|
+
assert.Equal(t, "platform", cfg.Identity.Clients["admin-web"].ProductCode)
|
|
136
|
+
assert.Equal(t, "admin_web", cfg.Identity.Clients["admin-web"].ApplicationCode)
|
|
137
|
+
assert.ElementsMatch(t, []string{"user"}, cfg.Identity.Clients["admin-web"].AllowedPrincipalTypes)
|
|
138
|
+
assert.ElementsMatch(t, []string{"openid", "profile"}, cfg.Identity.AccessToken.Resources["platform"].GuestScopes)
|
|
139
|
+
assert.Contains(t, cfg.Identity.AccessToken.Resources, "platform")
|
|
140
|
+
assert.NotContains(t, cfg.Identity.AccessToken.Resources, "onex")
|
|
141
|
+
assert.Equal(t, "http://localhost:3002", cfg.Identity.AccessToken.ProtectedResources["platform_internal_api"].ResourceIdentifier)
|
|
142
|
+
assert.Equal(t, serviceidentity.AudiencePlatformInternalAPI, cfg.Identity.AccessToken.ProtectedResources["platform_internal_api"].Audience)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
t.Run("openai defaults", func(t *testing.T) {
|
|
146
|
+
assert.Equal(t, "", v.GetString("openai.api_key"))
|
|
147
|
+
assert.Equal(t, "gpt-4", v.GetString("openai.model"))
|
|
148
|
+
assert.Equal(t, "https://api.openai.com/v1", v.GetString("openai.base_url"))
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
t.Run("anthropic defaults", func(t *testing.T) {
|
|
152
|
+
assert.Equal(t, "", v.GetString("anthropic.api_key"))
|
|
153
|
+
assert.Equal(t, "claude-3-opus-20240229", v.GetString("anthropic.model"))
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
t.Run("log defaults", func(t *testing.T) {
|
|
157
|
+
assert.Equal(t, "debug", v.GetString("log.level"))
|
|
158
|
+
assert.Equal(t, "development", v.GetString("log.env"))
|
|
159
|
+
assert.Equal(t, "debug", v.GetString("log.request_success_level"))
|
|
160
|
+
assert.InDelta(t, 0.0, v.GetFloat64("log.request_success_sample_rate"), 0.001)
|
|
161
|
+
assert.Equal(t, "2s", v.GetString("log.request_slow_threshold"))
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
t.Run("audit access log defaults", func(t *testing.T) {
|
|
165
|
+
assert.True(t, v.GetBool("audit.access_log.enabled"))
|
|
166
|
+
assert.InDelta(t, 0.05, v.GetFloat64("audit.access_log.success_read_sample_rate"), 0.001)
|
|
167
|
+
assert.Equal(t, "2s", v.GetString("audit.access_log.slow_request_threshold"))
|
|
168
|
+
assert.True(t, v.GetBool("audit.access_log.record_write_methods"))
|
|
169
|
+
assert.True(t, v.GetBool("audit.access_log.record_client_errors"))
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
t.Run("throttle defaults", func(t *testing.T) {
|
|
173
|
+
assert.Equal(t, 60, v.GetInt("throttle.ttl"))
|
|
174
|
+
assert.Equal(t, 100, v.GetInt("throttle.limit"))
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
t.Run("internal service defaults", func(t *testing.T) {
|
|
178
|
+
assert.Equal(t, "http://platform-api:3002/internal/v1", v.GetString("internal_service.platform_base_url"))
|
|
179
|
+
assert.Equal(t, "http://documentation-api:3010/api/v1/documentation", v.GetString("internal_service.documentation_base_url"))
|
|
180
|
+
assert.Equal(t, "iam-service-local-2026-08", v.GetString("internal_service.service_token_signing.key_id"))
|
|
181
|
+
assert.Empty(t, v.GetStringMap("internal_service.outbound_identities"))
|
|
182
|
+
assert.Equal(t, defaultInternalServiceTokenTTLSeconds, v.GetInt("internal_service.token_ttl_seconds"))
|
|
183
|
+
assert.Equal(t, defaultIAMConsistencyTokenTTLSeconds, v.GetInt("internal_service.authorization_consistency_token_ttl_seconds"))
|
|
184
|
+
assert.Equal(t, "5m0s", v.GetString("identity.access_token.delegated_token_ttl"))
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
t.Run("documentation privacy defaults", func(t *testing.T) {
|
|
188
|
+
assert.Equal(t, "env://DOCUMENTATION_PRIVACY_HMAC_KEY", v.GetString("documentation.privacy_hmac_key_ref"))
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
t.Run("API contract compatibility evaluator defaults", func(t *testing.T) {
|
|
192
|
+
assert.Equal(t, "oasdiff", v.GetString("api_contract.compatibility_evaluator.executable"))
|
|
193
|
+
assert.Equal(t, "2m", v.GetString("api_contract.compatibility_evaluator.timeout"))
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
t.Run("product admin defaults", func(t *testing.T) {
|
|
197
|
+
assert.Empty(t, v.GetStringMap("product_admin.targets"))
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
t.Run("export defaults", func(t *testing.T) {
|
|
201
|
+
assert.Equal(t, "/tmp/exports", v.GetString("export.local_dir"))
|
|
202
|
+
assert.Equal(t, "exports", v.GetString("export.path_prefix"))
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
t.Run("tracing defaults", func(t *testing.T) {
|
|
206
|
+
assert.False(t, v.GetBool("tracing.enabled"))
|
|
207
|
+
assert.Equal(t, "localhost:4318", v.GetString("tracing.endpoint"))
|
|
208
|
+
assert.Equal(t, "onex-backend", v.GetString("tracing.service_name"))
|
|
209
|
+
assert.Equal(t, "1.0.0", v.GetString("tracing.service_version"))
|
|
210
|
+
assert.Equal(t, "development", v.GetString("tracing.environment"))
|
|
211
|
+
assert.InDelta(t, 1.0, v.GetFloat64("tracing.sampling_ratio"), 0.001)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
t.Run("clamav defaults", func(t *testing.T) {
|
|
215
|
+
assert.False(t, v.GetBool("clamav.enabled"))
|
|
216
|
+
assert.Equal(t, "tcp://localhost:3310", v.GetString("clamav.address"))
|
|
217
|
+
assert.Equal(t, 30, v.GetInt("clamav.timeout"))
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
t.Run("communication reputation defaults", func(t *testing.T) {
|
|
221
|
+
assert.Equal(t, []string{"zen.spamhaus.org"}, v.GetStringSlice("communication.reputation.ip_blocklist_zones"))
|
|
222
|
+
assert.Equal(t, []string{"dbl.spamhaus.org"}, v.GetStringSlice("communication.reputation.domain_blocklist_zones"))
|
|
223
|
+
assert.Equal(t, 5, v.GetInt("communication.reputation.dns_lookup_timeout_seconds"))
|
|
224
|
+
assert.Equal(t, 24, v.GetInt("communication.reputation.recheck_interval_hours"))
|
|
225
|
+
assert.Equal(t, 50, v.GetInt("communication.reputation.recheck_batch_limit"))
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
t.Run("temporal defaults", func(t *testing.T) {
|
|
229
|
+
assert.False(t, v.GetBool("temporal.enabled"))
|
|
230
|
+
assert.Equal(t, "", v.GetString("temporal.host_port"))
|
|
231
|
+
assert.Equal(t, "", v.GetString("temporal.namespace"))
|
|
232
|
+
assert.False(t, v.GetBool("temporal.tls.enabled"))
|
|
233
|
+
assert.Equal(t, "", v.GetString("temporal.tls.server_name"))
|
|
234
|
+
assert.False(t, v.GetBool("temporal.tls.disable_host_verification"))
|
|
235
|
+
assert.Equal(t, "", v.GetString("temporal.tls.ca_path"))
|
|
236
|
+
assert.Equal(t, "", v.GetString("temporal.tls.cert_path"))
|
|
237
|
+
assert.Equal(t, "", v.GetString("temporal.tls.key_path"))
|
|
238
|
+
assert.Equal(t, 4, v.GetInt("temporal.worker.max_concurrent_activities"))
|
|
239
|
+
assert.Equal(t, 16, v.GetInt("temporal.worker.max_concurrent_workflow_tasks"))
|
|
240
|
+
assert.Equal(t, 2, v.GetInt("temporal.worker.max_concurrent_activity_task_pollers"))
|
|
241
|
+
assert.Equal(t, 2, v.GetInt("temporal.worker.max_concurrent_workflow_task_pollers"))
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
t.Run("kafka defaults", func(t *testing.T) {
|
|
245
|
+
assert.Equal(t, "localhost:9092", v.GetString("kafka.brokers"))
|
|
246
|
+
assert.Equal(t, "ai-chat-platform", v.GetString("kafka.client_id"))
|
|
247
|
+
assert.Equal(t, "ai-chat-api-consumer", v.GetString("kafka.group_id"))
|
|
248
|
+
assert.Equal(t, 10000, v.GetInt("kafka.connection_timeout"))
|
|
249
|
+
assert.Equal(t, 10000, v.GetInt("kafka.authentication_timeout"))
|
|
250
|
+
assert.Equal(t, 30000, v.GetInt("kafka.request_timeout"))
|
|
251
|
+
assert.Equal(t, "plain", v.GetString("kafka.sasl_mechanism"))
|
|
252
|
+
assert.False(t, v.GetBool("kafka.ssl_enabled"))
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
func TestSecretConfigUsesDeploymentSelectedDriverAndKeys(t *testing.T) {
|
|
257
|
+
v := viper.New()
|
|
258
|
+
setDefaults(v)
|
|
259
|
+
t.Setenv("SECRET_ACTIVE_DRIVER_CODE", "envelope_aead")
|
|
260
|
+
t.Setenv("SECRET_FINGERPRINT_KEY", strings.Repeat("f", 32))
|
|
261
|
+
t.Setenv("SECRET_DRIVER_HEALTH_TIMEOUT", "7s")
|
|
262
|
+
t.Setenv("SECRET_ENVELOPE_DRIVER_CODE", "envelope_aead")
|
|
263
|
+
t.Setenv("SECRET_ENVELOPE_MAXIMUM_PLAINTEXT_BYTES", "131072")
|
|
264
|
+
t.Setenv("SECRET_RUNTIME_SERVICE_ACCOUNT_CODE", "svc_platform_api_prod")
|
|
265
|
+
t.Setenv("SECRET_RUNTIME_AUDIENCE", "urn:onex:resource:platform-internal-api")
|
|
266
|
+
t.Setenv("SECRET_RUNTIME_DEFAULT_PRODUCT_CODE", "platform")
|
|
267
|
+
t.Setenv("SECRET_RUNTIME_LEASE_TTL", "45s")
|
|
268
|
+
t.Setenv("SECRET_MINIMUM_DESTRUCTION_DELAY", "48h")
|
|
269
|
+
t.Setenv("SECRET_ACCESS_EVENT_PURGE_ENABLED", "true")
|
|
270
|
+
t.Setenv("SECRET_WORKER_SERVICE_ACCOUNT_CODE", "svc_secret_worker")
|
|
271
|
+
t.Setenv("SECRET_WORKER_BATCH_SIZE", "80")
|
|
272
|
+
t.Setenv("SECRET_WORKER_PARTITION_MONTHS_AHEAD", "4")
|
|
273
|
+
require.NoError(t, bindEnvVars(v))
|
|
274
|
+
|
|
275
|
+
var cfg Config
|
|
276
|
+
require.NoError(t, v.Unmarshal(&cfg))
|
|
277
|
+
assert.Equal(t, "envelope_aead", cfg.Secret.ActiveDriverCode)
|
|
278
|
+
assert.Equal(t, strings.Repeat("f", 32), cfg.Secret.FingerprintKey)
|
|
279
|
+
assert.Equal(t, 7*time.Second, cfg.Secret.DriverHealthTimeout)
|
|
280
|
+
assert.Equal(t, "envelope_aead", cfg.Secret.Envelope.DriverCode)
|
|
281
|
+
assert.Equal(t, 131072, cfg.Secret.Envelope.MaximumPlaintextBytes)
|
|
282
|
+
assert.Equal(t, "svc_platform_api_prod", cfg.Secret.Runtime.ServiceAccountCode)
|
|
283
|
+
assert.Equal(t, "urn:onex:resource:platform-internal-api", cfg.Secret.Runtime.Audience)
|
|
284
|
+
assert.Equal(t, "platform", cfg.Secret.Runtime.DefaultProductCode)
|
|
285
|
+
assert.Equal(t, 45*time.Second, cfg.Secret.Runtime.LeaseTTL)
|
|
286
|
+
assert.Equal(t, 48*time.Hour, cfg.Secret.Retention.MinimumDestructionDelay)
|
|
287
|
+
assert.True(t, cfg.Secret.Retention.AccessEventPurgeEnabled)
|
|
288
|
+
assert.Equal(t, "svc_secret_worker", cfg.Secret.Worker.ServiceAccountCode)
|
|
289
|
+
assert.Equal(t, 80, cfg.Secret.Worker.BatchSize)
|
|
290
|
+
assert.Equal(t, 4, cfg.Secret.Worker.PartitionMonthsAhead)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
func TestSecretConfigHasNoDefaultDriverOrKey(t *testing.T) {
|
|
294
|
+
v := viper.New()
|
|
295
|
+
setDefaults(v)
|
|
296
|
+
|
|
297
|
+
assert.Empty(t, v.GetString("secret.active_driver_code"))
|
|
298
|
+
assert.Empty(t, v.GetString("secret.envelope.driver_code"))
|
|
299
|
+
assert.Empty(t, v.GetString("secret.fingerprint_key"))
|
|
300
|
+
assert.Empty(t, v.GetString("secret.runtime.service_account_code"))
|
|
301
|
+
assert.Empty(t, v.GetString("secret.runtime.audience"))
|
|
302
|
+
assert.Empty(t, v.GetString("secret.worker.service_account_code"))
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
func TestValidateSecretBrokerConfig(t *testing.T) {
|
|
306
|
+
valid := func() SecretConfig {
|
|
307
|
+
return SecretConfig{
|
|
308
|
+
ActiveDriverCode: "envelope_aead",
|
|
309
|
+
FingerprintKey: strings.Repeat("f", 32),
|
|
310
|
+
DriverHealthTimeout: 5 * time.Second,
|
|
311
|
+
Envelope: SecretEnvelopeDriverConfig{
|
|
312
|
+
DriverCode: "envelope_aead",
|
|
313
|
+
MaximumPlaintextBytes: 256 * 1024,
|
|
314
|
+
},
|
|
315
|
+
Runtime: SecretRuntimeIdentityConfig{
|
|
316
|
+
ServiceAccountCode: "svc_platform_api_prod",
|
|
317
|
+
Audience: "urn:onex:resource:platform-internal-api",
|
|
318
|
+
DefaultProductCode: "platform",
|
|
319
|
+
LeaseTTL: 30 * time.Second,
|
|
320
|
+
},
|
|
321
|
+
Retention: SecretRetentionConfig{
|
|
322
|
+
MinimumDestructionDelay: 24 * time.Hour,
|
|
323
|
+
},
|
|
324
|
+
Worker: SecretWorkerConfig{
|
|
325
|
+
ServiceAccountCode: "svc_secret_worker",
|
|
326
|
+
BatchSize: 100,
|
|
327
|
+
PartitionMonthsAhead: 3,
|
|
328
|
+
},
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
require.NoError(t, validateSecretBrokerConfig("platform-api", SecretConfig{}))
|
|
333
|
+
require.NoError(t, validateSecretBrokerConfig("worker", valid()))
|
|
334
|
+
apiConfig := valid()
|
|
335
|
+
apiConfig.Worker = SecretWorkerConfig{}
|
|
336
|
+
require.NoError(t, validateSecretBrokerConfig("platform-api", apiConfig))
|
|
337
|
+
require.ErrorContains(t, validateSecretBrokerConfig("worker", apiConfig), "SECRET_WORKER_SERVICE_ACCOUNT_CODE")
|
|
338
|
+
|
|
339
|
+
tests := []struct {
|
|
340
|
+
name string
|
|
341
|
+
mutate func(*SecretConfig)
|
|
342
|
+
want string
|
|
343
|
+
}{
|
|
344
|
+
{name: "active driver", mutate: func(cfg *SecretConfig) { cfg.ActiveDriverCode = "" }, want: "SECRET_ACTIVE_DRIVER_CODE"},
|
|
345
|
+
{name: "envelope driver", mutate: func(cfg *SecretConfig) { cfg.Envelope.DriverCode = " envelope_aead " }, want: "SECRET_ENVELOPE_DRIVER_CODE"},
|
|
346
|
+
{name: "fingerprint key", mutate: func(cfg *SecretConfig) { cfg.FingerprintKey = "short" }, want: "SECRET_FINGERPRINT_KEY"},
|
|
347
|
+
{name: "health timeout", mutate: func(cfg *SecretConfig) { cfg.DriverHealthTimeout = 31 * time.Second }, want: "SECRET_DRIVER_HEALTH_TIMEOUT"},
|
|
348
|
+
{name: "plaintext limit", mutate: func(cfg *SecretConfig) { cfg.Envelope.MaximumPlaintextBytes = 256*1024 + 1 }, want: "SECRET_ENVELOPE_MAXIMUM_PLAINTEXT_BYTES"},
|
|
349
|
+
{name: "runtime service account", mutate: func(cfg *SecretConfig) { cfg.Runtime.ServiceAccountCode = "platform-api" }, want: "SECRET_RUNTIME_SERVICE_ACCOUNT_CODE"},
|
|
350
|
+
{name: "runtime audience", mutate: func(cfg *SecretConfig) { cfg.Runtime.Audience = "platform-api" }, want: "SECRET_RUNTIME_AUDIENCE"},
|
|
351
|
+
{name: "runtime product", mutate: func(cfg *SecretConfig) { cfg.Runtime.DefaultProductCode = "Platform" }, want: "SECRET_RUNTIME_DEFAULT_PRODUCT_CODE"},
|
|
352
|
+
{name: "runtime lease TTL", mutate: func(cfg *SecretConfig) { cfg.Runtime.LeaseTTL = 5 * time.Second }, want: "SECRET_RUNTIME_LEASE_TTL"},
|
|
353
|
+
{name: "retention delay", mutate: func(cfg *SecretConfig) { cfg.Retention.MinimumDestructionDelay = 31 * 24 * time.Hour }, want: "SECRET_MINIMUM_DESTRUCTION_DELAY"},
|
|
354
|
+
{name: "worker service account", mutate: func(cfg *SecretConfig) { cfg.Worker.ServiceAccountCode = "secret-worker" }, want: "SECRET_WORKER_SERVICE_ACCOUNT_CODE"},
|
|
355
|
+
{name: "worker batch", mutate: func(cfg *SecretConfig) { cfg.Worker.BatchSize = 501 }, want: "SECRET_WORKER_BATCH_SIZE"},
|
|
356
|
+
{name: "partition horizon", mutate: func(cfg *SecretConfig) { cfg.Worker.PartitionMonthsAhead = 25 }, want: "SECRET_WORKER_PARTITION_MONTHS_AHEAD"},
|
|
357
|
+
}
|
|
358
|
+
for _, testCase := range tests {
|
|
359
|
+
t.Run(testCase.name, func(t *testing.T) {
|
|
360
|
+
cfg := valid()
|
|
361
|
+
testCase.mutate(&cfg)
|
|
362
|
+
err := validateSecretBrokerConfig("worker", cfg)
|
|
363
|
+
require.ErrorContains(t, err, testCase.want)
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
func TestValidateIdentityClientRegistry(t *testing.T) {
|
|
369
|
+
newConfig := func() *Config {
|
|
370
|
+
return &Config{
|
|
371
|
+
App: AppConfig{Name: "platform-api", Env: "production", Port: 3000},
|
|
372
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
tests := []struct {
|
|
377
|
+
name string
|
|
378
|
+
mutate func(*Config)
|
|
379
|
+
wantMessage string
|
|
380
|
+
}{
|
|
381
|
+
{
|
|
382
|
+
name: "empty client registry",
|
|
383
|
+
mutate: func(cfg *Config) {
|
|
384
|
+
cfg.Identity.Clients = nil
|
|
385
|
+
},
|
|
386
|
+
wantMessage: "identity.clients requires at least one client",
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: "client id with whitespace",
|
|
390
|
+
mutate: func(cfg *Config) {
|
|
391
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
392
|
+
delete(cfg.Identity.Clients, "product-alpha-web")
|
|
393
|
+
cfg.Identity.Clients[" product-alpha-web "] = client
|
|
394
|
+
},
|
|
395
|
+
wantMessage: "client id",
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: "client id with underscore",
|
|
399
|
+
mutate: func(cfg *Config) {
|
|
400
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
401
|
+
delete(cfg.Identity.Clients, "product-alpha-web")
|
|
402
|
+
cfg.Identity.Clients["product_alpha_web"] = client
|
|
403
|
+
},
|
|
404
|
+
wantMessage: "client id",
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
name: "unknown client product",
|
|
408
|
+
mutate: func(cfg *Config) {
|
|
409
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
410
|
+
client.ProductCode = "unknown"
|
|
411
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
412
|
+
},
|
|
413
|
+
wantMessage: "references unknown resource",
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
name: "registration source with whitespace",
|
|
417
|
+
mutate: func(cfg *Config) {
|
|
418
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
419
|
+
client.RegistrationSource = " product_alpha_web "
|
|
420
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
421
|
+
},
|
|
422
|
+
wantMessage: "registration_source is invalid",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: "empty application code",
|
|
426
|
+
mutate: func(cfg *Config) {
|
|
427
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
428
|
+
client.ApplicationCode = ""
|
|
429
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
430
|
+
},
|
|
431
|
+
wantMessage: "application_code is invalid",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
name: "application code with whitespace",
|
|
435
|
+
mutate: func(cfg *Config) {
|
|
436
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
437
|
+
client.ApplicationCode = " consumer_web "
|
|
438
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
439
|
+
},
|
|
440
|
+
wantMessage: "application_code is invalid",
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: "empty allowed principal types",
|
|
444
|
+
mutate: func(cfg *Config) {
|
|
445
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
446
|
+
client.AllowedPrincipalTypes = nil
|
|
447
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
448
|
+
},
|
|
449
|
+
wantMessage: "requires at least one principal type",
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "invalid allowed principal type",
|
|
453
|
+
mutate: func(cfg *Config) {
|
|
454
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
455
|
+
client.AllowedPrincipalTypes = []string{"service"}
|
|
456
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
457
|
+
},
|
|
458
|
+
wantMessage: "invalid principal type",
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: "duplicate allowed principal type",
|
|
462
|
+
mutate: func(cfg *Config) {
|
|
463
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
464
|
+
client.AllowedPrincipalTypes = []string{"user", "user"}
|
|
465
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
466
|
+
},
|
|
467
|
+
wantMessage: "duplicate principal type",
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: "duplicate resource audience",
|
|
471
|
+
mutate: func(cfg *Config) {
|
|
472
|
+
cfg.Identity.AccessToken.Resources["product_beta"] = IdentityAccessTokenResourceConfig{
|
|
473
|
+
Audience: "urn:onex:resource:product_alpha-api",
|
|
474
|
+
UserScopes: []string{"email", "openid", "profile"},
|
|
475
|
+
GuestScopes: []string{"openid", "profile"},
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
wantMessage: "duplicates resource",
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
name: "empty protected resource registry",
|
|
482
|
+
mutate: func(cfg *Config) {
|
|
483
|
+
cfg.Identity.AccessToken.ProtectedResources = nil
|
|
484
|
+
},
|
|
485
|
+
wantMessage: "protected_resources requires at least one resource",
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
name: "insecure protected resource in production",
|
|
489
|
+
mutate: func(cfg *Config) {
|
|
490
|
+
resource := cfg.Identity.AccessToken.ProtectedResources["platform_internal_api"]
|
|
491
|
+
resource.ResourceIdentifier = "http://localhost:3002"
|
|
492
|
+
cfg.Identity.AccessToken.ProtectedResources["platform_internal_api"] = resource
|
|
493
|
+
},
|
|
494
|
+
wantMessage: "must use https in production",
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
name: "duplicate protected resource identifier",
|
|
498
|
+
mutate: func(cfg *Config) {
|
|
499
|
+
cfg.Identity.AccessToken.ProtectedResources["documentation_api"] = IdentityProtectedResourceConfig{
|
|
500
|
+
ResourceIdentifier: "https://api.example.com",
|
|
501
|
+
Audience: serviceidentity.AudienceDocumentationAPI,
|
|
502
|
+
ResourceName: "OneX Documentation API",
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
wantMessage: "resource_identifier duplicates resource",
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: "invalid token exchange actor",
|
|
509
|
+
mutate: func(cfg *Config) {
|
|
510
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
511
|
+
client.TokenExchangeServiceAccounts = []string{"product-alpha-bff"}
|
|
512
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
513
|
+
},
|
|
514
|
+
wantMessage: "invalid service account",
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: "identity token service cannot be target resource",
|
|
518
|
+
mutate: func(cfg *Config) {
|
|
519
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
520
|
+
client.TokenExchangeResources = []string{"urn:onex:resource:identity-token-service"}
|
|
521
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
522
|
+
},
|
|
523
|
+
wantMessage: "invalid audience",
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: "token exchange actors and resources are paired",
|
|
527
|
+
mutate: func(cfg *Config) {
|
|
528
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
529
|
+
client.TokenExchangeResources = nil
|
|
530
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
531
|
+
},
|
|
532
|
+
wantMessage: "configured together",
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: "unknown token exchange resource",
|
|
536
|
+
mutate: func(cfg *Config) {
|
|
537
|
+
client := cfg.Identity.Clients["product-alpha-web"]
|
|
538
|
+
client.TokenExchangeResources = []string{"urn:onex:resource:unregistered-api"}
|
|
539
|
+
cfg.Identity.Clients["product-alpha-web"] = client
|
|
540
|
+
},
|
|
541
|
+
wantMessage: "references unknown protected resource audience",
|
|
542
|
+
},
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
for _, testCase := range tests {
|
|
546
|
+
t.Run(testCase.name, func(t *testing.T) {
|
|
547
|
+
cfg := newConfig()
|
|
548
|
+
testCase.mutate(cfg)
|
|
549
|
+
err := validateIdentityAccessTokenConfig(cfg)
|
|
550
|
+
require.Error(t, err)
|
|
551
|
+
assert.Contains(t, err.Error(), testCase.wantMessage)
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
assert.NoError(t, validateIdentityAccessTokenConfig(newConfig()))
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// TestConfigValidate 验证 validate() 对必填字段的校验逻辑
|
|
559
|
+
func TestConfigValidate(t *testing.T) {
|
|
560
|
+
t.Run("returns error when OAuth state signing secret is empty", func(t *testing.T) {
|
|
561
|
+
identity := validIdentityRuntimeConfigForTest()
|
|
562
|
+
identity.OAuthStateSigningSecret = ""
|
|
563
|
+
cfg := &Config{
|
|
564
|
+
App: AppConfig{Name: "platform-api", Port: 3000},
|
|
565
|
+
Identity: identity,
|
|
566
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
567
|
+
}
|
|
568
|
+
err := validate(cfg)
|
|
569
|
+
require.Error(t, err)
|
|
570
|
+
assert.Contains(t, err.Error(), "IDENTITY_OAUTH_STATE_SIGNING_SECRET")
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
t.Run("returns error when port is 0", func(t *testing.T) {
|
|
574
|
+
cfg := &Config{
|
|
575
|
+
App: AppConfig{Port: 0},
|
|
576
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
577
|
+
}
|
|
578
|
+
err := validate(cfg)
|
|
579
|
+
require.Error(t, err)
|
|
580
|
+
assert.Contains(t, err.Error(), "APP_PORT")
|
|
581
|
+
})
|
|
582
|
+
|
|
583
|
+
t.Run("returns error when port is negative", func(t *testing.T) {
|
|
584
|
+
cfg := &Config{
|
|
585
|
+
App: AppConfig{Port: -1},
|
|
586
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
587
|
+
}
|
|
588
|
+
err := validate(cfg)
|
|
589
|
+
require.Error(t, err)
|
|
590
|
+
assert.Contains(t, err.Error(), "APP_PORT")
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
t.Run("returns error when port exceeds 65535", func(t *testing.T) {
|
|
594
|
+
cfg := &Config{
|
|
595
|
+
App: AppConfig{Port: 65536},
|
|
596
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
597
|
+
}
|
|
598
|
+
err := validate(cfg)
|
|
599
|
+
require.Error(t, err)
|
|
600
|
+
assert.Contains(t, err.Error(), "APP_PORT")
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
t.Run("returns nil when all required fields are valid", func(t *testing.T) {
|
|
604
|
+
cfg := &Config{
|
|
605
|
+
App: AppConfig{Name: "platform-api", Env: "production", Port: 3000},
|
|
606
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
607
|
+
FeatureFlag: validFeatureFlagConfigForTest(),
|
|
608
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
609
|
+
Documentation: DocumentationConfig{PrivacyHMACKeyRef: "env://DOCUMENTATION_PRIVACY_HMAC_KEY"},
|
|
610
|
+
}
|
|
611
|
+
assert.NoError(t, validate(cfg))
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
t.Run("returns nil when admin verifier omits private signing key", func(t *testing.T) {
|
|
615
|
+
identity := validIdentityRuntimeConfigForTest()
|
|
616
|
+
identity.AccessToken.PrivateKeyPath = ""
|
|
617
|
+
cfg := &Config{
|
|
618
|
+
App: AppConfig{Name: "admin-api", Env: "production", Port: 3000},
|
|
619
|
+
Identity: identity,
|
|
620
|
+
FeatureFlag: validFeatureFlagConfigForTest(),
|
|
621
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
622
|
+
}
|
|
623
|
+
assert.NoError(t, validate(cfg))
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
t.Run("returns error when platform phone hash key is empty", func(t *testing.T) {
|
|
627
|
+
cfg := &Config{
|
|
628
|
+
App: AppConfig{Name: "platform-api", Port: 3000},
|
|
629
|
+
}
|
|
630
|
+
err := validate(cfg)
|
|
631
|
+
require.Error(t, err)
|
|
632
|
+
assert.Contains(t, err.Error(), "IDENTITY_PHONE_HASH_KEY")
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
t.Run("returns error when admin phone hash key is too short", func(t *testing.T) {
|
|
636
|
+
cfg := &Config{
|
|
637
|
+
App: AppConfig{Name: "admin-api", Port: 3000},
|
|
638
|
+
Identity: IdentityConfig{PhoneHashKey: "short-phone-hash-key"},
|
|
639
|
+
}
|
|
640
|
+
err := validate(cfg)
|
|
641
|
+
require.Error(t, err)
|
|
642
|
+
assert.Contains(t, err.Error(), "IDENTITY_PHONE_HASH_KEY")
|
|
643
|
+
})
|
|
644
|
+
|
|
645
|
+
t.Run("returns error when worker phone hash key is placeholder", func(t *testing.T) {
|
|
646
|
+
cfg := &Config{
|
|
647
|
+
App: AppConfig{Name: "worker", Port: 3000},
|
|
648
|
+
Identity: IdentityConfig{PhoneHashKey: "change-me-phone-hash-key-min-32chars"},
|
|
649
|
+
}
|
|
650
|
+
err := validate(cfg)
|
|
651
|
+
require.Error(t, err)
|
|
652
|
+
assert.Contains(t, err.Error(), "IDENTITY_PHONE_HASH_KEY")
|
|
653
|
+
})
|
|
654
|
+
|
|
655
|
+
t.Run("returns nil for boundary port 1", func(t *testing.T) {
|
|
656
|
+
cfg := &Config{
|
|
657
|
+
App: AppConfig{Port: 1},
|
|
658
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
659
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
660
|
+
}
|
|
661
|
+
assert.NoError(t, validate(cfg))
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
t.Run("returns nil for boundary port 65535", func(t *testing.T) {
|
|
665
|
+
cfg := &Config{
|
|
666
|
+
App: AppConfig{Port: 65535},
|
|
667
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
668
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
669
|
+
}
|
|
670
|
+
assert.NoError(t, validate(cfg))
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
t.Run("returns error when temporal workflow task concurrency is unsupported", func(t *testing.T) {
|
|
674
|
+
cfg := &Config{
|
|
675
|
+
App: AppConfig{Port: 3000},
|
|
676
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
677
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
678
|
+
Temporal: TemporalConfig{
|
|
679
|
+
Worker: TemporalWorkerConfig{
|
|
680
|
+
MaxConcurrentWorkflowTasks: 1,
|
|
681
|
+
MaxConcurrentWorkflowTaskPollers: 2,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
}
|
|
685
|
+
err := validate(cfg)
|
|
686
|
+
require.Error(t, err)
|
|
687
|
+
assert.Contains(t, err.Error(), "TEMPORAL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS")
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
t.Run("returns error when temporal workflow poller concurrency is unsupported", func(t *testing.T) {
|
|
691
|
+
cfg := &Config{
|
|
692
|
+
App: AppConfig{Port: 3000},
|
|
693
|
+
Identity: validIdentityRuntimeConfigForTest(),
|
|
694
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
695
|
+
Temporal: TemporalConfig{
|
|
696
|
+
Worker: TemporalWorkerConfig{
|
|
697
|
+
MaxConcurrentWorkflowTasks: 16,
|
|
698
|
+
MaxConcurrentWorkflowTaskPollers: 1,
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
}
|
|
702
|
+
err := validate(cfg)
|
|
703
|
+
require.Error(t, err)
|
|
704
|
+
assert.Contains(t, err.Error(), "TEMPORAL_WORKER_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS")
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
t.Run("returns error when IAM signing key id is invalid", func(t *testing.T) {
|
|
708
|
+
cfg := validInternalServiceRuntimeConfigForTest()
|
|
709
|
+
cfg.InternalService.ServiceTokenSigning = ServiceTokenSigningConfig{
|
|
710
|
+
KeyID: "invalid key id", PublicKeyDirectory: testServiceTokenPublicKeyDirectory,
|
|
711
|
+
}
|
|
712
|
+
err := validate(cfg)
|
|
713
|
+
require.Error(t, err)
|
|
714
|
+
assert.Contains(t, err.Error(), "ONEX_IAM_SERVICE_TOKEN_SIGNING_KEY_ID")
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
t.Run("returns error when outbound identity credential ref is template", func(t *testing.T) {
|
|
718
|
+
cfg := validInternalServiceRuntimeConfigForTest()
|
|
719
|
+
identity := cfg.InternalService.OutboundIdentities["platform"]
|
|
720
|
+
identity.CredentialRef = "replace-with-bootstrap-ref"
|
|
721
|
+
cfg.InternalService.OutboundIdentities["platform"] = identity
|
|
722
|
+
err := validate(cfg)
|
|
723
|
+
require.Error(t, err)
|
|
724
|
+
assert.Contains(t, err.Error(), "credential_ref")
|
|
725
|
+
})
|
|
726
|
+
|
|
727
|
+
t.Run("returns error when token ttl is below minimum", func(t *testing.T) {
|
|
728
|
+
cfg := validInternalServiceRuntimeConfigForTest()
|
|
729
|
+
cfg.InternalService.TokenTTLSeconds = 0
|
|
730
|
+
err := validate(cfg)
|
|
731
|
+
require.Error(t, err)
|
|
732
|
+
assert.Contains(t, err.Error(), "ONEX_IAM_SERVICE_TOKEN_TTL_SECONDS")
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
t.Run("returns error when token ttl exceeds maximum", func(t *testing.T) {
|
|
736
|
+
cfg := validInternalServiceRuntimeConfigForTest()
|
|
737
|
+
cfg.InternalService.TokenTTLSeconds = maxInternalServiceTokenTTLSeconds + 1
|
|
738
|
+
err := validate(cfg)
|
|
739
|
+
require.Error(t, err)
|
|
740
|
+
assert.Contains(t, err.Error(), "ONEX_IAM_SERVICE_TOKEN_TTL_SECONDS")
|
|
741
|
+
})
|
|
742
|
+
|
|
743
|
+
t.Run("returns nil for token ttl bounds", func(t *testing.T) {
|
|
744
|
+
for _, ttl := range []int{1, maxInternalServiceTokenTTLSeconds} {
|
|
745
|
+
cfg := validInternalServiceRuntimeConfigForTest()
|
|
746
|
+
cfg.InternalService.TokenTTLSeconds = ttl
|
|
747
|
+
assert.NoError(t, validate(cfg))
|
|
748
|
+
}
|
|
749
|
+
})
|
|
750
|
+
|
|
751
|
+
t.Run("returns error when temporal provider poll worker concurrency is unsupported", func(t *testing.T) {
|
|
752
|
+
cfg := &Config{
|
|
753
|
+
App: AppConfig{Port: 3000},
|
|
754
|
+
InternalService: validInternalServiceConfigForTest(),
|
|
755
|
+
Temporal: TemporalConfig{
|
|
756
|
+
ProviderPollWorker: TemporalWorkerConfig{
|
|
757
|
+
MaxConcurrentWorkflowTasks: 1,
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
}
|
|
761
|
+
err := validate(cfg)
|
|
762
|
+
require.Error(t, err)
|
|
763
|
+
assert.Contains(t, err.Error(), "TEMPORAL_PROVIDER_POLL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS")
|
|
764
|
+
})
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// TestConfigLoadEnvOverride 验证 Load() 通过环境变量覆盖默认值
|
|
768
|
+
// Load() 会静默忽略找不到的配置文件,所以可以在无配置文件的环境中安全运行
|
|
769
|
+
func TestConfigLoadEnvOverride(t *testing.T) {
|
|
770
|
+
t.Setenv("APP_ENV", "production")
|
|
771
|
+
t.Setenv("IDENTITY_PHONE_HASH_KEY", "abcdef0123456789abcdef0123456789")
|
|
772
|
+
t.Setenv("IDENTITY_OAUTH_STATE_SIGNING_SECRET", "oauth-state-env-secret-key-at-least-32-bytes")
|
|
773
|
+
t.Setenv("IDENTITY_ACCESS_TOKEN_ISSUER", "https://identity.example.com")
|
|
774
|
+
t.Setenv("IDENTITY_ACCESS_TOKEN_SIGNING_KEY_ID", "identity-key-2026-07")
|
|
775
|
+
t.Setenv("IDENTITY_ACCESS_TOKEN_PRIVATE_KEY_PATH", "/run/secrets/identity-access-token-private.pem")
|
|
776
|
+
t.Setenv("IDENTITY_ACCESS_TOKEN_PUBLIC_KEY_DIRECTORY", "/run/secrets/identity-access-token-public")
|
|
777
|
+
t.Setenv("ONEX_IDENTITY_PROTECTED_RESOURCES", `{"platform_internal_api":{"resource_identifier":"https://api.example.com","audience":"urn:onex:resource:platform-internal-api","resource_name":"OneX Platform Internal API"},"documentation_api":{"resource_identifier":"https://documentation-api.example.com","audience":"urn:onex:resource:documentation-api","resource_name":"OneX Documentation API"}}`)
|
|
778
|
+
t.Setenv("IDENTITY_GUEST_CAPABILITY_SECRET_PROVIDER_FILE", "/run/secrets/identity-guest-capability.json")
|
|
779
|
+
t.Setenv("IDENTITY_GUEST_CAPABILITY_INITIAL_KEY_ID", "guest-capability-2026-07")
|
|
780
|
+
t.Setenv("IDENTITY_GUEST_CAPABILITY_VERIFIER_INSTANCE_ID", "platform-api-1")
|
|
781
|
+
t.Setenv("APP_PORT", "8080")
|
|
782
|
+
t.Setenv("APP_NAME", "platform-api")
|
|
783
|
+
t.Setenv("REDIS_HOST", "redis.example.com")
|
|
784
|
+
t.Setenv("DATABASE_HOST", "db.example.com")
|
|
785
|
+
t.Setenv("OPENAI_MODEL", "gpt-4o")
|
|
786
|
+
t.Setenv("TEMPORAL_ENABLED", "true")
|
|
787
|
+
t.Setenv("TEMPORAL_HOST_PORT", "temporal.example.com:7233")
|
|
788
|
+
t.Setenv("TEMPORAL_NAMESPACE", "onex-prod")
|
|
789
|
+
t.Setenv("TEMPORAL_TLS_ENABLED", "true")
|
|
790
|
+
t.Setenv("TEMPORAL_TLS_SERVER_NAME", "temporal.example.com")
|
|
791
|
+
t.Setenv("TEMPORAL_WORKER_MAX_CONCURRENT_ACTIVITIES", "3")
|
|
792
|
+
t.Setenv("TEMPORAL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS", "18")
|
|
793
|
+
t.Setenv("TEMPORAL_WORKER_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS", "4")
|
|
794
|
+
t.Setenv("TEMPORAL_WORKER_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS", "6")
|
|
795
|
+
t.Setenv("TEMPORAL_PROVIDER_POLL_WORKER_MAX_CONCURRENT_ACTIVITIES", "12")
|
|
796
|
+
t.Setenv("TEMPORAL_PROVIDER_POLL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS", "20")
|
|
797
|
+
t.Setenv("TEMPORAL_PROVIDER_POLL_WORKER_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS", "5")
|
|
798
|
+
t.Setenv("TEMPORAL_PROVIDER_POLL_WORKER_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS", "8")
|
|
799
|
+
t.Setenv("AUDIT_ACCESS_LOG_SUCCESS_READ_SAMPLE_RATE", "0.25")
|
|
800
|
+
t.Setenv("AUDIT_ACCESS_LOG_SLOW_REQUEST_THRESHOLD", "3s")
|
|
801
|
+
t.Setenv("ONEX_IAM_SERVICE_TOKEN_SIGNING_KEY_ID", "iam-service-key-2026-08")
|
|
802
|
+
t.Setenv("ONEX_IAM_SERVICE_TOKEN_PRIVATE_KEY_PATH", testServiceTokenPrivateKeyPath)
|
|
803
|
+
t.Setenv("ONEX_IAM_SERVICE_TOKEN_PUBLIC_KEY_DIRECTORY", testServiceTokenPublicKeyDirectory)
|
|
804
|
+
t.Setenv("ONEX_INTERNAL_SERVICE_OUTBOUND_IDENTITIES", `{"documentation":{"credential_ref":"`+testBootstrapCredentialRef+`","allowed_product_codes":["platform"],"audience":"urn:onex:resource:documentation-api","expected_service_account_code":"svc_ai_documentation_prod"}}`)
|
|
805
|
+
t.Setenv("ONEX_IAM_SERVICE_TOKEN_TTL_SECONDS", "600")
|
|
806
|
+
|
|
807
|
+
cfg, err := Load()
|
|
808
|
+
require.NoError(t, err)
|
|
809
|
+
|
|
810
|
+
assert.Equal(t, "production", cfg.App.Env)
|
|
811
|
+
assert.Equal(t, "abcdef0123456789abcdef0123456789", cfg.Identity.PhoneHashKey)
|
|
812
|
+
assert.Equal(t, "oauth-state-env-secret-key-at-least-32-bytes", cfg.Identity.OAuthStateSigningSecret)
|
|
813
|
+
assert.Equal(t, "https://identity.example.com", cfg.Identity.AccessToken.Issuer)
|
|
814
|
+
assert.Equal(t, "identity-key-2026-07", cfg.Identity.AccessToken.SigningKeyID)
|
|
815
|
+
assert.Equal(t, "/run/secrets/identity-access-token-private.pem", cfg.Identity.AccessToken.PrivateKeyPath)
|
|
816
|
+
assert.Equal(t, "/run/secrets/identity-access-token-public", cfg.Identity.AccessToken.PublicKeyDirectory)
|
|
817
|
+
assert.Equal(t, "/run/secrets/identity-guest-capability.json", cfg.Identity.GuestCapability.SecretProviderFile)
|
|
818
|
+
assert.Equal(t, "guest-capability-2026-07", cfg.Identity.GuestCapability.InitialKeyID)
|
|
819
|
+
assert.Equal(t, "platform-api-1", cfg.Identity.GuestCapability.VerifierInstanceID)
|
|
820
|
+
assert.Equal(t, 8080, cfg.App.Port)
|
|
821
|
+
assert.Equal(t, "platform-api", cfg.App.Name)
|
|
822
|
+
assert.Equal(t, "redis.example.com", cfg.Redis.Host)
|
|
823
|
+
assert.Equal(t, "db.example.com", cfg.Database.Host)
|
|
824
|
+
assert.Equal(t, "gpt-4o", cfg.OpenAI.Model)
|
|
825
|
+
assert.True(t, cfg.Temporal.Enabled)
|
|
826
|
+
assert.Equal(t, "temporal.example.com:7233", cfg.Temporal.HostPort)
|
|
827
|
+
assert.Equal(t, "onex-prod", cfg.Temporal.Namespace)
|
|
828
|
+
assert.True(t, cfg.Temporal.TLS.Enabled)
|
|
829
|
+
assert.Equal(t, "temporal.example.com", cfg.Temporal.TLS.ServerName)
|
|
830
|
+
assert.Equal(t, 3, cfg.Temporal.Worker.MaxConcurrentActivities)
|
|
831
|
+
assert.Equal(t, 18, cfg.Temporal.Worker.MaxConcurrentWorkflowTasks)
|
|
832
|
+
assert.Equal(t, 4, cfg.Temporal.Worker.MaxConcurrentActivityTaskPollers)
|
|
833
|
+
assert.Equal(t, 6, cfg.Temporal.Worker.MaxConcurrentWorkflowTaskPollers)
|
|
834
|
+
assert.Equal(t, 12, cfg.Temporal.ProviderPollWorker.MaxConcurrentActivities)
|
|
835
|
+
assert.Equal(t, 20, cfg.Temporal.ProviderPollWorker.MaxConcurrentWorkflowTasks)
|
|
836
|
+
assert.Equal(t, 5, cfg.Temporal.ProviderPollWorker.MaxConcurrentActivityTaskPollers)
|
|
837
|
+
assert.Equal(t, 8, cfg.Temporal.ProviderPollWorker.MaxConcurrentWorkflowTaskPollers)
|
|
838
|
+
assert.InDelta(t, 0.25, cfg.Audit.AccessLog.SuccessReadSampleRate, 0.001)
|
|
839
|
+
assert.Equal(t, "3s", cfg.Audit.AccessLog.SlowRequestThreshold.String())
|
|
840
|
+
assert.Equal(t, "iam-service-key-2026-08", cfg.InternalService.ServiceTokenSigning.KeyID)
|
|
841
|
+
assert.Equal(t, testServiceTokenPrivateKeyPath, cfg.InternalService.ServiceTokenSigning.PrivateKeyPath)
|
|
842
|
+
assert.Equal(t, testServiceTokenPublicKeyDirectory, cfg.InternalService.ServiceTokenSigning.PublicKeyDirectory)
|
|
843
|
+
assert.Equal(t, testBootstrapCredentialRef, cfg.InternalService.OutboundIdentities["documentation"].CredentialRef)
|
|
844
|
+
assert.Equal(t, "urn:onex:resource:documentation-api", cfg.InternalService.OutboundIdentities["documentation"].Audience)
|
|
845
|
+
assert.Equal(t, 600, cfg.InternalService.TokenTTLSeconds)
|
|
846
|
+
assert.True(t, cfg.IsProduction())
|
|
847
|
+
assert.False(t, cfg.IsDevelopment())
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
func TestLoadDatabaseCommandConfigDoesNotRequireRuntimeSecrets(t *testing.T) {
|
|
851
|
+
t.Chdir(t.TempDir())
|
|
852
|
+
t.Setenv("APP_ENV", "local")
|
|
853
|
+
t.Setenv("IDENTITY_PHONE_HASH_KEY", "")
|
|
854
|
+
t.Setenv("DATABASE_HOST", "127.0.0.1")
|
|
855
|
+
t.Setenv("DATABASE_PORT", "5432")
|
|
856
|
+
t.Setenv("DATABASE_USERNAME", "validator")
|
|
857
|
+
t.Setenv("DATABASE_NAME", "platform_validator")
|
|
858
|
+
|
|
859
|
+
cfg, err := LoadDatabaseCommandConfig()
|
|
860
|
+
require.NoError(t, err)
|
|
861
|
+
assert.Equal(t, "127.0.0.1", cfg.Database.Host)
|
|
862
|
+
assert.Equal(t, 5432, cfg.Database.Port)
|
|
863
|
+
assert.Equal(t, "validator", cfg.Database.Username)
|
|
864
|
+
assert.Equal(t, "platform_validator", cfg.Database.Name)
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
func TestLoadBootstrapCommandConfigDoesNotRequireRuntimeSecrets(t *testing.T) {
|
|
868
|
+
t.Chdir(t.TempDir())
|
|
869
|
+
t.Setenv("APP_ENV", "local")
|
|
870
|
+
t.Setenv("IDENTITY_PHONE_HASH_KEY", "")
|
|
871
|
+
t.Setenv("DATABASE_HOST", "127.0.0.1")
|
|
872
|
+
t.Setenv("DATABASE_PORT", "5432")
|
|
873
|
+
t.Setenv("DATABASE_USERNAME", "bootstrap")
|
|
874
|
+
t.Setenv("DATABASE_NAME", "platform_bootstrap")
|
|
875
|
+
t.Setenv("ENCRYPTION_KEY", "bootstrap-encryption-key")
|
|
876
|
+
|
|
877
|
+
cfg, err := LoadBootstrapCommandConfig()
|
|
878
|
+
require.NoError(t, err)
|
|
879
|
+
assert.Equal(t, "127.0.0.1", cfg.Database.Host)
|
|
880
|
+
assert.Equal(t, 5432, cfg.Database.Port)
|
|
881
|
+
assert.Equal(t, "bootstrap", cfg.Database.Username)
|
|
882
|
+
assert.Equal(t, "platform_bootstrap", cfg.Database.Name)
|
|
883
|
+
assert.Equal(t, "bootstrap-encryption-key", cfg.EncryptionKey)
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// TestConfigLoadEnvMissingSecret 验证身份运行时缺少 OAuth state 专用密钥时返回错误。
|
|
887
|
+
func TestConfigLoadEnvMissingSecret(t *testing.T) {
|
|
888
|
+
t.Chdir(t.TempDir())
|
|
889
|
+
t.Setenv("APP_ENV", "local")
|
|
890
|
+
t.Setenv("APP_NAME", "platform-api")
|
|
891
|
+
t.Setenv("IDENTITY_PHONE_HASH_KEY", testIdentityPhoneHashKey)
|
|
892
|
+
t.Setenv("IDENTITY_OAUTH_STATE_SIGNING_SECRET", "")
|
|
893
|
+
t.Setenv("IDENTITY_ACCESS_TOKEN_PRIVATE_KEY_PATH", "/run/secrets/identity-access-token-private.pem")
|
|
894
|
+
|
|
895
|
+
_, err := Load()
|
|
896
|
+
require.Error(t, err)
|
|
897
|
+
assert.Contains(t, err.Error(), "IDENTITY_OAUTH_STATE_SIGNING_SECRET")
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
func TestValidateAdminExperienceConfig(t *testing.T) {
|
|
901
|
+
valid := AdminExperienceConfig{ExternalProducts: []AdminExperienceExternalProductConfig{{
|
|
902
|
+
ProductCode: "product_alpha",
|
|
903
|
+
BaseURL: "https://product_alpha.internal.example/admin-experience",
|
|
904
|
+
Datasets: []AdminExperienceExternalDatasetConfig{{
|
|
905
|
+
Key: "product_alpha.user.safety_summary", DescriptorHash: strings.Repeat("a", 64),
|
|
906
|
+
}},
|
|
907
|
+
}}}
|
|
908
|
+
require.NoError(t, validateAdminExperienceConfig(valid))
|
|
909
|
+
|
|
910
|
+
tests := []struct {
|
|
911
|
+
name string
|
|
912
|
+
mutate func(*AdminExperienceConfig)
|
|
913
|
+
}{
|
|
914
|
+
{name: "duplicate product", mutate: func(cfg *AdminExperienceConfig) {
|
|
915
|
+
cfg.ExternalProducts = append(cfg.ExternalProducts, cfg.ExternalProducts[0])
|
|
916
|
+
}},
|
|
917
|
+
{name: "untrusted URL", mutate: func(cfg *AdminExperienceConfig) {
|
|
918
|
+
cfg.ExternalProducts[0].BaseURL = "https://user@example.com/path?secret=value"
|
|
919
|
+
}},
|
|
920
|
+
{name: "unnamespaced dataset", mutate: func(cfg *AdminExperienceConfig) {
|
|
921
|
+
cfg.ExternalProducts[0].Datasets[0].Key = "other.user.safety_summary"
|
|
922
|
+
}},
|
|
923
|
+
{name: "invalid hash", mutate: func(cfg *AdminExperienceConfig) {
|
|
924
|
+
cfg.ExternalProducts[0].Datasets[0].DescriptorHash = "not-a-hash"
|
|
925
|
+
}},
|
|
926
|
+
{name: "missing dataset", mutate: func(cfg *AdminExperienceConfig) {
|
|
927
|
+
cfg.ExternalProducts[0].Datasets = nil
|
|
928
|
+
}},
|
|
929
|
+
}
|
|
930
|
+
for _, tc := range tests {
|
|
931
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
932
|
+
cfg := valid
|
|
933
|
+
cfg.ExternalProducts = append([]AdminExperienceExternalProductConfig(nil), valid.ExternalProducts...)
|
|
934
|
+
cfg.ExternalProducts[0].Datasets = append(
|
|
935
|
+
[]AdminExperienceExternalDatasetConfig(nil), valid.ExternalProducts[0].Datasets...,
|
|
936
|
+
)
|
|
937
|
+
tc.mutate(&cfg)
|
|
938
|
+
require.Error(t, validateAdminExperienceConfig(cfg))
|
|
939
|
+
})
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
func validInternalServiceConfigForTest() InternalServiceConfig {
|
|
944
|
+
return InternalServiceConfig{
|
|
945
|
+
PlatformBaseURL: "http://platform-api:3002/internal/v1",
|
|
946
|
+
DocumentationBaseURL: "http://documentation-api:3010/api/v1/documentation",
|
|
947
|
+
OutboundIdentities: map[string]InternalServiceIdentityConfig{
|
|
948
|
+
"platform": {
|
|
949
|
+
CredentialRef: testBootstrapCredentialRef,
|
|
950
|
+
AllowedProductCodes: []string{"product_alpha"},
|
|
951
|
+
Audience: "urn:onex:resource:platform-internal-api",
|
|
952
|
+
ExpectedServiceAccountCode: "svc_product_alpha_bff_prod",
|
|
953
|
+
},
|
|
954
|
+
},
|
|
955
|
+
TokenTTLSeconds: defaultInternalServiceTokenTTLSeconds,
|
|
956
|
+
AuthorizationConsistencyTokenTTLSeconds: defaultIAMConsistencyTokenTTLSeconds,
|
|
957
|
+
RequestTimeout: 10 * time.Second,
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
func validFeatureFlagConfigForTest() FeatureFlagConfig {
|
|
962
|
+
return FeatureFlagConfig{
|
|
963
|
+
FreshnessTTL: 30 * time.Second,
|
|
964
|
+
MaximumStaleAge: 15 * time.Minute,
|
|
965
|
+
CacheTTL: 30 * time.Minute,
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
func validIdentityRuntimeConfigForTest() IdentityConfig {
|
|
970
|
+
return IdentityConfig{
|
|
971
|
+
PhoneHashKey: testIdentityPhoneHashKey,
|
|
972
|
+
OAuthStateSigningSecret: testIdentityOAuthStateSigningSecret,
|
|
973
|
+
Clients: map[string]IdentityClientConfig{
|
|
974
|
+
"product-alpha-web": {
|
|
975
|
+
ProductCode: "product_alpha",
|
|
976
|
+
ApplicationCode: "consumer_web",
|
|
977
|
+
AllowedPrincipalTypes: []string{"user", "guest"},
|
|
978
|
+
RegistrationSource: "product_alpha_web",
|
|
979
|
+
TokenExchangeServiceAccounts: []string{"svc_product_alpha_bff_prod"},
|
|
980
|
+
TokenExchangeResources: []string{
|
|
981
|
+
"urn:onex:resource:platform-internal-api",
|
|
982
|
+
"urn:onex:resource:documentation-api",
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
},
|
|
986
|
+
GuestCapability: IdentityGuestCapabilityConfig{
|
|
987
|
+
SecretProviderFile: "/run/secrets/identity-guest-capability.json",
|
|
988
|
+
InitialKeyID: "guest-capability-2026-07",
|
|
989
|
+
VerifierInstanceID: "platform-api-1",
|
|
990
|
+
},
|
|
991
|
+
AccessToken: IdentityAccessTokenConfig{
|
|
992
|
+
Issuer: "https://identity.example.com",
|
|
993
|
+
SigningKeyID: "identity-key-2026-07",
|
|
994
|
+
PrivateKeyPath: "/run/secrets/identity-access-token-private.pem",
|
|
995
|
+
PublicKeyDirectory: "/run/secrets/identity-access-token-public",
|
|
996
|
+
ClockSkewLeeway: defaultIdentityClockSkewLeeway,
|
|
997
|
+
DelegatedTokenTTL: time.Duration(defaultDelegatedAccessTokenTTLSeconds) * time.Second,
|
|
998
|
+
ProtectedResources: map[string]IdentityProtectedResourceConfig{
|
|
999
|
+
"platform_internal_api": {
|
|
1000
|
+
ResourceIdentifier: "https://api.example.com",
|
|
1001
|
+
Audience: serviceidentity.AudiencePlatformInternalAPI,
|
|
1002
|
+
ResourceName: "OneX Platform Internal API",
|
|
1003
|
+
},
|
|
1004
|
+
"documentation_api": {
|
|
1005
|
+
ResourceIdentifier: "https://documentation-api.example.com",
|
|
1006
|
+
Audience: serviceidentity.AudienceDocumentationAPI,
|
|
1007
|
+
ResourceName: "OneX Documentation API",
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
Resources: map[string]IdentityAccessTokenResourceConfig{
|
|
1011
|
+
"product_alpha": {
|
|
1012
|
+
Audience: "urn:onex:resource:product_alpha-api",
|
|
1013
|
+
UserScopes: []string{"email", "openid", "profile", "product_alpha.read", "product_alpha.write"},
|
|
1014
|
+
GuestScopes: []string{"openid", "profile", "product_alpha.read"},
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
func validInternalServiceRuntimeConfigForTest() *Config {
|
|
1022
|
+
internal := validInternalServiceConfigForTest()
|
|
1023
|
+
identity := internal.OutboundIdentities["platform"]
|
|
1024
|
+
identity.AllowedProductCodes = []string{"product_beta"}
|
|
1025
|
+
identity.ExpectedServiceAccountCode = "svc_product_beta_bff_prod"
|
|
1026
|
+
internal.OutboundIdentities["platform"] = identity
|
|
1027
|
+
return &Config{
|
|
1028
|
+
App: AppConfig{Name: "sample-product-bff", Env: "docker", Port: 3004},
|
|
1029
|
+
InternalService: internal,
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
func TestApplyInternalServiceOutboundIdentitiesEnvironment(t *testing.T) {
|
|
1034
|
+
t.Setenv("ONEX_INTERNAL_SERVICE_OUTBOUND_IDENTITIES", `{
|
|
1035
|
+
"platform": {
|
|
1036
|
+
"credential_ref": "env://ONEX_PRODUCT_A_PLATFORM_CREDENTIAL",
|
|
1037
|
+
"allowed_product_codes": ["product_alpha"],
|
|
1038
|
+
"audience": "urn:onex:resource:platform-internal-api",
|
|
1039
|
+
"expected_service_account_code": "svc_product_alpha_bff_prod"
|
|
1040
|
+
},
|
|
1041
|
+
"documentation": {
|
|
1042
|
+
"credential_ref": "file:///run/secrets/product-alpha-documentation.credential",
|
|
1043
|
+
"allowed_product_codes": ["product_alpha"],
|
|
1044
|
+
"audience": "urn:onex:resource:documentation-api",
|
|
1045
|
+
"expected_service_account_code": "svc_product_alpha_documentation_prod"
|
|
1046
|
+
}
|
|
1047
|
+
}`)
|
|
1048
|
+
v := viper.New()
|
|
1049
|
+
require.NoError(t, applyInternalServiceOutboundIdentitiesEnvironment(v))
|
|
1050
|
+
var loaded struct {
|
|
1051
|
+
InternalService InternalServiceConfig `mapstructure:"internal_service"`
|
|
1052
|
+
}
|
|
1053
|
+
require.NoError(t, v.Unmarshal(&loaded))
|
|
1054
|
+
require.Equal(t, map[string]InternalServiceIdentityConfig{
|
|
1055
|
+
"platform": {
|
|
1056
|
+
CredentialRef: "env://ONEX_PRODUCT_A_PLATFORM_CREDENTIAL",
|
|
1057
|
+
AllowedProductCodes: []string{"product_alpha"},
|
|
1058
|
+
Audience: "urn:onex:resource:platform-internal-api",
|
|
1059
|
+
ExpectedServiceAccountCode: "svc_product_alpha_bff_prod",
|
|
1060
|
+
},
|
|
1061
|
+
"documentation": {
|
|
1062
|
+
CredentialRef: "file:///run/secrets/product-alpha-documentation.credential",
|
|
1063
|
+
AllowedProductCodes: []string{"product_alpha"},
|
|
1064
|
+
Audience: "urn:onex:resource:documentation-api",
|
|
1065
|
+
ExpectedServiceAccountCode: "svc_product_alpha_documentation_prod",
|
|
1066
|
+
},
|
|
1067
|
+
}, loaded.InternalService.OutboundIdentities)
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
func TestApplyIdentityProtectedResourcesEnvironment(t *testing.T) {
|
|
1071
|
+
t.Setenv("ONEX_IDENTITY_PROTECTED_RESOURCES", `{
|
|
1072
|
+
"platform_internal_api": {
|
|
1073
|
+
"resource_identifier": "https://api.example.com",
|
|
1074
|
+
"audience": "urn:onex:resource:platform-internal-api",
|
|
1075
|
+
"resource_name": "OneX Platform Internal API"
|
|
1076
|
+
}
|
|
1077
|
+
}`)
|
|
1078
|
+
v := viper.New()
|
|
1079
|
+
require.NoError(t, applyJSONRegistryEnvironment[IdentityProtectedResourceConfig](v, "ONEX_IDENTITY_PROTECTED_RESOURCES", "identity.access_token.protected_resources"))
|
|
1080
|
+
var loaded struct {
|
|
1081
|
+
Identity IdentityConfig `mapstructure:"identity"`
|
|
1082
|
+
}
|
|
1083
|
+
require.NoError(t, v.Unmarshal(&loaded))
|
|
1084
|
+
require.Equal(t, map[string]IdentityProtectedResourceConfig{
|
|
1085
|
+
"platform_internal_api": {
|
|
1086
|
+
ResourceIdentifier: "https://api.example.com",
|
|
1087
|
+
Audience: serviceidentity.AudiencePlatformInternalAPI,
|
|
1088
|
+
ResourceName: "OneX Platform Internal API",
|
|
1089
|
+
},
|
|
1090
|
+
}, loaded.Identity.AccessToken.ProtectedResources)
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
func TestApplyIdentityProtectedResourcesEnvironmentRejectsInvalidRegistry(t *testing.T) {
|
|
1094
|
+
for _, raw := range []string{
|
|
1095
|
+
`null`,
|
|
1096
|
+
`{"platform_internal_api":{"resource_identifier":"https://api.example.com","audience":"urn:onex:resource:platform-internal-api","resource_name":"OneX Platform Internal API","unknown":true}}`,
|
|
1097
|
+
`{} {}`,
|
|
1098
|
+
} {
|
|
1099
|
+
t.Run(raw, func(t *testing.T) {
|
|
1100
|
+
t.Setenv("ONEX_IDENTITY_PROTECTED_RESOURCES", raw)
|
|
1101
|
+
require.Error(t, applyJSONRegistryEnvironment[IdentityProtectedResourceConfig](viper.New(), "ONEX_IDENTITY_PROTECTED_RESOURCES", "identity.access_token.protected_resources"))
|
|
1102
|
+
})
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
func TestIdentityClientsEnvironmentReplacesFileRegistry(t *testing.T) {
|
|
1107
|
+
v := viper.New()
|
|
1108
|
+
setDefaults(v)
|
|
1109
|
+
v.SetConfigType("yaml")
|
|
1110
|
+
require.NoError(t, v.ReadConfig(strings.NewReader("identity:\n clients:\n fixture-web:\n product_code: fixture\n")))
|
|
1111
|
+
t.Setenv("ONEX_IDENTITY_CLIENTS", `{"admin-web":{"product_code":"platform","application_code":"admin_web","allowed_principal_types":["user"],"registration_source":"admin"}}`)
|
|
1112
|
+
require.NoError(t, applyJSONRegistryEnvironment[IdentityClientConfig](v, "ONEX_IDENTITY_CLIENTS", "identity.clients"))
|
|
1113
|
+
var cfg Config
|
|
1114
|
+
require.NoError(t, v.Unmarshal(&cfg))
|
|
1115
|
+
require.Len(t, cfg.Identity.Clients, 1)
|
|
1116
|
+
require.Equal(t, "admin_web", cfg.Identity.Clients["admin-web"].ApplicationCode)
|
|
1117
|
+
require.Equal(t, []string{"user"}, cfg.Identity.Clients["admin-web"].AllowedPrincipalTypes)
|
|
1118
|
+
for _, raw := range []string{"null", "[]", "{} {}", `{"admin-web":{"unknown":true}}`} {
|
|
1119
|
+
t.Setenv("ONEX_IDENTITY_CLIENTS", raw)
|
|
1120
|
+
require.Error(t, applyJSONRegistryEnvironment[IdentityClientConfig](viper.New(), "ONEX_IDENTITY_CLIENTS", "identity.clients"))
|
|
1121
|
+
}
|
|
1122
|
+
}
|