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

feat: added leakage verification #2051

Closed
Show file tree
Hide file tree
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
31 changes: 17 additions & 14 deletions dataclients/kubernetes/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/zalando/skipper/dataclients/kubernetes/definitions"
"github.com/zalando/skipper/eskip"
Expand Down Expand Up @@ -579,6 +580,8 @@ func TestIngressClassFilter(t *testing.T) {
}

func TestIngress(t *testing.T) {
defer goleak.VerifyNone(t)

api := newTestAPI(t, nil, &definitions.IngressList{})
defer api.Close()

Expand Down Expand Up @@ -741,8 +744,8 @@ func TestIngress(t *testing.T) {
}

checkRoutes(t, r, map[string]string{
"kube_namespace1__default_only______": "", //shunted because invalid backend
"kube_namespace1__mega__foo_example_org___test1__service1": "", //shunted because invalid backend
"kube_namespace1__default_only______": "", // shunted because invalid backend
"kube_namespace1__mega__foo_example_org___test1__service1": "", // shunted because invalid backend
})
})

Expand Down Expand Up @@ -1864,7 +1867,7 @@ func TestBuildHTTPClient(t *testing.T) {
t.Errorf("should return invalid certificate")
}

err = os.WriteFile("ca.empty.crt", []byte(""), 0644)
err = os.WriteFile("ca.empty.crt", []byte(""), 0o644)
if err != nil {
t.Error(err)
}
Expand All @@ -1875,8 +1878,8 @@ func TestBuildHTTPClient(t *testing.T) {
t.Error("empty certificate is invalid certificate")
}

//create CA file
err = os.WriteFile("ca.temp.crt", generateSSCert(), 0644)
// create CA file
err = os.WriteFile("ca.temp.crt", generateSSCert(), 0o644)
if err != nil {
t.Error(err)
}
Expand All @@ -1899,7 +1902,7 @@ func TestScoping(t *testing.T) {

// generateSSCert only for testing purposes
func generateSSCert() []byte {
//create root CA
// create root CA
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, _ := rand.Int(rand.Reader, serialNumberLimit)

Expand All @@ -1923,8 +1926,8 @@ func generateSSCert() []byte {
}

func createCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) (
cert *x509.Certificate, certPEM []byte, err error) {

cert *x509.Certificate, certPEM []byte, err error,
) {
certDER, err := x509.CreateCertificate(rand.Reader, template, parent, pub, parentPriv)
if err != nil {
return
Expand Down Expand Up @@ -2164,7 +2167,8 @@ func TestComputeBackendWeights(t *testing.T) {
Backend: &definitions.Backend{
ServiceName: "baz",
},
}, {
},
{
Path: "",
Backend: &definitions.Backend{
ServiceName: "qux",
Expand Down Expand Up @@ -2990,7 +2994,6 @@ func TestSkipperDefaultFilters(t *testing.T) {
defer dc.Close()

r, err := dc.LoadAll()

if err != nil {
t.Error("should not return an error", err)
return
Expand All @@ -3012,7 +3015,7 @@ func TestSkipperDefaultFilters(t *testing.T) {
t.Error(err)
}
file := filepath.Join(defaultFiltersDir, "service1.namespace1")
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0o666); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -3052,7 +3055,7 @@ func TestSkipperDefaultFilters(t *testing.T) {
t.Error(err)
}
file := filepath.Join(dir, "service1.namespace1")
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0o666); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -3084,15 +3087,15 @@ func TestSkipperDefaultFilters(t *testing.T) {
t.Error(err)
}
invalidFileName := filepath.Join(defaultFiltersDir, "file.name.doesnt.match.our.pattern")
if err := os.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0o666); err != nil {
t.Error(err)
}
err = os.Mkdir(filepath.Join(defaultFiltersDir, "some.directory"), os.ModePerm)
if err != nil {
t.Error(err)
}
bigFile := filepath.Join(defaultFiltersDir, "huge.file")
if err := os.WriteFile(bigFile, make([]byte, 1024*1024+1), 0666); err != nil {
if err := os.WriteFile(bigFile, make([]byte, 1024*1024+1), 0o666); err != nil {
t.Error(err)
}

Expand Down
11 changes: 11 additions & 0 deletions dataclients/kubernetes/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kubernetes_test

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
11 changes: 11 additions & 0 deletions eskipfile/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eskipfile_test

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
15 changes: 15 additions & 0 deletions eskipfile/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/logging/loggingtest"
"github.com/zalando/skipper/routing"
"go.uber.org/goleak"
)

const testWatchFile = "fixtures/watch-test.eskip"
Expand Down Expand Up @@ -172,12 +173,16 @@ func (t *watchTest) close() {
}

func TestWatchInitialFails(t *testing.T) {
defer goleak.VerifyNone(t)

test := initWatchTest(t)
defer test.close()
test.timeoutInitial()
}

func TestWatchInitialRecovers(t *testing.T) {
defer goleak.VerifyNone(t)

test := initWatchTest(t)
defer test.close()
test.timeoutInitial()
Expand All @@ -187,6 +192,8 @@ func TestWatchInitialRecovers(t *testing.T) {
}

func TestWatchUpdateFails(t *testing.T) {
defer goleak.VerifyNone(t)

createFile(t)
defer deleteFile(t)
test := initWatchTest(t)
Expand All @@ -197,6 +204,8 @@ func TestWatchUpdateFails(t *testing.T) {
}

func TestWatchUpdateRecover(t *testing.T) {
defer goleak.VerifyNone(t)

createFile(t)
defer deleteFile(t)
test := initWatchTest(t)
Expand All @@ -209,6 +218,8 @@ func TestWatchUpdateRecover(t *testing.T) {
}

func TestInitialAndUnchanged(t *testing.T) {
defer goleak.VerifyNone(t)

createFile(t)
defer deleteFile(t)
test := initWatchTest(t)
Expand All @@ -218,6 +229,8 @@ func TestInitialAndUnchanged(t *testing.T) {
}

func TestInitialAndDeleteFile(t *testing.T) {
defer goleak.VerifyNone(t)

createFile(t)
defer deleteFile(t)
test := initWatchTest(t)
Expand All @@ -228,6 +241,8 @@ func TestInitialAndDeleteFile(t *testing.T) {
}

func TestWatchUpdate(t *testing.T) {
defer goleak.VerifyNone(t)

createFile(t)
defer deleteFile(t)
test := initWatchTest(t)
Expand Down
3 changes: 3 additions & 0 deletions filters/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/zalando/skipper/filters/filtertest"
"go.uber.org/goleak"
)

const testDelay = 12 * time.Millisecond
Expand Down Expand Up @@ -95,6 +96,8 @@ func TestBlock(t *testing.T) {
}

func TestServe(t *testing.T) {
defer goleak.VerifyNone(t)

parts := []string{"foo", "bar", "baz"}
ctx := &filtertest.Context{FRequest: &http.Request{}}
ServeHTTP(ctx, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/yookoala/gofast v0.6.0
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9
go.uber.org/atomic v1.9.0
go.uber.org/goleak v1.1.12
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
Expand Down Expand Up @@ -1008,6 +1009,7 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand Down