@@ -1721,3 +1721,137 @@ var processSecurityGroupsPage = func(ctx context.Context, _, y interface{}, requ
1721
1721
},
1722
1722
}, true )
1723
1723
}
1724
+
1725
+ func TestExpandIngressRules (t * testing.T ) {
1726
+ tests := []struct {
1727
+ name string
1728
+ input infrav1.IngressRules
1729
+ expected infrav1.IngressRules
1730
+ }{
1731
+ {
1732
+ name : "nothing to expand, nothing to do" ,
1733
+ input : infrav1.IngressRules {
1734
+ {
1735
+ Description : "SSH" ,
1736
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1737
+ FromPort : 22 ,
1738
+ ToPort : 22 ,
1739
+ },
1740
+ },
1741
+ expected : infrav1.IngressRules {
1742
+ {
1743
+ Description : "SSH" ,
1744
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1745
+ FromPort : 22 ,
1746
+ ToPort : 22 ,
1747
+ },
1748
+ },
1749
+ },
1750
+ {
1751
+ name : "nothing to expand, security group roles is removed" ,
1752
+ input : infrav1.IngressRules {
1753
+ {
1754
+ Description : "SSH" ,
1755
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1756
+ FromPort : 22 ,
1757
+ ToPort : 22 ,
1758
+ SourceSecurityGroupRoles : []infrav1.SecurityGroupRole {
1759
+ infrav1 .SecurityGroupControlPlane ,
1760
+ },
1761
+ },
1762
+ },
1763
+ expected : infrav1.IngressRules {
1764
+ {
1765
+ Description : "SSH" ,
1766
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1767
+ FromPort : 22 ,
1768
+ ToPort : 22 ,
1769
+ },
1770
+ },
1771
+ },
1772
+ {
1773
+ name : "cidr blocks expand" ,
1774
+ input : infrav1.IngressRules {
1775
+ {
1776
+ Description : "SSH" ,
1777
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1778
+ FromPort : 22 ,
1779
+ ToPort : 22 ,
1780
+ CidrBlocks : []string {"0.0.0.0/0" , "1.1.1.1/0" },
1781
+ IPv6CidrBlocks : []string {"::/0" , "::/1" },
1782
+ },
1783
+ },
1784
+ expected : infrav1.IngressRules {
1785
+ {
1786
+ Description : "SSH" ,
1787
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1788
+ FromPort : 22 ,
1789
+ ToPort : 22 ,
1790
+ CidrBlocks : []string {"0.0.0.0/0" },
1791
+ },
1792
+ {
1793
+ Description : "SSH" ,
1794
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1795
+ FromPort : 22 ,
1796
+ ToPort : 22 ,
1797
+ CidrBlocks : []string {"1.1.1.1/0" },
1798
+ },
1799
+ {
1800
+ Description : "SSH" ,
1801
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1802
+ FromPort : 22 ,
1803
+ ToPort : 22 ,
1804
+ IPv6CidrBlocks : []string {"::/0" },
1805
+ },
1806
+ {
1807
+ Description : "SSH" ,
1808
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1809
+ FromPort : 22 ,
1810
+ ToPort : 22 ,
1811
+ IPv6CidrBlocks : []string {"::/1" },
1812
+ },
1813
+ },
1814
+ },
1815
+ {
1816
+ name : "security group ids expand, security group roles removed" ,
1817
+ input : infrav1.IngressRules {
1818
+ {
1819
+ Description : "SSH" ,
1820
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1821
+ FromPort : 22 ,
1822
+ ToPort : 22 ,
1823
+ SourceSecurityGroupIDs : []string {"sg-1" , "sg-2" },
1824
+ SourceSecurityGroupRoles : []infrav1.SecurityGroupRole {
1825
+ infrav1 .SecurityGroupControlPlane ,
1826
+ infrav1 .SecurityGroupNode ,
1827
+ },
1828
+ },
1829
+ },
1830
+ expected : infrav1.IngressRules {
1831
+ {
1832
+ Description : "SSH" ,
1833
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1834
+ FromPort : 22 ,
1835
+ ToPort : 22 ,
1836
+ SourceSecurityGroupIDs : []string {"sg-1" },
1837
+ },
1838
+ {
1839
+ Description : "SSH" ,
1840
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
1841
+ FromPort : 22 ,
1842
+ ToPort : 22 ,
1843
+ SourceSecurityGroupIDs : []string {"sg-2" },
1844
+ },
1845
+ },
1846
+ },
1847
+ }
1848
+
1849
+ for _ , tc := range tests {
1850
+ t .Run (tc .name , func (t * testing.T ) {
1851
+ g := NewGomegaWithT (t )
1852
+ output := expandIngressRules (tc .input )
1853
+
1854
+ g .Expect (output ).To (Equal (tc .expected ))
1855
+ })
1856
+ }
1857
+ }
0 commit comments