@@ -23,6 +23,14 @@ def mock_success_function(_event, _context):
2323 def mock_function_raises (_event , _context ):
2424 raise ValueError ("Test error" )
2525
26+ def extract_all_call_args_for_logger (self , mock_logger ) -> list :
27+ """Extracts all arguments for logger.*."""
28+ return (
29+ [ args [0 ] for args , _ in mock_logger .info .call_args_list ]
30+ + [ args [0 ] for args , _ in mock_logger .warning .call_args_list ]
31+ + [ args [0 ] for args , _ in mock_logger .error .call_args_list ]
32+ )
33+
2634 def test_successful_execution (self , mock_logger , mock_firehose_logger ):
2735 # Arrange
2836 test_correlation = "test_correlation"
@@ -65,6 +73,37 @@ def test_successful_execution(self, mock_logger, mock_firehose_logger):
6573 self .assertEqual (logged_info ['local_id' ], '12345^http://test' )
6674 self .assertEqual (logged_info ['vaccine_type' ], 'FLU' )
6775
76+ def test_successful_execution_pii (self , mock_logger , mock_firehose_logger ):
77+ """Pass personally identifiable information in an event, and ensure that it is not logged anywhere."""
78+ # Arrange
79+ test_correlation = "test_correlation"
80+ test_request = "test_request"
81+ test_supplier = "test_supplier"
82+ test_actual_path = "/test"
83+ test_resource_path = "/test"
84+
85+ self .mock_redis_client .hget .return_value = "FLU"
86+ wrapped_function = function_info (self .mock_success_function )
87+ event = {
88+ 'headers' : {
89+ 'X-Correlation-ID' : test_correlation ,
90+ 'X-Request-ID' : test_request ,
91+ 'SupplierSystem' : test_supplier
92+ },
93+ 'path' : test_actual_path ,
94+ 'requestContext' : {'resourcePath' : test_resource_path },
95+ 'body' : "{\" identifier\" : [{\" system\" : \" http://test\" , \" value\" : \" 12345\" }], \" contained\" : [{\" resourceType\" : \" Patient\" , \" id\" : \" Pat1\" , \" identifier\" : [{\" system\" : \" https://fhir.nhs.uk/Id/nhs-number\" , \" value\" : \" 9693632109\" }]}], \" protocolApplied\" : [{\" targetDisease\" : [{\" coding\" : [{\" system\" : \" http://snomed.info/sct\" , \" code\" : \" 840539006\" , \" display\" : \" Disease caused by severe acute respiratory syndrome coronavirus 2\" }]}]}]}"
96+ }
97+
98+ # Act
99+ result = wrapped_function (event , {})
100+
101+ # Assert
102+ self .assertEqual (result , "Success" )
103+
104+ for logger_info in self .extract_all_call_args_for_logger (mock_logger ):
105+ self .assertNotIn ("9693632109" , str (logger_info ))
106+
68107 def test_exception_handling (self , mock_logger , mock_firehose_logger ):
69108 # Arrange
70109 test_correlation = "failed_test_correlation"
0 commit comments