@@ -49,19 +49,14 @@ func TestValidateRemoteManagedGroups(t *testing.T) {
49
49
wantErr : true ,
50
50
},
51
51
{
52
- name : "Valid rule with missing remoteManagedGroups" ,
52
+ name : "Valid rule with no remoteManagedGroups" ,
53
53
rule : infrav1.SecurityGroupRuleSpec {
54
- PortRangeMin : ptr .To (22 ),
55
- PortRangeMax : ptr .To (22 ),
56
- Protocol : ptr .To ("tcp" ),
54
+ PortRangeMin : ptr .To (22 ),
55
+ PortRangeMax : ptr .To (22 ),
56
+ Protocol : ptr .To ("tcp" ),
57
+ RemoteIPPrefix : ptr .To ("0.0.0.0/0" ),
57
58
},
58
- remoteManagedGroups : map [string ]string {
59
- "self" : "self" ,
60
- "controlplane" : "1" ,
61
- "worker" : "2" ,
62
- "bastion" : "3" ,
63
- },
64
- wantErr : true ,
59
+ wantErr : false ,
65
60
},
66
61
{
67
62
name : "Valid rule with remoteManagedGroups" ,
@@ -171,6 +166,70 @@ func TestGetAllNodesRules(t *testing.T) {
171
166
},
172
167
},
173
168
},
169
+ {
170
+ name : "Valid remoteIPPrefix in a rule" ,
171
+ remoteManagedGroups : map [string ]string {
172
+ "controlplane" : "1" ,
173
+ "worker" : "2" ,
174
+ },
175
+ allNodesSecurityGroupRules : []infrav1.SecurityGroupRuleSpec {
176
+ {
177
+ Protocol : ptr .To ("tcp" ),
178
+ PortRangeMin : ptr .To (22 ),
179
+ PortRangeMax : ptr .To (22 ),
180
+ RemoteIPPrefix : ptr .To ("0.0.0.0/0" ),
181
+ },
182
+ },
183
+ wantRules : []resolvedSecurityGroupRuleSpec {
184
+ {
185
+ Protocol : "tcp" ,
186
+ PortRangeMin : 22 ,
187
+ PortRangeMax : 22 ,
188
+ RemoteIPPrefix : "0.0.0.0/0" ,
189
+ },
190
+ },
191
+ },
192
+ {
193
+ name : "Valid allNodesSecurityGroupRules with no remote parameter" ,
194
+ remoteManagedGroups : map [string ]string {
195
+ "controlplane" : "1" ,
196
+ "worker" : "2" ,
197
+ },
198
+ allNodesSecurityGroupRules : []infrav1.SecurityGroupRuleSpec {
199
+ {
200
+ Protocol : ptr .To ("tcp" ),
201
+ PortRangeMin : ptr .To (22 ),
202
+ PortRangeMax : ptr .To (22 ),
203
+ },
204
+ },
205
+ wantRules : []resolvedSecurityGroupRuleSpec {
206
+ {
207
+ Protocol : "tcp" ,
208
+ PortRangeMin : 22 ,
209
+ PortRangeMax : 22 ,
210
+ },
211
+ },
212
+ wantErr : false ,
213
+ },
214
+ {
215
+ name : "Invalid allNodesSecurityGroupRules with bastion while remoteManagedGroups does not have bastion" ,
216
+ remoteManagedGroups : map [string ]string {
217
+ "controlplane" : "1" ,
218
+ "worker" : "2" ,
219
+ },
220
+ allNodesSecurityGroupRules : []infrav1.SecurityGroupRuleSpec {
221
+ {
222
+ Protocol : ptr .To ("tcp" ),
223
+ PortRangeMin : ptr .To (22 ),
224
+ PortRangeMax : ptr .To (22 ),
225
+ RemoteManagedGroups : []infrav1.ManagedSecurityGroupName {
226
+ "bastion" ,
227
+ },
228
+ },
229
+ },
230
+ wantRules : nil ,
231
+ wantErr : true ,
232
+ },
174
233
{
175
234
name : "Invalid allNodesSecurityGroupRules with wrong remoteManagedGroups" ,
176
235
remoteManagedGroups : map [string ]string {
0 commit comments