def test_delay_auto_approval_indefinitely_and_restrict(self): user1 = user_factory(last_login_ip='5.6.7.8') user2 = user_factory(last_login_ip='') user3 = user_factory() user4 = user_factory(last_login_ip='4.8.15.16') addon = addon_factory(users=[user1, user2]) FileUpload.objects.create( addon=addon, user=user3, version=addon.current_version.version, ip_address='1.2.3.4', ) version = addon.current_version assert not version.needs_human_review assert addon.auto_approval_delayed_until is None _delay_auto_approval_indefinitely_and_restrict(version) assert addon.auto_approval_delayed_until == datetime.max assert version.needs_human_review assert EmailUserRestriction.objects.filter( email_pattern=user1.email).exists() assert EmailUserRestriction.objects.filter( email_pattern=user2.email).exists() assert EmailUserRestriction.objects.filter( email_pattern=user3.email).exists() assert not EmailUserRestriction.objects.filter( email_pattern=user4.email).exists() assert IPNetworkUserRestriction.objects.filter( network='5.6.7.8/32').exists() assert IPNetworkUserRestriction.objects.filter( network='1.2.3.4/32').exists() assert not IPNetworkUserRestriction.objects.filter( network=None).exists() assert not IPNetworkUserRestriction.objects.filter(network='').exists()
def test_delay_auto_approval_indefinitely_and_restrict_already_restricted( self): user1 = user_factory(last_login_ip='5.6.7.8') user2 = user_factory(last_login_ip='') user3 = user_factory() user4 = user_factory(last_login_ip='4.8.15.16') EmailUserRestriction.objects.create(email_pattern=user1.email) EmailUserRestriction.objects.create(email_pattern=user3.email) IPNetworkUserRestriction.objects.create(network='5.6.7.8/32') addon = addon_factory(users=[user1, user2]) FileUpload.objects.create( addon=addon, user=user3, version=addon.current_version.version, ip_address='1.2.3.4', source=amo.UPLOAD_SOURCE_DEVHUB, ) version = addon.current_version assert not version.needs_human_review assert addon.auto_approval_delayed_until is None _delay_auto_approval_indefinitely_and_restrict(version) assert addon.auto_approval_delayed_until == datetime.max assert version.needs_human_review assert EmailUserRestriction.objects.filter( email_pattern=user1.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert EmailUserRestriction.objects.filter( email_pattern=user2.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert EmailUserRestriction.objects.filter( email_pattern=user3.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert not EmailUserRestriction.objects.filter( email_pattern=user4.email).exists() assert IPNetworkUserRestriction.objects.filter( network='5.6.7.8/32', restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert IPNetworkUserRestriction.objects.filter( network='1.2.3.4/32', restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert not IPNetworkUserRestriction.objects.filter( network=None).exists() assert not IPNetworkUserRestriction.objects.filter(network='').exists()
def test_delay_auto_approval_indefinitely_and_restrict_already_restricted_other( self, ): user1 = user_factory(last_login_ip='5.6.7.8') user2 = user_factory(last_login_ip='') user3 = user_factory() user4 = user_factory(last_login_ip='4.8.15.16') EmailUserRestriction.objects.create( email_pattern=user1.email, restriction_type=RESTRICTION_TYPES.APPROVAL) EmailUserRestriction.objects.create( email_pattern=user3.email, restriction_type=RESTRICTION_TYPES.APPROVAL) IPNetworkUserRestriction.objects.create( network='5.6.7.8/32', restriction_type=RESTRICTION_TYPES.APPROVAL) addon = addon_factory(users=[user1, user2]) FileUpload.objects.create( addon=addon, user=user3, version=addon.current_version.version, ip_address='1.2.3.4', source=amo.UPLOAD_SOURCE_DEVHUB, ) version = addon.current_version assert not version.needs_human_review assert addon.auto_approval_delayed_until is None _delay_auto_approval_indefinitely_and_restrict(version) assert addon.auto_approval_delayed_until == datetime.max assert version.needs_human_review # We added a new restriction for submission without touching the existing one # for approval for user1 and user3 assert EmailUserRestriction.objects.filter( email_pattern=user1.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert EmailUserRestriction.objects.filter( email_pattern=user1.email, restriction_type=RESTRICTION_TYPES.APPROVAL).exists() assert EmailUserRestriction.objects.filter( email_pattern=user2.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert EmailUserRestriction.objects.filter( email_pattern=user3.email, restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert EmailUserRestriction.objects.filter( email_pattern=user3.email, restriction_type=RESTRICTION_TYPES.APPROVAL).exists() assert not EmailUserRestriction.objects.filter( email_pattern=user4.email).exists() # Like above, we added a new restriction for submission, this time for the ip, # but we left the one for approval. assert IPNetworkUserRestriction.objects.filter( network='5.6.7.8/32', restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert IPNetworkUserRestriction.objects.filter( network='5.6.7.8/32', restriction_type=RESTRICTION_TYPES.APPROVAL).exists() assert IPNetworkUserRestriction.objects.filter( network='1.2.3.4/32', restriction_type=RESTRICTION_TYPES.SUBMISSION).exists() assert not IPNetworkUserRestriction.objects.filter( network=None).exists() assert not IPNetworkUserRestriction.objects.filter(network='').exists()