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
21 changes: 21 additions & 0 deletions src/utils/getAuthCookieDomain/getAuthCookieDomain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getAuthCookieDomain } from "./getAuthCookieDomain";

describe("getAuthCookieDomain", () => {
it.each(["finditem.kr", "www.finditem.kr", "a.finditem.kr", "a.finditem.kr:443"])(
"%s이면 상위 도메인을 반환한다",
(host) => {
expect(getAuthCookieDomain(host)).toBe(".finditem.kr");
}
);

it.each(["localhost:3000", "evilfinditem.kr", "finditem.kr.evil.com", ""])(
"%s이면 도메인을 붙이지 않는다",
(host) => {
expect(getAuthCookieDomain(host)).toBeUndefined();
}
);

it("Host 헤더가 없으면 도메인을 붙이지 않는다", () => {
expect(getAuthCookieDomain(null)).toBeUndefined();
});
});
4 changes: 4 additions & 0 deletions tests/e2e/auth-login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ test.describe("관리자 로그인 (/login)", () => {

await expect(page).toHaveURL(/\/login\?reason=forbidden$/);
await expect(page.getByText("관리자 권한이 있는 계정으로 로그인해 주세요.")).toBeVisible();

// 토큰은 운영 앱과 공유하므로 권한이 없어도 지우지 않는다.
const cookieNames = (await context.cookies()).map((cookie) => cookie.name);
expect(cookieNames).toEqual(expect.arrayContaining(["access_token", "refresh_token"]));
});

test("관리자 계정으로 로그인 화면에 접근하면 관리자 메인으로 이동한다", async ({
Expand Down
Loading