@@ -308,3 +308,38 @@ def test_extraction_priority_without_x_forwarded_for(self):
308308 client_ip = RequestUtils .get_client_ip_from_request (request , options )
309309
310310 self .assertEqual ("203.0.113.1" , client_ip )
311+
312+ def test_strip_down_pii_data_from_headers (self ):
313+ headers = {
314+ 'Host' : 'net.example.com' ,
315+ 'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)' ,
316+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ,
317+ 'Accept-Language' : 'en-us,en;q=0.5' ,
318+ 'Accept-Encoding' : 'gzip,deflate' ,
319+ 'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' ,
320+ 'Keep-Alive' : '300' ,
321+ 'Connection' : 'keep-alive' ,
322+ 'Cookie' : 'PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120' ,
323+ 'Pragma' : 'no-cache' ,
324+ 'Cache-Control' : 'no-cache' ,
325+ 'authorization' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
326+ 'access_token' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
327+ 'apikey' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
328+ 'password' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
329+ 'passwd' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
330+ 'secret' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z' ,
331+ 'api_key' : 'ylSkZIjbdWybfs4fUQe9BqP0LH5Z'
332+ }
333+
334+ with requests_mock .Mocker (real_http = True ) as request :
335+ request .headers = headers
336+
337+ h = RequestUtils .get_headers_from_request (request .headers )
338+
339+ self .assertEqual (h .get ('authorization' ), None )
340+ self .assertEqual (h .get ('access_token' ), None )
341+ self .assertEqual (h .get ('apikey' ), None )
342+ self .assertEqual (h .get ('password' ), None )
343+ self .assertEqual (h .get ('passwd]' ), None )
344+ self .assertEqual (h .get ('secret' ), None )
345+ self .assertEqual (h .get ('api_key' ), None )
0 commit comments