@@ -603,8 +603,12 @@ def _mcp_payload(server: Optional[str] = 'github') -> AIHookPayload:
603603 )
604604
605605
606- def _cached_statuses (* rows : tuple [str , str ]) -> McpServerStatuses :
607- return McpServerStatuses (servers = [{'alias' : a , 'status' : s } for a , s in rows ], fetched_at = time .time ())
606+ def _cached_statuses (* rows : tuple [str , str ], treat_unreviewed : bool = False ) -> McpServerStatuses :
607+ return McpServerStatuses (
608+ servers = [{'alias' : a , 'status' : s } for a , s in rows ],
609+ fetched_at = time .time (),
610+ treat_unreviewed_as_unauthorized = treat_unreviewed ,
611+ )
608612
609613
610614def _reported_event (mock_ctx : MagicMock ) -> tuple [AIHookOutcome , Optional [BlockReason ]]:
@@ -662,16 +666,20 @@ def test_unauthorized_mcp_server_report_then_secret_block_takes_over(
662666
663667
664668@pytest .mark .parametrize (
665- ('rows' , 'server' , 'expected_action' ),
669+ ('rows' , 'treat_unreviewed' , ' server' , 'expected_action' ),
666670 [
667- # Only explicitly Unauthorized servers are enforced.
668- ((('github' , 'Unreviewed' ),), 'github' , DecisionAction .ALLOW ),
669- ((('github' , 'Authorized' ),), 'github' , DecisionAction .ALLOW ),
670- ((), 'github' , DecisionAction .ALLOW ),
671+ # Default policy: only explicitly Unauthorized servers.
672+ ((('github' , 'Unreviewed' ),), False , 'github' , DecisionAction .ALLOW ),
673+ ((('github' , 'Authorized' ),), False , 'github' , DecisionAction .ALLOW ),
674+ ((), False , 'github' , DecisionAction .ALLOW ),
675+ # Strict: anything not Authorized, a server the platform never saw included.
676+ ((('github' , 'Unreviewed' ),), True , 'github' , DecisionAction .DENY ),
677+ ((), True , 'github' , DecisionAction .DENY ),
678+ ((('github' , 'Authorized' ),), True , 'github' , DecisionAction .ALLOW ),
671679 # One alias, several servers: the most restrictive status wins.
672- ((('github' , 'Authorized' ), ('GitHub' , 'Unauthorized' )), 'github' , DecisionAction .DENY ),
673- # No server name to check: fail open.
674- ((( 'github' , 'Unauthorized' ),) , None , DecisionAction .ALLOW ),
680+ ((('github' , 'Authorized' ), ('GitHub' , 'Unauthorized' )), False , 'github' , DecisionAction .DENY ),
681+ # No server name to check: fail open, even in strict mode .
682+ ((), True , None , DecisionAction .ALLOW ),
675683 ],
676684)
677685@patch ('cycode.cli.apps.ai_guardrails.scan.handlers._scan_text_for_secrets' , return_value = ScanOutcome ())
@@ -682,10 +690,11 @@ def test_unauthorized_mcp_server_enforcement(
682690 mock_ctx : MagicMock ,
683691 default_policy : dict [str , Any ],
684692 rows : tuple ,
693+ treat_unreviewed : bool ,
685694 server : Optional [str ],
686695 expected_action : DecisionAction ,
687696) -> None :
688- mock_statuses .return_value = _cached_statuses (* rows )
697+ mock_statuses .return_value = _cached_statuses (* rows , treat_unreviewed = treat_unreviewed )
689698 policy = _server_check_policy (default_policy )
690699
691700 result = handle_before_mcp_execution (mock_ctx , _mcp_payload (server ), policy )
0 commit comments