@@ -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 } )
0 commit comments