@dataparade/cli 0.0.9 → 0.0.10
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/README.md +1 -1
- package/dist/package.json +1 -1
- package/dist/src/ai-enrichment/lambda-init-error.d.ts +5 -0
- package/dist/src/ai-enrichment/lambda-init-error.js +38 -0
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +5 -0
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +27 -1
- package/dist/src/analyzers/cpp/cpp-detection-config.d.ts +73 -0
- package/dist/src/analyzers/cpp/cpp-detection-config.js +137 -0
- package/dist/src/analyzers/cpp/dependency-manifests.d.ts +8 -0
- package/dist/src/analyzers/cpp/dependency-manifests.js +130 -0
- package/dist/src/analyzers/cpp/detector.d.ts +3 -0
- package/dist/src/analyzers/cpp/detector.js +21 -0
- package/dist/src/analyzers/cpp/index.d.ts +2 -0
- package/dist/src/analyzers/cpp/index.js +11 -0
- package/dist/src/analyzers/cpp/manifest-parsers.d.ts +13 -0
- package/dist/src/analyzers/cpp/manifest-parsers.js +104 -0
- package/dist/src/analyzers/cpp/parser.d.ts +35 -0
- package/dist/src/analyzers/cpp/parser.js +206 -0
- package/dist/src/analyzers/cpp/patterns.d.ts +3 -0
- package/dist/src/analyzers/cpp/patterns.js +37 -0
- package/dist/src/analyzers/csharp/csharp-detection-config.d.ts +100 -0
- package/dist/src/analyzers/csharp/csharp-detection-config.js +160 -0
- package/dist/src/analyzers/csharp/dependency-manifests.d.ts +13 -0
- package/dist/src/analyzers/csharp/dependency-manifests.js +184 -0
- package/dist/src/analyzers/csharp/detector.d.ts +3 -0
- package/dist/src/analyzers/csharp/detector.js +21 -0
- package/dist/src/analyzers/csharp/index.d.ts +2 -0
- package/dist/src/analyzers/csharp/index.js +11 -0
- package/dist/src/analyzers/csharp/manifest-parsers.d.ts +34 -0
- package/dist/src/analyzers/csharp/manifest-parsers.js +130 -0
- package/dist/src/analyzers/csharp/parser.d.ts +48 -0
- package/dist/src/analyzers/csharp/parser.js +277 -0
- package/dist/src/analyzers/csharp/patterns.d.ts +3 -0
- package/dist/src/analyzers/csharp/patterns.js +57 -0
- package/dist/src/analyzers/go/dependency-manifests.d.ts +10 -0
- package/dist/src/analyzers/go/dependency-manifests.js +117 -0
- package/dist/src/analyzers/go/detector.d.ts +3 -0
- package/dist/src/analyzers/go/detector.js +21 -0
- package/dist/src/analyzers/go/go-detection-config.d.ts +97 -0
- package/dist/src/analyzers/go/go-detection-config.js +164 -0
- package/dist/src/analyzers/go/index.d.ts +2 -0
- package/dist/src/analyzers/go/index.js +11 -0
- package/dist/src/analyzers/go/manifest-parsers.d.ts +20 -0
- package/dist/src/analyzers/go/manifest-parsers.js +104 -0
- package/dist/src/analyzers/go/parser.d.ts +40 -0
- package/dist/src/analyzers/go/parser.js +186 -0
- package/dist/src/analyzers/go/patterns.d.ts +3 -0
- package/dist/src/analyzers/go/patterns.js +50 -0
- package/dist/src/analyzers/jvm/dependency-manifests.d.ts +16 -0
- package/dist/src/analyzers/jvm/dependency-manifests.js +205 -0
- package/dist/src/analyzers/jvm/detector.d.ts +3 -0
- package/dist/src/analyzers/jvm/detector.js +21 -0
- package/dist/src/analyzers/jvm/index.d.ts +9 -0
- package/dist/src/analyzers/jvm/index.js +18 -0
- package/dist/src/analyzers/jvm/jvm-detection-config.d.ts +136 -0
- package/dist/src/analyzers/jvm/jvm-detection-config.js +195 -0
- package/dist/src/analyzers/jvm/manifest-parsers.d.ts +61 -0
- package/dist/src/analyzers/jvm/manifest-parsers.js +246 -0
- package/dist/src/analyzers/jvm/parser.d.ts +54 -0
- package/dist/src/analyzers/jvm/parser.js +419 -0
- package/dist/src/analyzers/jvm/patterns.d.ts +3 -0
- package/dist/src/analyzers/jvm/patterns.js +64 -0
- package/dist/src/analyzers/python/detector.js +1 -1
- package/dist/src/analyzers/python/parser.d.ts +1 -0
- package/dist/src/analyzers/python/parser.js +7 -0
- package/dist/src/analyzers/python/patterns.d.ts +1 -0
- package/dist/src/analyzers/python/patterns.js +22 -77
- package/dist/src/analyzers/python/python-detection-config.d.ts +18 -0
- package/dist/src/analyzers/python/python-detection-config.js +20 -0
- package/dist/src/analyzers/registry.js +15 -0
- package/dist/src/analyzers/shared/c-family-calls.d.ts +26 -0
- package/dist/src/analyzers/shared/c-family-calls.js +118 -0
- package/dist/src/analyzers/shared/strip-comments.d.ts +32 -0
- package/dist/src/analyzers/shared/strip-comments.js +167 -0
- package/dist/src/analyzers/typescript/detector.js +1 -1
- package/dist/src/analyzers/typescript/typescript-detection-config.d.ts +37 -0
- package/dist/src/analyzers/typescript/typescript-detection-config.js +48 -0
- package/dist/src/analyzers/typescript/typescript-detection.d.ts +1 -0
- package/dist/src/analyzers/typescript/typescript-detection.js +27 -29
- package/dist/src/cli.js +1 -1
- package/dist/src/config/file.js +5 -0
- package/dist/src/config/resolve.js +5 -0
- package/dist/src/core/pipeline/graph-mapping.js +3 -0
- package/dist/src/core/pipeline/structural-scan.js +154 -31
- package/dist/src/core/schema/scan-config.schema.d.ts +5 -0
- package/dist/src/core/schema/scan-config.schema.js +5 -0
- package/dist/src/core/schema/scan-result.schema.d.ts +5 -0
- package/dist/src/core/schema/scan-result.schema.js +5 -0
- package/dist/src/core/sectioning/discover-service-sections.js +27 -1
- package/dist/src/core/types/file.d.ts +1 -1
- package/dist/src/ingest/file-system.js +27 -0
- package/dist/src/patterns/config.d.ts +8 -0
- package/dist/src/patterns/config.js +136 -0
- package/dist/src/patterns/detectors/cpp.d.ts +8 -0
- package/dist/src/patterns/detectors/cpp.js +243 -0
- package/dist/src/patterns/detectors/csharp.d.ts +9 -0
- package/dist/src/patterns/detectors/csharp.js +385 -0
- package/dist/src/patterns/detectors/go.d.ts +9 -0
- package/dist/src/patterns/detectors/go.js +298 -0
- package/dist/src/patterns/detectors/helpers.d.ts +3 -0
- package/dist/src/patterns/detectors/helpers.js +5 -0
- package/dist/src/patterns/detectors/jvm.d.ts +15 -0
- package/dist/src/patterns/detectors/jvm.js +537 -0
- package/dist/src/patterns/detectors/python.d.ts +1 -0
- package/dist/src/patterns/detectors/python.js +92 -5
- package/dist/src/patterns/detectors/typescript.d.ts +2 -0
- package/dist/src/patterns/detectors/typescript.js +156 -4
- package/dist/src/patterns/engine.d.ts +18 -0
- package/dist/src/patterns/engine.js +30 -0
- package/dist/src/patterns/scan-exclusions.js +20 -0
- package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
- package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
- package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
- package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
- package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
- package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
- package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
- package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
- package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
- package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
- package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
- package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
- package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
- package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
- package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
- package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
- package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
- package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
- package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
- package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/go-scan.spec.js +78 -0
- package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
- package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
- package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
- package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
- package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
- package/package.json +1 -1
- package/patterns/cpp.md +176 -0
- package/patterns/cpp.patterns.yaml +314 -0
- package/patterns/csharp.md +211 -0
- package/patterns/csharp.patterns.yaml +375 -0
- package/patterns/go.md +211 -0
- package/patterns/go.patterns.yaml +429 -0
- package/patterns/jvm.md +160 -0
- package/patterns/jvm.patterns.yaml +884 -0
- package/patterns/python.patterns.yaml +177 -0
- package/patterns/third-party.patterns.yaml +5 -0
- package/patterns/typescript.patterns.yaml +222 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const parser_1 = require("../../../../src/analyzers/jvm/parser");
|
|
4
|
+
function createJavaFile(content, path = "Service.java") {
|
|
5
|
+
return { path, name: path, content, language: "java", size: content.length };
|
|
6
|
+
}
|
|
7
|
+
function createKotlinFile(content, path = "Service.kt") {
|
|
8
|
+
return { path, name: path, content, language: "kotlin", size: content.length };
|
|
9
|
+
}
|
|
10
|
+
describe("JVM parser - Java", () => {
|
|
11
|
+
it("indexes package, imports, annotated types, and methods", () => {
|
|
12
|
+
const content = [
|
|
13
|
+
"package com.acme.billing.web;",
|
|
14
|
+
"",
|
|
15
|
+
"import java.util.List;",
|
|
16
|
+
"import static org.junit.Assert.assertEquals;",
|
|
17
|
+
"import org.springframework.web.bind.annotation.*;",
|
|
18
|
+
"",
|
|
19
|
+
"@RestController",
|
|
20
|
+
'@RequestMapping("/api/customers")',
|
|
21
|
+
"public class CustomersController extends BaseController implements Auditable {",
|
|
22
|
+
"",
|
|
23
|
+
' @GetMapping("/{id}")',
|
|
24
|
+
" public Customer byId(@PathVariable Long id) {",
|
|
25
|
+
" return repository.findById(id);",
|
|
26
|
+
" }",
|
|
27
|
+
"}",
|
|
28
|
+
"",
|
|
29
|
+
].join("\n");
|
|
30
|
+
const result = (0, parser_1.parseJvmSourceFile)(createJavaFile(content));
|
|
31
|
+
expect(result.warnings).toEqual([]);
|
|
32
|
+
expect(result.packageName).toBe("com.acme.billing.web");
|
|
33
|
+
expect(result.isKotlin).toBe(false);
|
|
34
|
+
expect(result.imports.map((i) => i.qualifiedName)).toEqual([
|
|
35
|
+
"java.util.List",
|
|
36
|
+
"org.junit.Assert.assertEquals",
|
|
37
|
+
"org.springframework.web.bind.annotation",
|
|
38
|
+
]);
|
|
39
|
+
expect(result.imports[1].isStatic).toBe(true);
|
|
40
|
+
expect(result.imports[2].isWildcard).toBe(true);
|
|
41
|
+
expect(result.types).toHaveLength(1);
|
|
42
|
+
const type = result.types[0];
|
|
43
|
+
expect(type.name).toBe("CustomersController");
|
|
44
|
+
expect(type.kind).toBe("class");
|
|
45
|
+
expect(type.baseTypes).toEqual(["BaseController", "Auditable"]);
|
|
46
|
+
expect(type.annotations.map((a) => a.name).sort()).toEqual([
|
|
47
|
+
"RequestMapping",
|
|
48
|
+
"RestController",
|
|
49
|
+
]);
|
|
50
|
+
expect(type.annotations.find((a) => a.name === "RequestMapping")?.argumentsSnippet).toBe('"/api/customers"');
|
|
51
|
+
expect(result.methods.map((m) => m.name)).toEqual(["byId"]);
|
|
52
|
+
expect(result.methods[0].declaringType).toBe("CustomersController");
|
|
53
|
+
expect(result.methods[0].annotations[0].raw).toBe('GetMapping("/{id}")');
|
|
54
|
+
});
|
|
55
|
+
it("carries an annotation whose arguments wrap across lines", () => {
|
|
56
|
+
const content = [
|
|
57
|
+
"package com.acme;",
|
|
58
|
+
"",
|
|
59
|
+
"import org.springframework.web.bind.annotation.RequestMapping;",
|
|
60
|
+
"",
|
|
61
|
+
"public class Api {",
|
|
62
|
+
" @RequestMapping(",
|
|
63
|
+
' value = "/{id}",',
|
|
64
|
+
" method = RequestMethod.DELETE)",
|
|
65
|
+
" public void remove(Long id) {",
|
|
66
|
+
" }",
|
|
67
|
+
"}",
|
|
68
|
+
"",
|
|
69
|
+
].join("\n");
|
|
70
|
+
const result = (0, parser_1.parseJvmSourceFile)(createJavaFile(content));
|
|
71
|
+
expect(result.methods.map((m) => m.name)).toEqual(["remove"]);
|
|
72
|
+
const annotation = result.methods[0].annotations[0];
|
|
73
|
+
expect(annotation.name).toBe("RequestMapping");
|
|
74
|
+
expect(annotation.argumentsSnippet).toContain('value = "/{id}"');
|
|
75
|
+
expect(annotation.argumentsSnippet).toContain("RequestMethod.DELETE");
|
|
76
|
+
});
|
|
77
|
+
it("does not read statements or field initializers as method declarations", () => {
|
|
78
|
+
const content = [
|
|
79
|
+
"package com.acme;",
|
|
80
|
+
"",
|
|
81
|
+
"public class Api {",
|
|
82
|
+
" private final RestTemplate restTemplate = new RestTemplate();",
|
|
83
|
+
"",
|
|
84
|
+
" void handle() {",
|
|
85
|
+
" return compute(1);",
|
|
86
|
+
" }",
|
|
87
|
+
"}",
|
|
88
|
+
"",
|
|
89
|
+
].join("\n");
|
|
90
|
+
const result = (0, parser_1.parseJvmSourceFile)(createJavaFile(content));
|
|
91
|
+
// `handle` is package-private with no modifier; `restTemplate` is a field
|
|
92
|
+
// and `return compute(...)` is a statement.
|
|
93
|
+
expect(result.methods.map((m) => m.name)).toEqual(["handle"]);
|
|
94
|
+
});
|
|
95
|
+
it("keeps URLs inside comments out of the stripped source", () => {
|
|
96
|
+
const content = [
|
|
97
|
+
"package com.acme;",
|
|
98
|
+
"",
|
|
99
|
+
"public class Api {",
|
|
100
|
+
" // see https://internal.example.com/runbook",
|
|
101
|
+
' String live = "https://api.stripe.com/v1/charges";',
|
|
102
|
+
"}",
|
|
103
|
+
"",
|
|
104
|
+
].join("\n");
|
|
105
|
+
const result = (0, parser_1.parseJvmSourceFile)(createJavaFile(content));
|
|
106
|
+
expect(result.strippedContent).not.toContain("internal.example.com");
|
|
107
|
+
expect(result.strippedContent).toContain("api.stripe.com");
|
|
108
|
+
// Comments are blanked, not removed, so line numbers stay accurate.
|
|
109
|
+
expect(result.strippedContent.split("\n")).toHaveLength(content.split("\n").length);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("JVM parser - Kotlin", () => {
|
|
113
|
+
it("indexes Kotlin declarations, supertypes, and aliased imports", () => {
|
|
114
|
+
const content = [
|
|
115
|
+
"package com.acme.ledger",
|
|
116
|
+
"",
|
|
117
|
+
"import io.ktor.server.routing.get",
|
|
118
|
+
"import org.jetbrains.exposed.sql.Database as Db",
|
|
119
|
+
"",
|
|
120
|
+
"@Serializable",
|
|
121
|
+
"data class Invoice(val id: Long) : Auditable, Comparable<Invoice> {",
|
|
122
|
+
" fun total(): Long = id",
|
|
123
|
+
"}",
|
|
124
|
+
"",
|
|
125
|
+
"suspend fun fetchRates(client: HttpClient): String {",
|
|
126
|
+
' return client.get("https://api.exchangerate.host/latest")',
|
|
127
|
+
"}",
|
|
128
|
+
"",
|
|
129
|
+
].join("\n");
|
|
130
|
+
const result = (0, parser_1.parseJvmSourceFile)(createKotlinFile(content));
|
|
131
|
+
expect(result.warnings).toEqual([]);
|
|
132
|
+
expect(result.isKotlin).toBe(true);
|
|
133
|
+
expect(result.packageName).toBe("com.acme.ledger");
|
|
134
|
+
const aliased = result.imports.find((i) => i.qualifiedName === "org.jetbrains.exposed.sql.Database");
|
|
135
|
+
expect(aliased?.alias).toBe("Db");
|
|
136
|
+
expect(result.types.map((t) => t.name)).toEqual(["Invoice"]);
|
|
137
|
+
// The primary constructor's parameters must not be read as supertypes.
|
|
138
|
+
expect(result.types[0].baseTypes).toEqual(["Auditable", "Comparable"]);
|
|
139
|
+
expect(result.types[0].annotations.map((a) => a.name)).toEqual([
|
|
140
|
+
"Serializable",
|
|
141
|
+
]);
|
|
142
|
+
expect(result.methods.map((m) => m.name).sort()).toEqual([
|
|
143
|
+
"fetchRates",
|
|
144
|
+
"total",
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
it("drops Kotlin use-site annotation targets", () => {
|
|
148
|
+
const content = [
|
|
149
|
+
"package com.acme",
|
|
150
|
+
"",
|
|
151
|
+
"class Config {",
|
|
152
|
+
" @field:Value(\"\\${db.url}\")",
|
|
153
|
+
" lateinit var dbUrl: String",
|
|
154
|
+
"",
|
|
155
|
+
" @get:Secured",
|
|
156
|
+
" fun secret(): String = \"x\"",
|
|
157
|
+
"}",
|
|
158
|
+
"",
|
|
159
|
+
].join("\n");
|
|
160
|
+
const result = (0, parser_1.parseJvmSourceFile)(createKotlinFile(content));
|
|
161
|
+
const secret = result.methods.find((m) => m.name === "secret");
|
|
162
|
+
expect(secret?.annotations.map((a) => a.name)).toEqual(["Secured"]);
|
|
163
|
+
});
|
|
164
|
+
it("handles nested block comments and raw strings", () => {
|
|
165
|
+
const content = [
|
|
166
|
+
"package com.acme",
|
|
167
|
+
"",
|
|
168
|
+
"/* outer /* inner */ still comment */",
|
|
169
|
+
"val query = \"\"\"",
|
|
170
|
+
" SELECT * FROM customers",
|
|
171
|
+
"\"\"\"",
|
|
172
|
+
'val url = "https://api.stripe.com/v1"',
|
|
173
|
+
"",
|
|
174
|
+
].join("\n");
|
|
175
|
+
const result = (0, parser_1.parseJvmSourceFile)(createKotlinFile(content));
|
|
176
|
+
expect(result.strippedContent).not.toContain("still comment");
|
|
177
|
+
expect(result.strippedContent).toContain("api.stripe.com");
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe("JVM parser - guards", () => {
|
|
181
|
+
it("warns and returns an empty model for a non-JVM language", () => {
|
|
182
|
+
const file = {
|
|
183
|
+
path: "main.go",
|
|
184
|
+
name: "main.go",
|
|
185
|
+
content: "package main",
|
|
186
|
+
language: "go",
|
|
187
|
+
size: 12,
|
|
188
|
+
};
|
|
189
|
+
const result = (0, parser_1.parseJvmSourceFile)(file);
|
|
190
|
+
expect(result.warnings).toHaveLength(1);
|
|
191
|
+
expect(result.warnings[0]).toContain("Unsupported language 'go'");
|
|
192
|
+
expect(result.types).toEqual([]);
|
|
193
|
+
expect(result.methods).toEqual([]);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const detector_1 = require("../../../../src/analyzers/jvm/detector");
|
|
4
|
+
function makeJavaFile(content, path = "Api.java") {
|
|
5
|
+
return { path, name: path, content, language: "java", size: content.length };
|
|
6
|
+
}
|
|
7
|
+
function makeKotlinFile(content, path = "Api.kt") {
|
|
8
|
+
return { path, name: path, content, language: "kotlin", size: content.length };
|
|
9
|
+
}
|
|
10
|
+
describe("JVM analyzer - Spring routes", () => {
|
|
11
|
+
it("composes the class-level template with the method-level mapping", () => {
|
|
12
|
+
const content = [
|
|
13
|
+
"package com.acme;",
|
|
14
|
+
"",
|
|
15
|
+
"import org.springframework.web.bind.annotation.GetMapping;",
|
|
16
|
+
"import org.springframework.web.bind.annotation.PostMapping;",
|
|
17
|
+
"import org.springframework.web.bind.annotation.RequestMapping;",
|
|
18
|
+
"import org.springframework.web.bind.annotation.RestController;",
|
|
19
|
+
"",
|
|
20
|
+
"@RestController",
|
|
21
|
+
'@RequestMapping("/api/customers")',
|
|
22
|
+
"public class CustomersController {",
|
|
23
|
+
' @GetMapping("/{id}")',
|
|
24
|
+
" public Customer byId(Long id) { return null; }",
|
|
25
|
+
"",
|
|
26
|
+
" @PostMapping",
|
|
27
|
+
" public Customer create(Customer c) { return c; }",
|
|
28
|
+
"}",
|
|
29
|
+
"",
|
|
30
|
+
].join("\n");
|
|
31
|
+
const routes = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "CustomersController.java")).filter((f) => f.pattern === "express_route");
|
|
32
|
+
expect(routes.map((r) => r.name).sort()).toEqual([
|
|
33
|
+
"GET /api/customers/{id}",
|
|
34
|
+
"POST /api/customers",
|
|
35
|
+
]);
|
|
36
|
+
expect(routes[0].properties.framework).toBe("spring_mvc");
|
|
37
|
+
expect(routes[0].properties.controller).toBe("CustomersController");
|
|
38
|
+
});
|
|
39
|
+
it("reads the verb from a method-level @RequestMapping argument", () => {
|
|
40
|
+
const content = [
|
|
41
|
+
"package com.acme;",
|
|
42
|
+
"",
|
|
43
|
+
"import org.springframework.web.bind.annotation.RequestMapping;",
|
|
44
|
+
"import org.springframework.web.bind.annotation.RestController;",
|
|
45
|
+
"",
|
|
46
|
+
"@RestController",
|
|
47
|
+
'@RequestMapping("/api/customers")',
|
|
48
|
+
"public class CustomersController {",
|
|
49
|
+
' @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)',
|
|
50
|
+
" public void remove(Long id) {}",
|
|
51
|
+
"}",
|
|
52
|
+
"",
|
|
53
|
+
].join("\n");
|
|
54
|
+
const routes = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "CustomersController.java")).filter((f) => f.pattern === "express_route");
|
|
55
|
+
expect(routes.map((r) => r.name)).toEqual(["DELETE /api/customers/{id}"]);
|
|
56
|
+
expect(routes[0].properties.httpMethods).toEqual(["DELETE"]);
|
|
57
|
+
});
|
|
58
|
+
it("combines a JAX-RS verb annotation with its sibling @Path", () => {
|
|
59
|
+
const content = [
|
|
60
|
+
"package com.acme;",
|
|
61
|
+
"",
|
|
62
|
+
"import jakarta.ws.rs.GET;",
|
|
63
|
+
"import jakarta.ws.rs.Path;",
|
|
64
|
+
"",
|
|
65
|
+
'@Path("/customers")',
|
|
66
|
+
"public class CustomerResource {",
|
|
67
|
+
" @GET",
|
|
68
|
+
' @Path("/{id}")',
|
|
69
|
+
" public Customer byId(Long id) { return null; }",
|
|
70
|
+
"}",
|
|
71
|
+
"",
|
|
72
|
+
].join("\n");
|
|
73
|
+
const routes = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "CustomerResource.java")).filter((f) => f.pattern === "express_route");
|
|
74
|
+
expect(routes.map((r) => r.name)).toEqual(["GET /customers/{id}"]);
|
|
75
|
+
expect(routes[0].properties.framework).toBe("jaxrs");
|
|
76
|
+
});
|
|
77
|
+
it("detects Ktor routing DSL registrations", () => {
|
|
78
|
+
const content = [
|
|
79
|
+
"package com.acme",
|
|
80
|
+
"",
|
|
81
|
+
"import io.ktor.server.routing.get",
|
|
82
|
+
"import io.ktor.server.routing.routing",
|
|
83
|
+
"",
|
|
84
|
+
"fun Application.routes() {",
|
|
85
|
+
" routing {",
|
|
86
|
+
' get("/health") { call.respondText("ok") }',
|
|
87
|
+
' post("/api/invoices") { call.respondText("created") }',
|
|
88
|
+
" }",
|
|
89
|
+
"}",
|
|
90
|
+
"",
|
|
91
|
+
].join("\n");
|
|
92
|
+
const routes = (0, detector_1.detectJvmPatterns)(makeKotlinFile(content)).filter((f) => f.pattern === "express_route");
|
|
93
|
+
expect(routes.map((r) => r.name).sort()).toEqual([
|
|
94
|
+
"GET /health",
|
|
95
|
+
"POST /api/invoices",
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe("JVM analyzer - databases", () => {
|
|
100
|
+
it("resolves the engine from a JDBC URL sub-protocol", () => {
|
|
101
|
+
const content = [
|
|
102
|
+
"package com.acme;",
|
|
103
|
+
"",
|
|
104
|
+
"import com.zaxxer.hikari.HikariConfig;",
|
|
105
|
+
"",
|
|
106
|
+
"public class Db {",
|
|
107
|
+
" void configure(HikariConfig config) {",
|
|
108
|
+
' config.setJdbcUrl("jdbc:postgresql://db.internal:5432/billing");',
|
|
109
|
+
" }",
|
|
110
|
+
"}",
|
|
111
|
+
"",
|
|
112
|
+
].join("\n");
|
|
113
|
+
const databases = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Db.java")).filter((f) => f.pattern === "database_connection");
|
|
114
|
+
const jdbc = databases.find((f) => f.name === "jdbc:postgresql");
|
|
115
|
+
expect(jdbc).toBeDefined();
|
|
116
|
+
expect(jdbc?.properties.databaseType).toBe("postgres");
|
|
117
|
+
expect(databases.map((f) => f.name)).toContain("hikaricp");
|
|
118
|
+
});
|
|
119
|
+
it("degrades an unknown JDBC driver rather than dropping it", () => {
|
|
120
|
+
const content = [
|
|
121
|
+
"package com.acme;",
|
|
122
|
+
"",
|
|
123
|
+
"public class Db {",
|
|
124
|
+
' String url = "jdbc:acmedb://host/db";',
|
|
125
|
+
"}",
|
|
126
|
+
"",
|
|
127
|
+
].join("\n");
|
|
128
|
+
const jdbc = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Db.java")).find((f) => f.name === "jdbc:acmedb");
|
|
129
|
+
expect(jdbc?.properties.databaseType).toBe("sql");
|
|
130
|
+
expect(jdbc?.properties.driver).toBe("acmedb");
|
|
131
|
+
});
|
|
132
|
+
it("detects Spring Data JPA from a persistence annotation", () => {
|
|
133
|
+
const content = [
|
|
134
|
+
"package com.acme;",
|
|
135
|
+
"",
|
|
136
|
+
"import jakarta.persistence.Entity;",
|
|
137
|
+
"",
|
|
138
|
+
"@Entity",
|
|
139
|
+
"public class Customer {",
|
|
140
|
+
"}",
|
|
141
|
+
"",
|
|
142
|
+
].join("\n");
|
|
143
|
+
const databases = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Customer.java")).filter((f) => f.pattern === "database_connection");
|
|
144
|
+
expect(databases.map((f) => f.name)).toContain("spring_data_jpa");
|
|
145
|
+
});
|
|
146
|
+
it("detects Exposed from Database.connect in Kotlin", () => {
|
|
147
|
+
const content = [
|
|
148
|
+
"package com.acme",
|
|
149
|
+
"",
|
|
150
|
+
"import org.jetbrains.exposed.sql.Database",
|
|
151
|
+
"",
|
|
152
|
+
"fun init() {",
|
|
153
|
+
' Database.connect("jdbc:postgresql://db/ledger", driver = "org.postgresql.Driver")',
|
|
154
|
+
"}",
|
|
155
|
+
"",
|
|
156
|
+
].join("\n");
|
|
157
|
+
const databases = (0, detector_1.detectJvmPatterns)(makeKotlinFile(content)).filter((f) => f.pattern === "database_connection");
|
|
158
|
+
expect(databases.map((f) => f.name)).toContain("exposed");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe("JVM analyzer - external API calls", () => {
|
|
162
|
+
it("attributes a RestTemplate call to its catalogued service", () => {
|
|
163
|
+
const content = [
|
|
164
|
+
"package com.acme;",
|
|
165
|
+
"",
|
|
166
|
+
"import org.springframework.web.client.RestTemplate;",
|
|
167
|
+
"",
|
|
168
|
+
"public class Charges {",
|
|
169
|
+
" void charge(RestTemplate restTemplate) {",
|
|
170
|
+
' restTemplate.postForObject("https://api.stripe.com/v1/charges", null, String.class);',
|
|
171
|
+
" }",
|
|
172
|
+
"}",
|
|
173
|
+
"",
|
|
174
|
+
].join("\n");
|
|
175
|
+
const calls = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Charges.java")).filter((f) => f.pattern === "external_api_call" && f.properties.url);
|
|
176
|
+
expect(calls).toHaveLength(1);
|
|
177
|
+
expect(calls[0].properties.url).toBe("https://api.stripe.com/v1/charges");
|
|
178
|
+
expect(calls[0].properties.serviceName).toBe("stripe");
|
|
179
|
+
});
|
|
180
|
+
it("does not read a Ktor server route as a Ktor client call", () => {
|
|
181
|
+
const content = [
|
|
182
|
+
"package com.acme",
|
|
183
|
+
"",
|
|
184
|
+
"import io.ktor.client.HttpClient",
|
|
185
|
+
"import io.ktor.server.routing.get",
|
|
186
|
+
"import io.ktor.server.routing.routing",
|
|
187
|
+
"",
|
|
188
|
+
"fun Application.routes() {",
|
|
189
|
+
" routing {",
|
|
190
|
+
' get("/health") { call.respondText("ok") }',
|
|
191
|
+
" }",
|
|
192
|
+
"}",
|
|
193
|
+
"",
|
|
194
|
+
"suspend fun rates(client: HttpClient): String {",
|
|
195
|
+
' return client.get("https://api.exchangerate.host/latest").bodyAsText()',
|
|
196
|
+
"}",
|
|
197
|
+
"",
|
|
198
|
+
].join("\n");
|
|
199
|
+
const findings = (0, detector_1.detectJvmPatterns)(makeKotlinFile(content));
|
|
200
|
+
const clientCalls = findings.filter((f) => f.pattern === "external_api_call" && f.name === "ktor_client_call");
|
|
201
|
+
expect(clientCalls).toHaveLength(1);
|
|
202
|
+
expect(clientCalls[0].properties.url).toBe("https://api.exchangerate.host/latest");
|
|
203
|
+
// The `/health` registration is a route, and only a route.
|
|
204
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
205
|
+
expect(routes.map((r) => r.name)).toContain("GET /health");
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe("JVM analyzer - auth, env, and serverless", () => {
|
|
209
|
+
it("detects Spring method security from an annotation", () => {
|
|
210
|
+
const content = [
|
|
211
|
+
"package com.acme;",
|
|
212
|
+
"",
|
|
213
|
+
"import org.springframework.security.access.prepost.PreAuthorize;",
|
|
214
|
+
"",
|
|
215
|
+
"public class Admin {",
|
|
216
|
+
" @PreAuthorize(\"hasRole('ADMIN')\")",
|
|
217
|
+
" public void purge() {}",
|
|
218
|
+
"}",
|
|
219
|
+
"",
|
|
220
|
+
].join("\n");
|
|
221
|
+
const auth = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Admin.java")).filter((f) => f.pattern === "auth_middleware");
|
|
222
|
+
const methodSecurity = auth.find((f) => f.name === "spring_method_security");
|
|
223
|
+
expect(methodSecurity).toBeDefined();
|
|
224
|
+
expect(methodSecurity?.properties.policy).toBe("hasRole('ADMIN')");
|
|
225
|
+
});
|
|
226
|
+
it("extracts env keys and Spring property placeholders", () => {
|
|
227
|
+
const content = [
|
|
228
|
+
"package com.acme;",
|
|
229
|
+
"",
|
|
230
|
+
"import org.springframework.beans.factory.annotation.Value;",
|
|
231
|
+
"",
|
|
232
|
+
"public class Settings {",
|
|
233
|
+
' @Value("${billing.rates.url}")',
|
|
234
|
+
" private String ratesUrl;",
|
|
235
|
+
"",
|
|
236
|
+
" String key() {",
|
|
237
|
+
' return System.getenv("BILLING_API_KEY");',
|
|
238
|
+
" }",
|
|
239
|
+
"}",
|
|
240
|
+
"",
|
|
241
|
+
].join("\n");
|
|
242
|
+
const findings = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Settings.java"));
|
|
243
|
+
const env = findings.find((f) => f.pattern === "env_variable");
|
|
244
|
+
expect(env?.properties.key).toBe("BILLING_API_KEY");
|
|
245
|
+
const property = findings.find((f) => f.pattern === "config_file" && f.name === "property(billing.rates.url)");
|
|
246
|
+
expect(property?.properties.key).toBe("billing.rates.url");
|
|
247
|
+
});
|
|
248
|
+
it("detects an AWS Lambda handler from its implemented interface", () => {
|
|
249
|
+
const content = [
|
|
250
|
+
"package com.acme;",
|
|
251
|
+
"",
|
|
252
|
+
"import com.amazonaws.services.lambda.runtime.Context;",
|
|
253
|
+
"import com.amazonaws.services.lambda.runtime.RequestHandler;",
|
|
254
|
+
"",
|
|
255
|
+
"public class ChargeHandler implements RequestHandler<Event, String> {",
|
|
256
|
+
" public String handleRequest(Event event, Context context) {",
|
|
257
|
+
' return "ok";',
|
|
258
|
+
" }",
|
|
259
|
+
"}",
|
|
260
|
+
"",
|
|
261
|
+
].join("\n");
|
|
262
|
+
const handlers = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "ChargeHandler.java")).filter((f) => f.pattern === "lambda_handler");
|
|
263
|
+
expect(handlers).toHaveLength(1);
|
|
264
|
+
expect(handlers[0].name).toBe("aws_lambda_java ChargeHandler");
|
|
265
|
+
});
|
|
266
|
+
it("detects an Azure Functions handler from @FunctionName", () => {
|
|
267
|
+
const content = [
|
|
268
|
+
"package com.acme;",
|
|
269
|
+
"",
|
|
270
|
+
"import com.microsoft.azure.functions.annotation.FunctionName;",
|
|
271
|
+
"",
|
|
272
|
+
"public class Functions {",
|
|
273
|
+
' @FunctionName("chargeCustomer")',
|
|
274
|
+
" public String run(String payload) {",
|
|
275
|
+
" return payload;",
|
|
276
|
+
" }",
|
|
277
|
+
"}",
|
|
278
|
+
"",
|
|
279
|
+
].join("\n");
|
|
280
|
+
const handlers = (0, detector_1.detectJvmPatterns)(makeJavaFile(content, "Functions.java")).filter((f) => f.pattern === "lambda_handler");
|
|
281
|
+
expect(handlers).toHaveLength(1);
|
|
282
|
+
expect(handlers[0].properties.functionName).toBe("chargeCustomer");
|
|
283
|
+
});
|
|
284
|
+
});
|
|
@@ -286,4 +286,173 @@ describe("Python analyzer patterns - DP-P0-CLI-703", () => {
|
|
|
286
286
|
f.properties.serviceName === expectedServiceName);
|
|
287
287
|
expect(serviceFinding).toBeDefined();
|
|
288
288
|
});
|
|
289
|
+
it("detects AWS Lambda handlers as lambda_handler findings", () => {
|
|
290
|
+
const content = [
|
|
291
|
+
"import boto3",
|
|
292
|
+
"",
|
|
293
|
+
"def lambda_handler(event, context):",
|
|
294
|
+
" return {'statusCode': 200}",
|
|
295
|
+
"",
|
|
296
|
+
].join("\n");
|
|
297
|
+
const file = makePythonFile(content, "handler.py");
|
|
298
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
299
|
+
const handlers = findings.filter((f) => f.pattern === "lambda_handler");
|
|
300
|
+
expect(handlers.length).toBeGreaterThan(0);
|
|
301
|
+
expect(handlers[0].properties.framework).toBe("aws_lambda");
|
|
302
|
+
expect(handlers[0].properties.handler).toBe("lambda_handler");
|
|
303
|
+
expect(handlers[0].properties.handlerType).toBe("serverless_handler");
|
|
304
|
+
});
|
|
305
|
+
it("detects GCP Cloud Functions handlers as lambda_handler findings", () => {
|
|
306
|
+
const content = [
|
|
307
|
+
"import functions_framework",
|
|
308
|
+
"",
|
|
309
|
+
"@functions_framework.http",
|
|
310
|
+
"def hello_http(request):",
|
|
311
|
+
' return "Hello"',
|
|
312
|
+
"",
|
|
313
|
+
].join("\n");
|
|
314
|
+
const file = makePythonFile(content, "main.py");
|
|
315
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
316
|
+
const handlers = findings.filter((f) => f.pattern === "lambda_handler");
|
|
317
|
+
expect(handlers.length).toBeGreaterThan(0);
|
|
318
|
+
expect(handlers[0].properties.framework).toBe("gcp_functions");
|
|
319
|
+
expect(handlers[0].properties.handler).toBe("hello_http");
|
|
320
|
+
expect(handlers[0].properties.handlerType).toBe("serverless_handler");
|
|
321
|
+
});
|
|
322
|
+
it("detects gRPC client channels as external_api_call findings", () => {
|
|
323
|
+
const content = [
|
|
324
|
+
"import grpc",
|
|
325
|
+
"",
|
|
326
|
+
'channel = grpc.insecure_channel("localhost:50051")',
|
|
327
|
+
"",
|
|
328
|
+
].join("\n");
|
|
329
|
+
const file = makePythonFile(content, "grpc_client.py");
|
|
330
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
331
|
+
const apiFindings = findings.filter((f) => f.pattern === "external_api_call");
|
|
332
|
+
expect(apiFindings.length).toBeGreaterThan(0);
|
|
333
|
+
expect(apiFindings.some((f) => f.properties.serviceName === "grpc")).toBe(true);
|
|
334
|
+
});
|
|
335
|
+
it("detects OAuth2 libraries as auth_middleware findings", () => {
|
|
336
|
+
const content = [
|
|
337
|
+
"from authlib.integrations.flask_client import OAuth",
|
|
338
|
+
"",
|
|
339
|
+
"oauth = OAuth()",
|
|
340
|
+
"",
|
|
341
|
+
].join("\n");
|
|
342
|
+
const file = makePythonFile(content, "oauth_app.py");
|
|
343
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
344
|
+
const authFindings = findings.filter((f) => f.pattern === "auth_middleware");
|
|
345
|
+
expect(authFindings.length).toBeGreaterThan(0);
|
|
346
|
+
expect(authFindings.some((f) => f.properties.strategy === "oauth2")).toBe(true);
|
|
347
|
+
});
|
|
348
|
+
it("detects gRPC routes as express_route findings", () => {
|
|
349
|
+
const content = [
|
|
350
|
+
"import grpc",
|
|
351
|
+
"",
|
|
352
|
+
"def serve():",
|
|
353
|
+
" server = grpc.server(None)",
|
|
354
|
+
' server.add_insecure_port("0.0.0.0:50051")',
|
|
355
|
+
"",
|
|
356
|
+
].join("\n");
|
|
357
|
+
const file = makePythonFile(content, "grpc_server.py");
|
|
358
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
359
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
360
|
+
expect(routes.length).toBeGreaterThan(0);
|
|
361
|
+
expect(routes[0].properties.framework).toBe("grpc");
|
|
362
|
+
expect(routes[0].properties.handlerType).toBe("grpc_service");
|
|
363
|
+
});
|
|
364
|
+
it("detects Bearer authorization headers as auth_middleware findings", () => {
|
|
365
|
+
const content = [
|
|
366
|
+
'headers = {"Authorization": "Bearer secret-token"}',
|
|
367
|
+
"",
|
|
368
|
+
].join("\n");
|
|
369
|
+
const file = makePythonFile(content, "auth_headers.py");
|
|
370
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
371
|
+
const authFindings = findings.filter((f) => f.pattern === "auth_middleware");
|
|
372
|
+
expect(authFindings.length).toBeGreaterThan(0);
|
|
373
|
+
expect(authFindings.some((f) => f.properties.strategy === "bearer_token")).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
it("detects pymysql as database_connection with databaseType mysql", () => {
|
|
376
|
+
const content = [
|
|
377
|
+
"import pymysql",
|
|
378
|
+
"",
|
|
379
|
+
"conn = pymysql.connect(host='localhost', user='root', db='mydb')",
|
|
380
|
+
"",
|
|
381
|
+
].join("\n");
|
|
382
|
+
const file = makePythonFile(content, "db_mysql.py");
|
|
383
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
384
|
+
const dbFindings = findings.filter((f) => f.pattern === "database_connection");
|
|
385
|
+
expect(dbFindings.length).toBeGreaterThan(0);
|
|
386
|
+
expect(dbFindings.some((f) => f.properties.databaseType === "mysql")).toBe(true);
|
|
387
|
+
expect(dbFindings.some((f) => f.properties.client === "pymysql")).toBe(true);
|
|
388
|
+
});
|
|
389
|
+
it("detects pymongo/motor as database_connection with databaseType mongodb", () => {
|
|
390
|
+
const content = [
|
|
391
|
+
"from motor.motor_asyncio import AsyncIOMotorClient",
|
|
392
|
+
"",
|
|
393
|
+
"client = AsyncIOMotorClient('mongodb://localhost:27017')",
|
|
394
|
+
"",
|
|
395
|
+
].join("\n");
|
|
396
|
+
const file = makePythonFile(content, "db_motor.py");
|
|
397
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
398
|
+
const dbFindings = findings.filter((f) => f.pattern === "database_connection");
|
|
399
|
+
expect(dbFindings.length).toBeGreaterThan(0);
|
|
400
|
+
expect(dbFindings.some((f) => f.properties.databaseType === "mongodb")).toBe(true);
|
|
401
|
+
});
|
|
402
|
+
it("detects redis-py as database_connection with databaseType redis", () => {
|
|
403
|
+
const content = [
|
|
404
|
+
"import redis",
|
|
405
|
+
"",
|
|
406
|
+
"r = redis.Redis(host='localhost', port=6379)",
|
|
407
|
+
"",
|
|
408
|
+
].join("\n");
|
|
409
|
+
const file = makePythonFile(content, "db_redis.py");
|
|
410
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
411
|
+
const dbFindings = findings.filter((f) => f.pattern === "database_connection");
|
|
412
|
+
expect(dbFindings.length).toBeGreaterThan(0);
|
|
413
|
+
expect(dbFindings.some((f) => f.properties.databaseType === "redis")).toBe(true);
|
|
414
|
+
});
|
|
415
|
+
it("detects asyncpg as database_connection with databaseType postgres", () => {
|
|
416
|
+
const content = [
|
|
417
|
+
"import asyncpg",
|
|
418
|
+
"",
|
|
419
|
+
"conn = await asyncpg.connect('postgresql://localhost/mydb')",
|
|
420
|
+
"",
|
|
421
|
+
].join("\n");
|
|
422
|
+
const file = makePythonFile(content, "db_asyncpg.py");
|
|
423
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
424
|
+
const dbFindings = findings.filter((f) => f.pattern === "database_connection");
|
|
425
|
+
expect(dbFindings.length).toBeGreaterThan(0);
|
|
426
|
+
expect(dbFindings.some((f) => f.properties.databaseType === "postgres")).toBe(true);
|
|
427
|
+
expect(dbFindings.some((f) => f.properties.client === "asyncpg")).toBe(true);
|
|
428
|
+
});
|
|
429
|
+
it("detects elasticsearch-py as database_connection with databaseType elasticsearch", () => {
|
|
430
|
+
const content = [
|
|
431
|
+
"from elasticsearch import Elasticsearch",
|
|
432
|
+
"",
|
|
433
|
+
"es = Elasticsearch(['http://localhost:9200'])",
|
|
434
|
+
"",
|
|
435
|
+
].join("\n");
|
|
436
|
+
const file = makePythonFile(content, "db_elastic.py");
|
|
437
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
438
|
+
const dbFindings = findings.filter((f) => f.pattern === "database_connection");
|
|
439
|
+
expect(dbFindings.length).toBeGreaterThan(0);
|
|
440
|
+
expect(dbFindings.some((f) => f.properties.databaseType === "elasticsearch")).toBe(true);
|
|
441
|
+
});
|
|
442
|
+
it("does not match routes commented out in Python sources", () => {
|
|
443
|
+
const content = [
|
|
444
|
+
"from fastapi import FastAPI",
|
|
445
|
+
"",
|
|
446
|
+
"app = FastAPI()",
|
|
447
|
+
"",
|
|
448
|
+
"# @app.get('/hidden')",
|
|
449
|
+
"async def hidden():",
|
|
450
|
+
" return {}",
|
|
451
|
+
"",
|
|
452
|
+
].join("\n");
|
|
453
|
+
const file = makePythonFile(content, "commented_routes.py");
|
|
454
|
+
const findings = (0, detector_1.detectPythonPatterns)(file);
|
|
455
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
456
|
+
expect(routes).toHaveLength(0);
|
|
457
|
+
});
|
|
289
458
|
});
|