Skip to content

Commit 1c8f2b2

Browse files
committed
test(keto-client-wrapper): create E2E test suite
1 parent f5c3616 commit 1c8f2b2

File tree

9 files changed

+351
-2
lines changed

9 files changed

+351
-2
lines changed

package-lock.json

Lines changed: 141 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@types/jest": "^29.4.0",
3131
"@types/lodash.get": "^4.4.9",
3232
"@types/node": "18.16.9",
33+
"@types/supertest": "^6.0.2",
3334
"@typescript-eslint/eslint-plugin": "^6.9.1",
3435
"@typescript-eslint/parser": "^6.9.1",
3536
"eslint": "~8.48.0",
@@ -38,6 +39,7 @@
3839
"jest-environment-node": "^29.4.1",
3940
"nx": "17.2.8",
4041
"prettier": "^2.6.2",
42+
"supertest": "^6.3.3",
4143
"ts-jest": "^29.1.0",
4244
"ts-node": "10.9.1",
4345
"typescript": "~5.2.2",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Controller, Get, Logger, Param, UseGuards } from '@nestjs/common';
2+
3+
import { ExampleService } from './app.service.mock';
4+
import { OryAuthorizationGuard } from '../src/lib/ory-authorization.guard';
5+
import { OryPermissionChecks } from '../src/lib/ory-permission-checks.decorator';
6+
import { RelationTupleBuilder } from '@getlarge/keto-relations-parser';
7+
8+
@Controller('Example')
9+
export class ExampleController {
10+
constructor(private readonly exampleService: ExampleService) {}
11+
12+
@OryPermissionChecks((ctx) => {
13+
const req = ctx.switchToHttp().getRequest();
14+
const currentUserId = req.headers['x-current-user-id'] as string;
15+
const resourceId = req.params.id;
16+
return new RelationTupleBuilder()
17+
.subject('User', currentUserId)
18+
.isIn('owners')
19+
.of('Toy', resourceId)
20+
.toString();
21+
})
22+
@UseGuards(
23+
OryAuthorizationGuard({
24+
postCheck(relationTuple, isPermitted) {
25+
Logger.log('relationTuple', relationTuple);
26+
Logger.log('isPermitted', isPermitted);
27+
},
28+
})
29+
)
30+
@Get(':id')
31+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
32+
getExample(@Param('id') id?: string) {
33+
return this.exampleService.getExample();
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class ExampleService {
5+
getExample() {
6+
return {
7+
message: 'OK',
8+
};
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '2.7'
2+
3+
services:
4+
keto:
5+
image: oryd/keto:v0.11.1
6+
ports:
7+
- '44660:4466' # public
8+
- '44670:4467' # admin
9+
command: serve -c /home/ory/keto.yaml
10+
restart: on-failure
11+
volumes:
12+
- type: bind
13+
source: ./keto.yaml
14+
target: /home/ory/keto.yaml
15+
- type: bind
16+
source: ./namespaces.ts
17+
target: /home/ory/namespaces.ts

0 commit comments

Comments
 (0)