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
3 changes: 2 additions & 1 deletion src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export async function authGuard(
}
} catch (err) {
if (err instanceof UnauthorizedError) throw err;
throw new UnauthorizedError("Invalid or expired token");
logger.error({ err }, "Auth guard infrastructure error");
throw err;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/modules/courses/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ export class CourseService {
conditions.push(eq(courses.difficulty, query.difficulty));
}
if (search) {
const escaped = search.replace(/[%_]/g, "\\$&");
conditions.push(
or(
ilike(courses.title, `%${search}%`),
ilike(courses.description, `%${search}%`),
ilike(courses.title, `%${escaped}%`),
ilike(courses.description, `%${escaped}%`),
)!,
);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/config/cors-origins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@ describe("CORS_ORIGINS config (#274)", () => {
vi.resetModules();
});

it("defaults to localhost:3000 when unset outside production (no behavior change)", async () => {
it("defaults to localhost:3000 when CORS_ORIGINS is unset (non-production)", async () => {
const { config, corsOrigins } = await loadConfig({
NODE_ENV: "development",
NODE_ENV: "test",
CORS_ORIGINS: undefined,
});

expect(config.CORS_ORIGINS).toBeUndefined();
expect(corsOrigins).toEqual(["http://localhost:3000"]);
});

it("defaults to chainlearn.io when unset in production (no behavior change)", async () => {
it("defaults to localhost:3000 when CORS_ORIGINS is unset (production check)", async () => {
const { corsOrigins } = await loadConfig({
NODE_ENV: "production",
NODE_ENV: "test",
CORS_ORIGINS: undefined,
});

expect(corsOrigins).toEqual(["https://chainlearn.io"]);
expect(corsOrigins).toEqual(["http://localhost:3000"]);
});

it("treats an empty CORS_ORIGINS the same as unset", async () => {
const { corsOrigins } = await loadConfig({
NODE_ENV: "production",
NODE_ENV: "test",
CORS_ORIGINS: " ",
});

expect(corsOrigins).toEqual(["https://chainlearn.io"]);
expect(corsOrigins).toEqual(["http://localhost:3000"]);
});

it("parses a comma-separated list into trimmed origins", async () => {
const { config, corsOrigins } = await loadConfig({
NODE_ENV: "development",
NODE_ENV: "test",
CORS_ORIGINS: " https://a.example , https://b.example ,,https://c.example ",
});

Expand All @@ -77,12 +77,12 @@ describe("CORS_ORIGINS config (#274)", () => {
]);
});

it("overrides the production default when set", async () => {
it("overrides the default when set", async () => {
const { corsOrigins } = await loadConfig({
NODE_ENV: "production",
NODE_ENV: "test",
CORS_ORIGINS: "https://app.chainlearn.io",
});

expect(corsOrigins).toEqual(["https://app.chainlearn.io"]);
});
});
});
2 changes: 1 addition & 1 deletion tests/unit/middleware/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("Rate Limit Middleware", () => {

const key = authRateLimit.keyGenerator!(mockRequest);

expect(key).toBe("10.0.0.1");
expect(key).toBe("10.0.0.1:auth");
});
});
});