@@ -89,23 +89,65 @@ def test_secrets_manager_different_region_but_still_fips(self, mock_boto3_client
8989
9090 @patch ("datadog_lambda.config.Config.fips_mode_enabled" , True )
9191 @patch ("botocore.session.Session.create_client" )
92- def test_ssm_fips_endpoint (self , mock_boto3_client ):
92+ def test_ssm_fips_endpoint_supported_region (self , mock_boto3_client ):
9393 mock_client = MagicMock ()
9494 mock_client .get_parameter .return_value = {
9595 "Parameter" : {"Value" : "test-api-key" }
9696 }
9797 mock_boto3_client .return_value = mock_client
9898
99- os .environ ["AWS_REGION" ] = "us-gov-west -1"
99+ os .environ ["AWS_REGION" ] = "us-east -1"
100100 os .environ ["DD_API_KEY_SSM_NAME" ] = "test-ssm-param"
101101
102102 api_key = api .get_api_key ()
103103
104104 mock_boto3_client .assert_called_with (
105- "ssm" , endpoint_url = "https://ssm-fips.us-gov-west -1.amazonaws.com"
105+ "ssm" , endpoint_url = "https://ssm-fips.us-east -1.amazonaws.com"
106106 )
107107 self .assertEqual (api_key , "test-api-key" )
108108
109+ @patch ("datadog_lambda.config.Config.fips_mode_enabled" , True )
110+ @patch ("datadog_lambda.config.Config.is_gov_region" , True )
111+ @patch ("botocore.session.Session.create_client" )
112+ def test_ssm_gov_endpoint (self , mock_boto3_client ):
113+ mock_client = MagicMock ()
114+ mock_client .get_parameter .return_value = {
115+ "Parameter" : {"Value" : "test-api-key" }
116+ }
117+ mock_boto3_client .return_value = mock_client
118+
119+ os .environ ["AWS_REGION" ] = "us-gov-west-1"
120+ os .environ ["DD_API_KEY_SSM_NAME" ] = "test-ssm-param"
121+
122+ api_key = api .get_api_key ()
123+
124+ mock_boto3_client .assert_called_with ("ssm" , endpoint_url = None )
125+ self .assertEqual (api_key , "test-api-key" )
126+
127+ @patch ("datadog_lambda.config.Config.fips_mode_enabled" , True )
128+ @patch ("botocore.session.Session.create_client" )
129+ def test_ssm_fips_endpoint_unsupported_region (self , mock_boto3_client ):
130+ mock_client = MagicMock ()
131+ mock_client .get_parameter .return_value = {
132+ "Parameter" : {"Value" : "test-api-key" }
133+ }
134+ mock_boto3_client .return_value = mock_client
135+
136+ os .environ ["AWS_REGION" ] = "eu-west-1"
137+ os .environ ["DD_API_KEY_SSM_NAME" ] = "test-ssm-param"
138+
139+ with self .assertLogs ("datadog_lambda.api" , level = "WARNING" ) as log_context :
140+ api_key = api .get_api_key ()
141+
142+ mock_boto3_client .assert_called_with ("ssm" , endpoint_url = None )
143+ self .assertEqual (api_key , "test-api-key" )
144+ self .assertTrue (
145+ any (
146+ "does not support SSM FIPS endpoints" in log_msg
147+ for log_msg in log_context .output
148+ )
149+ )
150+
109151 @patch ("datadog_lambda.config.Config.fips_mode_enabled" , True )
110152 @patch ("botocore.session.Session.create_client" )
111153 @patch ("datadog_lambda.api.decrypt_kms_api_key" )
0 commit comments