forked from CycloneDX/cdxgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evinser.test.js
93 lines (89 loc) · 2.98 KB
/
evinser.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { expect, test } from "@jest/globals";
import {
constructServiceName,
detectServicesFromUsages,
extractEndpoints
} from "./evinser.js";
import { readFileSync } from "node:fs";
test("Service detection test", () => {
const usageSlice = JSON.parse(
readFileSync("./test/data/usages.json", { encoding: "utf-8" })
);
const objectSlices = usageSlice.objectSlices;
const servicesMap = {};
for (const slice of objectSlices) {
detectServicesFromUsages("java", slice, servicesMap);
expect(servicesMap).toBeDefined();
const serviceName = constructServiceName("java", slice);
expect(serviceName).toBeDefined();
}
});
test("extract endpoints test", () => {
expect(
extractEndpoints("java", '@GetMapping(value = { "/", "/home" })')
).toEqual(["/", "/home"]);
expect(
extractEndpoints(
"java",
'@PostMapping(value = "/issue", consumes = MediaType.APPLICATION_XML_VALUE)'
)
).toEqual(["/issue"]);
expect(extractEndpoints("java", '@GetMapping("/token")')).toEqual(["/token"]);
expect(
extractEndpoints(
"javascript",
'router.use("/api/v2/users",userRoutes.routes(),userRoutes.allowedMethods())'
)
).toEqual(["/api/v2/users"]);
expect(
extractEndpoints(
"javascript",
"app.use('/encryptionkeys', serveIndexMiddleware, serveIndex('encryptionkeys', { icons: true, view: 'details' }))"
)
).toEqual(["/encryptionkeys"]);
expect(
extractEndpoints(
"javascript",
"app.use(express.static(path.resolve('frontend/dist/frontend')))"
)
).toEqual(["frontend/dist/frontend"]);
expect(
extractEndpoints(
"javascript",
"app.use('/ftp(?!/quarantine)/:file', fileServer())"
)
).toEqual(["/ftp(?!/quarantine)/:file"]);
expect(
extractEndpoints(
"javascript",
"app.use('/rest/basket/:id', security.isAuthorized())"
)
).toEqual(["/rest/basket/:id"]);
expect(
extractEndpoints(
"javascript",
"app.get(['/.well-known/security.txt', '/security.txt'], verify.accessControlChallenges())"
)
).toEqual(["/.well-known/security.txt", "/security.txt"]);
expect(
extractEndpoints(
"javascript",
'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;}})'
)
).toEqual(["/convert"]);
expect(
extractEndpoints(
"java",
'@RequestMapping(path = "/{name}", method = RequestMethod.GET)'
)
).toEqual(["/{name}"]);
expect(
extractEndpoints("java", "@RequestMapping(method = RequestMethod.POST)")
).toEqual([]);
expect(
extractEndpoints(
"java",
'@RequestMapping(value = "/{accountName}", method = RequestMethod.GET)'
)
).toEqual(["/{accountName}"]);
});