@j3r3mcdev/oast-server 1.0.0 → 1.1.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.
- package/.github/workflows/ci.yml +29 -29
- package/.github/workflows/publish.yml +31 -31
- package/README.md +192 -192
- package/dist/api/controllers/__tests__/tasks.controller.test.d.ts +1 -0
- package/dist/api/controllers/events.controller.d.ts +6 -0
- package/dist/api/controllers/health.controller.d.ts +4 -0
- package/dist/api/controllers/index.d.ts +0 -0
- package/dist/api/controllers/tasks.controller.d.ts +40 -0
- package/dist/api/dto/__tests__/create-task.dto.test.d.ts +1 -0
- package/dist/api/dto/__tests__/filter-tasks.dto.test.d.ts +1 -0
- package/dist/api/dto/create-task.dto.d.ts +9 -0
- package/dist/api/dto/filter-tasks.dto.d.ts +8 -0
- package/dist/api/services/__tests__/events.service.test.d.ts +1 -0
- package/dist/api/services/__tests__/tasks.service.test.d.ts +1 -0
- package/dist/api/services/events.service.d.ts +8 -0
- package/dist/api/services/tasks.service.d.ts +22 -0
- package/dist/api/sse/events.stream.d.ts +25 -0
- package/dist/config/constants.d.ts +0 -0
- package/dist/config/env.d.ts +0 -0
- package/dist/core/__tests__/core-router.test.d.ts +1 -0
- package/dist/core/__tests__/core-server.test.d.ts +1 -0
- package/dist/core/__tests__/event.normalizer.test.d.ts +1 -0
- package/dist/core/__tests__/event.router.test.d.ts +1 -0
- package/dist/core/__tests__/logger.test.d.ts +1 -0
- package/dist/core/__tests__/storage-manager.test.d.ts +1 -0
- package/dist/core/event.normalizer.d.ts +10 -0
- package/dist/core/event.router.d.ts +7 -0
- package/dist/core/http/__tests__/adapter-node.test.d.ts +1 -0
- package/dist/core/http/__tests__/body-parser-multipart.test.d.ts +1 -0
- package/dist/core/http/__tests__/body-parser-raw.test.d.ts +1 -0
- package/dist/core/http/__tests__/body-parser-text.test.d.ts +1 -0
- package/dist/core/http/__tests__/compile-path.test.d.ts +1 -0
- package/dist/core/http/__tests__/middleware-pipeline.test.d.ts +1 -0
- package/dist/core/http/__tests__/request.test.d.ts +1 -0
- package/dist/core/http/__tests__/response.test.d.ts +1 -0
- package/dist/core/http/__tests__/router-match.test.d.ts +1 -0
- package/dist/core/http/adapter-node.d.ts +8 -0
- package/dist/core/http/buildRequest.d.ts +2 -0
- package/dist/core/http/compile-path.d.ts +13 -0
- package/dist/core/http/errors.d.ts +9 -0
- package/dist/core/http/http-server.d.ts +7 -0
- package/dist/core/http/index.d.ts +0 -0
- package/dist/core/http/main.d.ts +0 -0
- package/dist/core/http/middleware.d.ts +12 -0
- package/dist/core/http/request.d.ts +35 -0
- package/dist/core/http/response.d.ts +17 -0
- package/dist/core/http/router.d.ts +28 -0
- package/dist/core/http/utils.d.ts +0 -0
- package/dist/core/id-generator.d.ts +3 -0
- package/dist/core/logger.d.ts +29 -0
- package/dist/core/router.d.ts +16 -0
- package/dist/core/server.d.ts +25 -0
- package/dist/core/storage.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/listeners/api/__tests__/api.controller.test.d.ts +1 -0
- package/dist/listeners/api/__tests__/api.extractor.test.d.ts +1 -0
- package/dist/listeners/api/__tests__/api.listener.test.d.ts +1 -0
- package/dist/listeners/api/__tests__/api.routes.test.d.ts +1 -0
- package/dist/listeners/api/__tests__/api.sse.test.d.ts +1 -0
- package/dist/listeners/api/api.controllers.d.ts +9 -0
- package/dist/listeners/api/api.extractor.d.ts +5 -0
- package/dist/listeners/api/api.listener.d.ts +17 -0
- package/dist/listeners/api/api.routes.d.ts +5 -0
- package/dist/listeners/api/api.sse.d.ts +10 -0
- package/dist/listeners/dns/__tests__/dns.test.d.ts +1 -0
- package/dist/listeners/dns/dns.extractor.d.ts +8 -0
- package/dist/listeners/dns/dns.listener.d.ts +15 -0
- package/dist/listeners/http/__tests__/http.extractor.test.d.ts +1 -0
- package/dist/listeners/http/__tests__/http.listener.test.d.ts +1 -0
- package/dist/listeners/http/http.extractor.d.ts +11 -0
- package/dist/listeners/http/http.listener.d.ts +17 -0
- package/dist/listeners/listener.interface.d.ts +4 -0
- package/dist/listeners/smtp/__tests__/smtp.extractor.test.d.ts +1 -0
- package/dist/listeners/smtp/__tests__/smtp.listener.test.d.ts +1 -0
- package/dist/listeners/smtp/smtp.extractor.d.ts +12 -0
- package/dist/listeners/smtp/smtp.listener.d.ts +13 -0
- package/dist/listeners/ssrf/__tests__/ssrf.extractor.test.d.ts +1 -0
- package/dist/listeners/ssrf/__tests__/ssrf.listener.test.d.ts +1 -0
- package/dist/listeners/ssrf/__tests__/ssrf.listener.test.js +4 -16
- package/dist/listeners/ssrf/ssrf.extractor.d.ts +10 -0
- package/dist/listeners/ssrf/ssrf.listener.d.ts +8 -0
- package/dist/listeners/tcp/tcp.extractor.d.ts +4 -0
- package/dist/listeners/tcp/tcp.listener.d.ts +18 -0
- package/dist/listeners/webhook/__tests__/webhook.extractor.test.d.ts +1 -0
- package/dist/listeners/webhook/__tests__/webhook.listener.test.d.ts +1 -0
- package/dist/listeners/webhook/webhook.extractor.d.ts +8 -0
- package/dist/listeners/webhook/webhook.listener.d.ts +8 -0
- package/dist/listeners/websocket/__tests__/websocket.extractor.test.d.ts +1 -0
- package/dist/listeners/websocket/__tests__/websocket.listener.test.d.ts +1 -0
- package/dist/listeners/websocket/websocket.extractor.d.ts +10 -0
- package/dist/listeners/websocket/websocket.listener.d.ts +8 -0
- package/dist/storage-adapters/adapters/__tests__/memory.storage.test.d.ts +1 -0
- package/dist/storage-adapters/adapters/memory.storage.d.ts +21 -0
- package/dist/storage-adapters/adapters/redis.storage.d.ts +0 -0
- package/dist/storage-adapters/adapters/sqlite.storage.d.ts +0 -0
- package/dist/storage-adapters/storage.interface.d.ts +18 -0
- package/dist/types/event.types.d.ts +118 -0
- package/dist/utils/token.d.ts +0 -0
- package/jest.config.js +14 -11
- package/package.json +45 -45
- package/sadmin list shadows +9 -9
- package/src/api/controllers/__tests__/tasks.controller.test.ts +74 -74
- package/src/api/controllers/events.controller.ts +10 -10
- package/src/api/controllers/health.controller.ts +7 -7
- package/src/api/controllers/tasks.controller.ts +41 -41
- package/src/api/dto/__tests__/create-task.dto.test.ts +41 -41
- package/src/api/dto/__tests__/filter-tasks.dto.test.ts +35 -35
- package/src/api/dto/create-task.dto.ts +33 -33
- package/src/api/dto/filter-tasks.dto.ts +33 -33
- package/src/api/services/__tests__/events.service.test.ts +41 -41
- package/src/api/services/__tests__/tasks.service.test.ts +41 -41
- package/src/api/services/events.service.ts +17 -17
- package/src/api/services/tasks.service.ts +79 -79
- package/src/api/sse/events.stream.ts +90 -90
- package/src/core/__tests__/core-router.test.ts +30 -30
- package/src/core/__tests__/core-server.test.ts +44 -44
- package/src/core/__tests__/event.normalizer.test.ts +56 -56
- package/src/core/__tests__/event.router.test.ts +89 -89
- package/src/core/__tests__/logger.test.ts +32 -32
- package/src/core/__tests__/storage-manager.test.ts +74 -74
- package/src/core/event.normalizer.ts +147 -147
- package/src/core/event.router.ts +13 -13
- package/src/core/http/__tests__/adapter-node.test.ts +52 -52
- package/src/core/http/__tests__/body-parser-multipart.test.ts +41 -41
- package/src/core/http/__tests__/body-parser-raw.test.ts +28 -28
- package/src/core/http/__tests__/body-parser-text.test.ts +28 -28
- package/src/core/http/__tests__/compile-path.test.ts +39 -39
- package/src/core/http/__tests__/middleware-pipeline.test.ts +51 -51
- package/src/core/http/__tests__/request.test.ts +34 -34
- package/src/core/http/__tests__/response.test.ts +35 -35
- package/src/core/http/__tests__/router-match.test.ts +171 -171
- package/src/core/http/adapter-node.ts +51 -51
- package/src/core/http/buildRequest.ts +18 -18
- package/src/core/http/compile-path.ts +32 -32
- package/src/core/http/errors.ts +37 -37
- package/src/core/http/http-server.ts +52 -52
- package/src/core/http/middleware.ts +160 -160
- package/src/core/http/request.ts +55 -55
- package/src/core/http/response.ts +93 -93
- package/src/core/http/router.ts +138 -138
- package/src/core/id-generator.ts +8 -8
- package/src/core/logger.ts +113 -113
- package/src/core/router.ts +44 -44
- package/src/core/server.ts +85 -85
- package/src/core/storage.ts +64 -64
- package/src/index.ts +89 -89
- package/src/listeners/api/__tests__/api.controller.test.ts +116 -116
- package/src/listeners/api/__tests__/api.extractor.test.ts +46 -46
- package/src/listeners/api/__tests__/api.listener.test.ts +82 -82
- package/src/listeners/api/__tests__/api.routes.test.ts +155 -155
- package/src/listeners/api/__tests__/api.sse.test.ts +105 -105
- package/src/listeners/api/api.controllers.ts +67 -67
- package/src/listeners/api/api.extractor.ts +43 -43
- package/src/listeners/api/api.listener.ts +50 -50
- package/src/listeners/api/api.routes.ts +76 -76
- package/src/listeners/api/api.sse.ts +38 -38
- package/src/listeners/dns/__tests__/dns.test.ts +118 -118
- package/src/listeners/dns/dns.extractor.ts +14 -14
- package/src/listeners/dns/dns.listener.ts +61 -61
- package/src/listeners/http/__tests__/http.extractor.test.ts +59 -59
- package/src/listeners/http/__tests__/http.listener.test.ts +133 -133
- package/src/listeners/http/http.extractor.ts +15 -15
- package/src/listeners/http/http.listener.ts +110 -110
- package/src/listeners/listener.interface.ts +4 -4
- package/src/listeners/smtp/__tests__/smtp.extractor.test.ts +69 -69
- package/src/listeners/smtp/__tests__/smtp.listener.test.ts +150 -150
- package/src/listeners/smtp/smtp.extractor.ts +18 -18
- package/src/listeners/smtp/smtp.listener.ts +60 -60
- package/src/listeners/ssrf/__tests__/ssrf.extractor.test.ts +41 -41
- package/src/listeners/ssrf/__tests__/ssrf.listener.test.ts +87 -98
- package/src/listeners/ssrf/ssrf.extractor.ts +14 -14
- package/src/listeners/ssrf/ssrf.listener.ts +37 -37
- package/src/listeners/tcp/tcp.extractor.ts +16 -16
- package/src/listeners/tcp/tcp.listener.ts +61 -61
- package/src/listeners/webhook/__tests__/webhook.extractor.test.ts +35 -35
- package/src/listeners/webhook/__tests__/webhook.listener.test.ts +122 -122
- package/src/listeners/webhook/webhook.extractor.ts +12 -12
- package/src/listeners/webhook/webhook.listener.ts +58 -58
- package/src/listeners/websocket/__tests__/websocket.extractor.test.ts +33 -33
- package/src/listeners/websocket/__tests__/websocket.listener.test.ts +90 -90
- package/src/listeners/websocket/websocket.extractor.ts +11 -11
- package/src/listeners/websocket/websocket.listener.ts +40 -40
- package/src/storage-adapters/adapters/__tests__/memory.storage.test.ts +75 -75
- package/src/storage-adapters/adapters/memory.storage.ts +64 -64
- package/src/storage-adapters/storage.interface.ts +26 -26
- package/src/types/event.types.ts +147 -147
- package/tsconfig.json +21 -15
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { bodyParserMultipart } from "../middleware";
|
|
2
|
-
import { Request } from "../request";
|
|
3
|
-
import { Response } from "../response";
|
|
4
|
-
import { describe, it, expect } from "@jest/globals";
|
|
5
|
-
|
|
6
|
-
describe("bodyParserMultipart", () => {
|
|
7
|
-
it("parse un champ texte et un fichier", async () => {
|
|
8
|
-
const boundary = "----1234";
|
|
9
|
-
|
|
10
|
-
const raw = {
|
|
11
|
-
headers: { "content-type": `multipart/form-data; boundary=${boundary}` },
|
|
12
|
-
[Symbol.asyncIterator]: async function* () {
|
|
13
|
-
yield Buffer.from(
|
|
14
|
-
`--${boundary}\r\n` +
|
|
15
|
-
`Content-Disposition: form-data; name="username"\r\n\r\n` +
|
|
16
|
-
`jeremy\r\n` +
|
|
17
|
-
`--${boundary}\r\n` +
|
|
18
|
-
`Content-Disposition: form-data; name="file"; filename="test.txt"\r\n` +
|
|
19
|
-
`Content-Type: text/plain\r\n\r\n` +
|
|
20
|
-
`Hello world\r\n` +
|
|
21
|
-
`--${boundary}--`,
|
|
22
|
-
);
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const req = new Request({
|
|
27
|
-
method: "POST",
|
|
28
|
-
path: "/upload",
|
|
29
|
-
headers: raw.headers,
|
|
30
|
-
raw,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const res = new Response({});
|
|
34
|
-
|
|
35
|
-
await bodyParserMultipart(req, res);
|
|
36
|
-
|
|
37
|
-
expect(req.form?.username).toBe("jeremy");
|
|
38
|
-
expect(req.files?.[0].filename).toBe("test.txt");
|
|
39
|
-
expect(req.files?.[0].data.toString()).toBe("Hello world");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
1
|
+
import { bodyParserMultipart } from "../middleware";
|
|
2
|
+
import { Request } from "../request";
|
|
3
|
+
import { Response } from "../response";
|
|
4
|
+
import { describe, it, expect } from "@jest/globals";
|
|
5
|
+
|
|
6
|
+
describe("bodyParserMultipart", () => {
|
|
7
|
+
it("parse un champ texte et un fichier", async () => {
|
|
8
|
+
const boundary = "----1234";
|
|
9
|
+
|
|
10
|
+
const raw = {
|
|
11
|
+
headers: { "content-type": `multipart/form-data; boundary=${boundary}` },
|
|
12
|
+
[Symbol.asyncIterator]: async function* () {
|
|
13
|
+
yield Buffer.from(
|
|
14
|
+
`--${boundary}\r\n` +
|
|
15
|
+
`Content-Disposition: form-data; name="username"\r\n\r\n` +
|
|
16
|
+
`jeremy\r\n` +
|
|
17
|
+
`--${boundary}\r\n` +
|
|
18
|
+
`Content-Disposition: form-data; name="file"; filename="test.txt"\r\n` +
|
|
19
|
+
`Content-Type: text/plain\r\n\r\n` +
|
|
20
|
+
`Hello world\r\n` +
|
|
21
|
+
`--${boundary}--`,
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const req = new Request({
|
|
27
|
+
method: "POST",
|
|
28
|
+
path: "/upload",
|
|
29
|
+
headers: raw.headers,
|
|
30
|
+
raw,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const res = new Response({});
|
|
34
|
+
|
|
35
|
+
await bodyParserMultipart(req, res);
|
|
36
|
+
|
|
37
|
+
expect(req.form?.username).toBe("jeremy");
|
|
38
|
+
expect(req.files?.[0].filename).toBe("test.txt");
|
|
39
|
+
expect(req.files?.[0].data.toString()).toBe("Hello world");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { bodyParserRaw } from "../middleware";
|
|
2
|
-
import { Request } from "../request";
|
|
3
|
-
import { Response } from "../response";
|
|
4
|
-
import { describe, it, expect } from "@jest/globals";
|
|
5
|
-
|
|
6
|
-
describe("bodyParserRaw", () => {
|
|
7
|
-
it("lit le body brut", async () => {
|
|
8
|
-
const raw = {
|
|
9
|
-
headers: { "content-type": "application/octet-stream" },
|
|
10
|
-
[Symbol.asyncIterator]: async function* () {
|
|
11
|
-
yield Buffer.from([1, 2, 3, 4]);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const req = new Request({
|
|
16
|
-
method: "POST",
|
|
17
|
-
path: "/",
|
|
18
|
-
headers: raw.headers,
|
|
19
|
-
raw,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const res = new Response({});
|
|
23
|
-
|
|
24
|
-
await bodyParserRaw(req, res);
|
|
25
|
-
|
|
26
|
-
expect(req.bodyRaw).toEqual(Buffer.from([1, 2, 3, 4]));
|
|
27
|
-
});
|
|
28
|
-
});
|
|
1
|
+
import { bodyParserRaw } from "../middleware";
|
|
2
|
+
import { Request } from "../request";
|
|
3
|
+
import { Response } from "../response";
|
|
4
|
+
import { describe, it, expect } from "@jest/globals";
|
|
5
|
+
|
|
6
|
+
describe("bodyParserRaw", () => {
|
|
7
|
+
it("lit le body brut", async () => {
|
|
8
|
+
const raw = {
|
|
9
|
+
headers: { "content-type": "application/octet-stream" },
|
|
10
|
+
[Symbol.asyncIterator]: async function* () {
|
|
11
|
+
yield Buffer.from([1, 2, 3, 4]);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const req = new Request({
|
|
16
|
+
method: "POST",
|
|
17
|
+
path: "/",
|
|
18
|
+
headers: raw.headers,
|
|
19
|
+
raw,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const res = new Response({});
|
|
23
|
+
|
|
24
|
+
await bodyParserRaw(req, res);
|
|
25
|
+
|
|
26
|
+
expect(req.bodyRaw).toEqual(Buffer.from([1, 2, 3, 4]));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { bodyParserText } from "../middleware";
|
|
2
|
-
import { Request } from "../request";
|
|
3
|
-
import { Response } from "../response";
|
|
4
|
-
import { describe, it, expect } from "@jest/globals";
|
|
5
|
-
|
|
6
|
-
describe("bodyParserText", () => {
|
|
7
|
-
it("lit le body text", async () => {
|
|
8
|
-
const raw = {
|
|
9
|
-
headers: { "content-type": "text/plain" },
|
|
10
|
-
[Symbol.asyncIterator]: async function* () {
|
|
11
|
-
yield Buffer.from("Hello world");
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const req = new Request({
|
|
16
|
-
method: "POST",
|
|
17
|
-
path: "/",
|
|
18
|
-
headers: raw.headers,
|
|
19
|
-
raw,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const res = new Response({});
|
|
23
|
-
|
|
24
|
-
await bodyParserText(req, res);
|
|
25
|
-
|
|
26
|
-
expect(req.bodyText).toBe("Hello world");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
1
|
+
import { bodyParserText } from "../middleware";
|
|
2
|
+
import { Request } from "../request";
|
|
3
|
+
import { Response } from "../response";
|
|
4
|
+
import { describe, it, expect } from "@jest/globals";
|
|
5
|
+
|
|
6
|
+
describe("bodyParserText", () => {
|
|
7
|
+
it("lit le body text", async () => {
|
|
8
|
+
const raw = {
|
|
9
|
+
headers: { "content-type": "text/plain" },
|
|
10
|
+
[Symbol.asyncIterator]: async function* () {
|
|
11
|
+
yield Buffer.from("Hello world");
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const req = new Request({
|
|
16
|
+
method: "POST",
|
|
17
|
+
path: "/",
|
|
18
|
+
headers: raw.headers,
|
|
19
|
+
raw,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const res = new Response({});
|
|
23
|
+
|
|
24
|
+
await bodyParserText(req, res);
|
|
25
|
+
|
|
26
|
+
expect(req.bodyText).toBe("Hello world");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { compilePath } from "../compile-path";
|
|
2
|
-
import { describe, it, expect } from "@jest/globals";
|
|
3
|
-
|
|
4
|
-
describe("compilePath", () => {
|
|
5
|
-
it("compile un chemin simple avec segment statique", () => {
|
|
6
|
-
const result = compilePath("/tasks");
|
|
7
|
-
|
|
8
|
-
expect(result).toEqual([{ type: "static", value: "tasks" }]);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("compile un chemin avec paramètre", () => {
|
|
12
|
-
const result = compilePath("/tasks/:id");
|
|
13
|
-
|
|
14
|
-
expect(result).toEqual([
|
|
15
|
-
{ type: "static", value: "tasks" },
|
|
16
|
-
{ type: "param", name: "id" },
|
|
17
|
-
]);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("compile un chemin avec paramètre", () => {
|
|
21
|
-
const result = compilePath("/tasks/:id");
|
|
22
|
-
|
|
23
|
-
expect(result).toEqual([
|
|
24
|
-
{ type: "static", value: "tasks" },
|
|
25
|
-
{ type: "param", name: "id" },
|
|
26
|
-
]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("compile un chemin complexe avec static, param et wildcard", () => {
|
|
30
|
-
const result = compilePath("/a/:b/*/c");
|
|
31
|
-
|
|
32
|
-
expect(result).toEqual([
|
|
33
|
-
{ type: "static", value: "a" },
|
|
34
|
-
{ type: "param", name: "b" },
|
|
35
|
-
{ type: "wildcard" },
|
|
36
|
-
{ type: "static", value: "c" },
|
|
37
|
-
]);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
1
|
+
import { compilePath } from "../compile-path";
|
|
2
|
+
import { describe, it, expect } from "@jest/globals";
|
|
3
|
+
|
|
4
|
+
describe("compilePath", () => {
|
|
5
|
+
it("compile un chemin simple avec segment statique", () => {
|
|
6
|
+
const result = compilePath("/tasks");
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual([{ type: "static", value: "tasks" }]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("compile un chemin avec paramètre", () => {
|
|
12
|
+
const result = compilePath("/tasks/:id");
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual([
|
|
15
|
+
{ type: "static", value: "tasks" },
|
|
16
|
+
{ type: "param", name: "id" },
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("compile un chemin avec paramètre", () => {
|
|
21
|
+
const result = compilePath("/tasks/:id");
|
|
22
|
+
|
|
23
|
+
expect(result).toEqual([
|
|
24
|
+
{ type: "static", value: "tasks" },
|
|
25
|
+
{ type: "param", name: "id" },
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("compile un chemin complexe avec static, param et wildcard", () => {
|
|
30
|
+
const result = compilePath("/a/:b/*/c");
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual([
|
|
33
|
+
{ type: "static", value: "a" },
|
|
34
|
+
{ type: "param", name: "b" },
|
|
35
|
+
{ type: "wildcard" },
|
|
36
|
+
{ type: "static", value: "c" },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { MiddlewarePipeline } from "../../http/middleware";
|
|
2
|
-
import { Request } from "../../http/request";
|
|
3
|
-
import { Response } from "../../http/response";
|
|
4
|
-
import { describe, it, expect, jest } from "@jest/globals";
|
|
5
|
-
|
|
6
|
-
describe("MiddlewarePipeline", () => {
|
|
7
|
-
it("exécute les middlewares dans l'ordre", async () => {
|
|
8
|
-
const pipeline = new MiddlewarePipeline();
|
|
9
|
-
|
|
10
|
-
const calls: string[] = [];
|
|
11
|
-
|
|
12
|
-
pipeline.use(async (req, res, next) => {
|
|
13
|
-
calls.push("mw1");
|
|
14
|
-
await next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
pipeline.use(async (req, res, next) => {
|
|
18
|
-
calls.push("mw2");
|
|
19
|
-
await next();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const req = new Request({ method: "GET", path: "/", headers: {} });
|
|
23
|
-
const res = new Response({ setHeader: jest.fn(), end: jest.fn() });
|
|
24
|
-
|
|
25
|
-
await pipeline.run(req, res);
|
|
26
|
-
|
|
27
|
-
expect(calls).toEqual(["mw1", "mw2"]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("arrête la chaîne si next() n'est pas appelé", async () => {
|
|
31
|
-
const pipeline = new MiddlewarePipeline();
|
|
32
|
-
|
|
33
|
-
const calls: string[] = [];
|
|
34
|
-
|
|
35
|
-
pipeline.use(async () => {
|
|
36
|
-
calls.push("mw1");
|
|
37
|
-
// pas de next()
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
pipeline.use(async () => {
|
|
41
|
-
calls.push("mw2");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const req = new Request({ method: "GET", path: "/", headers: {} });
|
|
45
|
-
const res = new Response({ setHeader: jest.fn(), end: jest.fn() });
|
|
46
|
-
|
|
47
|
-
await pipeline.run(req, res);
|
|
48
|
-
|
|
49
|
-
expect(calls).toEqual(["mw1"]);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
1
|
+
import { MiddlewarePipeline } from "../../http/middleware";
|
|
2
|
+
import { Request } from "../../http/request";
|
|
3
|
+
import { Response } from "../../http/response";
|
|
4
|
+
import { describe, it, expect, jest } from "@jest/globals";
|
|
5
|
+
|
|
6
|
+
describe("MiddlewarePipeline", () => {
|
|
7
|
+
it("exécute les middlewares dans l'ordre", async () => {
|
|
8
|
+
const pipeline = new MiddlewarePipeline();
|
|
9
|
+
|
|
10
|
+
const calls: string[] = [];
|
|
11
|
+
|
|
12
|
+
pipeline.use(async (req, res, next) => {
|
|
13
|
+
calls.push("mw1");
|
|
14
|
+
await next();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
pipeline.use(async (req, res, next) => {
|
|
18
|
+
calls.push("mw2");
|
|
19
|
+
await next();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const req = new Request({ method: "GET", path: "/", headers: {} });
|
|
23
|
+
const res = new Response({ setHeader: jest.fn(), end: jest.fn() });
|
|
24
|
+
|
|
25
|
+
await pipeline.run(req, res);
|
|
26
|
+
|
|
27
|
+
expect(calls).toEqual(["mw1", "mw2"]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("arrête la chaîne si next() n'est pas appelé", async () => {
|
|
31
|
+
const pipeline = new MiddlewarePipeline();
|
|
32
|
+
|
|
33
|
+
const calls: string[] = [];
|
|
34
|
+
|
|
35
|
+
pipeline.use(async () => {
|
|
36
|
+
calls.push("mw1");
|
|
37
|
+
// pas de next()
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
pipeline.use(async () => {
|
|
41
|
+
calls.push("mw2");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const req = new Request({ method: "GET", path: "/", headers: {} });
|
|
45
|
+
const res = new Response({ setHeader: jest.fn(), end: jest.fn() });
|
|
46
|
+
|
|
47
|
+
await pipeline.run(req, res);
|
|
48
|
+
|
|
49
|
+
expect(calls).toEqual(["mw1"]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { Request } from "../request";
|
|
2
|
-
import { describe, it, expect } from "@jest/globals";
|
|
3
|
-
|
|
4
|
-
describe("Request", () => {
|
|
5
|
-
it("crée une requête immuable avec les bonnes propriétés", () => {
|
|
6
|
-
const req = new Request({
|
|
7
|
-
method: "GET",
|
|
8
|
-
path: "/test",
|
|
9
|
-
headers: { "content-type": "application/json" },
|
|
10
|
-
query: { a: "1" },
|
|
11
|
-
params: { id: "123" },
|
|
12
|
-
body: { x: 1 },
|
|
13
|
-
ip: "127.0.0.1",
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
expect(req.method).toBe("GET");
|
|
17
|
-
expect(req.path).toBe("/test");
|
|
18
|
-
expect(req.headers["content-type"]).toBe("application/json");
|
|
19
|
-
expect(req.query.a).toBe("1");
|
|
20
|
-
expect(req.params.id).toBe("123");
|
|
21
|
-
expect(req.body.x).toBe(1);
|
|
22
|
-
expect(req.ip).toBe("127.0.0.1");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("retourne un header via header()", () => {
|
|
26
|
-
const req = new Request({
|
|
27
|
-
method: "GET",
|
|
28
|
-
path: "/",
|
|
29
|
-
headers: { "x-test": "ok" },
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
expect(req.header("x-test")).toBe("ok");
|
|
33
|
-
});
|
|
34
|
-
});
|
|
1
|
+
import { Request } from "../request";
|
|
2
|
+
import { describe, it, expect } from "@jest/globals";
|
|
3
|
+
|
|
4
|
+
describe("Request", () => {
|
|
5
|
+
it("crée une requête immuable avec les bonnes propriétés", () => {
|
|
6
|
+
const req = new Request({
|
|
7
|
+
method: "GET",
|
|
8
|
+
path: "/test",
|
|
9
|
+
headers: { "content-type": "application/json" },
|
|
10
|
+
query: { a: "1" },
|
|
11
|
+
params: { id: "123" },
|
|
12
|
+
body: { x: 1 },
|
|
13
|
+
ip: "127.0.0.1",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
expect(req.method).toBe("GET");
|
|
17
|
+
expect(req.path).toBe("/test");
|
|
18
|
+
expect(req.headers["content-type"]).toBe("application/json");
|
|
19
|
+
expect(req.query.a).toBe("1");
|
|
20
|
+
expect(req.params.id).toBe("123");
|
|
21
|
+
expect(req.body.x).toBe(1);
|
|
22
|
+
expect(req.ip).toBe("127.0.0.1");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("retourne un header via header()", () => {
|
|
26
|
+
const req = new Request({
|
|
27
|
+
method: "GET",
|
|
28
|
+
path: "/",
|
|
29
|
+
headers: { "x-test": "ok" },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(req.header("x-test")).toBe("ok");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Response } from "../../http/response";
|
|
2
|
-
import { describe, it, expect, jest } from "@jest/globals";
|
|
3
|
-
|
|
4
|
-
describe("Response", () => {
|
|
5
|
-
it("enregistre le status et les headers", () => {
|
|
6
|
-
const raw = {
|
|
7
|
-
setHeader: jest.fn(),
|
|
8
|
-
end: jest.fn(),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const res = new Response(raw);
|
|
12
|
-
|
|
13
|
-
res.status(201).header("x-test", "ok").send("hello");
|
|
14
|
-
|
|
15
|
-
expect(raw.setHeader).toHaveBeenCalledWith("x-test", "ok");
|
|
16
|
-
expect(raw.end).toHaveBeenCalledWith("hello");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("envoie du JSON", () => {
|
|
20
|
-
const raw = {
|
|
21
|
-
setHeader: jest.fn(),
|
|
22
|
-
end: jest.fn(),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const res = new Response(raw);
|
|
26
|
-
|
|
27
|
-
res.json({ a: 1 });
|
|
28
|
-
|
|
29
|
-
expect(raw.setHeader).toHaveBeenCalledWith(
|
|
30
|
-
"content-type",
|
|
31
|
-
"application/json",
|
|
32
|
-
);
|
|
33
|
-
expect(raw.end).toHaveBeenCalledWith(JSON.stringify({ a: 1 }));
|
|
34
|
-
});
|
|
35
|
-
});
|
|
1
|
+
import { Response } from "../../http/response";
|
|
2
|
+
import { describe, it, expect, jest } from "@jest/globals";
|
|
3
|
+
|
|
4
|
+
describe("Response", () => {
|
|
5
|
+
it("enregistre le status et les headers", () => {
|
|
6
|
+
const raw = {
|
|
7
|
+
setHeader: jest.fn(),
|
|
8
|
+
end: jest.fn(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const res = new Response(raw);
|
|
12
|
+
|
|
13
|
+
res.status(201).header("x-test", "ok").send("hello");
|
|
14
|
+
|
|
15
|
+
expect(raw.setHeader).toHaveBeenCalledWith("x-test", "ok");
|
|
16
|
+
expect(raw.end).toHaveBeenCalledWith("hello");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("envoie du JSON", () => {
|
|
20
|
+
const raw = {
|
|
21
|
+
setHeader: jest.fn(),
|
|
22
|
+
end: jest.fn(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const res = new Response(raw);
|
|
26
|
+
|
|
27
|
+
res.json({ a: 1 });
|
|
28
|
+
|
|
29
|
+
expect(raw.setHeader).toHaveBeenCalledWith(
|
|
30
|
+
"content-type",
|
|
31
|
+
"application/json",
|
|
32
|
+
);
|
|
33
|
+
expect(raw.end).toHaveBeenCalledWith(JSON.stringify({ a: 1 }));
|
|
34
|
+
});
|
|
35
|
+
});
|