@dataparade/cli 0.0.9 → 0.0.11
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 +28 -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/src/platform-api/telemetry-client.d.ts +6 -0
- package/dist/src/platform-api/telemetry-client.js +65 -0
- package/dist/src/platform-api/telemetry.types.d.ts +13 -0
- package/dist/src/platform-api/telemetry.types.js +2 -0
- package/dist/src/platform-api/upload-client.d.ts +2 -0
- package/dist/src/platform-api/upload-client.js +4 -0
- package/dist/src/platform-api/upload.types.d.ts +2 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +10 -3
- package/dist/src/upload/run-upload.js +62 -19
- package/dist/src/upload/types.d.ts +2 -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/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
- package/dist/tests/unit/upload/run-upload.spec.js +18 -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,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const dependency_manifests_1 = require("../../../../src/analyzers/jvm/dependency-manifests");
|
|
8
|
+
const manifest_parsers_1 = require("../../../../src/analyzers/jvm/manifest-parsers");
|
|
9
|
+
function fixturePath(name) {
|
|
10
|
+
return path_1.default.join(__dirname, "..", "..", "..", "fixtures", name);
|
|
11
|
+
}
|
|
12
|
+
describe("JVM manifest parsers - Maven", () => {
|
|
13
|
+
it("reads dependency and parent coordinates, skipping test scope", () => {
|
|
14
|
+
const pom = [
|
|
15
|
+
"<project>",
|
|
16
|
+
" <parent>",
|
|
17
|
+
" <groupId>org.springframework.boot</groupId>",
|
|
18
|
+
" <artifactId>spring-boot-starter-parent</artifactId>",
|
|
19
|
+
" </parent>",
|
|
20
|
+
" <dependencies>",
|
|
21
|
+
" <dependency>",
|
|
22
|
+
" <groupId>org.postgresql</groupId>",
|
|
23
|
+
" <artifactId>postgresql</artifactId>",
|
|
24
|
+
" </dependency>",
|
|
25
|
+
" <dependency>",
|
|
26
|
+
" <groupId>org.springframework.boot</groupId>",
|
|
27
|
+
" <artifactId>spring-boot-starter-test</artifactId>",
|
|
28
|
+
" <scope>test</scope>",
|
|
29
|
+
" </dependency>",
|
|
30
|
+
" </dependencies>",
|
|
31
|
+
"</project>",
|
|
32
|
+
].join("\n");
|
|
33
|
+
expect((0, manifest_parsers_1.extractCoordinatesFromPom)(pom).sort()).toEqual([
|
|
34
|
+
"org.postgresql:postgresql",
|
|
35
|
+
"org.springframework.boot:spring-boot-starter-parent",
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
it("rejects unresolved property placeholders", () => {
|
|
39
|
+
const pom = [
|
|
40
|
+
"<project><dependencies><dependency>",
|
|
41
|
+
" <groupId>${spring.group}</groupId>",
|
|
42
|
+
" <artifactId>${spring.artifact}</artifactId>",
|
|
43
|
+
"</dependency></dependencies></project>",
|
|
44
|
+
].join("\n");
|
|
45
|
+
expect((0, manifest_parsers_1.extractCoordinatesFromPom)(pom)).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("JVM manifest parsers - Gradle", () => {
|
|
49
|
+
it("reads both DSL forms and unwraps platform() declarations", () => {
|
|
50
|
+
const gradle = [
|
|
51
|
+
"dependencies {",
|
|
52
|
+
' implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.0"))',
|
|
53
|
+
' implementation("org.springframework.boot:spring-boot-starter-web")',
|
|
54
|
+
" implementation 'redis.clients:jedis:5.1.0'",
|
|
55
|
+
" runtimeOnly group: 'org.postgresql', name: 'postgresql'",
|
|
56
|
+
"}",
|
|
57
|
+
].join("\n");
|
|
58
|
+
expect((0, manifest_parsers_1.extractCoordinatesFromGradle)(gradle).sort()).toEqual([
|
|
59
|
+
"org.postgresql:postgresql",
|
|
60
|
+
"org.springframework.boot:spring-boot-dependencies",
|
|
61
|
+
"org.springframework.boot:spring-boot-starter-web",
|
|
62
|
+
"redis.clients:jedis",
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
it("leaves test dependencies and non-dependency strings out", () => {
|
|
66
|
+
const gradle = [
|
|
67
|
+
"plugins {",
|
|
68
|
+
' kotlin("jvm") version "1.9.22"',
|
|
69
|
+
"}",
|
|
70
|
+
"repositories {",
|
|
71
|
+
' maven { url "https://repo.example.com/releases" }',
|
|
72
|
+
"}",
|
|
73
|
+
"dependencies {",
|
|
74
|
+
' implementation("com.zaxxer:HikariCP:5.1.0")',
|
|
75
|
+
' testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")',
|
|
76
|
+
"}",
|
|
77
|
+
].join("\n");
|
|
78
|
+
expect((0, manifest_parsers_1.extractCoordinatesFromGradle)(gradle)).toEqual([
|
|
79
|
+
"com.zaxxer:HikariCP",
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
it("reads a Gradle version catalog", () => {
|
|
83
|
+
const toml = [
|
|
84
|
+
"[versions]",
|
|
85
|
+
'postgres = "42.7.1"',
|
|
86
|
+
"",
|
|
87
|
+
"[libraries]",
|
|
88
|
+
'postgres = { module = "org.postgresql:postgresql", version.ref = "postgres" }',
|
|
89
|
+
'jedis = { group = "redis.clients", name = "jedis" }',
|
|
90
|
+
"",
|
|
91
|
+
"[plugins]",
|
|
92
|
+
'spring = { id = "org.springframework.boot", version = "3.2.0" }',
|
|
93
|
+
].join("\n");
|
|
94
|
+
expect((0, manifest_parsers_1.extractCoordinatesFromVersionCatalog)(toml).sort()).toEqual([
|
|
95
|
+
"org.postgresql:postgresql",
|
|
96
|
+
"redis.clients:jedis",
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("JVM manifest parsers - Spring datasource configuration", () => {
|
|
101
|
+
it("reads the driver token out of a URI without keeping the URI", () => {
|
|
102
|
+
expect((0, manifest_parsers_1.driverTokenFromUri)("jdbc:postgresql://host:5432/db")).toBe("postgresql");
|
|
103
|
+
expect((0, manifest_parsers_1.driverTokenFromUri)("r2dbc:mysql://host/db")).toBe("mysql");
|
|
104
|
+
expect((0, manifest_parsers_1.driverTokenFromUri)("mongodb+srv://cluster/db")).toBe("mongodb");
|
|
105
|
+
expect((0, manifest_parsers_1.driverTokenFromUri)("not-a-uri")).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
it("extracts datasource keys from application.properties", () => {
|
|
108
|
+
const properties = [
|
|
109
|
+
"# billing service",
|
|
110
|
+
"spring.datasource.url=jdbc:postgresql://db.internal:5432/billing",
|
|
111
|
+
"spring.datasource.password=super-secret-value",
|
|
112
|
+
"spring.data.mongodb.uri=mongodb://mongo.internal:27017/events",
|
|
113
|
+
"server.port=8080",
|
|
114
|
+
].join("\n");
|
|
115
|
+
expect((0, manifest_parsers_1.extractDatasourceRefsFromProperties)(properties)).toEqual([
|
|
116
|
+
{ key: "spring.datasource.url", driver: "postgresql" },
|
|
117
|
+
{ key: "spring.data.mongodb.uri", driver: "mongodb" },
|
|
118
|
+
]);
|
|
119
|
+
});
|
|
120
|
+
it("extracts datasource keys from every document of an application.yml", () => {
|
|
121
|
+
const yaml = [
|
|
122
|
+
"spring:",
|
|
123
|
+
" datasource:",
|
|
124
|
+
" url: jdbc:postgresql://db.internal:5432/billing",
|
|
125
|
+
"---",
|
|
126
|
+
"spring:",
|
|
127
|
+
" config:",
|
|
128
|
+
" activate:",
|
|
129
|
+
" on-profile: local",
|
|
130
|
+
" datasource:",
|
|
131
|
+
" url: jdbc:h2:mem:testdb",
|
|
132
|
+
].join("\n");
|
|
133
|
+
expect((0, manifest_parsers_1.extractDatasourceRefsFromYaml)(yaml)).toEqual([
|
|
134
|
+
{ key: "spring.datasource.url", driver: "postgresql" },
|
|
135
|
+
{ key: "spring.datasource.url", driver: "h2" },
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("JVM dependency manifest scanning", () => {
|
|
140
|
+
it("collects coordinates from every build file in the tree", async () => {
|
|
141
|
+
const manifests = await (0, dependency_manifests_1.parseJvmDependencyManifests)(fixturePath("jvm-manifests-basic"));
|
|
142
|
+
const byPath = new Map(manifests.map((m) => [m.manifestRelativePath, m.packages]));
|
|
143
|
+
expect(byPath.get("pom.xml")?.sort()).toEqual([
|
|
144
|
+
"org.postgresql:postgresql",
|
|
145
|
+
"org.springframework.boot:spring-boot-starter-data-jpa",
|
|
146
|
+
"org.springframework.boot:spring-boot-starter-parent",
|
|
147
|
+
"redis.clients:jedis",
|
|
148
|
+
]);
|
|
149
|
+
expect(byPath.get("services/ledger/build.gradle.kts")?.sort()).toEqual([
|
|
150
|
+
"com.mysql:mysql-connector-j",
|
|
151
|
+
"com.zaxxer:HikariCP",
|
|
152
|
+
"org.springframework.boot:spring-boot-dependencies",
|
|
153
|
+
"org.springframework.boot:spring-boot-starter-web",
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
it("maps coordinates and datasource URIs onto findings", async () => {
|
|
157
|
+
const findings = await (0, dependency_manifests_1.detectJvmPatternsFromDependencyManifests)(fixturePath("jvm-manifests-basic"));
|
|
158
|
+
const databases = findings.filter((f) => f.pattern === "database_connection");
|
|
159
|
+
const names = databases.map((f) => f.name);
|
|
160
|
+
// From pom.xml coordinates.
|
|
161
|
+
expect(names).toContain("postgresql_jdbc");
|
|
162
|
+
expect(names).toContain("spring_data_jpa");
|
|
163
|
+
expect(names).toContain("jedis");
|
|
164
|
+
// From build.gradle.kts coordinates.
|
|
165
|
+
expect(names).toContain("mysql_jdbc");
|
|
166
|
+
expect(names).toContain("hikaricp");
|
|
167
|
+
// From application.yml datasource URIs.
|
|
168
|
+
expect(names).toContain("jdbc:postgresql");
|
|
169
|
+
expect(names).toContain("jdbc:mongodb");
|
|
170
|
+
const mongo = databases.find((f) => f.name === "jdbc:mongodb");
|
|
171
|
+
expect(mongo?.properties.databaseType).toBe("mongodb");
|
|
172
|
+
expect(mongo?.properties.key).toBe("spring.data.mongodb.uri");
|
|
173
|
+
expect(findings.some((f) => f.pattern === "config_file" && f.name === "application.yml")).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
it("never carries a datasource password into a finding", async () => {
|
|
176
|
+
const findings = await (0, dependency_manifests_1.detectJvmPatternsFromDependencyManifests)(fixturePath("jvm-manifests-basic"));
|
|
177
|
+
expect(JSON.stringify(findings)).not.toContain("super-secret-value");
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|