@@ -64,6 +64,17 @@ func NetworkCreate(opt *option.Option) {
64
64
}
65
65
}
66
66
67
+ cleanupNetworkWithHTTP := func (network string ) func () {
68
+ return func () {
69
+ relativeUrl := fmt .Sprintf ("/networks/%s" , network )
70
+ apiUrl := client .ConvertToFinchUrl (version , relativeUrl )
71
+ req , err := http .NewRequest (http .MethodDelete , apiUrl , nil )
72
+ Expect (err ).ShouldNot (HaveOccurred ())
73
+ _ , err = uclient .Do (req )
74
+ Expect (err ).Should (BeNil ())
75
+ }
76
+ }
77
+
67
78
When ("a create network request is received with required configuration" , func () {
68
79
It ("should return 201 Created and the network ID" , func () {
69
80
request := types .NewCreateNetworkRequest (testNetwork )
@@ -172,6 +183,54 @@ func NetworkCreate(opt *option.Option) {
172
183
Expect (httpResponse ).Should (HaveHTTPStatus (http .StatusNotFound ))
173
184
})
174
185
})
186
+
187
+ When ("a network create request is made with network option com.docker.network.bridge.enable_icc set to false" , func () {
188
+ It ("should return 201 Created and the network ID" , func () {
189
+ testBridge := "br-test"
190
+ request := types .NewCreateNetworkRequest (testNetwork , withEnableICCdNetworkOptions ("false" , testBridge )... )
191
+
192
+ httpResponse := createNetwork (* request )
193
+ Expect (httpResponse ).Should (HaveHTTPStatus (http .StatusCreated ))
194
+
195
+ response := unmarshallHTTPResponse (httpResponse )
196
+ Expect (response .ID ).ShouldNot (BeEmpty ())
197
+ Expect (response .Warning ).Should (BeEmpty ())
198
+
199
+ DeferCleanup (cleanupNetworkWithHTTP (testNetwork ))
200
+
201
+ stdout := command .Stdout (opt , "network" , "inspect" , testNetwork )
202
+ Expect (stdout ).To (ContainSubstring (`"finch.network.bridge.enable_icc.ipv4": "false"` ))
203
+
204
+ // check iptables rules exists
205
+ iptOpt , _ := option .New ([]string {"iptables" })
206
+ command .Run (iptOpt , "-C" , "FINCH-ISOLATE-CHAIN" ,
207
+ "-i" , testBridge , "-o" , testBridge , "-j" , "DROP" )
208
+ })
209
+ })
210
+
211
+ When ("a network create request is made with network option com.docker.network.bridge.enable_icc set to true" , func () {
212
+ It ("should create the network without the enable_icc label" , func () {
213
+ testBridge := "br-test"
214
+ request := types .NewCreateNetworkRequest (testNetwork , withEnableICCdNetworkOptions ("true" , testBridge )... )
215
+
216
+ httpResponse := createNetwork (* request )
217
+ Expect (httpResponse ).Should (HaveHTTPStatus (http .StatusCreated ))
218
+
219
+ DeferCleanup (cleanupNetworkWithHTTP (testNetwork ))
220
+
221
+ response := unmarshallHTTPResponse (httpResponse )
222
+ Expect (response .ID ).ShouldNot (BeEmpty ())
223
+ Expect (response .Warning ).Should (BeEmpty ())
224
+
225
+ stdout := command .Stdout (opt , "network" , "inspect" , testNetwork )
226
+ Expect (stdout ).ShouldNot (ContainSubstring (`"finch.network.bridge.enable_icc.ipv4"` ))
227
+
228
+ // check iptables rules does not exist
229
+ iptOpt , _ := option .New ([]string {"iptables" })
230
+ command .RunWithoutSuccessfulExit (iptOpt , "-C" , "FINCH-ISOLATE-CHAIN" ,
231
+ "-i" , testBridge , "-o" , testBridge , "-j" , "DROP" )
232
+ })
233
+ })
175
234
})
176
235
}
177
236
@@ -245,3 +304,20 @@ func withUnsupportedNetworkOptions() []types.NetworkCreateOption {
245
304
}),
246
305
}
247
306
}
307
+
308
+ func withEnableICCdNetworkOptions (enableICC string , bridgeName string ) []types.NetworkCreateOption {
309
+ return []types.NetworkCreateOption {
310
+ types .WithIPAM (types.IPAM {
311
+ Driver : "default" ,
312
+ Config : []map [string ]string {
313
+ {
314
+ "Subnet" : "240.11.0.0/24" ,
315
+ },
316
+ },
317
+ }),
318
+ types .WithOptions (map [string ]string {
319
+ "com.docker.network.bridge.enable_icc" : enableICC ,
320
+ "com.docker.network.bridge.name" : bridgeName ,
321
+ }),
322
+ }
323
+ }
0 commit comments