| 1 | // Copyright 2017-2018 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 19 | "math/randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/" |
| 20 | "runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/" |
| 21 | "syncscip-go gomod github.com/golang/go/src go1.24.2 sync/" |
| 22 | |
| 23 | "github.com/coreos/go-iptables/iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/" |
| 24 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 25 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 26 | |
| 27 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 28 | "github.com/containernetworking/plugins/pkg/testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/" |
| 29 | ) |
| 30 | |
| 31 | const TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE. = "filter" // We'll monkey around here |
| 32 | |
| 33 | // TODO: run these tests in a new namespace |
| 34 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("chain tests", func() { |
| 35 | var testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain. chainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain# |
| 36 | var iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt. *iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.IPTablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables# |
| 37 | var testNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testNs. nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS# |
| 38 | var cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup. func() |
| 39 | |
| 40 | beforeEach := func() { |
| 41 | // Save a reference to the original namespace, |
| 42 | // Add a new NS |
| 43 | currNs, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetCurrentNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetCurrentNS().() |
| 44 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 45 | |
| 46 | testNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testNs., err = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.NewNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/NewNS().() |
| 47 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 48 | |
| 49 | tlChainName := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("cni-test-%d", randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/Intn().(10000000)) |
| 50 | chainName := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("cni-test-%d", randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/Intn().(10000000)) |
| 51 | |
| 52 | testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain. = chainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#{ |
| 53 | tablescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#table.: TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., |
| 54 | namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name.: chainName, |
| 55 | entryChainsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#entryChains.: []string{tlChainName}, |
| 56 | entryRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#entryRules.: [][]string{{"-d", "203.0.113.1"}}, |
| 57 | rulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#rules.: [][]string{ |
| 58 | {"-m", "comment", "--comment", "test 1", "-j", "RETURN"}, |
| 59 | {"-m", "comment", "--comment", "test 2", "-j", "RETURN"}, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt., err = iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.NewWithProtocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/NewWithProtocol().(iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.ProtocolIPv4scip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/ProtocolIPv4.) |
| 64 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 65 | |
| 66 | runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/.LockOSThreadscip-go gomod github.com/golang/go/src go1.24.2 runtime/LockOSThread().() |
| 67 | err = testNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testNs..Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.() |
| 68 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 69 | |
| 70 | err = iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ClearChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ClearChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName) // This will create the chain |
| 71 | if err != nil { |
| 72 | currNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.() |
| 73 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 74 | } |
| 75 | |
| 76 | cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup. = func() { |
| 77 | if iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt. == nil { |
| 78 | return |
| 79 | } |
| 80 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ClearChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ClearChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name.) |
| 81 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ClearChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ClearChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName) |
| 82 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..DeleteChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#DeleteChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name.) |
| 83 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..DeleteChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#DeleteChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName) |
| 84 | currNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.() |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("creates and destroys a chain", func() { |
| 89 | beforeEach() |
| 90 | defer cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup.() |
| 91 | |
| 92 | tlChainName := testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..entryChainsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#entryChains.[0] |
| 93 | |
| 94 | // add an extra rule to the test chain to make sure it's not touched |
| 95 | err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..Appendscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#Append().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName, "-m", "comment", "--comment", |
| 96 | "canary value", "-j", "ACCEPT") |
| 97 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 98 | |
| 99 | // Create the chain |
| 100 | err = testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#setup().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 101 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 102 | |
| 103 | // Verify the chain exists |
| 104 | ok := false |
| 105 | chains, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE.) |
| 106 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 107 | for _, chain := range chains { |
| 108 | if chain == testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. { |
| 109 | ok = true |
| 110 | break |
| 111 | } |
| 112 | } |
| 113 | if !ok { |
| 114 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("Could not find created chain") |
| 115 | } |
| 116 | |
| 117 | // Check that the entry rule was created |
| 118 | haveRules, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName) |
| 119 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 120 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(haveRules).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().([]string{ |
| 121 | "-N " + tlChainName, |
| 122 | "-A " + tlChainName + ` -m comment --comment "canary value" -j ACCEPT`, |
| 123 | "-A " + tlChainName + " -d 203.0.113.1/32 -j " + testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name., |
| 124 | })) |
| 125 | |
| 126 | // Check that the chain and rule was created |
| 127 | haveRules, err = iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name.) |
| 128 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 129 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(haveRules).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().([]string{ |
| 130 | "-N " + testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name., |
| 131 | "-A " + testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. + ` -m comment --comment "test 1" -j RETURN`, |
| 132 | "-A " + testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. + ` -m comment --comment "test 2" -j RETURN`, |
| 133 | })) |
| 134 | |
| 135 | err = testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#teardown().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 136 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 137 | |
| 138 | tlRules, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., tlChainName) |
| 139 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 140 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(tlRules).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().([]string{ |
| 141 | "-N " + tlChainName, |
| 142 | "-A " + tlChainName + ` -m comment --comment "canary value" -j ACCEPT`, |
| 143 | })) |
| 144 | |
| 145 | chains, err = iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE.) |
| 146 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 147 | for _, chain := range chains { |
| 148 | if chain == testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. { |
| 149 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("chain was not deleted") |
| 150 | } |
| 151 | } |
| 152 | }) |
| 153 | |
| 154 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("creates chains idempotently", func() { |
| 155 | beforeEach() |
| 156 | defer cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup.() |
| 157 | |
| 158 | err := testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#setup().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 159 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 160 | |
| 161 | // Create it again! |
| 162 | err = testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#setup().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 163 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 164 | |
| 165 | // Make sure there are only two rules |
| 166 | // (the first rule is an -N because go-iptables |
| 167 | rules, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name.) |
| 168 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 169 | |
| 170 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(rules).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(3)) |
| 171 | }) |
| 172 | |
| 173 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("deletes chains idempotently", func() { |
| 174 | beforeEach() |
| 175 | defer cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup.() |
| 176 | |
| 177 | err := testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#setup().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 178 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 179 | |
| 180 | err = testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#teardown().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 181 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 182 | |
| 183 | chains, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE.) |
| 184 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 185 | for _, chain := range chains { |
| 186 | if chain == testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. { |
| 187 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("Chain was not deleted") |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | err = testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#teardown().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 192 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 193 | chains, err = iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE.) |
| 194 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 195 | for _, chain := range chains { |
| 196 | if chain == testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. { |
| 197 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("Chain was not deleted") |
| 198 | } |
| 199 | } |
| 200 | }) |
| 201 | |
| 202 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("deletes chains idempotently in parallel", func() { |
| 203 | beforeEach() |
| 204 | defer cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:cleanup.() |
| 205 | // number of parallel executions |
| 206 | N := 10 |
| 207 | var wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:wg. syncscip-go gomod github.com/golang/go/src go1.24.2 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup# |
| 208 | err := testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#setup().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 209 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 210 | errCh := make(chan error, N) |
| 211 | for i := 0; i < N; i++ { |
| 212 | wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:wg..Addscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Add().(1) |
| 213 | go func() { |
| 214 | defer wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:wg..Donescip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Done().() |
| 215 | // teardown chain |
| 216 | errCh <- testNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testNs..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 217 | return testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#teardown().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt.) |
| 218 | }) |
| 219 | }() |
| 220 | } |
| 221 | wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:wg..Waitscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Wait().() |
| 222 | close(errCh) |
| 223 | for err := range errCh { |
| 224 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 225 | } |
| 226 | |
| 227 | chains, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/TABLE.) |
| 228 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 229 | for _, chain := range chains { |
| 230 | if chain == testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/_:testChain..namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/portmap`/chain#name. { |
| 231 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("Chain was not deleted") |
| 232 | } |
| 233 | } |
| 234 | }) |
| 235 | }) |