devanvil 0.0.0-stage → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ar.md +113 -0
- package/README.md +272 -2
- package/SECURITY.md +49 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +664 -0
- package/dist/core/contract-drift.d.ts +49 -0
- package/dist/core/contract-drift.js +312 -0
- package/dist/core/converters.d.ts +18 -0
- package/dist/core/converters.js +989 -0
- package/dist/core/cron.d.ts +33 -0
- package/dist/core/cron.js +309 -0
- package/dist/core/crypto.d.ts +59 -0
- package/dist/core/crypto.js +260 -0
- package/dist/core/curl.d.ts +17 -0
- package/dist/core/curl.js +174 -0
- package/dist/core/diff.d.ts +36 -0
- package/dist/core/diff.js +148 -0
- package/dist/core/encoding.d.ts +3 -0
- package/dist/core/encoding.js +143 -0
- package/dist/core/importers.d.ts +65 -0
- package/dist/core/importers.js +361 -0
- package/dist/core/jwt.d.ts +39 -0
- package/dist/core/jwt.js +269 -0
- package/dist/core/llm-tokens.d.ts +38 -0
- package/dist/core/llm-tokens.js +125 -0
- package/dist/core/log-analyzer.d.ts +30 -0
- package/dist/core/log-analyzer.js +155 -0
- package/dist/core/network.d.ts +72 -0
- package/dist/core/network.js +185 -0
- package/dist/core/oauth-protobuf.d.ts +74 -0
- package/dist/core/oauth-protobuf.js +396 -0
- package/dist/core/openapi.d.ts +27 -0
- package/dist/core/openapi.js +257 -0
- package/dist/core/pipeline.d.ts +28 -0
- package/dist/core/pipeline.js +154 -0
- package/dist/core/regex.d.ts +50 -0
- package/dist/core/regex.js +360 -0
- package/dist/core/runner.d.ts +53 -0
- package/dist/core/runner.js +250 -0
- package/dist/core/secrets.d.ts +87 -0
- package/dist/core/secrets.js +603 -0
- package/dist/core/security.d.ts +34 -0
- package/dist/core/security.js +301 -0
- package/dist/core/sql-explain.d.ts +50 -0
- package/dist/core/sql-explain.js +259 -0
- package/dist/core/tls.d.ts +44 -0
- package/dist/core/tls.js +169 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +31 -0
- package/dist/server/app.d.ts +31 -0
- package/dist/server/app.js +359 -0
- package/dist/server/http-proxy.d.ts +55 -0
- package/dist/server/http-proxy.js +373 -0
- package/dist/server/http-utils.d.ts +28 -0
- package/dist/server/http-utils.js +118 -0
- package/dist/server/load-tester.d.ts +53 -0
- package/dist/server/load-tester.js +137 -0
- package/dist/server/mcp.d.ts +35 -0
- package/dist/server/mcp.js +470 -0
- package/dist/server/mock-store.d.ts +38 -0
- package/dist/server/mock-store.js +238 -0
- package/dist/server/plugin-loader.d.ts +61 -0
- package/dist/server/plugin-loader.js +305 -0
- package/dist/server/recorder-store.d.ts +35 -0
- package/dist/server/recorder-store.js +147 -0
- package/dist/server/routes/network-routes.d.ts +3 -0
- package/dist/server/routes/network-routes.js +441 -0
- package/dist/server/routes/tools-routes.d.ts +3 -0
- package/dist/server/routes/tools-routes.js +299 -0
- package/dist/server/routes/workspace-routes.d.ts +3 -0
- package/dist/server/routes/workspace-routes.js +262 -0
- package/dist/server/webhook-store.d.ts +29 -0
- package/dist/server/webhook-store.js +100 -0
- package/dist/server/workspace-store.d.ts +91 -0
- package/dist/server/workspace-store.js +448 -0
- package/dist/server/ws-probe.d.ts +34 -0
- package/dist/server/ws-probe.js +291 -0
- package/dist/ui/app.js +290 -0
- package/dist/ui/favicon.svg +14 -0
- package/dist/ui/index.html +83 -0
- package/dist/ui/logo.png +0 -0
- package/dist/ui/styles.css +694 -0
- package/dist/ui/tools-data.js +719 -0
- package/dist/ui/tools-network.js +769 -0
- package/dist/ui/tools-ops.js +299 -0
- package/dist/ui/tools-pro.js +500 -0
- package/dist/ui/tools-security.js +397 -0
- package/dist/ui/tools-v12.js +765 -0
- package/dist/ui/tools-v13.js +321 -0
- package/dist/ui/tools-v20.js +563 -0
- package/dist/ui/tools-v21.js +411 -0
- package/package.json +75 -4
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { queryJsonPath } from './converters.js';
|
|
2
|
+
import { interpolateRequestWithEnv, } from './importers.js';
|
|
3
|
+
import { safeJsonParse } from './security.js';
|
|
4
|
+
import { executeProxyRequest } from '../server/http-proxy.js';
|
|
5
|
+
function evaluateAssertion(assertion, response) {
|
|
6
|
+
switch (assertion.type) {
|
|
7
|
+
case 'status': {
|
|
8
|
+
const expected = Number(assertion.expected ?? 200);
|
|
9
|
+
const passed = response.status === expected;
|
|
10
|
+
return {
|
|
11
|
+
type: 'status',
|
|
12
|
+
expected,
|
|
13
|
+
actual: response.status,
|
|
14
|
+
passed,
|
|
15
|
+
message: passed
|
|
16
|
+
? `HTTP status == ${expected}`
|
|
17
|
+
: `Expected HTTP ${expected}, got ${response.status}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
case 'maxLatencyMs': {
|
|
21
|
+
const limit = Number(assertion.expected ?? 1000);
|
|
22
|
+
const passed = response.latencyMs <= limit;
|
|
23
|
+
return {
|
|
24
|
+
type: 'maxLatencyMs',
|
|
25
|
+
expected: limit,
|
|
26
|
+
actual: response.latencyMs,
|
|
27
|
+
passed,
|
|
28
|
+
message: passed
|
|
29
|
+
? `Latency ${response.latencyMs}ms <= ${limit}ms`
|
|
30
|
+
: `Latency ${response.latencyMs}ms exceeded max ${limit}ms`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
case 'headerContains': {
|
|
34
|
+
const hdrName = (assertion.target ?? '').toLowerCase();
|
|
35
|
+
const needle = String(assertion.expected ?? '');
|
|
36
|
+
const entry = Object.entries(response.headers).find(([k]) => k.toLowerCase() === hdrName);
|
|
37
|
+
const actual = entry?.[1] ?? '';
|
|
38
|
+
const passed = Boolean(hdrName) && actual.toLowerCase().includes(needle.toLowerCase());
|
|
39
|
+
return {
|
|
40
|
+
type: 'headerContains',
|
|
41
|
+
target: assertion.target,
|
|
42
|
+
expected: needle,
|
|
43
|
+
actual,
|
|
44
|
+
passed,
|
|
45
|
+
message: passed
|
|
46
|
+
? `Header "${assertion.target}" contains "${needle}"`
|
|
47
|
+
: `Header "${assertion.target}" ("${actual}") does not contain "${needle}"`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case 'bodyContains': {
|
|
51
|
+
const needle = String(assertion.expected ?? '');
|
|
52
|
+
const passed = response.body.includes(needle);
|
|
53
|
+
return {
|
|
54
|
+
type: 'bodyContains',
|
|
55
|
+
expected: needle,
|
|
56
|
+
passed,
|
|
57
|
+
message: passed
|
|
58
|
+
? `Response body contains "${needle}"`
|
|
59
|
+
: `Response body missing expected substring "${needle}"`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
case 'jsonPathEquals': {
|
|
63
|
+
const expr = assertion.target ?? '$';
|
|
64
|
+
try {
|
|
65
|
+
const parsed = safeJsonParse(response.body);
|
|
66
|
+
const matches = queryJsonPath(parsed, expr);
|
|
67
|
+
const actual = matches.length === 1 ? matches[0] : matches;
|
|
68
|
+
const passed = actual === assertion.expected ||
|
|
69
|
+
String(actual) === String(assertion.expected);
|
|
70
|
+
return {
|
|
71
|
+
type: 'jsonPathEquals',
|
|
72
|
+
target: expr,
|
|
73
|
+
expected: assertion.expected,
|
|
74
|
+
actual,
|
|
75
|
+
passed,
|
|
76
|
+
message: passed
|
|
77
|
+
? `JSONPath ${expr} == ${JSON.stringify(assertion.expected)}`
|
|
78
|
+
: `JSONPath ${expr} expected ${JSON.stringify(assertion.expected)}, got ${JSON.stringify(actual)}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
return {
|
|
83
|
+
type: 'jsonPathEquals',
|
|
84
|
+
target: expr,
|
|
85
|
+
expected: assertion.expected,
|
|
86
|
+
passed: false,
|
|
87
|
+
message: `JSONPath ${expr} failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
return {
|
|
93
|
+
type: assertion.type,
|
|
94
|
+
passed: false,
|
|
95
|
+
message: `Unsupported assertion type "${String(assertion.type)}"`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Executes all requests in a DevAnvil Collection sequentially with active environment &
|
|
101
|
+
* optional `{{env.*}}` interpolation, SSRF protection, and declarative assertions.
|
|
102
|
+
* Zero-dependency alternative to Newman for local & CI API testing.
|
|
103
|
+
*/
|
|
104
|
+
export async function runCollection(collection, options = {}) {
|
|
105
|
+
const startedAt = new Date().toISOString();
|
|
106
|
+
const suiteStart = performance.now();
|
|
107
|
+
// Clone variable map so request chaining (`extract`) mutates only this run
|
|
108
|
+
const vars = { ...(options.variables ?? {}) };
|
|
109
|
+
const results = [];
|
|
110
|
+
for (const req of collection.requests) {
|
|
111
|
+
const resolved = interpolateRequestWithEnv({ method: req.method, url: req.url, headers: req.headers, body: req.body }, vars, { processEnv: options.processEnv });
|
|
112
|
+
const reqStart = performance.now();
|
|
113
|
+
try {
|
|
114
|
+
const resp = await executeProxyRequest({
|
|
115
|
+
method: resolved.method,
|
|
116
|
+
url: resolved.url,
|
|
117
|
+
headers: resolved.headers,
|
|
118
|
+
body: resolved.body,
|
|
119
|
+
timeoutMs: options.timeoutMs ?? 10_000,
|
|
120
|
+
}, { allowPrivate: options.allowPrivate });
|
|
121
|
+
const latencyMs = Math.round((performance.now() - reqStart) * 10) / 10;
|
|
122
|
+
// Request Chaining: extract variables from JSONPath or response headers for subsequent requests
|
|
123
|
+
const extracted = {};
|
|
124
|
+
if (Array.isArray(req.extract) && req.extract.length > 0) {
|
|
125
|
+
let parsedBody;
|
|
126
|
+
let bodyParsed = false;
|
|
127
|
+
for (const ext of req.extract) {
|
|
128
|
+
const varName = ext.variable?.trim();
|
|
129
|
+
if (!varName || /^(?:__proto__|constructor|prototype)$/.test(varName))
|
|
130
|
+
continue;
|
|
131
|
+
if (ext.source === 'header') {
|
|
132
|
+
const targetHdr = ext.expression.toLowerCase();
|
|
133
|
+
const hit = Object.entries(resp.headers).find(([k]) => k.toLowerCase() === targetHdr);
|
|
134
|
+
if (hit) {
|
|
135
|
+
vars[varName] = hit[1];
|
|
136
|
+
extracted[varName] = hit[1];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (ext.source === 'jsonPath') {
|
|
140
|
+
try {
|
|
141
|
+
if (!bodyParsed) {
|
|
142
|
+
parsedBody = safeJsonParse(resp.body);
|
|
143
|
+
bodyParsed = true;
|
|
144
|
+
}
|
|
145
|
+
const matches = queryJsonPath(parsedBody, ext.expression);
|
|
146
|
+
if (matches.length > 0 && matches[0] !== undefined && matches[0] !== null) {
|
|
147
|
+
const val = typeof matches[0] === 'string' ? matches[0] : JSON.stringify(matches[0]);
|
|
148
|
+
vars[varName] = val;
|
|
149
|
+
extracted[varName] = val;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// Ignore non-JSON body on extraction
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const assertionsToRun = req.assertions && req.assertions.length > 0
|
|
159
|
+
? req.assertions
|
|
160
|
+
: [{ type: 'status', expected: resp.status < 400 ? resp.status : 200 }];
|
|
161
|
+
const assertionResults = assertionsToRun.map((a) => evaluateAssertion(a, {
|
|
162
|
+
status: resp.status,
|
|
163
|
+
headers: resp.headers,
|
|
164
|
+
body: resp.body,
|
|
165
|
+
latencyMs,
|
|
166
|
+
}));
|
|
167
|
+
const passed = assertionResults.every((r) => r.passed);
|
|
168
|
+
results.push({
|
|
169
|
+
requestId: req.id,
|
|
170
|
+
name: req.name,
|
|
171
|
+
method: resolved.method,
|
|
172
|
+
resolvedUrl: resolved.url,
|
|
173
|
+
status: resp.status,
|
|
174
|
+
latencyMs,
|
|
175
|
+
passed,
|
|
176
|
+
assertions: assertionResults,
|
|
177
|
+
...(Object.keys(extracted).length > 0 ? { extracted } : {}),
|
|
178
|
+
});
|
|
179
|
+
if (!passed && options.stopOnFailure)
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
const latencyMs = Math.round((performance.now() - reqStart) * 10) / 10;
|
|
184
|
+
results.push({
|
|
185
|
+
requestId: req.id,
|
|
186
|
+
name: req.name,
|
|
187
|
+
method: resolved.method,
|
|
188
|
+
resolvedUrl: resolved.url,
|
|
189
|
+
latencyMs,
|
|
190
|
+
passed: false,
|
|
191
|
+
error: err instanceof Error ? err.message : String(err),
|
|
192
|
+
assertions: [],
|
|
193
|
+
});
|
|
194
|
+
if (options.stopOnFailure)
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const totalDurationMs = Math.round((performance.now() - suiteStart) * 10) / 10;
|
|
199
|
+
const passedRequests = results.filter((r) => r.passed).length;
|
|
200
|
+
const failedRequests = results.length - passedRequests;
|
|
201
|
+
return {
|
|
202
|
+
collectionName: collection.name,
|
|
203
|
+
environmentName: options.environmentName,
|
|
204
|
+
startedAt,
|
|
205
|
+
totalDurationMs,
|
|
206
|
+
totalRequests: results.length,
|
|
207
|
+
passedRequests,
|
|
208
|
+
failedRequests,
|
|
209
|
+
passed: failedRequests === 0,
|
|
210
|
+
results,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function xmlEsc(input) {
|
|
214
|
+
return input
|
|
215
|
+
.replace(/&/g, '&')
|
|
216
|
+
.replace(/</g, '<')
|
|
217
|
+
.replace(/>/g, '>')
|
|
218
|
+
.replace(/"/g, '"')
|
|
219
|
+
.replace(/'/g, ''');
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Formats a DevAnvil CollectionRunReport into standard JUnit XML for GitHub Actions,
|
|
223
|
+
* GitLab CI, Azure DevOps, and Jenkins test result panels.
|
|
224
|
+
*/
|
|
225
|
+
export function formatRunReportAsJunitXml(report) {
|
|
226
|
+
const cases = report.results
|
|
227
|
+
.map((r) => {
|
|
228
|
+
const secs = (r.latencyMs / 1000).toFixed(3);
|
|
229
|
+
const nameAttr = xmlEsc(`${r.method} ${r.name}`);
|
|
230
|
+
const classAttr = xmlEsc(report.collectionName);
|
|
231
|
+
if (r.passed) {
|
|
232
|
+
return ` <testcase classname="${classAttr}" name="${nameAttr}" time="${secs}" />`;
|
|
233
|
+
}
|
|
234
|
+
const failureMsg = r.error ??
|
|
235
|
+
r.assertions
|
|
236
|
+
.filter((a) => !a.passed)
|
|
237
|
+
.map((a) => a.message)
|
|
238
|
+
.join('; ');
|
|
239
|
+
return ` <testcase classname="${classAttr}" name="${nameAttr}" time="${secs}">\n <failure message="${xmlEsc(failureMsg)}" />\n </testcase>`;
|
|
240
|
+
})
|
|
241
|
+
.join('\n');
|
|
242
|
+
return [
|
|
243
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
244
|
+
`<testsuites tests="${report.totalRequests}" failures="${report.failedRequests}" time="${(report.totalDurationMs / 1000).toFixed(3)}">`,
|
|
245
|
+
` <testsuite name="${xmlEsc(report.collectionName)}" tests="${report.totalRequests}" failures="${report.failedRequests}" timestamp="${xmlEsc(report.startedAt)}">`,
|
|
246
|
+
cases,
|
|
247
|
+
' </testsuite>',
|
|
248
|
+
'</testsuites>',
|
|
249
|
+
].join('\n');
|
|
250
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface SecretRule {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
severity: 'critical' | 'high' | 'medium';
|
|
5
|
+
pattern: string;
|
|
6
|
+
flags?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SecretFinding {
|
|
9
|
+
ruleId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
severity: 'critical' | 'high' | 'medium';
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
masked: string;
|
|
17
|
+
entropy: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SecretScanResult {
|
|
20
|
+
clean: boolean;
|
|
21
|
+
totalFindings: number;
|
|
22
|
+
summary: {
|
|
23
|
+
critical: number;
|
|
24
|
+
high: number;
|
|
25
|
+
medium: number;
|
|
26
|
+
};
|
|
27
|
+
findings: SecretFinding[];
|
|
28
|
+
redactedText: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const SECRET_RULES: SecretRule[];
|
|
31
|
+
export declare function calculateShannonEntropy(value: string): number;
|
|
32
|
+
export declare function scanSecrets(input: string, options?: {
|
|
33
|
+
checkHighEntropy?: boolean;
|
|
34
|
+
entropyThreshold?: number;
|
|
35
|
+
}): SecretScanResult;
|
|
36
|
+
export interface EnvValidationIssue {
|
|
37
|
+
line: number;
|
|
38
|
+
key?: string;
|
|
39
|
+
severity: 'error' | 'warning' | 'info';
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export interface EnvAnalysisResult {
|
|
43
|
+
keys: string[];
|
|
44
|
+
valuesCount: number;
|
|
45
|
+
issues: EnvValidationIssue[];
|
|
46
|
+
missingFromTarget: string[];
|
|
47
|
+
extraInTarget: string[];
|
|
48
|
+
secretFindingsCount: number;
|
|
49
|
+
}
|
|
50
|
+
export declare function analyzeEnvFile(envContent: string, exampleContent?: string): EnvAnalysisResult;
|
|
51
|
+
export interface DirectorySecretFinding extends SecretFinding {
|
|
52
|
+
file: string;
|
|
53
|
+
}
|
|
54
|
+
export interface DirectoryScanResult {
|
|
55
|
+
rootDir: string;
|
|
56
|
+
scannedFiles: number;
|
|
57
|
+
skippedFiles: number;
|
|
58
|
+
clean: boolean;
|
|
59
|
+
totalFindings: number;
|
|
60
|
+
summary: {
|
|
61
|
+
critical: number;
|
|
62
|
+
high: number;
|
|
63
|
+
medium: number;
|
|
64
|
+
};
|
|
65
|
+
findings: DirectorySecretFinding[];
|
|
66
|
+
}
|
|
67
|
+
export declare function scanDirectory(targetDir: string, options?: {
|
|
68
|
+
maxFiles?: number;
|
|
69
|
+
maxFileBytes?: number;
|
|
70
|
+
checkHighEntropy?: boolean;
|
|
71
|
+
respectGitignore?: boolean;
|
|
72
|
+
}): DirectoryScanResult;
|
|
73
|
+
/**
|
|
74
|
+
* Scans ONLY files currently staged in the Git index (`git diff --cached`),
|
|
75
|
+
* reading each staged blob directly via `git show :<file>` so unstaged working-tree edits
|
|
76
|
+
* never cause false alarms in pre-commit hooks. Honors `.devanvilignore` and inline `devanvil-ignore`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function scanGitStaged(targetDir?: string, options?: {
|
|
79
|
+
maxFileBytes?: number;
|
|
80
|
+
checkHighEntropy?: boolean;
|
|
81
|
+
}): DirectoryScanResult;
|
|
82
|
+
/**
|
|
83
|
+
* Formats directory or single-file secret scan findings into valid SARIF 2.1.0 JSON
|
|
84
|
+
* for direct upload to GitHub Code Scanning (`github/codeql-action/upload-sarif`).
|
|
85
|
+
* Raw secrets are NEVER written into SARIF — only masked fingerprints.
|
|
86
|
+
*/
|
|
87
|
+
export declare function formatSecretsAsSarif(findings: DirectorySecretFinding[], toolVersion?: string): Record<string, unknown>;
|