コード例 #1
0
ファイル: modusers.py プロジェクト: dahito/Misago
    def ban_user(self):
        new_ban = Ban(banned_value=self.user.username,
                      user_message=self.cleaned_data['user_message'],
                      staff_message=self.cleaned_data['staff_message'],
                      valid_until=self.cleaned_data['valid_until'])
        new_ban.save()

        Ban.objects.invalidate_cache()
コード例 #2
0
    def ban_user(self):
        new_ban = Ban(banned_value=self.user.username,
                      user_message=self.cleaned_data['user_message'],
                      staff_message=self.cleaned_data['staff_message'],
                      valid_until=self.cleaned_data['valid_until'])
        new_ban.save()

        Ban.objects.invalidate_cache()
コード例 #3
0
ファイル: rest_permissions.py プロジェクト: pylixm/Misago
 def is_request_banned(self, request):
     ban = get_request_ip_ban(request)
     if ban:
         hydrated_ban = Ban(check_type=BAN_IP,
                            user_message=ban['message'],
                            expires_on=ban['expires_on'])
         raise Banned(hydrated_ban)
コード例 #4
0
    def test_banned(self):
        """banned exception is correctly handled"""
        ban = Ban(user_message="This is test ban!")

        response = exceptionhandler.handle_api_exception(Banned(ban), None)

        self.assertEqual(response.status_code, 403)
        self.assertEqual(response.data['detail']['html'], "<p>This is test ban!</p>")
        self.assertIn('expires_on', response.data)
コード例 #5
0
 def decorator(request, *args, **kwargs):
     ban = get_request_ip_ban(request)
     if ban:
         hydrated_ban = Ban(
             check_type=BAN_IP,
             user_message=ban['message'],
             expires_on=ban['expires_on'])
         raise Banned(hydrated_ban)
     else:
         return f(request, *args, **kwargs)
コード例 #6
0
def validate_ip_not_banned(strategy, details, backend, user=None, *args, **kwargs):
    """Pipeline step that interrupts pipeline if found user is non-staff and IP banned"""
    if not user or user.is_staff:
        return None
    
    ban = get_request_ip_ban(strategy.request)
    if ban:
        hydrated_ban = Ban(
            check_type=Ban.IP,
            user_message=ban['message'],
            expires_on=ban['expires_on'],
        )
        raise SocialAuthBanned(backend, hydrated_ban)
コード例 #7
0
    def handle(self, *args, **options):
        try:
            fake_bans_to_create = int(args[0])
        except IndexError:
            fake_bans_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()

        message = 'Creating %s fake bans...\n'
        self.stdout.write(message % fake_bans_to_create)

        message = '\n\nSuccessfully created %s fake bans'

        created_count = 0
        show_progress(self, created_count, fake_bans_to_create)
        for i in range(fake_bans_to_create):
            ban = Ban(check_type=random.randint(Ban.USERNAME, Ban.IP))
            ban.banned_value = create_fake_test(fake, ban.check_type)

            if random.randint(0, 10) == 0:
                ban.user_message = fake.sentence()

            if random.randint(0, 10) == 0:
                ban.staff_message = fake.sentence()

            if random.randint(0, 1):
                # Lets make ban temporary
                ban_length = timedelta(days=random.randint(0, 300))
                if random.randint(0, 1):
                    ban.valid_until = timezone.now().date() - ban_length
                else:
                    ban.valid_until = timezone.now().date() + ban_length

            ban.save()

            created_count += 1
            show_progress(self, created_count, fake_bans_to_create)

        self.stdout.write(message % created_count)
コード例 #8
0
ファイル: createfakebans.py プロジェクト: Didan/Misago
    def handle(self, *args, **options):
        try:
            fake_bans_to_create = int(args[0])
        except IndexError:
            fake_bans_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()

        message = 'Creating %s fake bans...\n'
        self.stdout.write(message % fake_bans_to_create)

        message = '\n\nSuccessfully created %s fake bans'

        created_count = 0
        show_progress(self, created_count, fake_bans_to_create)
        for i in xrange(fake_bans_to_create):
            ban = Ban(check_type=random.randint(BAN_USERNAME, BAN_IP))
            ban.banned_value = create_fake_test(fake, ban.check_type)

            if random.randint(0, 10) == 0:
                ban.user_message = fake.sentence()

            if random.randint(0, 10) == 0:
                ban.staff_message = fake.sentence()

            if random.randint(0, 1):
                # Lets make ban temporary
                ban_length = timedelta(days=random.randint(0, 300))
                if random.randint(0, 1):
                    ban.valid_until = timezone.now().date() - ban_length
                else:
                    ban.valid_until = timezone.now().date() + ban_length

            ban.save()

            created_count += 1
            show_progress(self, created_count, fake_bans_to_create)

        self.stdout.write(message % created_count)
コード例 #9
0
def raise_misago_banned(request):
    ban = Ban(user_message="Banned for test!")
    raise Banned(ban)
コード例 #10
0
def raise_social_auth_banned(request):
    ban = Ban(user_message="Banned in auth!")
    raise SocialAuthBanned(GithubOAuth2, ban)
コード例 #11
0
 def setUp(self):
     Ban.objects.bulk_create([
         Ban(check_type=Ban.USERNAME, banned_value='bob'),
         Ban(check_type=Ban.EMAIL, banned_value='*****@*****.**'),
         Ban(check_type=Ban.IP, banned_value='127.0.0.1'),
     ])
コード例 #12
0
    def test_check_value_ends_witch(self):
        """ban correctly tests given values"""
        test_ban = Ban(banned_value='*bob')

        self.assertTrue(test_ban.check_value('lebob'))
        self.assertFalse(test_ban.check_value('bobby'))
コード例 #13
0
    def test_check_value_middle_match(self):
        """ban correctly tests given values"""
        test_ban = Ban(banned_value='b*b')

        self.assertTrue(test_ban.check_value('bob'))
        self.assertFalse(test_ban.check_value('bobby'))
コード例 #14
0
    def test_check_value_starts_with(self):
        """ban correctly tests given values"""
        test_ban = Ban(banned_value='bob*')

        self.assertTrue(test_ban.check_value('bob'))
        self.assertTrue(test_ban.check_value('bobby'))
コード例 #15
0
 def setUp(self):
     Ban.objects.bulk_create([
         Ban(test=BAN_USERNAME, banned_value='bob'),
         Ban(test=BAN_EMAIL, banned_value='*****@*****.**'),
         Ban(test=BAN_IP, banned_value='127.0.0.1'),
     ])
コード例 #16
0
    def test_test_value_literal(self):
        """ban correctly tests given values"""
        test_ban = Ban(banned_value='bob')

        self.assertTrue(test_ban.test_value('bob'))
        self.assertFalse(test_ban.test_value('bobby'))