1717 DraftComment ,
1818 GenericMozillaUser ,
1919 IPLog ,
20+ RequestFingerprintLog ,
2021 ReviewActionReasonLog ,
2122 attachment_upload_path ,
2223)
@@ -374,7 +375,7 @@ def test_output(self):
374375 def test_to_string_num_queries_model_depending_on_addon (self ):
375376 addon = Addon .objects .get ()
376377 addon2 = addon_factory ()
377- with core .override_remote_addr ( '1.1.1.1' ):
378+ with core .override_remote_addr_or_metadata ( ip_address = '1.1.1.1' ):
378379 ActivityLog .objects .create (
379380 amo .LOG .ADD_VERSION ,
380381 addon ,
@@ -410,7 +411,7 @@ def test_ip_log(self):
410411 # create an IPLog.
411412 action = amo .LOG .REJECT_VERSION
412413 assert not getattr (action , 'store_ip' , False )
413- with core .override_remote_addr ( '127.0.4.8' ):
414+ with core .override_remote_addr_or_metadata ( ip_address = '127.0.4.8' ):
414415 activity = ActivityLog .objects .create (
415416 action ,
416417 addon ,
@@ -422,7 +423,7 @@ def test_ip_log(self):
422423 # create an IPLog.
423424 action = amo .LOG .ADD_VERSION
424425 assert getattr (action , 'store_ip' , False )
425- with core .override_remote_addr ( '15.16.23.42' ):
426+ with core .override_remote_addr_or_metadata ( ip_address = '15.16.23.42' ):
426427 activity = ActivityLog .objects .create (
427428 action ,
428429 addon ,
@@ -435,6 +436,48 @@ def test_ip_log(self):
435436 assert ip_log ._ip_address == '15.16.23.42'
436437 assert ip_log .ip_address_binary == IPv4Address ('15.16.23.42' )
437438
439+ def test_request_fingerprint_log (self ):
440+ addon = Addon .objects .get ()
441+ assert RequestFingerprintLog .objects .count () == 0
442+ # 37 charactors to test truncation to 36 characters.
443+ metadata = {
444+ 'Client-JA4' : 'a' * 37 ,
445+ 'X-SigSci-Tags' : 'TAG1,TAG2' ,
446+ 'other' : 'data' ,
447+ }
448+ # Creating an activity log for an action without store_ip=True doesn't
449+ # create an RequestFingerprintLog.
450+ action = amo .LOG .REJECT_VERSION
451+ assert not getattr (action , 'store_ip' , False )
452+ with core .override_remote_addr_or_metadata (
453+ ip_address = '127.0.4.8' , metadata = metadata
454+ ):
455+ activity = ActivityLog .objects .create (
456+ action ,
457+ addon ,
458+ addon .current_version ,
459+ user = self .request .user ,
460+ )
461+ assert RequestFingerprintLog .objects .count () == 0
462+ # Creating an activity log for an action *with* store_ip=True *does*
463+ # create an RequestFingerprintLog.
464+ action = amo .LOG .ADD_VERSION
465+ assert getattr (action , 'store_ip' , False )
466+ with core .override_remote_addr_or_metadata (
467+ ip_address = '15.16.23.42' , metadata = metadata
468+ ):
469+ activity = ActivityLog .objects .create (
470+ action ,
471+ addon ,
472+ addon .current_version ,
473+ user = self .request .user ,
474+ )
475+ assert RequestFingerprintLog .objects .count () == 1
476+ fingerprint_log = RequestFingerprintLog .objects .get ()
477+ assert fingerprint_log .activity_log == activity
478+ assert fingerprint_log .ja4 == 'a' * 36 # Truncated to 36 characters.
479+ assert fingerprint_log .signals == ['TAG1' , 'TAG2' ]
480+
438481 def test_review_action_reason_log (self ):
439482 addon = Addon .objects .get ()
440483 assert ReviewActionReasonLog .objects .count () == 0
0 commit comments