@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,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof Client DID Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for proof generation with clientDid tracking and extraction.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
8
|
+
import { MCPIRuntimeBase } from '../../runtime/base';
|
|
9
|
+
import { ProviderRuntimeConfig } from '../../config';
|
|
10
|
+
import { createMockProviders } from '../utils/mock-providers';
|
|
11
|
+
|
|
12
|
+
describe('MCPIRuntimeBase - Proof Client DID', () => {
|
|
13
|
+
let runtime: MCPIRuntimeBase;
|
|
14
|
+
let config: ProviderRuntimeConfig;
|
|
15
|
+
let mockProviders: ReturnType<typeof createMockProviders>;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
vi.clearAllMocks();
|
|
19
|
+
mockProviders = createMockProviders();
|
|
20
|
+
config = {
|
|
21
|
+
...mockProviders,
|
|
22
|
+
environment: 'development',
|
|
23
|
+
session: {
|
|
24
|
+
timestampSkewSeconds: 120,
|
|
25
|
+
ttlMinutes: 30
|
|
26
|
+
},
|
|
27
|
+
audit: {
|
|
28
|
+
enabled: false
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
runtime = new MCPIRuntimeBase(config);
|
|
32
|
+
await runtime.initialize();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('createProof with clientDid', () => {
|
|
36
|
+
it('should include clientDid in proof when provided in session', async () => {
|
|
37
|
+
const testData = { result: 'success' };
|
|
38
|
+
const session = {
|
|
39
|
+
id: 'session123',
|
|
40
|
+
audience: 'https://client.example.com',
|
|
41
|
+
nonce: 'test-nonce',
|
|
42
|
+
clientDid: 'did:key:zclient123'
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const proof = await runtime.createProof(testData, session);
|
|
46
|
+
|
|
47
|
+
expect(proof).toBeDefined();
|
|
48
|
+
expect(proof.did).toBe('did:key:zmock123'); // Agent DID
|
|
49
|
+
expect(proof.sessionId).toBe('session123');
|
|
50
|
+
expect(proof.audience).toBe('https://client.example.com');
|
|
51
|
+
// Note: clientDid is stored in proofData but not directly in proof object
|
|
52
|
+
// The proof structure includes sessionId which can be used to retrieve clientDid
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should include userDid in proof when provided in session', async () => {
|
|
56
|
+
const testData = { result: 'success' };
|
|
57
|
+
const session = {
|
|
58
|
+
id: 'session123',
|
|
59
|
+
audience: 'https://client.example.com',
|
|
60
|
+
nonce: 'test-nonce',
|
|
61
|
+
userDid: 'did:key:zuser456'
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const proof = await runtime.createProof(testData, session);
|
|
65
|
+
|
|
66
|
+
expect(proof).toBeDefined();
|
|
67
|
+
expect(proof.sessionId).toBe('session123');
|
|
68
|
+
// userDid is stored in session context
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should work without clientDid or userDid (backward compatibility)', async () => {
|
|
72
|
+
const testData = { result: 'success' };
|
|
73
|
+
const session = {
|
|
74
|
+
id: 'session123',
|
|
75
|
+
audience: 'https://client.example.com',
|
|
76
|
+
nonce: 'test-nonce'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const proof = await runtime.createProof(testData, session);
|
|
80
|
+
|
|
81
|
+
expect(proof).toBeDefined();
|
|
82
|
+
expect(proof.did).toBe('did:key:zmock123');
|
|
83
|
+
expect(proof.sessionId).toBe('session123');
|
|
84
|
+
expect(proof.audience).toBe('https://client.example.com');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should prioritize clientDid over userDid when both provided', async () => {
|
|
88
|
+
const testData = { result: 'success' };
|
|
89
|
+
const session = {
|
|
90
|
+
id: 'session123',
|
|
91
|
+
audience: 'https://client.example.com',
|
|
92
|
+
nonce: 'test-nonce',
|
|
93
|
+
clientDid: 'did:key:zclient123',
|
|
94
|
+
userDid: 'did:key:zuser456'
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const proof = await runtime.createProof(testData, session);
|
|
98
|
+
|
|
99
|
+
expect(proof).toBeDefined();
|
|
100
|
+
expect(proof.sessionId).toBe('session123');
|
|
101
|
+
// clientDid takes precedence in session context
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('processToolCall with clientDid', () => {
|
|
106
|
+
const mockHandler = vi.fn().mockResolvedValue({ result: 'success' });
|
|
107
|
+
|
|
108
|
+
it('should include clientDid in proof when session has clientDid', async () => {
|
|
109
|
+
const session = {
|
|
110
|
+
id: 'session123',
|
|
111
|
+
audience: 'https://client.example.com',
|
|
112
|
+
nonce: 'test-nonce',
|
|
113
|
+
clientDid: 'did:key:zclient123'
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
await runtime.processToolCall(
|
|
117
|
+
'testTool',
|
|
118
|
+
{ arg: 'value' },
|
|
119
|
+
mockHandler,
|
|
120
|
+
session
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const proof = runtime.getLastProof();
|
|
124
|
+
expect(proof).toBeDefined();
|
|
125
|
+
expect(proof.sessionId).toBe('session123');
|
|
126
|
+
expect(proof.audience).toBe('https://client.example.com');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should extract clientDid from handshake session', async () => {
|
|
130
|
+
// Create session via handshake
|
|
131
|
+
const handshakeResponse = await runtime.handleHandshake({
|
|
132
|
+
clientDid: 'did:key:zhandshake123',
|
|
133
|
+
audience: 'https://client.example.com'
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const session = await runtime.getCurrentSession();
|
|
137
|
+
const proof = await runtime.createProof(
|
|
138
|
+
{ test: 'data' },
|
|
139
|
+
session
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(proof.sessionId).toBe(handshakeResponse.sessionId);
|
|
143
|
+
expect(session.clientDid).toBe('did:key:zhandshake123');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should handle anonymous session from handshake (Phase 5)', async () => {
|
|
147
|
+
// Phase 5: Sessions start anonymous - no userDid at handshake
|
|
148
|
+
const configWithUserDid = {
|
|
149
|
+
...config,
|
|
150
|
+
identity: {
|
|
151
|
+
enabled: true,
|
|
152
|
+
generateUserDids: true,
|
|
153
|
+
environment: 'development'
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const runtimeWithUserDid = new MCPIRuntimeBase(configWithUserDid);
|
|
157
|
+
await runtimeWithUserDid.initialize();
|
|
158
|
+
|
|
159
|
+
const handshakeResponse = await runtimeWithUserDid.handleHandshake({
|
|
160
|
+
audience: 'https://client.example.com'
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const session = await runtimeWithUserDid.getCurrentSession();
|
|
164
|
+
expect(session).toBeDefined();
|
|
165
|
+
|
|
166
|
+
// Phase 5: Sessions start anonymous without userDid
|
|
167
|
+
// userDid is only set after OAuth identity resolution
|
|
168
|
+
expect(session.userDid).toBeUndefined();
|
|
169
|
+
expect(session.identityState).toBe('anonymous');
|
|
170
|
+
|
|
171
|
+
const proof = await runtimeWithUserDid.createProof(
|
|
172
|
+
{ test: 'data' },
|
|
173
|
+
session
|
|
174
|
+
);
|
|
175
|
+
expect(proof.sessionId).toBe(handshakeResponse.sessionId);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('verifyProof with clientDid context', () => {
|
|
180
|
+
let validProof: any;
|
|
181
|
+
const testData = { foo: 'bar' };
|
|
182
|
+
|
|
183
|
+
beforeEach(async () => {
|
|
184
|
+
// Set up DID document for verification
|
|
185
|
+
const fetchProvider = mockProviders.fetchProvider as any;
|
|
186
|
+
fetchProvider.setDIDDocument('did:key:zmock123', {
|
|
187
|
+
verificationMethod: [{
|
|
188
|
+
publicKeyBase64: 'mock-public-key'
|
|
189
|
+
}]
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const session = {
|
|
193
|
+
id: 'session123',
|
|
194
|
+
audience: 'https://client.example.com',
|
|
195
|
+
nonce: 'test-nonce',
|
|
196
|
+
clientDid: 'did:key:zclient123'
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
validProof = await runtime.createProof(testData, session);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should verify proof with clientDid in session context', async () => {
|
|
203
|
+
const nonceCache = mockProviders.nonceCacheProvider as any;
|
|
204
|
+
nonceCache.clear();
|
|
205
|
+
|
|
206
|
+
const isValid = await runtime.verifyProof(testData, validProof);
|
|
207
|
+
expect(isValid).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should verify proof independently of clientDid presence', async () => {
|
|
211
|
+
// Create proof without clientDid
|
|
212
|
+
const proofWithoutClientDid = await runtime.createProof(testData, {
|
|
213
|
+
id: 'session456',
|
|
214
|
+
audience: 'https://client.example.com',
|
|
215
|
+
nonce: 'other-nonce'
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const nonceCache = mockProviders.nonceCacheProvider as any;
|
|
219
|
+
nonceCache.clear();
|
|
220
|
+
|
|
221
|
+
const isValid = await runtime.verifyProof(testData, proofWithoutClientDid);
|
|
222
|
+
expect(isValid).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('clientDid extraction from session', () => {
|
|
227
|
+
it('should retrieve clientDid from active session', async () => {
|
|
228
|
+
const handshakeResponse = await runtime.handleHandshake({
|
|
229
|
+
clientDid: 'did:key:zclient789',
|
|
230
|
+
audience: 'https://client.example.com'
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const session = await runtime.getCurrentSession();
|
|
234
|
+
expect(session.clientDid).toBe('did:key:zclient789');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should handle anonymous session when no clientDid provided (Phase 5)', async () => {
|
|
238
|
+
// Phase 5: Sessions start anonymous - userDid and clientDid may both be undefined
|
|
239
|
+
const configWithUserDid = {
|
|
240
|
+
...config,
|
|
241
|
+
identity: {
|
|
242
|
+
enabled: true,
|
|
243
|
+
generateUserDids: true,
|
|
244
|
+
environment: 'development'
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const runtimeWithUserDid = new MCPIRuntimeBase(configWithUserDid);
|
|
248
|
+
await runtimeWithUserDid.initialize();
|
|
249
|
+
|
|
250
|
+
const handshakeResponse = await runtimeWithUserDid.handleHandshake({
|
|
251
|
+
audience: 'https://client.example.com'
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const session = await runtimeWithUserDid.getCurrentSession();
|
|
255
|
+
expect(session).toBeDefined();
|
|
256
|
+
|
|
257
|
+
// Phase 5: Sessions start anonymous without userDid
|
|
258
|
+
// userDid is only set after OAuth identity resolution
|
|
259
|
+
expect(session.userDid).toBeUndefined();
|
|
260
|
+
expect(session.identityState).toBe('anonymous');
|
|
261
|
+
|
|
262
|
+
// clientDid can also be undefined in anonymous sessions
|
|
263
|
+
// Both will be set after OAuth completes
|
|
264
|
+
|
|
265
|
+
// Verify proof includes the session
|
|
266
|
+
const proof = await runtimeWithUserDid.createProof(
|
|
267
|
+
{ test: 'data' },
|
|
268
|
+
session
|
|
269
|
+
);
|
|
270
|
+
expect(proof.sessionId).toBe(handshakeResponse.sessionId);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('edge cases', () => {
|
|
275
|
+
it('should handle empty clientDid string gracefully', async () => {
|
|
276
|
+
const session = {
|
|
277
|
+
id: 'session123',
|
|
278
|
+
audience: 'https://client.example.com',
|
|
279
|
+
nonce: 'test-nonce',
|
|
280
|
+
clientDid: ''
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const proof = await runtime.createProof({ test: 'data' }, session);
|
|
284
|
+
expect(proof).toBeDefined();
|
|
285
|
+
expect(proof.sessionId).toBe('session123');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('should handle null clientDid gracefully', async () => {
|
|
289
|
+
const session = {
|
|
290
|
+
id: 'session123',
|
|
291
|
+
audience: 'https://client.example.com',
|
|
292
|
+
nonce: 'test-nonce',
|
|
293
|
+
clientDid: null as any
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const proof = await runtime.createProof({ test: 'data' }, session);
|
|
297
|
+
expect(proof).toBeDefined();
|
|
298
|
+
expect(proof.sessionId).toBe('session123');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should handle undefined clientDid gracefully', async () => {
|
|
302
|
+
const session = {
|
|
303
|
+
id: 'session123',
|
|
304
|
+
audience: 'https://client.example.com',
|
|
305
|
+
nonce: 'test-nonce'
|
|
306
|
+
// clientDid is undefined
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const proof = await runtime.createProof({ test: 'data' }, session);
|
|
310
|
+
expect(proof).toBeDefined();
|
|
311
|
+
expect(proof.sessionId).toBe('session123');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('should handle invalid DID format in clientDid', async () => {
|
|
315
|
+
const session = {
|
|
316
|
+
id: 'session123',
|
|
317
|
+
audience: 'https://client.example.com',
|
|
318
|
+
nonce: 'test-nonce',
|
|
319
|
+
clientDid: 'invalid-did-format'
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const proof = await runtime.createProof({ test: 'data' }, session);
|
|
323
|
+
expect(proof).toBeDefined();
|
|
324
|
+
// Proof should still be created even with invalid DID format
|
|
325
|
+
expect(proof.sessionId).toBe('session123');
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
describe('proof metadata consistency', () => {
|
|
330
|
+
it('should maintain consistent proof structure with clientDid', async () => {
|
|
331
|
+
const session = {
|
|
332
|
+
id: 'session123',
|
|
333
|
+
audience: 'https://client.example.com',
|
|
334
|
+
nonce: 'test-nonce',
|
|
335
|
+
clientDid: 'did:key:zclient123'
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const proof1 = await runtime.createProof({ test: 'data1' }, session);
|
|
339
|
+
const proof2 = await runtime.createProof({ test: 'data2' }, session);
|
|
340
|
+
|
|
341
|
+
// Both proofs should have same sessionId and audience
|
|
342
|
+
expect(proof1.sessionId).toBe(proof2.sessionId);
|
|
343
|
+
expect(proof1.audience).toBe(proof2.audience);
|
|
344
|
+
|
|
345
|
+
// But different nonces (if not pre-provided)
|
|
346
|
+
// Since we're using same nonce, they should be same
|
|
347
|
+
expect(proof1.nonce).toBe(proof2.nonce);
|
|
348
|
+
|
|
349
|
+
// Different timestamps
|
|
350
|
+
expect(proof1.timestamp).toBeLessThanOrEqual(proof2.timestamp);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should use different proofs for different sessions', async () => {
|
|
354
|
+
const session1 = {
|
|
355
|
+
id: 'session1',
|
|
356
|
+
audience: 'https://client.example.com',
|
|
357
|
+
nonce: 'nonce1',
|
|
358
|
+
clientDid: 'did:key:zclient1'
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const session2 = {
|
|
362
|
+
id: 'session2',
|
|
363
|
+
audience: 'https://client.example.com',
|
|
364
|
+
nonce: 'nonce2',
|
|
365
|
+
clientDid: 'did:key:zclient2'
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const proof1 = await runtime.createProof({ test: 'data' }, session1);
|
|
369
|
+
const proof2 = await runtime.createProof({ test: 'data' }, session2);
|
|
370
|
+
|
|
371
|
+
expect(proof1.sessionId).not.toBe(proof2.sessionId);
|
|
372
|
+
expect(proof1.nonce).not.toBe(proof2.nonce);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Selection Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for the provider parameter in consent URLs and tool protection flow.
|
|
5
|
+
* This ensures the correct authentication method (OAuth provider or credential provider)
|
|
6
|
+
* is selected when multiple providers are configured for a project.
|
|
7
|
+
*
|
|
8
|
+
* Related changes:
|
|
9
|
+
* - buildConsentUrl now accepts a `provider` param
|
|
10
|
+
* - DelegationRequiredError includes provider in consent URL
|
|
11
|
+
* - ConsentService reads provider from URL query param
|
|
12
|
+
*/
|
|
13
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
14
|
+
import { MCPIRuntimeBase } from "../../runtime/base";
|
|
15
|
+
import type { ProviderRuntimeConfig } from "../../config";
|
|
16
|
+
import { DelegationRequiredError } from "../../types/tool-protection";
|
|
17
|
+
import {
|
|
18
|
+
createMockProviders,
|
|
19
|
+
MockClockProvider,
|
|
20
|
+
} from "../utils/mock-providers";
|
|
21
|
+
|
|
22
|
+
describe("Provider Selection in Consent URLs", () => {
|
|
23
|
+
let runtime: MCPIRuntimeBase;
|
|
24
|
+
let config: ProviderRuntimeConfig;
|
|
25
|
+
let mockProviders: ReturnType<typeof createMockProviders>;
|
|
26
|
+
let mockToolProtectionService: {
|
|
27
|
+
checkToolProtection: ReturnType<typeof vi.fn>;
|
|
28
|
+
};
|
|
29
|
+
let mockAccessControlService: {
|
|
30
|
+
verifyDelegation: ReturnType<typeof vi.fn>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
vi.clearAllMocks();
|
|
35
|
+
mockProviders = createMockProviders();
|
|
36
|
+
|
|
37
|
+
mockToolProtectionService = {
|
|
38
|
+
checkToolProtection: vi.fn(),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
mockAccessControlService = {
|
|
42
|
+
verifyDelegation: vi.fn(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
config = {
|
|
46
|
+
...mockProviders,
|
|
47
|
+
audit: { enabled: false },
|
|
48
|
+
toolProtectionService: mockToolProtectionService as any,
|
|
49
|
+
clock: new MockClockProvider(),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
runtime = new MCPIRuntimeBase(config);
|
|
53
|
+
// IMPORTANT: MCPIRuntimeBase doesn't read accessControlService from config
|
|
54
|
+
// It must be injected directly onto the runtime instance
|
|
55
|
+
(runtime as any).accessControlService = mockAccessControlService;
|
|
56
|
+
await runtime.initialize();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const mockHandler = vi.fn().mockResolvedValue({ result: "success" });
|
|
60
|
+
const session = {
|
|
61
|
+
id: "session123",
|
|
62
|
+
audience: "https://client.example.com",
|
|
63
|
+
nonce: "test-nonce",
|
|
64
|
+
agentDid: "did:key:zmock123",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
describe("when tool has oauthProvider configured", () => {
|
|
68
|
+
it("should include provider param in consent URL", async () => {
|
|
69
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
70
|
+
requiresDelegation: true,
|
|
71
|
+
requiredScopes: ["checkout:execute"],
|
|
72
|
+
oauthProvider: "github", // Tool configured to use GitHub OAuth
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
await runtime.processToolCall(
|
|
77
|
+
"checkout",
|
|
78
|
+
{ cart: [] },
|
|
79
|
+
mockHandler,
|
|
80
|
+
session
|
|
81
|
+
);
|
|
82
|
+
expect.fail("Should have thrown DelegationRequiredError");
|
|
83
|
+
} catch (error: any) {
|
|
84
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
85
|
+
expect(error.consentUrl).toBeDefined();
|
|
86
|
+
// Provider should be included in URL
|
|
87
|
+
expect(error.consentUrl).toContain("provider=github");
|
|
88
|
+
expect(error.consentUrl).toContain("tool=checkout");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should include credential provider in consent URL", async () => {
|
|
93
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
94
|
+
requiresDelegation: true,
|
|
95
|
+
requiredScopes: ["login:execute"],
|
|
96
|
+
oauthProvider: "credentials", // Tool configured to use credential auth
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
await runtime.processToolCall(
|
|
101
|
+
"login",
|
|
102
|
+
{ username: "test" },
|
|
103
|
+
mockHandler,
|
|
104
|
+
session
|
|
105
|
+
);
|
|
106
|
+
expect.fail("Should have thrown DelegationRequiredError");
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
109
|
+
expect(error.consentUrl).toBeDefined();
|
|
110
|
+
// Credential provider should be in URL
|
|
111
|
+
expect(error.consentUrl).toContain("provider=credentials");
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should include custom provider name in consent URL", async () => {
|
|
116
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
117
|
+
requiresDelegation: true,
|
|
118
|
+
requiredScopes: ["order:create"],
|
|
119
|
+
oauthProvider: "hardwareworld", // Custom credential provider
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await runtime.processToolCall(
|
|
124
|
+
"createOrder",
|
|
125
|
+
{ items: [] },
|
|
126
|
+
mockHandler,
|
|
127
|
+
session
|
|
128
|
+
);
|
|
129
|
+
expect.fail("Should have thrown DelegationRequiredError");
|
|
130
|
+
} catch (error: any) {
|
|
131
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
132
|
+
expect(error.consentUrl).toContain("provider=hardwareworld");
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("when tool does NOT have oauthProvider configured", () => {
|
|
138
|
+
it("should NOT include provider param in consent URL", async () => {
|
|
139
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
140
|
+
requiresDelegation: true,
|
|
141
|
+
requiredScopes: ["files:write"],
|
|
142
|
+
// No oauthProvider - tool uses default project-level auth
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
await runtime.processToolCall(
|
|
147
|
+
"uploadFile",
|
|
148
|
+
{ file: "test.txt" },
|
|
149
|
+
mockHandler,
|
|
150
|
+
session
|
|
151
|
+
);
|
|
152
|
+
expect.fail("Should have thrown DelegationRequiredError");
|
|
153
|
+
} catch (error: any) {
|
|
154
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
155
|
+
expect(error.consentUrl).toBeDefined();
|
|
156
|
+
// Provider should NOT be in URL when not specified
|
|
157
|
+
expect(error.consentUrl).not.toContain("provider=");
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("provider param URL encoding", () => {
|
|
163
|
+
it("should properly encode provider with special characters", async () => {
|
|
164
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
165
|
+
requiresDelegation: true,
|
|
166
|
+
requiredScopes: ["api:call"],
|
|
167
|
+
oauthProvider: "my-custom-idp", // Provider with hyphen
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
await runtime.processToolCall(
|
|
172
|
+
"apiCall",
|
|
173
|
+
{},
|
|
174
|
+
mockHandler,
|
|
175
|
+
session
|
|
176
|
+
);
|
|
177
|
+
expect.fail("Should have thrown DelegationRequiredError");
|
|
178
|
+
} catch (error: any) {
|
|
179
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
180
|
+
// Hyphen should be preserved in URL
|
|
181
|
+
expect(error.consentUrl).toContain("provider=my-custom-idp");
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("multiple tools with different providers", () => {
|
|
187
|
+
it("should use correct provider for each tool", async () => {
|
|
188
|
+
// First tool: GitHub OAuth
|
|
189
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValueOnce({
|
|
190
|
+
requiresDelegation: true,
|
|
191
|
+
requiredScopes: ["repo:read"],
|
|
192
|
+
oauthProvider: "github",
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
await runtime.processToolCall("readRepo", {}, mockHandler, session);
|
|
197
|
+
} catch (error: any) {
|
|
198
|
+
expect(error.consentUrl).toContain("provider=github");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Second tool: Credential auth
|
|
202
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValueOnce({
|
|
203
|
+
requiresDelegation: true,
|
|
204
|
+
requiredScopes: ["user:login"],
|
|
205
|
+
oauthProvider: "credentials",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
await runtime.processToolCall("login", {}, mockHandler, session);
|
|
210
|
+
} catch (error: any) {
|
|
211
|
+
expect(error.consentUrl).toContain("provider=credentials");
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("consent URL structure with provider", () => {
|
|
217
|
+
it("should have correct query parameter order", async () => {
|
|
218
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
219
|
+
requiresDelegation: true,
|
|
220
|
+
requiredScopes: ["data:read"],
|
|
221
|
+
oauthProvider: "google",
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
await runtime.processToolCall("readData", {}, mockHandler, session);
|
|
226
|
+
} catch (error: any) {
|
|
227
|
+
const url = new URL(error.consentUrl);
|
|
228
|
+
|
|
229
|
+
// Verify all expected params are present
|
|
230
|
+
expect(url.searchParams.get("tool")).toBe("readData");
|
|
231
|
+
expect(url.searchParams.get("scopes")).toBe("data:read");
|
|
232
|
+
expect(url.searchParams.get("provider")).toBe("google");
|
|
233
|
+
expect(url.searchParams.get("session_id")).toBe("session123");
|
|
234
|
+
expect(url.searchParams.get("agent_did")).toBe("did:key:zmock123");
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("should include resume_token in consent URL", async () => {
|
|
239
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
240
|
+
requiresDelegation: true,
|
|
241
|
+
requiredScopes: ["payment:send"],
|
|
242
|
+
oauthProvider: "stripe",
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
await runtime.processToolCall("sendPayment", {}, mockHandler, session);
|
|
247
|
+
} catch (error: any) {
|
|
248
|
+
const url = new URL(error.consentUrl);
|
|
249
|
+
expect(url.searchParams.get("resume_token")).toMatch(/^resume_/);
|
|
250
|
+
expect(url.searchParams.get("provider")).toBe("stripe");
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("delegation verification failures with provider", () => {
|
|
256
|
+
it("should include provider in consent URL after verification failure", async () => {
|
|
257
|
+
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
258
|
+
requiresDelegation: true,
|
|
259
|
+
requiredScopes: ["admin:access"],
|
|
260
|
+
oauthProvider: "okta",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Mock delegation verification failure
|
|
264
|
+
mockAccessControlService.verifyDelegation.mockResolvedValue({
|
|
265
|
+
success: true,
|
|
266
|
+
data: {
|
|
267
|
+
valid: false,
|
|
268
|
+
reason: "delegation_expired",
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const sessionWithDelegation = {
|
|
273
|
+
...session,
|
|
274
|
+
delegationToken: "expired-token",
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
await runtime.processToolCall(
|
|
279
|
+
"adminPanel",
|
|
280
|
+
{},
|
|
281
|
+
mockHandler,
|
|
282
|
+
sessionWithDelegation
|
|
283
|
+
);
|
|
284
|
+
} catch (error: any) {
|
|
285
|
+
expect(error).toBeInstanceOf(DelegationRequiredError);
|
|
286
|
+
// Provider should still be in URL for re-authorization
|
|
287
|
+
expect(error.consentUrl).toContain("provider=okta");
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|