@cyclonedx/cdxgen 9.4.0 → 9.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ import { expect, test } from "@jest/globals";
2
+
3
+ import {
4
+ constructServiceName,
5
+ detectServicesFromUsages,
6
+ extractEndpoints
7
+ } from "./evinser.js";
8
+
9
+ import { readFileSync } from "node:fs";
10
+
11
+ test("Service detection test", () => {
12
+ const usageSlice = JSON.parse(
13
+ readFileSync("./test/data/usages.json", { encoding: "utf-8" })
14
+ );
15
+ const objectSlices = usageSlice.objectSlices;
16
+ const servicesMap = {};
17
+ for (const slice of objectSlices) {
18
+ detectServicesFromUsages("java", slice, servicesMap);
19
+ expect(servicesMap).toBeDefined();
20
+ const serviceName = constructServiceName("java", slice);
21
+ expect(serviceName).toBeDefined();
22
+ }
23
+ });
24
+
25
+ test("extract endpoints test", () => {
26
+ expect(
27
+ extractEndpoints("java", '@GetMapping(value = { "/", "/home" })')
28
+ ).toEqual(["/", "/home"]);
29
+ expect(
30
+ extractEndpoints(
31
+ "java",
32
+ '@PostMapping(value = "/issue", consumes = MediaType.APPLICATION_XML_VALUE)'
33
+ )
34
+ ).toEqual(["/issue"]);
35
+ expect(extractEndpoints("java", '@GetMapping("/token")')).toEqual(["/token"]);
36
+ expect(
37
+ extractEndpoints(
38
+ "javascript",
39
+ 'router.use("/api/v2/users",userRoutes.routes(),userRoutes.allowedMethods())'
40
+ )
41
+ ).toEqual(["/api/v2/users"]);
42
+ expect(
43
+ extractEndpoints(
44
+ "javascript",
45
+ "app.use('/encryptionkeys', serveIndexMiddleware, serveIndex('encryptionkeys', { icons: true, view: 'details' }))"
46
+ )
47
+ ).toEqual(["/encryptionkeys"]);
48
+ expect(
49
+ extractEndpoints(
50
+ "javascript",
51
+ "app.use(express.static(path.resolve('frontend/dist/frontend')))"
52
+ )
53
+ ).toEqual(["frontend/dist/frontend"]);
54
+ expect(
55
+ extractEndpoints(
56
+ "javascript",
57
+ "app.use('/ftp(?!/quarantine)/:file', fileServer())"
58
+ )
59
+ ).toEqual(["/ftp(?!/quarantine)/:file"]);
60
+ expect(
61
+ extractEndpoints(
62
+ "javascript",
63
+ "app.use('/rest/basket/:id', security.isAuthorized())"
64
+ )
65
+ ).toEqual(["/rest/basket/:id"]);
66
+ expect(
67
+ extractEndpoints(
68
+ "javascript",
69
+ "app.get(['/.well-known/security.txt', '/security.txt'], verify.accessControlChallenges())"
70
+ )
71
+ ).toEqual(["/.well-known/security.txt", "/security.txt"]);
72
+ expect(
73
+ extractEndpoints(
74
+ "javascript",
75
+ 'router.post("/convert",async(ctx:Context):Promise<void>=>{constparameters=ctx.request.body;constbatchClient=newBatchClient({region:"us-west-1"});constcommand=newSubmitJobCommand({jobName:parameters?.jobName,jobQueue:"FOO-ARN",jobDefinition:"BAR-ARN",parameters,});try{constobjectsOutput=awaitbatchClient.send(command);ctx.response.body=objectsOutput;}catch(err){//Poorexceptionhandlingctx.response.body=err;}})'
76
+ )
77
+ ).toEqual(["/convert"]);
78
+ expect(
79
+ extractEndpoints(
80
+ "java",
81
+ '@RequestMapping(path = "/{name}", method = RequestMethod.GET)'
82
+ )
83
+ ).toEqual(["/{name}"]);
84
+ expect(
85
+ extractEndpoints("java", "@RequestMapping(method = RequestMethod.POST)")
86
+ ).toEqual([]);
87
+ expect(
88
+ extractEndpoints(
89
+ "java",
90
+ '@RequestMapping(value = "/{accountName}", method = RequestMethod.GET)'
91
+ )
92
+ ).toEqual(["/{accountName}"]);
93
+ });