Skip to content

Commit

Permalink
chore: Update auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Jan 4, 2025
1 parent 6c060e3 commit fbf607d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions control-plane/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe("extractAuthState", () => {

const result = await extractAuthState("");
expect(result).toMatchObject({
entityId: "cluster_1",
entityId: "clerk:cluster_1",
organizationId: "org_1",
organizationRole: "org:member",
canAccess: expect.any(Function),
Expand All @@ -296,7 +296,7 @@ describe("extractAuthState", () => {

const result = await extractAuthState("");
expect(result).toMatchObject({
entityId: owner.userId,
entityId: `clerk:${owner.userId}`,
organizationId: owner.organizationId,
organizationRole: "org:member",
canAccess: expect.any(Function),
Expand Down Expand Up @@ -337,7 +337,7 @@ describe("extractAuthState", () => {

owner1AuthState = await extractAuthState("");
expect(owner1AuthState).toMatchObject({
entityId: owner1.userId,
entityId: `clerk:${owner1.userId}`,
organizationId: owner1.organizationId,
organizationRole: "org:member",
canAccess: expect.any(Function),
Expand All @@ -353,7 +353,7 @@ describe("extractAuthState", () => {

owner2AuthState = await extractAuthState("");
expect(owner2AuthState).toMatchObject({
entityId: owner2.userId,
entityId: `clerk:${owner2.userId}`,
organizationId: owner2.organizationId,
organizationRole: "org:member",
canAccess: expect.any(Function),
Expand Down Expand Up @@ -426,7 +426,7 @@ describe("extractAuthState", () => {

const ownerAuthState = await extractAuthState("");
expect(ownerAuthState).toMatchObject({
entityId: admin.userId,
entityId: `clerk:${admin.userId}`,
organizationId: admin.organizationId,
organizationRole: "org:admin",
canAccess: expect.any(Function),
Expand Down Expand Up @@ -464,7 +464,7 @@ describe("extractAuthState", () => {

const ownerAuthState = await extractAuthState("");
expect(ownerAuthState).toMatchObject({
entityId: admin.userId,
entityId: `clerk:${admin.userId}`,
organizationId: admin.organizationId,
organizationRole: "org:admin",
canAccess: expect.any(Function),
Expand Down
3 changes: 3 additions & 0 deletions control-plane/src/modules/workflows/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export const getRunsByMetadata = async ({
key,
value,
limit = 10,
userId,
configId,
}: {
clusterId: string;
key: string;
value: string;
limit?: number;
configId?: string;
userId?: string
}) => {
return await db
.select({
Expand All @@ -36,6 +38,7 @@ export const getRunsByMetadata = async ({
eq(workflowMetadata.key, key),
eq(workflowMetadata.value, value),
...(configId ? [eq(workflows.config_id, configId)] : []),
...(userId ? [eq(workflows.user_id, userId)] : []),
),
)
.rightJoin(workflows, eq(workflowMetadata.workflow_id, workflows.id))
Expand Down
14 changes: 11 additions & 3 deletions control-plane/src/modules/workflows/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { initServer } from "@ts-rest/fastify";
import { dereferenceSync } from "dereference-json-schema";
import { JsonSchemaInput } from "inferable/bin/types";
import { ulid } from "ulid";
import { NotFoundError } from "../../utilities/errors";
import { AuthenticationError, NotFoundError } from "../../utilities/errors";
import { getBlobsForJobs } from "../blobs";
import { contract } from "../contract";
import { getJobReferences } from "../jobs/jobs";
Expand Down Expand Up @@ -150,7 +150,7 @@ export const runsRouter = initServer().router(

configId: runConfig?.id,

// Customer Auth
// Customer Auth context (In the future all auth types should inject context into the run)
authContext: customAuth?.context,

context: body.context,
Expand Down Expand Up @@ -281,11 +281,17 @@ export const runsRouter = initServer().router(
},
listRuns: async request => {
const { clusterId } = request.params;
const { userId, test, limit, metadata, configId } = request.query;
const { test, limit, metadata, configId } = request.query;
let { userId } = request.query;

const auth = request.request.getAuth();
await auth.canAccess({ cluster: { clusterId } });

// Custom auth can only access their own Runs
if (auth.type === "custom") {
userId = auth.entityId
}

if (metadata) {
// ?meta=key:value
const [key, value] = metadata.split(":");
Expand All @@ -305,6 +311,7 @@ export const runsRouter = initServer().router(
value,
limit,
configId,
userId
});

return {
Expand All @@ -313,6 +320,7 @@ export const runsRouter = initServer().router(
};
}


const result = await getClusterWorkflows({
clusterId,
userId,
Expand Down

0 comments on commit fbf607d

Please sign in to comment.