all the haul
This commit is contained in:
@@ -9,6 +9,7 @@ const { mockApi, mockOptima, mockIsInvalidSignatureError, mockRedirect } =
|
||||
auth: {},
|
||||
user: {
|
||||
isLoggedIn: vi.fn(),
|
||||
isLoggedInServer: vi.fn(),
|
||||
logout: vi.fn(),
|
||||
refreshSession: vi.fn(),
|
||||
fetchInfo: vi.fn(),
|
||||
@@ -128,7 +129,7 @@ describe("hooks.server handle", () => {
|
||||
|
||||
it("redirects to / when visiting /login while already logged in", async () => {
|
||||
mockApi.get.mockResolvedValueOnce({ status: 418 });
|
||||
mockOptima.user.isLoggedIn.mockReturnValue(true);
|
||||
mockOptima.user.isLoggedInServer.mockReturnValue(true);
|
||||
const event = createMockEvent({
|
||||
url: new URL("http://localhost/login"),
|
||||
});
|
||||
@@ -147,7 +148,7 @@ describe("hooks.server handle", () => {
|
||||
|
||||
it("resolves /login normally when user is not logged in", async () => {
|
||||
mockApi.get.mockResolvedValueOnce({ status: 418 });
|
||||
mockOptima.user.isLoggedIn.mockReturnValue(false);
|
||||
mockOptima.user.isLoggedInServer.mockReturnValue(false);
|
||||
const event = createMockEvent({
|
||||
url: new URL("http://localhost/login"),
|
||||
});
|
||||
@@ -188,7 +189,7 @@ describe("hooks.server handle", () => {
|
||||
sub: "user-1",
|
||||
};
|
||||
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
||||
"base64url",
|
||||
"base64url"
|
||||
);
|
||||
const fakeJwt = `header.${encodedPayload}.signature`;
|
||||
|
||||
@@ -216,7 +217,7 @@ describe("hooks.server handle", () => {
|
||||
// Create an expired JWT
|
||||
const payload = { exp: Math.floor(Date.now() / 1000) - 100, sub: "u1" };
|
||||
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
||||
"base64url",
|
||||
"base64url"
|
||||
);
|
||||
const fakeJwt = `h.${encodedPayload}.s`;
|
||||
|
||||
@@ -241,7 +242,7 @@ describe("hooks.server handle", () => {
|
||||
expect(event.cookies.set).toHaveBeenCalledWith(
|
||||
"accessToken",
|
||||
"new-access",
|
||||
{ path: "/" },
|
||||
{ path: "/" }
|
||||
);
|
||||
expect(resolve).toHaveBeenCalledWith(event);
|
||||
});
|
||||
@@ -252,7 +253,7 @@ describe("hooks.server handle", () => {
|
||||
mockApi.get.mockResolvedValueOnce({ status: 418 });
|
||||
const payload = { exp: Math.floor(Date.now() / 1000) - 100, sub: "u1" };
|
||||
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
||||
"base64url",
|
||||
"base64url"
|
||||
);
|
||||
const fakeJwt = `h.${encodedPayload}.s`;
|
||||
|
||||
@@ -360,7 +361,7 @@ describe("hooks.server handle", () => {
|
||||
mockApi.get.mockResolvedValueOnce({ status: 418 });
|
||||
mockIsInvalidSignatureError.mockReturnValue(false);
|
||||
mockOptima.user.refreshSession.mockRejectedValueOnce(
|
||||
new Error("Refresh failed"),
|
||||
new Error("Refresh failed")
|
||||
);
|
||||
|
||||
const event = createMockEvent({
|
||||
@@ -395,7 +396,7 @@ describe("hooks.server handle", () => {
|
||||
.mockReturnValueOnce(false)
|
||||
.mockReturnValueOnce(true);
|
||||
mockOptima.user.refreshSession.mockRejectedValueOnce(
|
||||
new Error("invalid signature"),
|
||||
new Error("invalid signature")
|
||||
);
|
||||
|
||||
const event = createMockEvent({
|
||||
@@ -415,7 +416,7 @@ describe("hooks.server handle", () => {
|
||||
}
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
"Invalid refresh token signature — forcing logout.",
|
||||
"Invalid refresh token signature — forcing logout."
|
||||
);
|
||||
expect(mockOptima.user.logout).toHaveBeenCalled();
|
||||
warnSpy.mockRestore();
|
||||
|
||||
Reference in New Issue
Block a user