Skip to content

Commit

Permalink
feat: Check cluster customer auth status
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 9, 2024
1 parent 9609a90 commit 7b7aa15
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion control-plane/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ describe("extractAuthState", () => {
describe("extractCustomerAuthState", () => {
let owner: Awaited<ReturnType<typeof createOwner>>;
beforeEach(async () => {
owner = await createOwner();
owner = await createOwner({
enableCustomerAuth: true,
});
jest.resetAllMocks();
});

Expand Down Expand Up @@ -527,6 +529,19 @@ describe("extractCustomerAuthState", () => {
});
});

it("should throw if customer auth is not enabled for cluster", async () => {
owner = await createOwner({
enableCustomerAuth: false,
});

mockCustomer.verifyCustomerProvidedAuth.mockResolvedValue({
someAuthValue: "someValue",
});

await expect(extractCustomerAuthState("abc123", owner.clusterId)).rejects.toThrow("Customer auth is not enabled for this cluster");
});


describe("isUser", () => {
it("should throw", async () => {
mockCustomer.verifyCustomerProvidedAuth.mockResolvedValue({
Expand Down
6 changes: 6 additions & 0 deletions control-plane/src/modules/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ export const extractCustomerAuthState = async (
return undefined;
}

if (!cluster.enable_customer_auth) {
throw new AuthenticationError(
"Customer auth is not enabled for this cluster",
);
}

const context = await verifyCustomerProvidedAuth({
token: token,
clusterId: clusterId,
Expand Down
1 change: 1 addition & 0 deletions control-plane/src/modules/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getClusterDetails = async (clusterId: string) => {
id: data.clusters.id,
name: data.clusters.name,
description: data.clusters.description,
enable_customer_auth: data.clusters.enable_customer_auth,
additional_context: data.clusters.additional_context,
organization_id: data.clusters.organization_id,
deleted_at: data.clusters.deleted_at,
Expand Down
2 changes: 2 additions & 0 deletions control-plane/src/modules/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as data from "../data";
export const createOwner = async (params?: {
clusterId?: string;
organizationId?: string;
enableCustomerAuth?: boolean;
}) => {
const clusterId = params?.clusterId || `test-cluster-${Math.random()}`;

Expand All @@ -15,6 +16,7 @@ export const createOwner = async (params?: {
id: clusterId,
name: clusterId,
organization_id: organizationId,
enable_customer_auth: params?.enableCustomerAuth ?? false,
})
.execute();

Expand Down

0 comments on commit 7b7aa15

Please sign in to comment.