Skip to content

Commit

Permalink
fix: instantiate default HTTPException with empty constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Feb 6, 2024
1 parent e7e5e53 commit a542cbd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/keto-client-wrapper/src/lib/ory-authorization.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface OryAuthorizationGuardOptions {
}

const defaultOptions: OryAuthorizationGuardOptions = {
unauthorizedFactory: (ctx, error) => {
return new ForbiddenException(error);
unauthorizedFactory: () => {
return new ForbiddenException();
},
};

Expand All @@ -43,7 +43,7 @@ export const OryAuthorizationGuard = (
if (!factories?.length) {
return true;
}
const { unauthorizedFactory } = {
const { postCheck, unauthorizedFactory } = {
...defaultOptions,
...options,
};
Expand All @@ -60,13 +60,13 @@ export const OryAuthorizationGuard = (
} catch (error) {
throw unauthorizedFactory(context, error);
}
if (options.postCheck) {
options.postCheck(relationTuple, isPermitted);
if (postCheck) {
postCheck(relationTuple, isPermitted);
}
if (!isPermitted) {
throw unauthorizedFactory(
context,
new Error(`Unauthorized access for ${relationTuple}`)
new Error(`Unauthorized access for ${relationTuple.toString()}`)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ describe('Keto client wrapper E2E', () => {
'x-current-user-id': subjectObject,
});
expect(body).toEqual({
error: 'Forbidden',
message: 'Forbidden resource',
message: 'Forbidden',
statusCode: 403,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const defaultOptions: OryAuthenticationGuardOptions = {
.getRequest()
?.headers?.authorization?.replace('Bearer ', ''),
cookieResolver: (ctx) => ctx.switchToHttp().getRequest()?.headers?.cookie,
unauthorizedFactory(ctx, error) {
return new UnauthorizedException(error);
unauthorizedFactory() {
return new UnauthorizedException();
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ describe('Kratos client wrapper E2E', () => {
Authorization: `Bearer ory_st_${randomBytes(8).toString('hex')}`,
});
expect(body).toEqual({
error: 'Forbidden',
message: 'Forbidden resource',
statusCode: 403,
message: 'Unauthorized',
statusCode: 401,
});
});
});

0 comments on commit a542cbd

Please sign in to comment.