@rsdk/core 5.8.0-next.5 → 5.8.0-next.7
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/package.json +2 -2
- package/testFuzz/tracing-interceptor/corpus_samples/input_data_01 +4 -0
- package/testFuzz/tracing-interceptor/corpus_samples/input_data_02 +4 -0
- package/testFuzz/tracing-interceptor/corpus_samples/input_data_03 +4 -0
- package/testFuzz/tracing-interceptor/tracing.interceptor.ts +91 -0
- package/tsconfig.build.json +1 -0
- package/tsconfig.fuzzing.json +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/core",
|
|
3
|
-
"version": "5.8.0-next.
|
|
3
|
+
"version": "5.8.0-next.7",
|
|
4
4
|
"description": "Nestjs based microservice chassis",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"optional": true
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "377615d43c65f95746213e3ddc5384275f38f721"
|
|
53
53
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { AsyncContextStorage } from '@rsdk/actx/dist/async-context.storage'; // TODO: исправить после влития PR по ACTX
|
|
3
|
+
|
|
4
|
+
import { InternalException, ProtocolDetector } from '../../src';
|
|
5
|
+
import { DEFAULT_TRACING_HEADERS } from '../../src/tracing/constants';
|
|
6
|
+
import { TracingInterceptor } from '../../src/tracing/tracing.interceptor';
|
|
7
|
+
import type {
|
|
8
|
+
GenericHeaders,
|
|
9
|
+
WithGenericHeaders,
|
|
10
|
+
} from '../../src/types/transports';
|
|
11
|
+
|
|
12
|
+
interface Input {
|
|
13
|
+
type: string;
|
|
14
|
+
headerKey: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class LoggerMock {
|
|
18
|
+
trace(): void {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const extractHeaders = (ctx: ExecutionContext): GenericHeaders => ({
|
|
22
|
+
get: (key: string) => ctx.getArgByIndex(0).headers[key],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const transport = {
|
|
26
|
+
extractHeaders,
|
|
27
|
+
getProtocol: (): string => 'some-transport-protocol',
|
|
28
|
+
matchByContext: (ctx: ArgumentsHost): boolean => ctx.getType() === 'http',
|
|
29
|
+
} as any;
|
|
30
|
+
|
|
31
|
+
const plugin = {
|
|
32
|
+
tracingHeadersExtractors: (): {
|
|
33
|
+
protocol: string;
|
|
34
|
+
extractor: WithGenericHeaders;
|
|
35
|
+
}[] => [
|
|
36
|
+
{
|
|
37
|
+
protocol: 'some-plugin-protocol',
|
|
38
|
+
extractor: { extractHeaders },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
} as any;
|
|
42
|
+
|
|
43
|
+
const tracingInterceptor = new TracingInterceptor(
|
|
44
|
+
new LoggerMock() as any,
|
|
45
|
+
new Set([transport]),
|
|
46
|
+
new Set([plugin]),
|
|
47
|
+
DEFAULT_TRACING_HEADERS,
|
|
48
|
+
new ProtocolDetector([transport]),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const callHandler = {
|
|
52
|
+
handle: () => {},
|
|
53
|
+
} as any;
|
|
54
|
+
|
|
55
|
+
export async function fuzz(buffer: Buffer): Promise<any> {
|
|
56
|
+
try {
|
|
57
|
+
const input = parseInput(buffer);
|
|
58
|
+
if (!input) return;
|
|
59
|
+
|
|
60
|
+
const ctx: any = {
|
|
61
|
+
getType: () => input.type,
|
|
62
|
+
getArgByIndex: (_: number) => ({
|
|
63
|
+
headers: { [input.headerKey]: 'some-value' },
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
AsyncContextStorage.run(new Map(), () => {
|
|
68
|
+
tracingInterceptor.intercept(ctx, callHandler as any);
|
|
69
|
+
});
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof InternalException) return;
|
|
72
|
+
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseInput(buffer: Buffer): Input | null {
|
|
77
|
+
let input: any;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
input = JSON.parse(buffer.toString());
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (typeof input !== 'object' || input === null) return null;
|
|
86
|
+
if (typeof input.type !== 'string') return null;
|
|
87
|
+
if (typeof input.headerKey !== 'string') return null;
|
|
88
|
+
|
|
89
|
+
return input;
|
|
90
|
+
}
|
|
91
|
+
}
|
package/tsconfig.build.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"removeComments": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"noUnusedParameters": false,
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"src/**/*",
|
|
13
|
+
"testFuzz/**/*"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"node_modules",
|
|
17
|
+
"test",
|
|
18
|
+
"dist",
|
|
19
|
+
"__tests__",
|
|
20
|
+
"**/*spec.ts",
|
|
21
|
+
"**/*.test.ts",
|
|
22
|
+
"**/*.test.e2e.ts",
|
|
23
|
+
"**/*.test.manual-e2e.ts",
|
|
24
|
+
]
|
|
25
|
+
}
|