4
4
5
5
import pytest
6
6
7
- from orchestrator import app_settings
7
+ from oauth2_lib .fastapi import OIDCUserModel
8
+ from orchestrator import app_settings , workflow
9
+ from orchestrator .targets import Target
10
+ from orchestrator .workflow import done , init
8
11
from test .unit_tests .fixtures .workflows import add_soft_deleted_workflows # noqa: F401
12
+ from test .unit_tests .workflows import WorkflowInstanceForTests
9
13
10
14
11
15
@pytest .fixture (autouse = True )
@@ -32,6 +36,7 @@ def get_workflows_query(
32
36
workflowId
33
37
name
34
38
description
39
+ isAllowed
35
40
createdAt
36
41
steps {
37
42
name
@@ -81,6 +86,7 @@ def test_workflows_query(test_client):
81
86
assert "errors" not in result
82
87
assert len (workflows ) == 2
83
88
89
+ assert all (workflow ["isAllowed" ] for workflow in workflows )
84
90
assert all (len (workflow ["steps" ]) > 0 for workflow in workflows )
85
91
86
92
assert pageinfo == {
@@ -232,3 +238,23 @@ def test_workflows_sort_by_resource_type_desc(test_client):
232
238
"modify_note" ,
233
239
]
234
240
assert [rt ["name" ] for rt in workflows ] == expected_workflows
241
+
242
+
243
+ def test_workflows_not_allowed (test_client ):
244
+ forbidden_workflow_name = "unauthorized_workflow"
245
+
246
+ def disallow (_ : OIDCUserModel | None = None ) -> bool :
247
+ return False
248
+
249
+ @workflow (forbidden_workflow_name , target = Target .CREATE , authorize_callback = disallow )
250
+ def unauthorized_workflow ():
251
+ return init >> done
252
+
253
+ with WorkflowInstanceForTests (unauthorized_workflow , forbidden_workflow_name ):
254
+ data = get_workflows_query (filter_by = [{"field" : "name" , "value" : forbidden_workflow_name }])
255
+ response = test_client .post ("/api/graphql" , content = data , headers = {"Content-Type" : "application/json" })
256
+ assert HTTPStatus .OK == response .status_code
257
+ result = response .json ()
258
+
259
+ workflow_data = result ["data" ]["workflows" ]["page" ][0 ]
260
+ assert not workflow_data ["isAllowed" ]
0 commit comments