def test_raise_if_banned(self):
        """pipeline raises if user's IP is banned"""
        Ban.objects.create(banned_value='188.*', check_type=Ban.IP)

        try:
            validate_ip_not_banned(MockStrategy(user_ip='188.1.2.3'), {}, GithubOAuth2, self.user)
            self.fail("validate_ip_not_banned should raise SocialAuthBanned")
        except SocialAuthBanned as e:
            self.assertTrue(isinstance(e.ban, Ban))
Exemple #2
0
    def test_exclude_staff(self):
        """pipeline excludes staff from bans"""
        self.user.is_staff = True
        self.user.save()

        Ban.objects.create(banned_value='188.*', check_type=Ban.IP)

        result = validate_ip_not_banned(MockStrategy(user_ip='188.1.2.3'), {},
                                        GithubOAuth2, self.user)
        self.assertIsNone(result)
Exemple #3
0
 def test_skip_if_user_not_set(self):
     """pipeline step is skipped if no user was passed"""
     result = validate_ip_not_banned(None, {}, GithubOAuth2)
     self.assertIsNone(result)