1+ from ipaddress import IPv4Network
2+
13from pycfmodel .model .resources .wafv2_ip_set import WAFv2IPSet , WAFv2IPSetProperties
24
35
@@ -22,8 +24,8 @@ def test_wafv2_ipset_with_large_cidr():
2224 assert resource .Type == "AWS::WAFv2::IPSet"
2325 assert isinstance (resource .Properties , WAFv2IPSetProperties )
2426 assert len (resource .Properties .Addresses ) == 3
25- assert resource .Properties .Addresses [0 ] == " 17.0.0.0/8"
26- assert isinstance (resource .Properties .Addresses [0 ], str )
27+ assert resource .Properties .Addresses [0 ] == IPv4Network ( ' 17.0.0.0/8' )
28+ assert isinstance (resource .Properties .Addresses [0 ], IPv4Network )
2729 assert resource .Properties .IPAddressVersion == "IPV4"
2830 assert resource .Properties .Scope == "CLOUDFRONT"
2931
@@ -74,3 +76,21 @@ def test_wafv2_ipset_with_tags():
7476 assert resource .Properties .Scope == "REGIONAL"
7577 assert len (resource .Properties .Tags ) == 2
7678 assert resource .Properties .Tags [0 ].Key == "Environment"
79+
80+
81+ def test_wafv2_ipset_with_invalid_ip ():
82+ """Test that WAFv2::IPSet fails validation when given an invalid IP address."""
83+ import pytest
84+ from pydantic import ValidationError
85+
86+ resource_dict = {
87+ "Type" : "AWS::WAFv2::IPSet" ,
88+ "Properties" : {
89+ "Addresses" : ["not.a.valid.ip" ],
90+ "IPAddressVersion" : "IPV4" ,
91+ "Scope" : "CLOUDFRONT" ,
92+ },
93+ }
94+
95+ with pytest .raises (ValidationError ):
96+ WAFv2IPSet (** resource_dict )
0 commit comments