Skip to content

Commit 3e2b627

Browse files
committed
fix: block passing empty string to custom ca trust certificates flag
1 parent 4c90880 commit 3e2b627

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,13 @@ def get_custom_ca_trust_certificates(self) -> Union[List[bytes], None]:
920920
:return: List[str] or None
921921
"""
922922
custom_ca_certs_file_path = self.raw_param.get("custom_ca_trust_certificates")
923-
if not custom_ca_certs_file_path:
923+
if custom_ca_certs_file_path is None:
924924
return None
925+
# Reject empty string - user must provide a valid file path
926+
if custom_ca_certs_file_path == "":
927+
raise InvalidArgumentValueError(
928+
"custom_ca_trust_certificates cannot be an empty string. Please provide a valid file path."
929+
)
925930
if not os.path.isfile(custom_ca_certs_file_path):
926931
raise InvalidArgumentValueError(
927932
"{} is not valid file, or not accessible.".format(

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6144,6 +6144,48 @@ def test_handle_upgrade_asm(self):
61446144
istio=self.models.IstioServiceMesh(revisions=["asm-1-17", "asm-1-18"]),
61456145
))
61466146

6147+
def test_get_custom_ca_trust_certificates(self):
6148+
# Test with None - should return None
6149+
ctx_1 = AKSManagedClusterContext(
6150+
self.cmd,
6151+
AKSManagedClusterParamDict({"custom_ca_trust_certificates": None}),
6152+
self.models,
6153+
DecoratorMode.CREATE,
6154+
)
6155+
self.assertEqual(ctx_1.get_custom_ca_trust_certificates(), None)
6156+
6157+
# Test with empty string - should raise error
6158+
ctx_2 = AKSManagedClusterContext(
6159+
self.cmd,
6160+
AKSManagedClusterParamDict({"custom_ca_trust_certificates": ""}),
6161+
self.models,
6162+
DecoratorMode.CREATE,
6163+
)
6164+
with self.assertRaises(InvalidArgumentValueError):
6165+
ctx_2.get_custom_ca_trust_certificates()
6166+
6167+
# Test with valid file path - should return certificates
6168+
ctx_3 = AKSManagedClusterContext(
6169+
self.cmd,
6170+
AKSManagedClusterParamDict({"custom_ca_trust_certificates": get_test_data_file_path("certs.txt")}),
6171+
self.models,
6172+
DecoratorMode.CREATE,
6173+
)
6174+
certs = ctx_3.get_custom_ca_trust_certificates()
6175+
self.assertIsNotNone(certs)
6176+
self.assertEqual(len(certs), 2)
6177+
6178+
# Test with empty file - should return empty list (for removal)
6179+
ctx_4 = AKSManagedClusterContext(
6180+
self.cmd,
6181+
AKSManagedClusterParamDict({"custom_ca_trust_certificates": get_test_data_file_path("certs_empty.txt")}),
6182+
self.models,
6183+
DecoratorMode.CREATE,
6184+
)
6185+
certs_empty = ctx_4.get_custom_ca_trust_certificates()
6186+
self.assertIsNotNone(certs_empty)
6187+
self.assertEqual(certs_empty, [])
6188+
61476189

61486190
class AKSManagedClusterCreateDecoratorTestCase(unittest.TestCase):
61496191
def setUp(self):

0 commit comments

Comments
 (0)