@aporthq/aport-agent-guardrails 1.0.8
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/LICENSE +217 -0
- package/README.md +481 -0
- package/bin/agent-guardrails +133 -0
- package/bin/aport-create-passport.sh +444 -0
- package/bin/aport-cursor-hook.sh +90 -0
- package/bin/aport-guardrail-api.sh +108 -0
- package/bin/aport-guardrail-bash.sh +394 -0
- package/bin/aport-guardrail-v2.sh +5 -0
- package/bin/aport-guardrail.sh +5 -0
- package/bin/aport-resolve-paths.sh +71 -0
- package/bin/aport-status.sh +276 -0
- package/bin/frameworks/crewai.sh +49 -0
- package/bin/frameworks/cursor.sh +95 -0
- package/bin/frameworks/langchain.sh +48 -0
- package/bin/frameworks/n8n.sh +36 -0
- package/bin/frameworks/openclaw.sh +19 -0
- package/bin/lib/allowlist.sh +18 -0
- package/bin/lib/common.sh +28 -0
- package/bin/lib/config.sh +46 -0
- package/bin/lib/constants.sh +232 -0
- package/bin/lib/detect.sh +65 -0
- package/bin/lib/error.sh +269 -0
- package/bin/lib/passport.sh +19 -0
- package/bin/lib/templates/.gitkeep +1 -0
- package/bin/lib/templates/config.yaml +6 -0
- package/bin/lib/validation.sh +206 -0
- package/bin/openclaw +660 -0
- package/docs/ADDING_A_FRAMEWORK.md +87 -0
- package/docs/AGENTS.md.example +40 -0
- package/docs/CODE_REVIEW.md +192 -0
- package/docs/DEPLOYMENT_READINESS.md +81 -0
- package/docs/FAQ_SECURITY_SCANNERS.md +373 -0
- package/docs/FRAMEWORK_ROADMAP.md +41 -0
- package/docs/HOSTED_PASSPORT_SETUP.md +362 -0
- package/docs/IMPLEMENTING_YOUR_OWN_EVALUATOR.md +433 -0
- package/docs/OPENCLAW_COMPATIBILITY.md +73 -0
- package/docs/OPENCLAW_LOCAL_INTEGRATION.md +596 -0
- package/docs/OPENCLAW_TOOLS_AND_POLICIES.md +54 -0
- package/docs/QUICKSTART.md +470 -0
- package/docs/QUICKSTART_OPENCLAW_PLUGIN.md +470 -0
- package/docs/README.md +28 -0
- package/docs/RELEASE.md +87 -0
- package/docs/REPO_LAYOUT.md +47 -0
- package/docs/SKILLS_ECOSYSTEM_ANALYSIS_FEB17.md +1260 -0
- package/docs/TOOL_POLICY_MAPPING.md +46 -0
- package/docs/UPGRADE.md +46 -0
- package/docs/VERIFICATION_METHODS.md +97 -0
- package/docs/assets/README.md +8 -0
- package/docs/assets/porter.svg +54 -0
- package/docs/development/ERROR_CODES.md +616 -0
- package/docs/frameworks/GITHUB_ISSUE_PROPOSALS.md +1105 -0
- package/docs/frameworks/crewai.md +114 -0
- package/docs/frameworks/cursor.md +159 -0
- package/docs/frameworks/langchain.md +72 -0
- package/docs/frameworks/n8n.md +40 -0
- package/docs/frameworks/openclaw.md +40 -0
- package/docs/launch/ADD_APORT_AWESOME_LISTS_INSTRUCTIONS.md +146 -0
- package/docs/launch/ANNOUNCEMENT_GUIDE.md +266 -0
- package/docs/launch/AWESOME_REPOS.md +53 -0
- package/docs/launch/CURSOR_VSCODE_HOOKS_RESEARCH.md +77 -0
- package/docs/launch/DEMO_TERMINAL_OUTPUT.txt +48 -0
- package/docs/launch/DRY_AND_PLAN_CHECKLIST.md +47 -0
- package/docs/launch/EVIDENCE_README.md +61 -0
- package/docs/launch/EVIDENCE_TERMINAL_CAPTURE.txt +10 -0
- package/docs/launch/FRAMEWORK_SUPPORT_PLAN.md +1640 -0
- package/docs/launch/LAUNCH_READINESS_CHECKLIST.md +237 -0
- package/docs/launch/LAUNCH_STRATEGY_SUMMARY.md +464 -0
- package/docs/launch/OPENCLAW_FEEDBACK_AND_FIXES.md +85 -0
- package/docs/launch/POST_1_VALENTINE_IMPROVED.md +233 -0
- package/docs/launch/POST_2_GUARDRAIL_IMPROVED.md +369 -0
- package/docs/launch/PRE_LAUNCH_FIXES.md +766 -0
- package/docs/launch/QUICK_LAUNCH_CHECKLIST.md +400 -0
- package/docs/launch/READINESS_SUMMARY.md +262 -0
- package/docs/launch/README.md +68 -0
- package/docs/launch/USER_STORIES.md +327 -0
- package/docs/launch/scripts/add-aport-awesome-pr.sh +69 -0
- package/docs/operations/MONITORING.md +588 -0
- package/docs/reviews/2026-02-18-staff-review.md +268 -0
- package/extensions/openclaw-aport/README.md +415 -0
- package/extensions/openclaw-aport/index.js +625 -0
- package/extensions/openclaw-aport/openclaw-aport.js +7 -0
- package/extensions/openclaw-aport/openclaw.plugin.json +46 -0
- package/extensions/openclaw-aport/package.json +36 -0
- package/extensions/openclaw-aport/test.js +307 -0
- package/external/aport-policies/README.md +363 -0
- package/external/aport-policies/agent.session.create.v1/README.md +345 -0
- package/external/aport-policies/agent.session.create.v1/policy.json +162 -0
- package/external/aport-policies/agent.tool.register.v1/README.md +361 -0
- package/external/aport-policies/agent.tool.register.v1/policy.json +172 -0
- package/external/aport-policies/code.release.publish.v1/README.md +51 -0
- package/external/aport-policies/code.release.publish.v1/policy.json +121 -0
- package/external/aport-policies/code.repository.merge.v1/README.md +287 -0
- package/external/aport-policies/code.repository.merge.v1/express.example.js +332 -0
- package/external/aport-policies/code.repository.merge.v1/fastapi.example.py +370 -0
- package/external/aport-policies/code.repository.merge.v1/policy.json +162 -0
- package/external/aport-policies/data.export.create.v1/README.md +226 -0
- package/external/aport-policies/data.export.create.v1/express.example.js +172 -0
- package/external/aport-policies/data.export.create.v1/fastapi.example.py +165 -0
- package/external/aport-policies/data.export.create.v1/policy.json +133 -0
- package/external/aport-policies/data.report.ingest.v1/README.md +134 -0
- package/external/aport-policies/data.report.ingest.v1/express.example.js +105 -0
- package/external/aport-policies/data.report.ingest.v1/minimal-example.js +68 -0
- package/external/aport-policies/data.report.ingest.v1/policy.json +174 -0
- package/external/aport-policies/finance.crypto.trade.v1/README.md +146 -0
- package/external/aport-policies/finance.crypto.trade.v1/express.example.js +109 -0
- package/external/aport-policies/finance.crypto.trade.v1/minimal-example.js +65 -0
- package/external/aport-policies/finance.crypto.trade.v1/policy.json +176 -0
- package/external/aport-policies/finance.payment.charge.v1/README.md +326 -0
- package/external/aport-policies/finance.payment.charge.v1/express.example.js +250 -0
- package/external/aport-policies/finance.payment.charge.v1/fastapi.example.py +227 -0
- package/external/aport-policies/finance.payment.charge.v1/minimal-example.js +64 -0
- package/external/aport-policies/finance.payment.charge.v1/policy.json +224 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/passport.instance.json +42 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/passport.template.json +40 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/payments-charge-policy.test.js +817 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/test_payments_charge_policy.py +486 -0
- package/external/aport-policies/finance.payment.payout.v1/README.md +78 -0
- package/external/aport-policies/finance.payment.payout.v1/policy.json +181 -0
- package/external/aport-policies/finance.payment.refund.v1/README.md +275 -0
- package/external/aport-policies/finance.payment.refund.v1/express.example.js +167 -0
- package/external/aport-policies/finance.payment.refund.v1/fastapi.example.py +136 -0
- package/external/aport-policies/finance.payment.refund.v1/minimal-example.js +183 -0
- package/external/aport-policies/finance.payment.refund.v1/policy.json +216 -0
- package/external/aport-policies/finance.payment.refund.v1/tests/refunds-policy.test.js +924 -0
- package/external/aport-policies/finance.payment.refund.v1/tests/test_refunds_policy.py +778 -0
- package/external/aport-policies/finance.transaction.execute.v1/README.md +309 -0
- package/external/aport-policies/finance.transaction.execute.v1/express.example.js +261 -0
- package/external/aport-policies/finance.transaction.execute.v1/fastapi.example.py +231 -0
- package/external/aport-policies/finance.transaction.execute.v1/minimal-example.js +78 -0
- package/external/aport-policies/finance.transaction.execute.v1/policy.json +189 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/passport.instance.json +42 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/passport.template.json +42 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/test_transactions_policy.py +214 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/transactions-policy.test.js +306 -0
- package/external/aport-policies/governance.data.access.v1/README.md +292 -0
- package/external/aport-policies/governance.data.access.v1/express.example.js +321 -0
- package/external/aport-policies/governance.data.access.v1/fastapi.example.py +279 -0
- package/external/aport-policies/governance.data.access.v1/minimal-example.js +65 -0
- package/external/aport-policies/governance.data.access.v1/policy.json +208 -0
- package/external/aport-policies/governance.data.access.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/governance.data.access.v1/tests/data-access-policy.test.js +308 -0
- package/external/aport-policies/governance.data.access.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/governance.data.access.v1/tests/passport.instance.json +56 -0
- package/external/aport-policies/governance.data.access.v1/tests/passport.template.json +56 -0
- package/external/aport-policies/governance.data.access.v1/tests/test_data_access_policy.py +214 -0
- package/external/aport-policies/legal.contract.review.v1/README.md +109 -0
- package/external/aport-policies/legal.contract.review.v1/policy.json +378 -0
- package/external/aport-policies/legal.contract.review.v1/tests/legal-contract-review-policy.test.js +609 -0
- package/external/aport-policies/legal.contract.review.v1/tests/passport.template.json +49 -0
- package/external/aport-policies/mcp.tool.execute.v1/README.md +301 -0
- package/external/aport-policies/mcp.tool.execute.v1/policy.json +141 -0
- package/external/aport-policies/messaging.message.send.v1/README.md +230 -0
- package/external/aport-policies/messaging.message.send.v1/express.example.js +183 -0
- package/external/aport-policies/messaging.message.send.v1/fastapi.example.py +193 -0
- package/external/aport-policies/messaging.message.send.v1/policy.json +144 -0
- package/external/aport-policies/policy-template.json +107 -0
- package/external/aport-policies/system.command.execute.v1/README.md +275 -0
- package/external/aport-policies/system.command.execute.v1/policy.json +146 -0
- package/external/aport-spec/CONTRIBUTING.md +273 -0
- package/external/aport-spec/LICENSE +21 -0
- package/external/aport-spec/README.md +168 -0
- package/external/aport-spec/conformance/README.md +294 -0
- package/external/aport-spec/conformance/cases/data.export.v1/contexts/allow_users.json +6 -0
- package/external/aport-spec/conformance/cases/data.export.v1/contexts/deny_pii.json +6 -0
- package/external/aport-spec/conformance/cases/data.export.v1/expected/allow_users.decision.json +19 -0
- package/external/aport-spec/conformance/cases/data.export.v1/expected/deny_pii.decision.json +19 -0
- package/external/aport-spec/conformance/cases/data.export.v1/passports/template.json +29 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/allow_50usd.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_150usd.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_currency.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/allow_50usd.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_150usd.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_currency.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/passports/template.json +42 -0
- package/external/aport-spec/conformance/package.json +44 -0
- package/external/aport-spec/conformance/pnpm-lock.yaml +642 -0
- package/external/aport-spec/conformance/src/cases.ts +371 -0
- package/external/aport-spec/conformance/src/ed25519.ts +167 -0
- package/external/aport-spec/conformance/src/jcs.ts +85 -0
- package/external/aport-spec/conformance/src/runner.ts +533 -0
- package/external/aport-spec/conformance/src/validators.ts +185 -0
- package/external/aport-spec/conformance/test-runner.js +315 -0
- package/external/aport-spec/conformance/tsconfig.json +21 -0
- package/external/aport-spec/error-schema.json +192 -0
- package/external/aport-spec/index.json +12 -0
- package/external/aport-spec/integrations/clawmoat/README.md +12 -0
- package/external/aport-spec/integrations/shield/README.md +245 -0
- package/external/aport-spec/integrations/shield/adapters/index.js +116 -0
- package/external/aport-spec/integrations/shield/adapters/system-command-execute.js +133 -0
- package/external/aport-spec/integrations/shield/test/README.md +58 -0
- package/external/aport-spec/integrations/shield/test/shield.md +40 -0
- package/external/aport-spec/integrations/shield/test/test-shield-to-verify.js +274 -0
- package/external/aport-spec/metrics-schema.json +504 -0
- package/external/aport-spec/oap/CHANGELOG.md +54 -0
- package/external/aport-spec/oap/VERSION.md +40 -0
- package/external/aport-spec/oap/capability-registry.md +229 -0
- package/external/aport-spec/oap/conformance.md +257 -0
- package/external/aport-spec/oap/decision-schema.json +114 -0
- package/external/aport-spec/oap/examples/context.refund.usd.50.json +9 -0
- package/external/aport-spec/oap/examples/decision.allow.sample.json +20 -0
- package/external/aport-spec/oap/examples/decision.deny.sample.json +23 -0
- package/external/aport-spec/oap/examples/passport.instance.v1.json +50 -0
- package/external/aport-spec/oap/examples/passport.template.v1.json +71 -0
- package/external/aport-spec/oap/oap-spec.md +426 -0
- package/external/aport-spec/oap/passport-schema.json +396 -0
- package/external/aport-spec/oap/security.md +213 -0
- package/external/aport-spec/oap/vc/context-oap-v1.jsonld +137 -0
- package/external/aport-spec/oap/vc/examples/oap-decision-vc.json +37 -0
- package/external/aport-spec/oap/vc/examples/oap-passport-vc.json +68 -0
- package/external/aport-spec/oap/vc/tools/INTEGRATION.md +375 -0
- package/external/aport-spec/oap/vc/tools/README.md +278 -0
- package/external/aport-spec/oap/vc/tools/examples/decision-to-vc.js +66 -0
- package/external/aport-spec/oap/vc/tools/examples/passport-to-vc.js +83 -0
- package/external/aport-spec/oap/vc/tools/examples/vc-to-decision.js +77 -0
- package/external/aport-spec/oap/vc/tools/examples/vc-to-passport.js +94 -0
- package/external/aport-spec/oap/vc/tools/package.json +38 -0
- package/external/aport-spec/oap/vc/tools/pnpm-lock.yaml +472 -0
- package/external/aport-spec/oap/vc/tools/src/cli.ts +226 -0
- package/external/aport-spec/oap/vc/tools/src/crypto-utils.ts +427 -0
- package/external/aport-spec/oap/vc/tools/src/index.ts +653 -0
- package/external/aport-spec/oap/vc/tools/src/test.ts +148 -0
- package/external/aport-spec/oap/vc/tools/src/vp.ts +382 -0
- package/external/aport-spec/oap/vc/tools/test-simple.js +214 -0
- package/external/aport-spec/oap/vc/tools/tsconfig.json +19 -0
- package/external/aport-spec/oap/vc/vc-mapping.md +443 -0
- package/external/aport-spec/passport-schema.json +586 -0
- package/external/aport-spec/rate-limiting.md +136 -0
- package/external/aport-spec/transport-profile.md +325 -0
- package/external/aport-spec/webhook-spec.md +314 -0
- package/package.json +70 -0
- package/skills/aport-agent-guardrail/SKILL.md +314 -0
- package/src/evaluator.js +252 -0
- package/src/server/index.js +72 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SHIELD integration tests: conversion, APort verify, and response shape.
|
|
5
|
+
*
|
|
6
|
+
* Flow: shield.md → adapters (index.js → system-command-execute) → policy + limits → verify.
|
|
7
|
+
* Policy is always generated from shield.md via the scope adapters.
|
|
8
|
+
*
|
|
9
|
+
* 1. Conversion: shield.md → OAP policy pack + limits (via adapters/index.js).
|
|
10
|
+
* 2. APort fit: POST /api/verify/policy/IN_BODY with that policy and passport.
|
|
11
|
+
* 3. Response shape: deny reason fits SHIELD/OAP.
|
|
12
|
+
*
|
|
13
|
+
* Run: node spec/integrations/shield/test/test-shield-to-verify.js
|
|
14
|
+
* Requires: shield.md in this folder. API_BASE:
|
|
15
|
+
* - APORT_API_BASE_URL set → use it
|
|
16
|
+
* - LOCAL=1 or RUN_LOCAL=1 → http://localhost:8787
|
|
17
|
+
* - else (e.g. CI) → https://api.aport.io (live)
|
|
18
|
+
*
|
|
19
|
+
* @see spec/integrations/shield/README.md
|
|
20
|
+
* @see spec/integrations/shield/adapters/index.js
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fs = require("fs");
|
|
24
|
+
const path = require("path");
|
|
25
|
+
|
|
26
|
+
const isLocal =
|
|
27
|
+
process.env.LOCAL === "1" ||
|
|
28
|
+
process.env.RUN_LOCAL === "1" ||
|
|
29
|
+
process.env.APORT_VERIFY_LOCAL === "1";
|
|
30
|
+
|
|
31
|
+
const API_BASE =
|
|
32
|
+
process.env.APORT_API_BASE_URL ||
|
|
33
|
+
(isLocal ? "http://localhost:8787" : "https://api.aport.io");
|
|
34
|
+
|
|
35
|
+
const shieldPath = path.join(__dirname, "shield.md");
|
|
36
|
+
|
|
37
|
+
const { convert } = require("../adapters/index.js");
|
|
38
|
+
|
|
39
|
+
function log(msg, type = "info") {
|
|
40
|
+
const c = {
|
|
41
|
+
info: "\x1b[36m",
|
|
42
|
+
success: "\x1b[32m",
|
|
43
|
+
error: "\x1b[31m",
|
|
44
|
+
warning: "\x1b[33m",
|
|
45
|
+
reset: "\x1b[0m",
|
|
46
|
+
};
|
|
47
|
+
console.log(`${c[type] || c.info}${msg}${c.reset}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function verifyWithPolicyInBody(body, expectAllow) {
|
|
51
|
+
const res = await fetch(`${API_BASE}/api/verify/policy/IN_BODY`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
body: JSON.stringify(body),
|
|
55
|
+
});
|
|
56
|
+
const data = await res.json();
|
|
57
|
+
const decision = data.data?.decision || data.decision;
|
|
58
|
+
const allowed = decision?.allow === true;
|
|
59
|
+
const firstReason = decision?.reasons?.[0];
|
|
60
|
+
|
|
61
|
+
if (res.status !== 200) {
|
|
62
|
+
log(`HTTP ${res.status}: ${JSON.stringify(data)}`, "error");
|
|
63
|
+
return { ok: false, allowed, decision, data, firstReason };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const pass = allowed === expectAllow;
|
|
67
|
+
log(
|
|
68
|
+
`${pass ? "✅" : "❌"} ${allowed ? "ALLOWED" : "DENIED"} (expected ${expectAllow ? "ALLOWED" : "DENIED"}) ${firstReason?.message || ""}`,
|
|
69
|
+
pass ? "success" : "error",
|
|
70
|
+
);
|
|
71
|
+
return { ok: pass, allowed, decision, data, firstReason };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runConversionTests() {
|
|
75
|
+
log("\n--- 1. Conversion (shield.md → OAP policy + limits) ---\n", "info");
|
|
76
|
+
let passed = 0;
|
|
77
|
+
let failed = 0;
|
|
78
|
+
|
|
79
|
+
if (!fs.existsSync(shieldPath)) {
|
|
80
|
+
log(
|
|
81
|
+
"shield.md not found; run from repo root with test/shield.md present",
|
|
82
|
+
"error",
|
|
83
|
+
);
|
|
84
|
+
failed++;
|
|
85
|
+
return { passed, failed, policy: null, limitsFragment: null };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { policy, limitsFragment, threats } = convert(shieldPath);
|
|
89
|
+
|
|
90
|
+
if (!policy || !policy.id || !policy.requires_capabilities) {
|
|
91
|
+
log(
|
|
92
|
+
"Conversion failed: policy missing id or requires_capabilities",
|
|
93
|
+
"error",
|
|
94
|
+
);
|
|
95
|
+
failed++;
|
|
96
|
+
} else {
|
|
97
|
+
log("Converted policy id: " + policy.id, "success");
|
|
98
|
+
passed++;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (
|
|
102
|
+
!limitsFragment ||
|
|
103
|
+
typeof limitsFragment.blocked_patterns === "undefined"
|
|
104
|
+
) {
|
|
105
|
+
log("Conversion failed: limits fragment missing blocked_patterns", "error");
|
|
106
|
+
failed++;
|
|
107
|
+
} else {
|
|
108
|
+
log(
|
|
109
|
+
"Limits fragment blocked_patterns: " +
|
|
110
|
+
limitsFragment.blocked_patterns.join(", "),
|
|
111
|
+
"success",
|
|
112
|
+
);
|
|
113
|
+
passed++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!Array.isArray(threats) || threats.length === 0) {
|
|
117
|
+
log("Conversion failed: no threats parsed", "error");
|
|
118
|
+
failed++;
|
|
119
|
+
} else {
|
|
120
|
+
log("Parsed " + threats.length + " threat(s) from shield.md", "success");
|
|
121
|
+
passed++;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { passed, failed, policy, limitsFragment };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function runVerifyTests(policy, passport) {
|
|
128
|
+
log("\n--- 2. APort verify (policy + passport → allow/deny) ---\n", "info");
|
|
129
|
+
let passed = 0;
|
|
130
|
+
let failed = 0;
|
|
131
|
+
|
|
132
|
+
const body = { context: {}, passport, policy };
|
|
133
|
+
|
|
134
|
+
const r1 = await verifyWithPolicyInBody(
|
|
135
|
+
{ ...body, context: { command: "npm", args: ["install"] } },
|
|
136
|
+
true,
|
|
137
|
+
);
|
|
138
|
+
if (r1.ok) passed++;
|
|
139
|
+
else failed++;
|
|
140
|
+
|
|
141
|
+
const r2 = await verifyWithPolicyInBody(
|
|
142
|
+
{ ...body, context: { command: "sh", args: ["-c", "rm -rf /tmp/foo"] } },
|
|
143
|
+
false,
|
|
144
|
+
);
|
|
145
|
+
if (r2.ok) passed++;
|
|
146
|
+
else failed++;
|
|
147
|
+
|
|
148
|
+
const r3 = await verifyWithPolicyInBody(
|
|
149
|
+
{ ...body, context: { command: "git", args: ["status"] } },
|
|
150
|
+
true,
|
|
151
|
+
);
|
|
152
|
+
if (r3.ok) passed++;
|
|
153
|
+
else failed++;
|
|
154
|
+
|
|
155
|
+
const r4 = await verifyWithPolicyInBody(
|
|
156
|
+
{ ...body, context: { command: "sudo", args: ["ls"] } },
|
|
157
|
+
false,
|
|
158
|
+
);
|
|
159
|
+
if (r4.ok) passed++;
|
|
160
|
+
else failed++;
|
|
161
|
+
|
|
162
|
+
return { passed, failed, denyReason: r2.firstReason };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function runResponseShapeTests(denyReason) {
|
|
166
|
+
log("\n--- 3. Response shape (deny fits SHIELD / OAP) ---\n", "info");
|
|
167
|
+
let passed = 0;
|
|
168
|
+
let failed = 0;
|
|
169
|
+
|
|
170
|
+
if (!denyReason) {
|
|
171
|
+
log("No deny reason to check (run verify tests first)", "warning");
|
|
172
|
+
return { passed, failed };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const msg = (denyReason.message || "").toLowerCase();
|
|
176
|
+
if (
|
|
177
|
+
msg.includes("blocked") ||
|
|
178
|
+
msg.includes("dangerous") ||
|
|
179
|
+
msg.includes("pattern") ||
|
|
180
|
+
msg.includes("not allowed")
|
|
181
|
+
) {
|
|
182
|
+
log(
|
|
183
|
+
"Deny reason is SHIELD/OAP-style: " +
|
|
184
|
+
(denyReason.message || "").slice(0, 80),
|
|
185
|
+
"success",
|
|
186
|
+
);
|
|
187
|
+
passed++;
|
|
188
|
+
} else {
|
|
189
|
+
log(
|
|
190
|
+
"Deny reason (optional SHIELD format): " +
|
|
191
|
+
(denyReason.message || "").slice(0, 80),
|
|
192
|
+
"info",
|
|
193
|
+
);
|
|
194
|
+
passed++;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (denyReason.code) {
|
|
198
|
+
log("Deny code present: " + denyReason.code, "success");
|
|
199
|
+
passed++;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return { passed, failed };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function run() {
|
|
206
|
+
log(
|
|
207
|
+
"\n=== SHIELD integration tests (conversion, verify, response) ===\n",
|
|
208
|
+
"info",
|
|
209
|
+
);
|
|
210
|
+
log("API_BASE=" + API_BASE + " pack_id=IN_BODY\n", "info");
|
|
211
|
+
|
|
212
|
+
let totalPassed = 0;
|
|
213
|
+
let totalFailed = 0;
|
|
214
|
+
|
|
215
|
+
const conv = runConversionTests();
|
|
216
|
+
totalPassed += conv.passed;
|
|
217
|
+
totalFailed += conv.failed;
|
|
218
|
+
|
|
219
|
+
const policy = conv.policy;
|
|
220
|
+
const limitsFragment = conv.limitsFragment;
|
|
221
|
+
|
|
222
|
+
if (!policy || !limitsFragment) {
|
|
223
|
+
log(
|
|
224
|
+
"Conversion did not produce policy/limits; cannot run verify tests",
|
|
225
|
+
"error",
|
|
226
|
+
);
|
|
227
|
+
totalFailed++;
|
|
228
|
+
} else {
|
|
229
|
+
const passport = {
|
|
230
|
+
agent_id: "ap_shield_demo_001",
|
|
231
|
+
name: "SHIELD demo agent",
|
|
232
|
+
controller_type: "person",
|
|
233
|
+
description: "Agent for SHIELD→OAP verify example",
|
|
234
|
+
owner_id: "ap_org_shield_demo",
|
|
235
|
+
owner: "SHIELD Demo Org",
|
|
236
|
+
role: "Developer",
|
|
237
|
+
capabilities: [
|
|
238
|
+
{
|
|
239
|
+
id: "system.command.execute",
|
|
240
|
+
description: "System command execution",
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
limits: limitsFragment,
|
|
244
|
+
regions: ["US"],
|
|
245
|
+
status: "active",
|
|
246
|
+
assurance_level: "L2",
|
|
247
|
+
contact: "shield-demo@example.com",
|
|
248
|
+
version: "1.0.0",
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const verify = await runVerifyTests(policy, passport);
|
|
252
|
+
totalPassed += verify.passed;
|
|
253
|
+
totalFailed += verify.failed;
|
|
254
|
+
|
|
255
|
+
const resp = runResponseShapeTests(verify.denyReason);
|
|
256
|
+
totalPassed += resp.passed;
|
|
257
|
+
totalFailed += resp.failed;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
log(
|
|
261
|
+
"\n--- Summary: " +
|
|
262
|
+
totalPassed +
|
|
263
|
+
" passed, " +
|
|
264
|
+
totalFailed +
|
|
265
|
+
" failed ---\n",
|
|
266
|
+
totalFailed ? "error" : "success",
|
|
267
|
+
);
|
|
268
|
+
process.exit(totalFailed > 0 ? 1 : 0);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
run().catch((err) => {
|
|
272
|
+
log("Error: " + err.message, "error");
|
|
273
|
+
process.exit(1);
|
|
274
|
+
});
|