@@ -77,5 +77,53 @@ def test_network_upsert(self):
7777 self .assertEqual (result [1 ].value , 'noodle' )
7878
7979
80+ class TestVpnConnectionCertAuthNoSharedKey (unittest .TestCase ):
81+ """Unit test to verify that --shared-key is not required when --auth-type Certificate is used."""
82+
83+ def _build_namespace (self , auth_type = None , shared_key = None ):
84+ namespace = mock .MagicMock ()
85+ namespace .resource_group_name = 'test-rg'
86+ namespace .vnet_gateway1 = ('/subscriptions/00000000-0000-0000-0000-000000000000/'
87+ 'resourceGroups/test-rg/providers/Microsoft.Network/'
88+ 'virtualNetworkGateways/gw1' )
89+ namespace .local_gateway2 = ('/subscriptions/00000000-0000-0000-0000-000000000000/'
90+ 'resourceGroups/test-rg/providers/Microsoft.Network/'
91+ 'localNetworkGateways/lgw2' )
92+ namespace .vnet_gateway2 = None
93+ namespace .express_route_circuit2 = None
94+ namespace .shared_key = shared_key
95+ namespace .shared_key_keyvault_id = None
96+ namespace .auth_type = auth_type
97+ namespace .tags = None
98+ namespace .location = 'eastus'
99+ return namespace
100+
101+ def test_cert_auth_without_shared_key_should_not_raise (self ):
102+ """--auth-type Certificate should not require --shared-key."""
103+ from azure .cli .command_modules .network ._validators import process_vpn_connection_create_namespace
104+
105+ cmd = mock .MagicMock ()
106+ namespace = self ._build_namespace (auth_type = 'Certificate' , shared_key = None )
107+
108+ try :
109+ process_vpn_connection_create_namespace (cmd , namespace )
110+ except CLIError as e :
111+ if '--shared-key is required' in str (e ):
112+ self .fail (
113+ 'Raised CLIError for missing --shared-key even though '
114+ '--auth-type Certificate was specified.' )
115+
116+ def test_no_shared_key_without_cert_auth_should_raise (self ):
117+ """without --auth-type Certificate, missing --shared-key must raise CLIError."""
118+ from azure .cli .command_modules .network ._validators import process_vpn_connection_create_namespace
119+
120+ cmd = mock .MagicMock ()
121+ namespace = self ._build_namespace (auth_type = None , shared_key = None )
122+
123+ with self .assertRaises (CLIError ) as ctx :
124+ process_vpn_connection_create_namespace (cmd , namespace )
125+ self .assertIn ('--shared-key is required' , str (ctx .exception ))
126+
127+
80128if __name__ == '__main__' :
81129 unittest .main ()
0 commit comments