Skip to content

Commit

Permalink
Correctly distinguish between cases of 401 Unauthorized which actuall…
Browse files Browse the repository at this point in the history
…y means 'unauthenticated' and 403 Forbidden
  • Loading branch information
Daniel Haarhoff committed Nov 28, 2024
1 parent bf9d11a commit ca79ae7
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/http/api-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const apiPost =
TE.filterOrElse(command.isAuthorized, () =>
failureWithStatus(
'You are not authorized to perform this action',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.chain(({input, actor}) =>
Expand Down
2 changes: 1 addition & 1 deletion src/http/email-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const emailPost =
TE.filterOrElse(command.isAuthorized, () =>
failureWithStatus(
'You are not authorized to perform this action',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.chainEitherK(({input, actor}) =>
Expand Down
2 changes: 1 addition & 1 deletion src/http/form-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const formPost =
TE.filterOrElse(command.isAuthorized, () =>
failureWithStatus(
'You are not authorized to perform this action',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.chain(({input, actor}) =>
Expand Down
2 changes: 1 addition & 1 deletion src/queries/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const admin: Query = deps => user => {
return TE.left(
failureWithStatus(
'You are not authorised to see this page',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/queries/failed-imports/construct-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const constructViewModel =
TE.filterOrElseW(readModels.superUsers.is(user.memberNumber), () =>
failureWithStatus(
'You are not authorised to see this page',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.map(events => ({
Expand Down
2 changes: 1 addition & 1 deletion src/queries/log/construct-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const constructViewModel = (deps: Dependencies) => (user: User) =>
TE.filterOrElse(readModels.superUsers.is(user.memberNumber), () =>
failureWithStatus(
'You do not have the necessary permission to see this page.',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.map(RA.reverse),
Expand Down
2 changes: 1 addition & 1 deletion src/queries/logcsv/construct-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const constructViewModel = (deps: Dependencies) => (user: User) =>
TE.filterOrElse(readModels.superUsers.is(user.memberNumber), () =>
failureWithStatus(
'You do not have the necessary permission to see this page.',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
),
TE.map(events => ({events}) satisfies ViewModel)
Expand Down
2 changes: 1 addition & 1 deletion src/queries/super-users/construct-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const constructViewModel =
readModels.superUsers.is(user.memberNumber),
failureWithStatus(
'Only super-users can see this page',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)
),
TE.map(events => ({
Expand Down
2 changes: 1 addition & 1 deletion src/queries/training-status-csv/construct-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const constructViewModel =
return E.left(
failureWithStatus(
'You do not have the necessary permission to see this page.',
StatusCodes.UNAUTHORIZED
StatusCodes.FORBIDDEN
)()
);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/failure-with-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ApplicationStatusCode =
| StatusCodes.INTERNAL_SERVER_ERROR
| StatusCodes.BAD_REQUEST
| StatusCodes.UNAUTHORIZED
| StatusCodes.FORBIDDEN
| StatusCodes.NOT_FOUND
| StatusCodes.NOT_IMPLEMENTED;

Expand Down
2 changes: 1 addition & 1 deletion tests/queries/log/construct-view-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('construct-view-model', () => {
T.map(getLeftOrFail)
)();

expect(failure.status).toStrictEqual(StatusCodes.UNAUTHORIZED);
expect(failure.status).toStrictEqual(StatusCodes.FORBIDDEN);
});
});
});

0 comments on commit ca79ae7

Please sign in to comment.