Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop session cookies after refresh failure #168

Merged
merged 3 commits into from
Aug 16, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
push: false
license-check:
runs-on: ubuntu-latest
container: golang:1.15
container: golang:1.16
steps:
- uses: actions/checkout@v2
- name: Download License Utility
run: go get -u github.com/google/addlicense
run: go install github.com/google/addlicense@master
- name: Check License Headers
run: |
shopt -s globstar
Expand Down
2 changes: 1 addition & 1 deletion server/middleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const tokenRefresh = () => async (req, res, next) => {
} catch (error) {
console.error("Error refreshing oidc token", error);

return res.redirect("/login");
return res.oidc.logout();
}
}

Expand Down
14 changes: 7 additions & 7 deletions test/server/middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ describe("middleware", () => {
},
};
response = {
redirect: jest.fn(),
oidc: {
logout: jest.fn(),
},
};
});

Expand All @@ -104,7 +106,7 @@ describe("middleware", () => {
expect(request.accessToken).toEqual(accessToken);
expect(next).toHaveBeenCalled();
expect(refresh).not.toHaveBeenCalled();
expect(response.redirect).not.toHaveBeenCalled();
expect(response.oidc.logout).not.toHaveBeenCalled();
});

describe("the token is expired", () => {
Expand All @@ -120,19 +122,17 @@ describe("middleware", () => {
expect(request.accessToken).toEqual(nextAccessToken);
expect(refresh).toHaveBeenCalled();
expect(next).toHaveBeenCalled();
expect(response.redirect).not.toHaveBeenCalled();
expect(response.oidc.logout).not.toHaveBeenCalled();
});

it("should redirect the request to the login route if the refresh fails", async () => {
it("should end the session", async () => {
refresh.mockRejectedValue(new Error("refresh failed"));

await tokenRefresh()(request, response, next);

expect(request.accessToken).toBeUndefined();
expect(next).not.toHaveBeenCalled();
expect(response.redirect)
.toHaveBeenCalledTimes(1)
.toHaveBeenCalledWith("/login");
expect(response.oidc.logout).toHaveBeenCalledTimes(1);
});
});
});
Expand Down