@@ -256,6 +256,29 @@ def test_event_source_unsupported(self):
256256 self .assertEqual (event_source .to_string (), "unknown" )
257257 self .assertEqual (event_source_arn , None )
258258
259+ def test_event_source_with_non_dict_request_context (self ):
260+ # Test with requestContext as a string instead of a dict
261+ event = {"requestContext" : "not_a_dict" }
262+ event_source = parse_event_source (event )
263+ # Should still return a valid event source (unknown in this case)
264+ self .assertEqual (event_source .to_string (), "unknown" )
265+
266+ def test_event_source_with_invalid_domain_name (self ):
267+ # Test with domainName that isn't a string
268+ event = {"requestContext" : {"stage" : "prod" , "domainName" : 12345 }}
269+ event_source = parse_event_source (event )
270+ # Should detect as API Gateway since stage is present
271+ self .assertEqual (event_source .to_string (), "api-gateway" )
272+
273+ def test_detect_lambda_function_url_domain_with_invalid_input (self ):
274+ from datadog_lambda .trigger import detect_lambda_function_url_domain
275+ # Test with non-string input
276+ self .assertFalse (detect_lambda_function_url_domain (None ))
277+ self .assertFalse (detect_lambda_function_url_domain (12345 ))
278+ self .assertFalse (detect_lambda_function_url_domain ({"not" : "a-string" }))
279+ # Test with string that would normally cause an exception when split
280+ self .assertFalse (detect_lambda_function_url_domain ("" ))
281+
259282
260283class GetTriggerTags (unittest .TestCase ):
261284 def test_extract_trigger_tags_api_gateway (self ):
@@ -530,6 +553,41 @@ def test_extract_trigger_tags_list_type_event(self):
530553 tags = extract_trigger_tags (event , ctx )
531554 self .assertEqual (tags , {})
532555
556+ def test_extract_http_tags_with_invalid_request_context (self ):
557+ from datadog_lambda .trigger import extract_http_tags
558+ # Test with requestContext as a string instead of a dict
559+ event = {"requestContext" : "not_a_dict" , "path" : "/test" , "httpMethod" : "GET" }
560+ http_tags = extract_http_tags (event )
561+ # Should still extract valid tags from the event
562+ self .assertEqual (http_tags , {"http.url_details.path" : "/test" , "http.method" : "GET" })
563+
564+ def test_extract_http_tags_with_invalid_apigateway_http (self ):
565+ from datadog_lambda .trigger import extract_http_tags
566+ # Test with http in requestContext that's not a dict
567+ event = {
568+ "requestContext" : {"stage" : "prod" , "http" : "not_a_dict" },
569+ "version" : "2.0"
570+ }
571+ http_tags = extract_http_tags (event )
572+ # Should not raise an exception
573+ self .assertEqual (http_tags , {})
574+
575+ def test_extract_http_tags_with_invalid_headers (self ):
576+ from datadog_lambda .trigger import extract_http_tags
577+ # Test with headers that's not a dict
578+ event = {"headers" : "not_a_dict" }
579+ http_tags = extract_http_tags (event )
580+ # Should not raise an exception
581+ self .assertEqual (http_tags , {})
582+
583+ def test_extract_http_tags_with_invalid_route (self ):
584+ from datadog_lambda .trigger import extract_http_tags
585+ # Test with routeKey that would cause a split error
586+ event = {"routeKey" : 12345 } # Not a string
587+ http_tags = extract_http_tags (event )
588+ # Should not raise an exception
589+ self .assertEqual (http_tags , {})
590+
533591
534592class ExtractHTTPStatusCodeTag (unittest .TestCase ):
535593 def test_extract_http_status_code_tag_from_response_dict (self ):
0 commit comments