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 @@ -14,11 +14,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
2 changes: 1 addition & 1 deletion models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function create(userId) {

async function renew(sessionId) {
const expiresAt = new Date(Date.now() + EXPIRATION_IN_MILLISECONDS);
const renewedSessionObject = runUpdateQuery(sessionId, expiresAt);
const renewedSessionObject = await runUpdateQuery(sessionId, expiresAt);
return renewedSessionObject;

async function runUpdateQuery(sessionId, expiresAt) {
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/api/v1/user/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ describe("GET api/v1/user", () => {
action: "Verifique se este usuário está logado e tente novamente.",
status_code: 401,
});

// Set-Cookie assertions
const parsedSetCookie = setCookieParser(response, {
map: true,
});

expect(parsedSetCookie.session_id).toEqual({
name: "session_id",
value: "invalid",
maxAge: -1,
path: "/",
httpOnly: true,
});
});
});
});