Skip to content

Commit b55b5ba

Browse files
committed
Refactored Nest framework test suite to use inline expectations
1 parent 74c9a06 commit b55b5ba

File tree

7 files changed

+101
-100
lines changed

7 files changed

+101
-100
lines changed

javascript/ql/test/library-tests/frameworks/Nest/global/validation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ export class Controller {
88
) { }
99

1010
@Get()
11-
route1(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
12-
if (Math.random()) return unvalidated; // NOT OK
13-
return validatedObj.key; // OK
14-
}
11+
route1(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
12+
if (Math.random()) return unvalidated; // $responseSendArgument
13+
return validatedObj.key; // $responseSendArgument
14+
} // $routeHandler
1515

1616
@Get()
1717
route2(@Query('x') x: string) {
1818
this.foo.fooMethod(x);
19-
}
19+
} // $routeHandler
2020
}
2121

2222
class Struct {

javascript/ql/test/library-tests/frameworks/Nest/local/customDecorator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Get, createParamDecorator, ExecutionContext } from '@nestjs/common';
22

33
export const SneakyQueryParam = createParamDecorator(
44
(data: unknown, ctx: ExecutionContext) => {
5-
const request = ctx.switchToHttp().getRequest();
5+
const request = ctx.switchToHttp().getRequest(); // $requestSource
66
return request.query.sneakyQueryParam;
77
},
88
);
@@ -16,11 +16,11 @@ export const SafeParam = createParamDecorator(
1616
export class Controller {
1717
@Get()
1818
sneaky(@SneakyQueryParam() value) {
19-
return value; // NOT OK
20-
}
19+
return value; // $responseSendArgument
20+
} // $routeHandler
2121

2222
@Get()
2323
safe(@SafeParam() value) {
24-
return value; // OK
25-
}
24+
return value; // $responseSendArgument
25+
} // $routeHandler
2626
}

javascript/ql/test/library-tests/frameworks/Nest/local/customPipe.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ export class CustomPropagatingPipe implements PipeTransform {
1818
export class Controller {
1919
@Get()
2020
sanitizingPipe1(@Query('x', CustomSanitizingPipe) sanitized: number): string {
21-
return '' + sanitized; // OK
22-
}
21+
return '' + sanitized; // $responseSendArgument
22+
} // $routeHandler
2323

2424
@Get()
2525
sanitizingPipe2(@Query('x', new CustomSanitizingPipe()) sanitized: number): string {
26-
return '' + sanitized; // OK
27-
}
26+
return '' + sanitized; // $responseSendArgument
27+
} // $routeHandler
2828

2929
@Get()
3030
@UsePipes(CustomSanitizingPipe)
3131
sanitizingPipe3(@Query('x') sanitized: number): string {
32-
return '' + sanitized; // OK
33-
}
32+
return '' + sanitized; // $responseSendArgument
33+
} // $routeHandler
3434

3535
@Get()
3636
propagatingPipe1(@Query('x', CustomPropagatingPipe) unsanitized: string): string {
37-
return '' + unsanitized; // NOT OK
38-
}
37+
return '' + unsanitized; // $responseSendArgument
38+
} // $routeHandler
3939

4040
@Get()
4141
propagatingPipe2(@Query('x', new CustomPropagatingPipe()) unsanitized: string): string {
42-
return '' + unsanitized; // NOT OK
43-
}
42+
return '' + unsanitized; // $responseSendArgument
43+
} // $routeHandler
4444

4545
@Get()
4646
@UsePipes(CustomPropagatingPipe)
4747
propagatingPipe3(@Query('x') unsanitized: string): string {
48-
return '' + unsanitized; // NOT OK
49-
}
48+
return '' + unsanitized; // $responseSendArgument
49+
} // $routeHandler
5050
}

javascript/ql/test/library-tests/frameworks/Nest/local/routes.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,70 @@ export class TestController {
55
@Get('foo')
66
getFoo() {
77
return 'foo';
8-
}
8+
} // $routeHandler
99

