Skip to content

Commit 3dfaec5

Browse files
committed
chore(execute): tidy credential-actor tests and comment
1 parent e39ae88 commit 3dfaec5

2 files changed

Lines changed: 24 additions & 33 deletions

File tree

‎apps/sim/app/api/workflows/[id]/execute/route.test.ts‎

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,13 +2241,16 @@ describe('workflow execute async route', () => {
22412241
})
22422242

22432243
describe('credential actor is derived from the authenticated caller', () => {
2244-
it.each([
2245-
['session without isClientSession', EXECUTION_CALLERS[0], true],
2246-
['personal API key', EXECUTION_CALLERS[1], true],
2247-
['workspace API key', EXECUTION_CALLERS[2], false],
2248-
['public API', EXECUTION_CALLERS[3], false],
2249-
['internal JWT', EXECUTION_CALLERS[4], false],
2250-
] as const)('%s: authenticated user is actor = %s', async (_name, caller, expected) => {
2244+
const ACTS_AS_AUTHENTICATED_USER: Record<string, boolean> = {
2245+
session: true,
2246+
'personal API key': true,
2247+
'workspace API key': false,
2248+
'public API': false,
2249+
'internal JWT': false,
2250+
}
2251+
2252+
it.each(EXECUTION_CALLERS)('$caseName', async (caller) => {
2253+
const expected = ACTS_AS_AUTHENTICATED_USER[caller.caseName]
22512254
configureExecutionCaller(caller)
22522255

22532256
const response = await POST(
@@ -2259,39 +2262,29 @@ describe('workflow execute async route', () => {
22592262
expect(mockPreprocessExecution).toHaveBeenCalledWith(
22602263
expect.objectContaining({ useAuthenticatedUserAsActor: expected })
22612264
)
2262-
const executionCall = mockExecuteWorkflowCore.mock.calls[0][0]
2263-
const snapshot =
2264-
typeof executionCall.snapshot === 'string'
2265-
? JSON.parse(executionCall.snapshot)
2266-
: executionCall.snapshot
2267-
expect(snapshot.metadata.enforceCredentialAccess).toBe(expected)
2268-
})
2269-
2270-
it('authorizes a session run that defaults to draft state at write', async () => {
2271-
const response = await POST(
2272-
createMockRequest('POST', { input: {} }, { 'Content-Type': 'application/json' }),
2273-
createRouteContext({ id: 'workflow-1' })
2274-
)
2275-
2276-
expect(response.status).toBe(200)
2277-
expect(mockAuthorizeWorkflowByWorkspacePermission).toHaveBeenCalledWith(
2278-
expect.objectContaining({ action: 'write' })
2279-
)
2265+
expect(
2266+
mockExecuteWorkflowCore.mock.calls[0][0].snapshot.metadata.enforceCredentialAccess
2267+
).toBe(expected)
22802268
})
2269+
})
22812270

2282-
it('authorizes a session run of the deployed state at read', async () => {
2271+
describe('execution access level', () => {
2272+
it.each([
2273+
[{}, 'write'],
2274+
[{ useDraftState: false }, 'read'],
2275+
] as const)('session run with %o authorizes at %s', async (bodyExtra, action) => {
22832276
const response = await POST(
22842277
createMockRequest(
22852278
'POST',
2286-
{ input: {}, useDraftState: false },
2279+
{ input: {}, ...bodyExtra },
22872280
{ 'Content-Type': 'application/json' }
22882281
),
22892282
createRouteContext({ id: 'workflow-1' })
22902283
)
22912284

22922285
expect(response.status).toBe(200)
22932286
expect(mockAuthorizeWorkflowByWorkspacePermission).toHaveBeenCalledWith(
2294-
expect.objectContaining({ action: 'read' })
2287+
expect.objectContaining({ action })
22952288
)
22962289
})
22972290
})

‎apps/sim/app/api/workflows/[id]/execute/route.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,9 @@ async function handleExecutePost(
987987
}
988988

989989
/**
990-
* Sessions and personal keys preserve the authenticated human as actor.
991-
* Preprocessing resolves the workspace payer independently. This follows
992-
* the auth type, never the body's `isClientSession`: a session runs the
993-
* draft it can edit, so letting it opt out would run that draft with the
994-
* billing account's credentials.
990+
* Sessions and personal keys act as the authenticated human. Keyed on auth
991+
* type, not the body's `isClientSession`, so a session cannot opt out and
992+
* run its editable draft on the billing account's credentials.
995993
*/
996994
const useAuthenticatedUserAsActor =
997995
auth.authType === AuthType.SESSION ||

0 commit comments

Comments
 (0)