Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add e2e test for com.docker.network.bridge.enable_icc option #104

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions e2e/tests/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ func NetworkCreate(opt *option.Option) {
}
}

cleanupNetworkWithHTTP := func(network string) func() {
return func() {
relativeUrl := fmt.Sprintf("/networks/%s", network)
apiUrl := client.ConvertToFinchUrl(version, relativeUrl)
req, err := http.NewRequest(http.MethodDelete, apiUrl, nil)
Expect(err).ShouldNot(HaveOccurred())
_, err = uclient.Do(req)
Expect(err).Should(BeNil())
}
}

When("a create network request is received with required configuration", func() {
It("should return 201 Created and the network ID", func() {
request := types.NewCreateNetworkRequest(testNetwork)
Expand Down Expand Up @@ -172,6 +183,54 @@ func NetworkCreate(opt *option.Option) {
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusNotFound))
})
})

When("a network create request is made with network option com.docker.network.bridge.enable_icc set to false", func() {
It("should return 201 Created and the network ID", func() {
testBridge := "br-test"
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("false", testBridge)...)

httpResponse := createNetwork(*request)
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))

response := unmarshallHTTPResponse(httpResponse)
Expect(response.ID).ShouldNot(BeEmpty())
Expect(response.Warning).Should(BeEmpty())

DeferCleanup(cleanupNetworkWithHTTP(testNetwork))

stdout := command.Stdout(opt, "network", "inspect", testNetwork)
Expect(stdout).To(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4": "false"`))

// check iptables rules exists
iptOpt, _ := option.New([]string{"iptables"})
command.Run(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
"-i", testBridge, "-o", testBridge, "-j", "DROP")
})
})

When("a network create request is made with network option com.docker.network.bridge.enable_icc set to true", func() {
It("should create the network without the enable_icc label", func() {
testBridge := "br-test"
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("true", testBridge)...)

httpResponse := createNetwork(*request)
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))

DeferCleanup(cleanupNetworkWithHTTP(testNetwork))

response := unmarshallHTTPResponse(httpResponse)
Expect(response.ID).ShouldNot(BeEmpty())
Expect(response.Warning).Should(BeEmpty())

stdout := command.Stdout(opt, "network", "inspect", testNetwork)
Expect(stdout).ShouldNot(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4"`))

// check iptables rules does not exist
iptOpt, _ := option.New([]string{"iptables"})
command.RunWithoutSuccessfulExit(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
"-i", testBridge, "-o", testBridge, "-j", "DROP")
})
})
})
}

Expand Down Expand Up @@ -245,3 +304,20 @@ func withUnsupportedNetworkOptions() []types.NetworkCreateOption {
}),
}
}

func withEnableICCdNetworkOptions(enableICC string, bridgeName string) []types.NetworkCreateOption {
return []types.NetworkCreateOption{
types.WithIPAM(types.IPAM{
Driver: "default",
Config: []map[string]string{
{
"Subnet": "240.11.0.0/24",
},
},
}),
types.WithOptions(map[string]string{
"com.docker.network.bridge.enable_icc": enableICC,
"com.docker.network.bridge.name": bridgeName,
}),
}
}
Loading