1010
@Post('foo')
1111
postFoo() {
1212
return 'foo';
13-
}
13+
} // $routeHandler
1414

1515
@Get()
1616
getRoot() {
1717
return 'foo';
18-
}
18+
} // $routeHandler
1919

2020
@All('bar')
2121
bar() {
2222
return 'bar';
23-
}
23+
} // $routeHandler
2424

2525
@Get('requestInputs/:x')
2626
requestInputs(
2727
@Param('x') x,
2828
@Query() queryObj,
2929
@Query('name') name,
30-
@Req() req
30+
@Req() req // $requestSource
3131
) {
32-
if (Math.random()) return x; // NOT OK
33-
if (Math.random()) return queryObj; // NOT OK
34-
if (Math.random()) return name; // NOT OK
35-
if (Math.random()) return req.query.abc; // NOT OK
32+
if (Math.random()) return x; // $responseSendArgument
33+
if (Math.random()) return queryObj; // $responseSendArgument
34+
if (Math.random()) return name; // $responseSendArgument
35+
if (Math.random()) return req.query.abc; // $responseSendArgument
3636
return;
37-
}
37+
} // $routeHandler
3838

3939
@Post('post')
4040
post(@Body() body) {
41-
return body.x; // NOT OK
42-
}
41+
return body.x; // $responseSendArgument
42+
} // $routeHandler
4343

4444
@Get('redir')
4545
@Redirect('https://example.com')
4646
redir() {
4747
return {
48-
url: '//other.example.com' // OK
48+
url: '//other.example.com' // $redirectSink
4949
};
50-
}
50+
} // $routeHandler
5151

5252
@Get('redir')
5353
@Redirect('https://example.com')
5454
redir2(@Query('redirect') target) {
5555
return {
56-
url: target // NOT OK
56+
url: target // $redirectSink
5757
};
58-
}
58+
} // $routeHandler
5959

6060
@Get()
61-
explicitSend(@Req() req, @Res() res) {
62-
res.send(req.query.x) // NOT OK
63-
}
61+
explicitSend(@Req() req, @Res() res) { // $requestSource $responseSource
62+
res.send(req.query.x) // $responseSource $responseSendArgument
63+
} // $routeHandler
6464

6565
@Post()
6666
upload(@UploadedFile() file) {
67-
return file.originalname; // NOT OK
68-
}
67+
return file.originalname; // $responseSendArgument
68+
} // $routeHandler
6969

7070
@Post()
7171
uploadMany(@UploadedFiles() files) {
72-
return files[0].originalname; // NOT OK
73-
}
72+
return files[0].originalname; // $responseSendArgument
73+
} // $routeHandler
7474
}

javascript/ql/test/library-tests/frameworks/Nest/local/validation.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ import { IsIn } from 'class-validator';
44
export class Controller {
55
@Get()
66
route1(@Query('x', new ValidationPipe()) validatedObj: Struct) {
7-
return validatedObj.key; // OK
8-
}
7+
return validatedObj.key; // $responseSendArgument
8+
} // $routeHandler
99

1010
@Get()
1111
route2(@Query('x', ValidationPipe) validatedObj: Struct) {
12-
return validatedObj.key; // OK
13-
}
12+
return validatedObj.key; // $responseSendArgument
13+
} // $routeHandler
1414

1515
@Get()
1616
@UsePipes(new ValidationPipe())
1717
route3(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
18-
if (Math.random()) return validatedObj.key; // OK
19-
return unvalidated; // NOT OK
20-
}
18+
if (Math.random()) return validatedObj.key; // $responseSendArgument
19+
return unvalidated; // $responseSendArgument
20+
} // $routeHandler
2121

2222
@Get()
2323
@UsePipes(ValidationPipe)
2424
route4(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
25-
if (Math.random()) return validatedObj.key; // OK
26-
return unvalidated; // NOT OK
27-
}
25+
if (Math.random()) return validatedObj.key; // $responseSendArgument
26+
return unvalidated; // $responseSendArgument
27+
} // $routeHandler
2828
}
2929

