Example #1
0
 def has_permission(self, request, view):
     checker = RestrictionChecker(request=request)
     if not checker.is_submission_allowed():
         self.message = checker.get_error_message()
         self.code = 'permission_denied_restriction'
         return False
     return True
Example #2
0
 def test_is_submission_allowed_bypassing_read_dev_agreement_restricted(
         self, incr_mock):
     # Mix of test_is_submission_allowed_email_restricted() and
     # test_is_submission_allowed_bypassing_read_dev_agreement() above:
     # this time, we're restricted by email while bypassing the read dev
     # agreement check. This ensures even when bypassing that check, we
     # still record everything properly when restricting.
     EmailUserRestriction.objects.create(
         email_pattern=self.request.user.email)
     checker = RestrictionChecker(request=self.request)
     assert not checker.is_submission_allowed(check_dev_agreement=False)
     assert checker.get_error_message() == (
         'The email address used for your account is not '
         'allowed for add-on submission.')
     assert incr_mock.call_count == 2
     assert incr_mock.call_args_list[0][0] == (
         'RestrictionChecker.is_submission_allowed.EmailUserRestriction.failure',
     )
     assert incr_mock.call_args_list[1][0] == (
         'RestrictionChecker.is_submission_allowed.failure', )
     assert UserRestrictionHistory.objects.count() == 1
     history = UserRestrictionHistory.objects.get()
     assert history.get_restriction_display() == 'EmailUserRestriction'
     assert history.user == self.request.user
     assert history.last_login_ip == self.request.user.last_login_ip
     assert history.ip_address == '10.0.0.1'
Example #3
0
 def test_is_submission_allowed_ip_restricted(self, incr_mock):
     IPNetworkUserRestriction.objects.create(network='10.0.0.0/24')
     checker = RestrictionChecker(request=self.request)
     assert not checker.is_submission_allowed()
     assert checker.get_error_message() == (
         'Multiple add-ons violating our policies have been submitted '
         'from your location. The IP address has been blocked.')
     assert incr_mock.call_count == 2
     assert incr_mock.call_args_list[0][0] == (
         'RestrictionChecker.is_submission_allowed.IPNetworkUserRestriction.failure',
     )
     assert incr_mock.call_args_list[1][0] == (
         'RestrictionChecker.is_submission_allowed.failure', )
     assert UserRestrictionHistory.objects.count() == 1
     history = UserRestrictionHistory.objects.get()
     assert history.get_restriction_display() == 'IPNetworkUserRestriction'
     assert history.user == self.request.user
     assert history.last_login_ip == self.request.user.last_login_ip
     assert history.ip_address == '10.0.0.1'
Example #4
0
 def test_is_submission_allowed_email_restricted(self, incr_mock):
     EmailUserRestriction.objects.create(
         email_pattern=self.request.user.email)
     checker = RestrictionChecker(request=self.request)
     assert not checker.is_submission_allowed()
     assert checker.get_error_message() == (
         'The email address used for your account is not '
         'allowed for add-on submission.')
     assert incr_mock.call_count == 2
     assert incr_mock.call_args_list[0][0] == (
         'RestrictionChecker.is_submission_allowed.EmailUserRestriction.failure',
     )
     assert incr_mock.call_args_list[1][0] == (
         'RestrictionChecker.is_submission_allowed.failure', )
     assert UserRestrictionHistory.objects.count() == 1
     history = UserRestrictionHistory.objects.get()
     assert history.get_restriction_display() == 'EmailUserRestriction'
     assert history.user == self.request.user
     assert history.last_login_ip == self.request.user.last_login_ip
     assert history.ip_address == '10.0.0.1'
Example #5
0
 def test_is_submission_allowed_hasnt_read_agreement(self, incr_mock):
     self.request.user.update(read_dev_agreement=None)
     checker = RestrictionChecker(request=self.request)
     assert not checker.is_submission_allowed()
     assert checker.get_error_message() == (
         'Before starting, please read and accept our Firefox Add-on '
         'Distribution Agreement as well as our Review Policies and Rules. '
         'The Firefox Add-on Distribution Agreement also links to our '
         'Privacy Notice which explains how we handle your information.')
     assert incr_mock.call_count == 2
     assert incr_mock.call_args_list[0][0] == (
         'RestrictionChecker.is_submission_allowed.DeveloperAgreementRestriction.'
         'failure', )
     assert incr_mock.call_args_list[1][0] == (
         'RestrictionChecker.is_submission_allowed.failure', )
     assert UserRestrictionHistory.objects.count() == 1
     history = UserRestrictionHistory.objects.get()
     assert history.get_restriction_display() == (
         'DeveloperAgreementRestriction')
     assert history.user == self.request.user
     assert history.last_login_ip == self.request.user.last_login_ip
     assert history.ip_address == '10.0.0.1'