コード例 #1
0
    def test_whitelist(self):
        WhitelistEntry(who=self.user, why='test', cidr='141.142.0.0/16').save()

        self.assertEqual(bool(is_whitelisted("1.2.3.4")), False)
        self.assertEqual(bool(is_whitelisted("1.2.3.0/24")), False)

        self.assertEqual(bool(is_whitelisted("141.142.2.2")), True)
        self.assertEqual(bool(is_whitelisted("141.142.4.0/24")), True)
        self.assertEqual(bool(is_whitelisted("141.0.0.0/8")), True)
コード例 #2
0
ファイル: tests.py プロジェクト: esnet/bhr-site
    def test_whitelist(self):
        WhitelistEntry(who=self.user, why='test', cidr='141.142.0.0/16').save()

        self.assertEqual(bool(is_whitelisted("1.2.3.4")), False)
        self.assertEqual(bool(is_whitelisted("1.2.3.0/24")), False)

        self.assertEqual(bool(is_whitelisted("141.142.2.2")), True)
        self.assertEqual(bool(is_whitelisted("141.142.4.0/24")), True)
        self.assertEqual(bool(is_whitelisted("141.0.0.0/8")), True)
コード例 #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
コード例 #4
0
ファイル: forms.py プロジェクト: buraglio/bhr-site
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
コード例 #5
0
ファイル: serializers.py プロジェクト: buraglio/bhr-site
    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
コード例 #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