@kya-os/mcp-i-runtime 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/dist/auth/handshake.d.ts +136 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +276 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +12 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +52 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +10 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/cache/tool-protection-cache.d.ts +102 -0
- package/dist/cache/tool-protection-cache.d.ts.map +1 -0
- package/dist/cache/tool-protection-cache.js +131 -0
- package/dist/cache/tool-protection-cache.js.map +1 -0
- package/dist/compliance/index.d.ts +8 -0
- package/dist/compliance/index.d.ts.map +1 -0
- package/dist/compliance/index.js +24 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/compliance/schema-registry.d.ts +50 -0
- package/dist/compliance/schema-registry.d.ts.map +1 -0
- package/dist/compliance/schema-registry.js +438 -0
- package/dist/compliance/schema-registry.js.map +1 -0
- package/dist/compliance/schema-verifier.d.ts +110 -0
- package/dist/compliance/schema-verifier.d.ts.map +1 -0
- package/dist/compliance/schema-verifier.js +518 -0
- package/dist/compliance/schema-verifier.js.map +1 -0
- package/dist/config/remote-config.d.ts +188 -0
- package/dist/config/remote-config.d.ts.map +1 -0
- package/dist/config/remote-config.js +268 -0
- package/dist/config/remote-config.js.map +1 -0
- package/dist/config.d.ts +182 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +69 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +136 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +80 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +14 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +228 -0
- package/dist/identity/user-did-manager.d.ts.map +1 -0
- package/dist/identity/user-did-manager.js +356 -0
- package/dist/identity/user-did-manager.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +5 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +10 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +33 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +104 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/proof/generator.d.ts +109 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +236 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +5 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +11 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/providers/base.d.ts +95 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +47 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/memory.d.ts +42 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +121 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +392 -0
- package/dist/runtime/base.d.ts.map +1 -0
- package/dist/runtime/base.js +1527 -0
- package/dist/runtime/base.js.map +1 -0
- package/dist/runtime/dif-core.d.ts +33 -0
- package/dist/runtime/dif-core.d.ts.map +1 -0
- package/dist/runtime/dif-core.js +14 -0
- package/dist/runtime/dif-core.js.map +1 -0
- package/dist/runtime/ext-apps-constants.d.ts +20 -0
- package/dist/runtime/ext-apps-constants.d.ts.map +1 -0
- package/dist/runtime/ext-apps-constants.js +23 -0
- package/dist/runtime/ext-apps-constants.js.map +1 -0
- package/dist/services/access-control.service.d.ts +138 -0
- package/dist/services/access-control.service.d.ts.map +1 -0
- package/dist/services/access-control.service.js +721 -0
- package/dist/services/access-control.service.js.map +1 -0
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +58 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/crypto.service.d.ts +69 -0
- package/dist/services/crypto.service.d.ts.map +1 -0
- package/dist/services/crypto.service.js +225 -0
- package/dist/services/crypto.service.js.map +1 -0
- package/dist/services/delegation-error-formatter.d.ts +124 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -0
- package/dist/services/delegation-error-formatter.js +214 -0
- package/dist/services/delegation-error-formatter.js.map +1 -0
- package/dist/services/errors.d.ts +49 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +66 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +15 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +141 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +88 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +128 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +122 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +442 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/policy.service.d.ts +130 -0
- package/dist/services/policy.service.d.ts.map +1 -0
- package/dist/services/policy.service.js +399 -0
- package/dist/services/policy.service.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +103 -0
- package/dist/services/proof-verifier.d.ts.map +1 -0
- package/dist/services/proof-verifier.js +190 -0
- package/dist/services/proof-verifier.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +89 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +196 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/session-registration.service.d.ts +80 -0
- package/dist/services/session-registration.service.d.ts.map +1 -0
- package/dist/services/session-registration.service.js +174 -0
- package/dist/services/session-registration.service.js.map +1 -0
- package/dist/services/storage.service.d.ts +116 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +411 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +74 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +215 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +209 -0
- package/dist/services/tool-protection.service.d.ts.map +1 -0
- package/dist/services/tool-protection.service.js +752 -0
- package/dist/services/tool-protection.service.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +11 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +118 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +285 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/oauth-required-error.d.ts +46 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +42 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/types/tool-protection.d.ts +144 -0
- package/dist/types/tool-protection.d.ts.map +1 -0
- package/dist/types/tool-protection.js +48 -0
- package/dist/types/tool-protection.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +103 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +32 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +172 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/cors.d.ts +52 -0
- package/dist/utils/cors.d.ts.map +1 -0
- package/dist/utils/cors.js +79 -0
- package/dist/utils/cors.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +168 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +222 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +24 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/storage-keys.d.ts +120 -0
- package/dist/utils/storage-keys.d.ts.map +1 -0
- package/dist/utils/storage-keys.js +217 -0
- package/dist/utils/storage-keys.js.map +1 -0
- package/dist/wire-format.d.ts +62 -0
- package/dist/wire-format.d.ts.map +1 -0
- package/dist/wire-format.js +89 -0
- package/dist/wire-format.js.map +1 -0
- package/package.json +83 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/config.test.ts +307 -0
- package/src/__tests__/identity/user-did-manager.test.ts +232 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +779 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +406 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +595 -0
- package/src/__tests__/runtime/base.test.ts +1328 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +159 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +1024 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +376 -0
- package/src/__tests__/runtime/provider-selection.test.ts +292 -0
- package/src/__tests__/runtime/route-interception.test.ts +670 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +989 -0
- package/src/__tests__/services/access-control-retry.test.ts +595 -0
- package/src/__tests__/services/agentshield-integration.test.ts +709 -0
- package/src/__tests__/services/cache-busting.test.ts +125 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +704 -0
- package/src/__tests__/services/oauth-service-pkce.test.ts +556 -0
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +349 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +591 -0
- package/src/__tests__/services/tool-protection-failsafe.test.ts +683 -0
- package/src/__tests__/services/tool-protection-merged-config.test.ts +664 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +300 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1201 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/__tests__/wire-format.test.ts +123 -0
- package/src/auth/__tests__/resume-token.test.ts +42 -0
- package/src/auth/handshake.ts +476 -0
- package/src/auth/index.ts +15 -0
- package/src/auth/types.ts +68 -0
- package/src/cache/__tests__/oauth-config-cache.test.ts +215 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +184 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +791 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/merged-config.spec.ts +445 -0
- package/src/config/__tests__/remote-config-edge-cases.test.ts +424 -0
- package/src/config/__tests__/remote-config-helpers.test.ts +280 -0
- package/src/config/__tests__/remote-config.spec.ts +265 -0
- package/src/config/remote-config.ts +368 -0
- package/src/config.ts +312 -0
- package/src/identity/__tests__/idp-token-resolver.test.ts +340 -0
- package/src/identity/__tests__/user-did-manager.test.ts +487 -0
- package/src/identity/idp-token-resolver.ts +181 -0
- package/src/identity/idp-token-storage.interface.ts +102 -0
- package/src/identity/user-did-manager.ts +592 -0
- package/src/index.ts +331 -0
- package/src/logging/__tests__/logger.test.ts +366 -0
- package/src/logging/index.ts +10 -0
- package/src/logging/logger.ts +112 -0
- package/src/proof/__tests__/crypto-parity.test.ts +202 -0
- package/src/proof/__tests__/proof-generator.test.ts +484 -0
- package/src/proof/generator.ts +347 -0
- package/src/proof/index.ts +12 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +100 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/__tests__/dif-esm-bridge.test.ts +33 -0
- package/src/runtime/__tests__/ext-apps-consent.test.ts +334 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +2100 -0
- package/src/runtime/dif-core.ts +39 -0
- package/src/runtime/ext-apps-constants.ts +20 -0
- package/src/services/__tests__/access-control.integration.test.ts +441 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +1132 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/delegation-error-formatter.test.ts +643 -0
- package/src/services/__tests__/oauth-config.service.test.ts +359 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/oauth-token-retrieval.service.test.ts +365 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +494 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +202 -0
- package/src/services/__tests__/provider-resolver.test.ts +213 -0
- package/src/services/__tests__/provider-validator.test.ts +370 -0
- package/src/services/__tests__/session-registration.service.test.ts +312 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/__tests__/tool-context-builder.test.ts +438 -0
- package/src/services/access-control.service.ts +1048 -0
- package/src/services/authorization/authorization-registry.ts +67 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +136 -0
- package/src/services/crypto.service.ts +296 -0
- package/src/services/delegation-error-formatter.ts +299 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +34 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +192 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +141 -0
- package/src/services/oauth-service.ts +652 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/policy.service.ts +527 -0
- package/src/services/proof-verifier.ts +295 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +236 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/session-registration.service.ts +259 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +285 -0
- package/src/services/tool-protection.service.ts +971 -0
- package/src/session/__tests__/session-manager.test.ts +327 -0
- package/src/session/index.ts +10 -0
- package/src/session/manager.ts +380 -0
- package/src/types/__tests__/oauth-required-error.test.ts +79 -0
- package/src/types/__tests__/tool-protection.test.ts +121 -0
- package/src/types/oauth-required-error.ts +71 -0
- package/src/types/tool-protection.ts +179 -0
- package/src/utils/__tests__/base58.test.ts +281 -0
- package/src/utils/__tests__/base64.test.ts +239 -0
- package/src/utils/__tests__/cors.test.ts +184 -0
- package/src/utils/__tests__/did-helpers.test.ts +156 -0
- package/src/utils/__tests__/storage-keys.test.ts +372 -0
- package/src/utils/base58.ts +109 -0
- package/src/utils/base64.ts +185 -0
- package/src/utils/cors.ts +93 -0
- package/src/utils/did-helpers.ts +229 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +285 -0
- package/src/wire-format.ts +114 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mts +57 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Resolver Tests
|
|
3
|
+
*
|
|
4
|
+
* @package @kya-os/mcp-i-core
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
8
|
+
import { ProviderResolver } from "../provider-resolver.js";
|
|
9
|
+
import { OAuthProviderRegistry } from "../oauth-provider-registry.js";
|
|
10
|
+
import { OAuthConfigService } from "../oauth-config.service.js";
|
|
11
|
+
import type { ToolProtection } from "@kya-os/contracts/tool-protection";
|
|
12
|
+
import type { OAuthConfig } from "@kya-os/contracts/config";
|
|
13
|
+
|
|
14
|
+
describe("ProviderResolver", () => {
|
|
15
|
+
let mockConfigService: OAuthConfigService;
|
|
16
|
+
let mockRegistry: OAuthProviderRegistry;
|
|
17
|
+
let resolver: ProviderResolver;
|
|
18
|
+
|
|
19
|
+
const mockOAuthConfig: OAuthConfig = {
|
|
20
|
+
providers: {
|
|
21
|
+
github: {
|
|
22
|
+
clientId: "github_client_id",
|
|
23
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
24
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
25
|
+
supportsPKCE: true,
|
|
26
|
+
requiresClientSecret: false,
|
|
27
|
+
},
|
|
28
|
+
google: {
|
|
29
|
+
clientId: "google_client_id",
|
|
30
|
+
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
31
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
32
|
+
supportsPKCE: true,
|
|
33
|
+
requiresClientSecret: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
mockConfigService = {
|
|
40
|
+
getOAuthConfig: vi.fn().mockResolvedValue(mockOAuthConfig),
|
|
41
|
+
} as any;
|
|
42
|
+
|
|
43
|
+
mockRegistry = {
|
|
44
|
+
hasProvider: vi.fn(),
|
|
45
|
+
getAllProviders: vi.fn().mockReturnValue([]),
|
|
46
|
+
getProviderNames: vi.fn().mockReturnValue([]),
|
|
47
|
+
loadFromAgentShield: vi.fn().mockResolvedValue(undefined),
|
|
48
|
+
getConfiguredProvider: vi.fn().mockReturnValue(null), // New method for configuredProvider
|
|
49
|
+
} as any;
|
|
50
|
+
|
|
51
|
+
resolver = new ProviderResolver(mockRegistry, mockConfigService);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("resolveProvider - Priority 1: Tool-specific provider", () => {
|
|
55
|
+
it("should return tool-specific oauthProvider when specified", async () => {
|
|
56
|
+
const toolProtection: ToolProtection = {
|
|
57
|
+
requiresDelegation: true,
|
|
58
|
+
requiredScopes: ["repo:read"],
|
|
59
|
+
oauthProvider: "github",
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
(mockRegistry.hasProvider as any).mockReturnValue(true);
|
|
63
|
+
|
|
64
|
+
const provider = await resolver.resolveProvider(
|
|
65
|
+
toolProtection,
|
|
66
|
+
"test-project"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(provider).toBe("github");
|
|
70
|
+
expect(mockRegistry.hasProvider).toHaveBeenCalledWith("github");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should throw error if tool-specific provider not configured", async () => {
|
|
74
|
+
const toolProtection: ToolProtection = {
|
|
75
|
+
requiresDelegation: true,
|
|
76
|
+
requiredScopes: ["repo:read"],
|
|
77
|
+
oauthProvider: "nonexistent",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
(mockRegistry.hasProvider as any).mockReturnValue(false);
|
|
81
|
+
|
|
82
|
+
await expect(
|
|
83
|
+
resolver.resolveProvider(toolProtection, "test-project")
|
|
84
|
+
).rejects.toThrow(/not configured for project/);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("resolveProvider - Priority 2: Scope inference", () => {
|
|
89
|
+
it("should infer provider from github scope prefix", async () => {
|
|
90
|
+
const toolProtection: ToolProtection = {
|
|
91
|
+
requiresDelegation: true,
|
|
92
|
+
requiredScopes: ["github:repo:read"],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
(mockRegistry.hasProvider as any).mockImplementation((name: string) => {
|
|
96
|
+
return name === "github";
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const provider = await resolver.resolveProvider(
|
|
100
|
+
toolProtection,
|
|
101
|
+
"test-project"
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(provider).toBe("github");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should infer provider from gmail scope prefix (maps to google)", async () => {
|
|
108
|
+
const toolProtection: ToolProtection = {
|
|
109
|
+
requiresDelegation: true,
|
|
110
|
+
requiredScopes: ["gmail:read"],
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
(mockRegistry.hasProvider as any).mockImplementation((name: string) => {
|
|
114
|
+
return name === "google";
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const provider = await resolver.resolveProvider(
|
|
118
|
+
toolProtection,
|
|
119
|
+
"test-project"
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(provider).toBe("google");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should fall back to configuredProvider for ambiguous scopes", async () => {
|
|
126
|
+
const toolProtection: ToolProtection = {
|
|
127
|
+
requiresDelegation: true,
|
|
128
|
+
requiredScopes: ["github:read", "google:read"],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Ambiguous scopes - both infer different providers
|
|
132
|
+
// Should fall through to Priority 3 (configuredProvider)
|
|
133
|
+
(mockRegistry.hasProvider as any).mockImplementation((name: string) => name === "github");
|
|
134
|
+
(mockRegistry.getConfiguredProvider as any).mockReturnValue("github");
|
|
135
|
+
|
|
136
|
+
const provider = await resolver.resolveProvider(
|
|
137
|
+
toolProtection,
|
|
138
|
+
"test-project"
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Falls back to configuredProvider
|
|
142
|
+
expect(provider).toBe("github");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("resolveProvider - Priority 3: Project-configured provider", () => {
|
|
147
|
+
it("should use configuredProvider as fallback", async () => {
|
|
148
|
+
const toolProtection: ToolProtection = {
|
|
149
|
+
requiresDelegation: true,
|
|
150
|
+
requiredScopes: ["custom:scope"],
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// configuredProvider is github
|
|
154
|
+
(mockRegistry.hasProvider as any).mockImplementation((name: string) => name === "github");
|
|
155
|
+
(mockRegistry.getConfiguredProvider as any).mockReturnValue("github");
|
|
156
|
+
|
|
157
|
+
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
158
|
+
|
|
159
|
+
const provider = await resolver.resolveProvider(
|
|
160
|
+
toolProtection,
|
|
161
|
+
"test-project"
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(provider).toBe("github");
|
|
165
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
166
|
+
expect.stringContaining("project-configured provider")
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
consoleSpy.mockRestore();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should log warning when using configuredProvider fallback", async () => {
|
|
173
|
+
const toolProtection: ToolProtection = {
|
|
174
|
+
requiresDelegation: true,
|
|
175
|
+
requiredScopes: [],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// configuredProvider is github
|
|
179
|
+
(mockRegistry.hasProvider as any).mockImplementation((name: string) => name === "github");
|
|
180
|
+
(mockRegistry.getConfiguredProvider as any).mockReturnValue("github");
|
|
181
|
+
|
|
182
|
+
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
183
|
+
|
|
184
|
+
await resolver.resolveProvider(toolProtection, "test-project");
|
|
185
|
+
|
|
186
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
187
|
+
expect.stringContaining("Consider explicitly setting oauthProvider")
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
consoleSpy.mockRestore();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("resolveProvider - Priority 4: Error if no provider", () => {
|
|
195
|
+
it("should throw error if no provider is configured", async () => {
|
|
196
|
+
const toolProtection: ToolProtection = {
|
|
197
|
+
requiresDelegation: true,
|
|
198
|
+
requiredScopes: [],
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// No configuredProvider set
|
|
202
|
+
(mockRegistry.hasProvider as any).mockReturnValue(false);
|
|
203
|
+
(mockRegistry.getConfiguredProvider as any).mockReturnValue(null);
|
|
204
|
+
(mockRegistry.getAllProviders as any).mockReturnValue([]);
|
|
205
|
+
(mockRegistry.getProviderNames as any).mockReturnValue([]);
|
|
206
|
+
|
|
207
|
+
await expect(
|
|
208
|
+
resolver.resolveProvider(toolProtection, "test-project")
|
|
209
|
+
).rejects.toThrow(/no provider is configured/);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Provider Validator
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
ProviderValidator,
|
|
8
|
+
ProviderValidationError,
|
|
9
|
+
} from "../provider-validator.js";
|
|
10
|
+
import type { OAuthProvider } from "@kya-os/contracts/config";
|
|
11
|
+
|
|
12
|
+
describe("ProviderValidator", () => {
|
|
13
|
+
let validator: ProviderValidator;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
validator = new ProviderValidator();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("validate", () => {
|
|
20
|
+
it("should validate correct provider configuration", () => {
|
|
21
|
+
const provider: OAuthProvider = {
|
|
22
|
+
clientId: "client-123",
|
|
23
|
+
clientSecret: "secret-456",
|
|
24
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
25
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
expect(() => validator.validate(provider, "github")).not.toThrow();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should throw error when clientId is missing", () => {
|
|
32
|
+
const provider: OAuthProvider = {
|
|
33
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
34
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
35
|
+
} as any;
|
|
36
|
+
|
|
37
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
38
|
+
ProviderValidationError
|
|
39
|
+
);
|
|
40
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
41
|
+
"must have a clientId"
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should throw error when clientId is empty string", () => {
|
|
46
|
+
const provider: OAuthProvider = {
|
|
47
|
+
clientId: "",
|
|
48
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
49
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
53
|
+
ProviderValidationError
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should throw error when clientId is whitespace only", () => {
|
|
58
|
+
const provider: OAuthProvider = {
|
|
59
|
+
clientId: " ",
|
|
60
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
61
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
65
|
+
ProviderValidationError
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should throw error when authorizationUrl is missing", () => {
|
|
70
|
+
const provider: OAuthProvider = {
|
|
71
|
+
clientId: "client-123",
|
|
72
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
73
|
+
} as any;
|
|
74
|
+
|
|
75
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
76
|
+
"must have an authorizationUrl"
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should throw error when tokenUrl is missing", () => {
|
|
81
|
+
const provider: OAuthProvider = {
|
|
82
|
+
clientId: "client-123",
|
|
83
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
84
|
+
} as any;
|
|
85
|
+
|
|
86
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
87
|
+
"must have a tokenUrl"
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should validate userInfoUrl when provided", () => {
|
|
92
|
+
const provider: OAuthProvider = {
|
|
93
|
+
clientId: "client-123",
|
|
94
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
95
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
96
|
+
userInfoUrl: "https://api.github.com/user",
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
expect(() => validator.validate(provider, "github")).not.toThrow();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should throw error for invalid authorizationUrl protocol", () => {
|
|
103
|
+
const provider: OAuthProvider = {
|
|
104
|
+
clientId: "client-123",
|
|
105
|
+
authorizationUrl: "ftp://github.com/login/oauth/authorize",
|
|
106
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
110
|
+
ProviderValidationError
|
|
111
|
+
);
|
|
112
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
113
|
+
"must use HTTP or HTTPS protocol"
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should throw error for invalid tokenUrl protocol", () => {
|
|
118
|
+
const provider: OAuthProvider = {
|
|
119
|
+
clientId: "client-123",
|
|
120
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
121
|
+
tokenUrl: "file:///path/to/token",
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
125
|
+
ProviderValidationError
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should throw error for invalid URL format", () => {
|
|
130
|
+
const provider: OAuthProvider = {
|
|
131
|
+
clientId: "client-123",
|
|
132
|
+
authorizationUrl: "not-a-valid-url",
|
|
133
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
137
|
+
ProviderValidationError
|
|
138
|
+
);
|
|
139
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
140
|
+
"is not a valid URL"
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should throw error when proxyMode is true but requiresClientSecret is false", () => {
|
|
145
|
+
const provider: OAuthProvider = {
|
|
146
|
+
clientId: "client-123",
|
|
147
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
148
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
149
|
+
proxyMode: true,
|
|
150
|
+
requiresClientSecret: false,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
154
|
+
ProviderValidationError
|
|
155
|
+
);
|
|
156
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
157
|
+
"proxyMode=true must have requiresClientSecret=true"
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should not throw when proxyMode is true and requiresClientSecret is true", () => {
|
|
162
|
+
const provider: OAuthProvider = {
|
|
163
|
+
clientId: "client-123",
|
|
164
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
165
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
166
|
+
proxyMode: true,
|
|
167
|
+
requiresClientSecret: true,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
expect(() => validator.validate(provider, "github")).not.toThrow();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should validate custom parameters", () => {
|
|
174
|
+
const provider: OAuthProvider = {
|
|
175
|
+
clientId: "client-123",
|
|
176
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
177
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
178
|
+
customParams: {
|
|
179
|
+
custom_param: "value",
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
expect(() => validator.validate(provider, "github")).not.toThrow();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should throw error when custom parameter conflicts with reserved parameter", () => {
|
|
187
|
+
const provider: OAuthProvider = {
|
|
188
|
+
clientId: "client-123",
|
|
189
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
190
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
191
|
+
customParams: {
|
|
192
|
+
response_type: "code", // Reserved!
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
197
|
+
ProviderValidationError
|
|
198
|
+
);
|
|
199
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
200
|
+
"conflicts with reserved OAuth parameter"
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should throw error when custom parameter has empty value", () => {
|
|
205
|
+
const provider: OAuthProvider = {
|
|
206
|
+
clientId: "client-123",
|
|
207
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
208
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
209
|
+
customParams: {
|
|
210
|
+
custom_param: "",
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
215
|
+
ProviderValidationError
|
|
216
|
+
);
|
|
217
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
218
|
+
"has empty value"
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("should throw error when custom parameter has whitespace-only value", () => {
|
|
223
|
+
const provider: OAuthProvider = {
|
|
224
|
+
clientId: "client-123",
|
|
225
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
226
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
227
|
+
customParams: {
|
|
228
|
+
custom_param: " ",
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
233
|
+
ProviderValidationError
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("should check all reserved parameters", () => {
|
|
238
|
+
const reservedParams = [
|
|
239
|
+
"response_type",
|
|
240
|
+
"client_id",
|
|
241
|
+
"redirect_uri",
|
|
242
|
+
"scope",
|
|
243
|
+
"state",
|
|
244
|
+
"code_challenge",
|
|
245
|
+
"code_challenge_method",
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
for (const param of reservedParams) {
|
|
249
|
+
const provider: OAuthProvider = {
|
|
250
|
+
clientId: "client-123",
|
|
251
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
252
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
253
|
+
customParams: {
|
|
254
|
+
[param]: "value",
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
259
|
+
ProviderValidationError
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("should handle case-insensitive reserved parameter check", () => {
|
|
265
|
+
const provider: OAuthProvider = {
|
|
266
|
+
clientId: "client-123",
|
|
267
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
268
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
269
|
+
customParams: {
|
|
270
|
+
RESPONSE_TYPE: "code", // Uppercase
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
expect(() => validator.validate(provider, "github")).toThrow(
|
|
275
|
+
ProviderValidationError
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("testProvider", () => {
|
|
281
|
+
it("should return true when endpoint is reachable", async () => {
|
|
282
|
+
const provider: OAuthProvider = {
|
|
283
|
+
clientId: "client-123",
|
|
284
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
285
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const mockFetch = async () =>
|
|
289
|
+
({
|
|
290
|
+
ok: true,
|
|
291
|
+
status: 200,
|
|
292
|
+
}) as Response;
|
|
293
|
+
|
|
294
|
+
const result = await validator.testProvider(provider, mockFetch as any);
|
|
295
|
+
|
|
296
|
+
expect(result).toBe(true);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("should return true when endpoint returns 405 Method Not Allowed", async () => {
|
|
300
|
+
const provider: OAuthProvider = {
|
|
301
|
+
clientId: "client-123",
|
|
302
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
303
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const mockFetch = async () =>
|
|
307
|
+
({
|
|
308
|
+
ok: false,
|
|
309
|
+
status: 405,
|
|
310
|
+
}) as Response;
|
|
311
|
+
|
|
312
|
+
const result = await validator.testProvider(provider, mockFetch as any);
|
|
313
|
+
|
|
314
|
+
expect(result).toBe(true); // 405 is acceptable
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("should return false when endpoint is not reachable", async () => {
|
|
318
|
+
const provider: OAuthProvider = {
|
|
319
|
+
clientId: "client-123",
|
|
320
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
321
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const mockFetch = async () => {
|
|
325
|
+
throw new Error("Network error");
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const result = await validator.testProvider(provider, mockFetch as any);
|
|
329
|
+
|
|
330
|
+
expect(result).toBe(false);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("should return false when endpoint returns error status", async () => {
|
|
334
|
+
const provider: OAuthProvider = {
|
|
335
|
+
clientId: "client-123",
|
|
336
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
337
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const mockFetch = async () =>
|
|
341
|
+
({
|
|
342
|
+
ok: false,
|
|
343
|
+
status: 500,
|
|
344
|
+
}) as Response;
|
|
345
|
+
|
|
346
|
+
const result = await validator.testProvider(provider, mockFetch as any);
|
|
347
|
+
|
|
348
|
+
expect(result).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe("ProviderValidationError", () => {
|
|
353
|
+
it("should create error with message", () => {
|
|
354
|
+
const error = new ProviderValidationError("Validation failed");
|
|
355
|
+
|
|
356
|
+
expect(error).toBeInstanceOf(Error);
|
|
357
|
+
expect(error.name).toBe("ProviderValidationError");
|
|
358
|
+
expect(error.message).toBe("Validation failed");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("should include optional field name", () => {
|
|
362
|
+
const error = new ProviderValidationError(
|
|
363
|
+
"Validation failed",
|
|
364
|
+
"clientId"
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
expect(error.field).toBe("clientId");
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
});
|