3030
@UsePipes(new ValidationPipe())
3131
export class Controller2 {
3232
@Get()
3333
route5(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
34-
if (Math.random()) return validatedObj.key; // OK
35-
return unvalidated; // NOT OK
36-
}
34+
if (Math.random()) return validatedObj.key; // $responseSendArgument
35+
return unvalidated; // $responseSendArgument
36+
} // $routeHandler
3737
}
3838

3939
@UsePipes(ValidationPipe)
4040
export class Controller3 {
4141
@Get()
4242
route6(@Query('x') validatedObj: Struct, @Query('y') unvalidated: string) {
43-
if (Math.random()) return validatedObj.key; // OK
44-
return unvalidated; // NOT OK
45-
}
43+
if (Math.random()) return validatedObj.key; // $responseSendArgument
44+
return unvalidated; // $responseSendArgument
45+
} // $routeHandler
4646
}
4747

4848
class Struct {

javascript/ql/test/library-tests/frameworks/Nest/test.expected

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
1-
testFailures
2-
routeHandler
3-
| global/validation.ts:11:3:14:3 | route1( ... OK\\n } |
4-
| global/validation.ts:17:3:19:3 | route2( ... x);\\n } |
5-
| local/customDecorator.ts:18:3:20:3 | sneaky( ... OK\\n } |
6-
| local/customDecorator.ts:23:3:25:3 | safe(@S ... OK\\n } |
7-
| local/customPipe.ts:20:5:22:5 | sanitiz ... K\\n } |
8-
| local/customPipe.ts:25:5:27:5 | sanitiz ... K\\n } |
9-
| local/customPipe.ts:31:5:33:5 | sanitiz ... K\\n } |
10-
| local/customPipe.ts:36:5:38:5 | propaga ... K\\n } |
11-
| local/customPipe.ts:41:5:43:5 | propaga ... K\\n } |
12-
| local/customPipe.ts:47:5:49:5 | propaga ... K\\n } |
13-
| local/routes.ts:6:3:8:3 | getFoo( ... o';\\n } |
14-
| local/routes.ts:11:3:13:3 | postFoo ... o';\\n } |
15-
| local/routes.ts:16:3:18:3 | getRoot ... o';\\n } |
16-
| local/routes.ts:21:3:23:3 | bar() { ... r';\\n } |
17-
| local/routes.ts:26:3:37:3 | request ... rn;\\n } |
18-
| local/routes.ts:40:3:42:3 | post(@B ... OK\\n } |
19-
| local/routes.ts:46:3:50:3 | redir() ... };\\n } |
20-
| local/routes.ts:54:3:58:3 | redir2( ... };\\n } |
21-
| local/routes.ts:61:3:63:3 | explici ... OK\\n } |
22-
| local/routes.ts:66:3:68:3 | upload( ... OK\\n } |
23-
| local/routes.ts:71:3:73:3 | uploadM ... OK\\n } |
24-
| local/validation.ts:6:3:8:3 | route1( ... OK\\n } |
25-
| local/validation.ts:11:3:13:3 | route2( ... OK\\n } |
26-
| local/validation.ts:17:3:20:3 | route3( ... OK\\n } |
27-
| local/validation.ts:24:3:27:3 | route4( ... OK\\n } |
28-
| local/validation.ts:33:3:36:3 | route5( ... OK\\n } |
29-
| local/validation.ts:42:3:45:3 | route6( ... OK\\n } |
30-
requestSource
31-
| local/customDecorator.ts:5:21:5:51 | ctx.swi ... quest() |
32-
| local/routes.ts:30:12:30:14 | req |
33-
| local/routes.ts:61:23:61:25 | req |
34-
responseSource
35-
| local/routes.ts:61:35:61:37 | res |
36-
| local/routes.ts:62:5:62:25 | res.sen ... uery.x) |
1+
redirectSink
2+
| local/routes.ts:48:12:48:32 | '//othe ... le.com' |
3+
| local/routes.ts:56:12:56:17 | target |
374
requestInputAccess
385
| body | local/routes.ts:40:16:40:19 | body |
396
| body | local/routes.ts:66:26:66:29 | file |
@@ -60,6 +27,10 @@ requestInputAccess
6027
| parameter | local/validation.ts:33:56:33:66 | unvalidated |
6128
| parameter | local/validation.ts:42:22:42:33 | validatedObj |
6229
| parameter | local/validation.ts:42:56:42:66 | unvalidated |
30+
requestSource
31+
| local/customDecorator.ts:5:21:5:51 | ctx.swi ... quest() |
32+
| local/routes.ts:30:12:30:14 | req |
33+
| local/routes.ts:61:23:61:25 | req |
6334
responseSendArgument
6435
| global/validation.ts:12:31:12:41 | unvalidated |
6536
| global/validation.ts:13:12:13:27 | validatedObj.key |
@@ -89,6 +60,34 @@ responseSendArgument
8960
| local/validation.ts:35:12:35:22 | unvalidated |
9061
| local/validation.ts:43:31:43:46 | validatedObj.key |
9162
| local/validation.ts:44:12:44:22 | unvalidated |
92-
redirectSink
93-
| local/routes.ts:48:12:48:32 | '//othe ... le.com' |
94-
| local/routes.ts:56:12:56:17 | target |
63+
responseSource
64+
| local/routes.ts:61:35:61:37 | res |
65+
| local/routes.ts:62:5:62:25 | res.sen ... uery.x) |
66+
routeHandler
67+
| global/validation.ts:11:3:14:3 | route1( ... ent\\n } |
68+
| global/validation.ts:17:3:19:3 | route2( ... x);\\n } |
69+
| local/customDecorator.ts:18:3:20:3 | sneaky( ... ent\\n } |
70+
| local/customDecorator.ts:23:3:25:3 | safe(@S ... ent\\n } |
71+
| local/customPipe.ts:20:5:22:5 | sanitiz ... t\\n } |
72+
| local/customPipe.ts:25:5:27:5 | sanitiz ... t\\n } |
73+
| local/customPipe.ts:31:5:33:5 | sanitiz ... t\\n } |
74+
| local/customPipe.ts:36:5:38:5 | propaga ... t\\n } |
75+
| local/customPipe.ts:41:5:43:5 | propaga ... t\\n } |
76+
| local/customPipe.ts:47:5:49:5 | propaga ... t\\n } |
77+
| local/routes.ts:6:3:8:3 | getFoo( ... o';\\n } |
78+
| local/routes.ts:11:3:13:3 | postFoo ... o';\\n } |
79+
| local/routes.ts:16:3:18:3 | getRoot ... o';\\n } |
80+
| local/routes.ts:21:3:23:3 | bar() { ... r';\\n } |
81+
| local/routes.ts:26:3:37:3 | request ... rn;\\n } |
82+
| local/routes.ts:40:3:42:3 | post(@B ... ent\\n } |
83+
| local/routes.ts:46:3:50:3 | redir() ... };\\n } |
84+
| local/routes.ts:54:3:58:3 | redir2( ... };\\n } |
85+
| local/routes.ts:61:3:63:3 | explici ... ent\\n } |
86+
| local/routes.ts:66:3:68:3 | upload( ... ent\\n } |
87+
| local/routes.ts:71:3:73:3 | uploadM ... ent\\n } |
88+
| local/validation.ts:6:3:8:3 | route1( ... ent\\n } |
89+
| local/validation.ts:11:3:13:3 | route2( ... ent\\n } |
90+
| local/validation.ts:17:3:20:3 | route3( ... ent\\n } |
91+
| local/validation.ts:24:3:27:3 | route4( ... ent\\n } |
92+
| local/validation.ts:33:3:36:3 | route5( ... ent\\n } |
93+
| local/validation.ts:42:3:45:3 | route6( ... ent\\n } |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: test.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)