Debian Codegraph @

pkg/link/spoofcheck_test.go

raw symbols SCIP
1 // Copyright 2021 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 link_testscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/
16
17 import (
18 "errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/"
19 "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/"
20
21 "github.com/networkplumbing/go-nft/nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/"
22 . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/"
23 . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/"
24
25 "github.com/containernetworking/plugins/pkg/linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/"
26 )
27
28 var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("spoofcheck", func() {
29 iface := "net0"
30 mac := "02:00:00:00:12:34"
31 id := "container99-net1"
32
33 Contextscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Context.("setup", func() {
34 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("succeeds", func() {
35 c := configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{}
36 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().(iface, mac, id, &c)
37 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
38
39 assertExpectedTableAndChainsInSetupConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedTableAndChainsInSetupConfig().(c)
40 assertExpectedRulesInSetupConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedRulesInSetupConfig().(c)
41 })
42
43 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails to setup config when 1st apply is unsuccessful (declare table and chains)", func() {
44 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{failFirstApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failFirstApplyConfig.: true}
45 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().(iface, mac, id, c)
46 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().("failed to setup spoof-check: " + errorFirstApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorFirstApplyText.))
47 })
48
49 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails to setup config when 2nd apply is unsuccessful (flush and add the rules)", func() {
50 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{failSecondApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failSecondApplyConfig.: true}
51 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().(iface, mac, id, c)
52 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().("failed to setup spoof-check: " + errorSecondApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorSecondApplyText.))
53 })
54 })
55
56 Contextscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Context.("teardown", func() {
57 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("succeeds", func() {
58 existingConfig := nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/NewConfig().()
59 existingConfig.FromJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().()))
60 c := configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig.: existingConfig}
61
62 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().("", "", id, &c)
63 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
64
65 assertExpectedBaseChainRuleDeletionInTeardownConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedBaseChainRuleDeletionInTeardownConfig().(c)
66 assertExpectedRegularChainsDeletionInTeardownConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedRegularChainsDeletionInTeardownConfig().(c)
67 })
68
69 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails, 1st apply is unsuccessful (delete iface match rule)", func() {
70 config := nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/NewConfig().()
71 config.FromJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().()))
72 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.: []*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#{config}, readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig.: config, failFirstApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failFirstApplyConfig.: true}
73 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().("", "", id, c)
74 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().(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().(
75 "failed to teardown spoof-check: failed to delete iface match rule: %s, <nil>", errorFirstApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorFirstApplyText.,
76 )))
77 })
78
79 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails, read current config is unsuccessful", func() {
80 config := nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/NewConfig().()
81 config.FromJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().()))
82 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.: []*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#{config}, readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig.: config, failReadConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failReadConfig.: true}
83 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().("", "", id, c)
84 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().(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().(
85 "failed to teardown spoof-check: %s, <nil>", errorReadTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorReadText.,
86 )))
87 })
88
89 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails, 2nd apply is unsuccessful (delete the regular chains)", func() {
90 config := nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/NewConfig().()
91 config.FromJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().()))
92 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.: []*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#{config}, readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig.: config, failSecondApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failSecondApplyConfig.: true}
93 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().("", "", id, c)
94 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().(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().(
95 "failed to teardown spoof-check: <nil>, failed to delete regular chains: %s", errorSecondApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorSecondApplyText.,
96 )))
97 })
98
99 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("fails, both applies are unsuccessful", func() {
100 config := nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/NewConfig().()
101 config.FromJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().()))
102 c := &configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{
103 applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.: []*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#{config},
104 readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig.: config,
105 failFirstApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failFirstApplyConfig.: true,
106 failSecondApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failSecondApplyConfig.: true,
107 }
108 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().("", "", id, c)
109 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().(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().(
110 "failed to teardown spoof-check: "+
111 "failed to delete iface match rule: %s, "+
112 "failed to delete regular chains: %s",
113 errorFirstApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorFirstApplyText., errorSecondApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorSecondApplyText.,
114 )))
115 })
116 })
117
118 Contextscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Context.("echo", func() {
119 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("succeeds, no read called", func() {
120 c := configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{}
121 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().(iface, mac, id, &c)
122 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
123 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
124 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(c.readCalledscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readCalled.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeFalsescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeFalse().())
125 })
126
127 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("succeeds, fall back to config read", func() {
128 c := configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#{applyReturnNilscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyReturnNil.: true}
129 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerWithConfigurerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofCheckerWithConfigurer().(iface, mac, id, &c)
130 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
131 c.readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig. = c.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.[0]
132 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().())
133 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(c.readCalledscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readCalled.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().())
134 })
135 })
136 })
137
138 func assertExpectedRegularChainsDeletionInTeardownConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedRegularChainsDeletionInTeardownConfig().(action configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) {
139 deleteRegularChainRulesJSONConfig, err := action.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.[1].ToJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
140 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, 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().())
141
142 expectedDeleteRegularChainRulesJSONConfig := `
143 {"nftables": [
144 {"delete": {"chain": {
145 "family": "bridge",
146 "table": "nat",
147 "name": "cni-br-iface-container99-net1"
148 }}},
149 {"delete": {"chain": {
150 "family": "bridge",
151 "table": "nat",
152 "name": "cni-br-iface-container99-net1-mac"
153 }}}
154 ]}`
155
156 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, string(deleteRegularChainRulesJSONConfig)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchJSONscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchJSON().(expectedDeleteRegularChainRulesJSONConfig))
157 }
158
159 func assertExpectedBaseChainRuleDeletionInTeardownConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedBaseChainRuleDeletionInTeardownConfig().(action configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) {
160 deleteBaseChainRuleJSONConfig, err := action.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.[0].ToJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
161 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().())
162
163 expectedDeleteIfaceMatchRuleJSONConfig := `
164 {"nftables": [
165 {"delete": {"rule": {
166 "family": "bridge",
167 "table": "nat",
168 "chain": "PREROUTING",
169 "expr": [
170 {"match": {
171 "op": "==",
172 "left": {"meta": {"key": "iifname"}},
173 "right": "net0"
174 }},
175 {"jump": {"target": "cni-br-iface-container99-net1"}}
176 ],
177 "comment": "macspoofchk-container99-net1"
178 }}}
179 ]}`
180 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(string(deleteBaseChainRuleJSONConfig)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchJSONscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchJSON().(expectedDeleteIfaceMatchRuleJSONConfig))
181 }
182
183 func rowConfigWithRulesOnlyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/rowConfigWithRulesOnly().() string {
184 return `
185 {"nftables":[
186 {"rule":{"family":"bridge","table":"nat","chain":"PREROUTING",
187 "expr":[
188 {"match":{"op":"==","left":{"meta":{"key":"iifname"}},"right":"net0"}},
189 {"jump":{"target":"cni-br-iface-container99-net1"}}
190 ],
191 "comment":"macspoofchk-container99-net1"}},
192 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1",
193 "expr":[
194 {"jump":{"target":"cni-br-iface-container99-net1-mac"}}
195 ],
196 "comment":"macspoofchk-container99-net1"}},
197 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1-mac",
198 "expr":[
199 {"match":{
200 "op":"==",
201 "left":{"payload":{"protocol":"ether","field":"saddr"}},
202 "right":"02:00:00:00:12:34"
203 }},
204 {"return":null}
205 ],
206 "comment":"macspoofchk-container99-net1"}},
207 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1-mac",
208 "expr":[{"drop":null}],
209 "index":0,
210 "comment":"macspoofchk-container99-net1"}}
211 ]}`
212 }
213
214 func assertExpectedTableAndChainsInSetupConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedTableAndChainsInSetupConfig().(c configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) {
215 config := c.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.[0]
216 jsonConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
217 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, 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().())
218
219 expectedConfig := `
220 {"nftables": [
221 {"table": {"family": "bridge", "name": "nat"}},
222 {"chain": {
223 "family": "bridge",
224 "table": "nat",
225 "name": "PREROUTING",
226 "type": "filter",
227 "hook": "prerouting",
228 "prio": -300,
229 "policy": "accept"
230 }},
231 {"chain": {
232 "family": "bridge",
233 "table": "nat",
234 "name": "cni-br-iface-container99-net1"
235 }},
236 {"chain": {
237 "family": "bridge",
238 "table": "nat",
239 "name": "cni-br-iface-container99-net1-mac"
240 }}
241 ]}`
242 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, string(jsonConfig)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchJSONscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchJSON().(expectedConfig))
243 }
244
245 func assertExpectedRulesInSetupConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/assertExpectedRulesInSetupConfig().(c configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) {
246 config := c.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig.[1]
247 jsonConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
248 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, 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().())
249
250 expectedConfig := `
251 {"nftables":[
252 {"flush":{"chain":{"family":"bridge","table":"nat","name":"cni-br-iface-container99-net1"}}},
253 {"flush":{"chain":{"family":"bridge","table":"nat","name":"cni-br-iface-container99-net1-mac"}}},
254 {"rule":{"family":"bridge","table":"nat","chain":"PREROUTING",
255 "expr":[
256 {"match":{"op":"==","left":{"meta":{"key":"iifname"}},"right":"net0"}},
257 {"jump":{"target":"cni-br-iface-container99-net1"}}
258 ],
259 "comment":"macspoofchk-container99-net1"}},
260 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1",
261 "expr":[
262 {"jump":{"target":"cni-br-iface-container99-net1-mac"}}
263 ],
264 "comment":"macspoofchk-container99-net1"}},
265 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1-mac",
266 "expr":[
267 {"match":{
268 "op":"==",
269 "left":{"payload":{"protocol":"ether","field":"saddr"}},
270 "right":"02:00:00:00:12:34"
271 }},
272 {"return":null}
273 ],
274 "comment":"macspoofchk-container99-net1"}},
275 {"rule":{"family":"bridge","table":"nat","chain":"cni-br-iface-container99-net1-mac",
276 "expr":[{"drop":null}],
277 "comment":"macspoofchk-container99-net1"}}
278 ]}`
279 ExpectWithOffsetscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/ExpectWithOffset().(1, string(jsonConfig)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchJSONscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchJSON().(expectedConfig))
280 }
281
282 const (
283 errorFirstApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorFirstApplyText. = "1st apply failed"
284 errorSecondApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorSecondApplyText. = "2nd apply failed"
285 errorReadTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorReadText. = "read failed"
286 )
287
288 type configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub# struct {
289 applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig. []*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#
290 readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig. *nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#
291
292 applyCounterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyCounter. int
293
294 failFirstApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failFirstApplyConfig. bool
295 failSecondApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failSecondApplyConfig. bool
296 failReadConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failReadConfig. bool
297
298 applyReturnNilscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyReturnNil. bool
299 readCalledscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readCalled. bool
300 }
301
302 func (a *configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) Applyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#Apply().(c *nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#) (*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#, error) {
303 a.applyCounterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyCounter.++
304 if a.failFirstApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failFirstApplyConfig. && a.applyCounterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyCounter. == 1 {
305 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().(errorFirstApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorFirstApplyText.)
306 }
307 if a.failSecondApplyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failSecondApplyConfig. && a.applyCounterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyCounter. == 2 {
308 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().(errorSecondApplyTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorSecondApplyText.)
309 }
310 a.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig. = append(a.applyConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyConfig., c)
311 if a.applyReturnNilscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#applyReturnNil. {
312 return nil, nil
313 }
314 return c, nil
315 }
316
317 func (a *configurerStubscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#) Readscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#Read().(_ ...string) (*nftscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft v0.4.0 `github.com/networkplumbing/go-nft/nft`/Config#, error) {
318 a.readCalledscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readCalled. = true
319 if a.failReadConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#failReadConfig. {
320 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().(errorReadTextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/errorReadText.)
321 }
322 return a.readConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link_test`/configurerStub#readConfig., nil
323 }