Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions infra/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ function onNoMatchHandler(request, response) {
}

function onErrorHandler(error, request, response) {
if (
error instanceof ValidationError ||
error instanceof NotFoundError ||
error instanceof UnauthorizedError
) {
if (error instanceof ValidationError || error instanceof NotFoundError) {
return response.status(error.statusCode).json(error);
}

if (error instanceof UnauthorizedError) {
clearSessionCookie(response);
return response.status(error.statusCode).json(error);
}

Expand Down
22 changes: 22 additions & 0 deletions test/integration/api/v1/user/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ describe("GET /api/v1/user", () => {
action: "Check if user is logged in and try again.",
status_code: 401,
});

// Set-Cookie assertions

const parsedCookie = setCookieParser(response, { map: true });
expect(parsedCookie.session_id).toEqual({
name: "session_id",
value: "invalid",
maxAge: -1,
path: "/",
httpOnly: true,
});
});

test("With expired session", async () => {
Expand Down Expand Up @@ -118,6 +129,17 @@ describe("GET /api/v1/user", () => {
action: "Check if user is logged in and try again.",
status_code: 401,
});

// Set-Cookie assertions

const parsedCookie = setCookieParser(response, { map: true });
expect(parsedCookie.session_id).toEqual({
name: "session_id",
value: "invalid",
maxAge: -1,
path: "/",
httpOnly: true,
});
});

test("With valid session about to expire", async () => {
Expand Down