@@ -532,6 +532,68 @@ def test_custom_url_timeout_and_identifier_encoding_are_used_for_all_requests():
532532 assert objects (result , "vulnerability" )
533533
534534
535+ def test_misp_null_configuration_reaches_the_api_and_keeps_default_enrichment ():
536+ query = {
537+ "module" : "vulnerability_lookup" ,
538+ "attribute" : {"type" : "vulnerability" , "value" : CVE , "uuid" : UUID },
539+ "config" : dict .fromkeys (vulnerability_lookup .moduleconfig ),
540+ "timeout" : 10 ,
541+ }
542+ query ["config" ]["timeout" ] = "80"
543+ with patch ("requests.get" , side_effect = [response (cve ()), response ({}, 404 ), response ({}, 404 )]) as get :
544+ result = vulnerability_lookup .handler (json .dumps (query ))
545+ assert objects (result , "vulnerability" )
546+ assert get .call_count == 3
547+ main_call = get .call_args_list [0 ]
548+ assert main_call .kwargs ["timeout" ] == 80
549+ assert main_call .kwargs ["params" ] == {
550+ "with_linked" : "true" ,
551+ "with_comments" : "true" ,
552+ "with_bundles" : "true" ,
553+ "with_sightings" : "true" ,
554+ "with_meta" : "true" ,
555+ }
556+ assert get .call_args_list [- 1 ].kwargs ["params" ]["per_page" ] == 50
557+ assert not any (call .args [0 ].endswith ("/timeline" ) for call in get .call_args_list )
558+
559+
560+ @pytest .mark .parametrize ("unset" , [None , "" , " " ])
561+ def test_unset_numeric_and_boolean_options_use_defaults (unset ):
562+ config = dict .fromkeys (vulnerability_lookup .moduleconfig , unset )
563+ _ , get = run (cve (), config = config , extra_responses = [response ({}, 404 ), response ({}, 404 )])
564+ assert get .call_args_list [0 ].kwargs ["timeout" ] == 30
565+ assert get .call_args_list [0 ].kwargs ["params" ]["with_linked" ] == "true"
566+ assert get .call_args_list [- 1 ].kwargs ["params" ]["per_page" ] == 50
567+
568+
569+ @pytest .mark .parametrize ("unset" , [None , "" , " " ])
570+ def test_unset_cpe_settings_use_defaults (unset ):
571+ config = dict .fromkeys (vulnerability_lookup .moduleconfig , unset )
572+ result , get = run (
573+ {"cvelistv5" : [cve ()]}, attribute_type = "cpe" , value = "cpe:2.3:a:example:app:*:*:*:*:*:*:*:*" , config = config
574+ )
575+ assert objects (result , "vulnerability" )
576+ assert get .call_args .kwargs ["params" ] == {"per_page" : 50 , "page" : 1 , "source" : "cvelistv5" }
577+
578+
579+ @pytest .mark .parametrize ("disabled" , [False , "false" , 0 , "0" ])
580+ def test_explicit_false_flags_are_not_replaced_by_defaults (disabled ):
581+ config = dict .fromkeys (vulnerability_lookup .moduleconfig )
582+ config .update ({name : disabled for name in vulnerability_lookup .moduleconfig if name .startswith ("with_" )})
583+ _ , get = run (cve (), config = config )
584+ assert get .call_count == 1
585+ assert all (value == "false" for value in get .call_args .kwargs ["params" ].values ())
586+
587+
588+ @pytest .mark .parametrize ("zero" , [0 , "0" ])
589+ def test_explicit_zero_related_limit_is_preserved (zero ):
590+ config = dict .fromkeys (vulnerability_lookup .moduleconfig )
591+ config .update ({"max_related" : zero , "with_epss" : False })
592+ result , get = run (cve (), config = config )
593+ assert objects (result , "vulnerability" )
594+ assert get .call_count == 1
595+
596+
535597@pytest .mark .parametrize ("query" , ["invalid" , "[]" , "null" , "{}" , '{"attribute": []}' ])
536598def test_invalid_input_is_an_error (query ):
537599 with patch ("requests.get" ) as get :
0 commit comments