@@ -278,21 +278,27 @@ def test_workflow_checks_grants_only_when_enabled_in_metadata(self, queryset, au
278278 queryset .return_value .filter .return_value = [knowledge (authentication = False )]
279279 self .assertEqual (access .filter_workflow_knowledge ([KID ], {}), [KID ])
280280
281- @patch .object (access , "authorized_ids" , return_value = set () )
281+ @patch .object (access , "authorized_ids" , return_value = { KID } )
282282 @patch .object (access , "QuerySet" )
283- def test_authenticated_anonymous_session_keeps_application_knowledge_access (self , queryset , authorized ):
283+ def test_anonymous_session_only_reaches_knowledge_without_authentication (self , queryset , authorized ):
284284 identity = access .identity_from_server (UID , "ANONYMOUS_USER" )
285+ self .assertIsNone (identity .user_id )
285286 for enabled in (False , True ):
286287 for authentication in (False , True ):
287288 with self .subTest (enabled = enabled , authentication = authentication ):
289+ authorized .reset_mock ()
290+ authorized .return_value = set ()
288291 queryset .return_value .filter .return_value = [
289292 knowledge (enabled = enabled , authentication = authentication )
290293 ]
291294 self .assertEqual (
292295 access .filter_workflow_knowledge ([KID , "missing-knowledge" ], {"retrieval_identity" : identity }),
293- [KID ],
296+ [] if authentication else [ KID ],
294297 )
295- authorized .assert_not_called ()
298+ if authentication :
299+ authorized .assert_called_once_with (None , [KID ])
300+ else :
301+ authorized .assert_not_called ()
296302
297303 @patch .object (access , "authorized_ids" , return_value = set ())
298304 @patch .object (access , "QuerySet" )
@@ -333,12 +339,15 @@ def test_child_tools_cannot_override_trusted_identity(self):
333339 self .assertFalse (child ["debug" ])
334340 self .assertIsNone (access .identity_from_server (UID , "APPLICATION_API_KEY" , True ).admin_user_id )
335341
342+ @patch .object (access , "authorized_ids" , return_value = set ())
336343 @patch .object (access , "QuerySet" )
337- def test_anonymous_identity_is_inherited_by_nested_tools (self , queryset ):
338- queryset .return_value .filter .return_value = [knowledge (authentication = True )]
344+ def test_anonymous_restriction_is_inherited_by_nested_tools (self , queryset , authorized ):
345+ open_item = SimpleNamespace (** {** vars (knowledge (authentication = False )), "id" : DID })
346+ queryset .return_value .filter .return_value = [knowledge (authentication = True ), open_item ]
339347 parent = {"retrieval_identity" : access .identity_from_server (UID , "ANONYMOUS_USER" )}
340- child = {"retrieval_identity" : {}, ** access .inherited_retrieval_context (parent )}
341- self .assertEqual (access .filter_workflow_knowledge ([KID ], child ), [KID ])
348+ child = {"retrieval_identity" : {"user_id" : UID }, ** access .inherited_retrieval_context (parent )}
349+ self .assertEqual (access .filter_workflow_knowledge ([KID , DID ], child ), [DID ])
350+ authorized .assert_called_once_with (None , [KID ])
342351
343352 @patch ("oss.serializers.file._check_workspace_resource_permission" )
344353 @patch ("common.auth.handle.impl.user_token.get_auth" )
0 commit comments