Example #1
0
    def test_prefixlen_too_small(self):
        from django.conf import settings
        settings.BHR['minimum_prefixlen'] = 24
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.4"), False)
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.0/24"), False)
        self.assertEqual(is_prefixlen_too_small(u"1.2.0.0/20"), True)

        settings.BHR['minimum_prefixlen'] = 32
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.0/24"), True)
Example #2
0
    def test_prefixlen_too_small(self):
        from django.conf import settings
        settings.BHR['minimum_prefixlen'] = 24
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.4"), False)
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.0/24"), False)
        self.assertEqual(is_prefixlen_too_small(u"1.2.0.0/20"), True)

        settings.BHR['minimum_prefixlen'] = 32
        self.assertEqual(is_prefixlen_too_small(u"1.2.3.0/24"), True)
Example #3
0
def check_whitelist(cleaned_data):
    cidr = cleaned_data.get('cidr')
    source = cleaned_data.get('source')
    skip_whitelist = cleaned_data.get('skip_whitelist')
    if cidr and not skip_whitelist:
        item = is_whitelisted(cidr)
        if item:
            raise forms.ValidationError("whitelisted: %s: %s" % (item.who, item.why))
        if is_prefixlen_too_small(cidr):
            raise forms.ValidationError("Prefix length in %s is too small" % cidr)
        item = is_source_blacklisted(source)
        if item:
            raise forms.ValidationError("Source %s is blacklisted: %s: %s" % (source, item.who, item.why))
    return cleaned_data
Example #4
0
def check_whitelist(cleaned_data):
    cidr = cleaned_data.get('cidr')
    source = cleaned_data.get('source')
    skip_whitelist = cleaned_data.get('skip_whitelist')
    if cidr and not skip_whitelist:
        item = is_whitelisted(cidr)
        if item:
            raise forms.ValidationError("whitelisted: %s: %s" % (item.who, item.why))
        if is_prefixlen_too_small(cidr):
            raise forms.ValidationError("Prefix length in %s is too small" % cidr)
        item = is_source_blacklisted(source)
        if item:
            raise forms.ValidationError("Source %s is blacklisted: %s: %s" % (source, item.who, item.why))
    return cleaned_data
Example #5
0
    def validate(self, attrs):
        if attrs.get('duration') and attrs.get('unblock_at'):
            raise serializers.ValidationError("Specify only one of duration and unblock_at")

        cidr = attrs.get('cidr')
        source = attrs.get('source')
        skip_whitelist = attrs.get('skip_whitelist')
        if cidr and not skip_whitelist:
            item = is_whitelisted(cidr)
            if item:
                raise serializers.ValidationError("whitelisted: %s: %s" % (item.who, item.why))
            if is_prefixlen_too_small(cidr):
                raise serializers.ValidationError("Prefix length in %s is too small" % cidr)
            item = is_source_blacklisted(source)
            if item:
                raise serializers.ValidationError("Source %s is blacklisted: %s: %s" % (source, item.who, item.why))

        return attrs
Example #6
0
    def validate(self, attrs):
        if attrs.get('duration') and attrs.get('unblock_at'):
            raise serializers.ValidationError(
                "Specify only one of duration and unblock_at")

        cidr = attrs.get('cidr')
        source = attrs.get('source')
        skip_whitelist = attrs.get('skip_whitelist')
        if cidr and not skip_whitelist:
            item = is_whitelisted(cidr)
            if item:
                raise serializers.ValidationError("whitelisted: %s: %s" %
                                                  (item.who, item.why))
            if is_prefixlen_too_small(cidr):
                raise serializers.ValidationError(
                    "Prefix length in %s is too small" % cidr)
            item = is_source_blacklisted(source)
            if item:
                raise serializers.ValidationError(
                    "Source %s is blacklisted: %s: %s" %
                    (source, item.who, item.why))

        return attrs
Example #7
0
 def test_prefixlen_too_small_v6(self):
     from django.conf import settings
     settings.BHR['minimum_prefixlen_v6'] = 64
     self.assertEqual(is_prefixlen_too_small(u"fe80::/32"), True)
     self.assertEqual(is_prefixlen_too_small(u"fe80::1/128"), False)
Example #8
0
 def test_prefixlen_too_small_v6(self):
     from django.conf import settings
     settings.BHR['minimum_prefixlen_v6'] = 64
     self.assertEqual(is_prefixlen_too_small(u"fe80::/32"), True)
     self.assertEqual(is_prefixlen_too_small(u"fe80::1/128"), False)
Example #9
0
 def test_prefixlen_too_small(self):
     self.assertEqual(bool(is_prefixlen_too_small(u"1.2.3.4")), False)
     self.assertEqual(bool(is_prefixlen_too_small(u"1.2.3.0/24")), False)
     self.assertEqual(bool(is_prefixlen_too_small(u"1.2.0.0/20")), True)
Example #10
0
 def test_prefixlen_too_small(self):
     self.assertEqual(bool(is_prefixlen_too_small("1.2.3.4")), False)
     self.assertEqual(bool(is_prefixlen_too_small("1.2.3.4/24")), False)
     self.assertEqual(bool(is_prefixlen_too_small("1.2.3.4/20")), True)