From 23142619dff59396a7fcd52de4e6f34769712205 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Mon, 30 Oct 2023 09:39:24 -0400 Subject: [PATCH 1/3] fixes sdk calls and 1hr off testing due to daylight savings --- router/xgress_edge/certchecker_test.go | 14 ++++++------ tests/addressable_terminators_test.go | 6 ++++-- tests/data_flow_close_test.go | 30 +++++++++++++++++++------- tests/data_flow_hs_rotating_test.go | 10 ++++++--- tests/data_flow_hs_test.go | 6 ++++-- 5 files changed, 44 insertions(+), 22 deletions(-) diff --git a/router/xgress_edge/certchecker_test.go b/router/xgress_edge/certchecker_test.go index 469821073..11e557120 100644 --- a/router/xgress_edge/certchecker_test.go +++ b/router/xgress_edge/certchecker_test.go @@ -8,13 +8,13 @@ import ( "crypto/x509" "crypto/x509/pkix" "github.com/openziti/channel/v2" - "github.com/openziti/ziti/common/eid" - "github.com/openziti/ziti/router/internal/edgerouter" - "github.com/openziti/ziti/router/env" "github.com/openziti/foundation/v2/tlz" "github.com/openziti/foundation/v2/versions" "github.com/openziti/identity" "github.com/openziti/transport/v2" + "github.com/openziti/ziti/common/eid" + "github.com/openziti/ziti/router/env" + "github.com/openziti/ziti/router/internal/edgerouter" "github.com/pkg/errors" "github.com/stretchr/testify/require" "math/big" @@ -46,7 +46,7 @@ func Test_CertExpirationChecker(t *testing.T) { req.LessOrEqual(waitTime, maxWaitTime) }) - t.Run("both 7d out is 0", func(t *testing.T) { + t.Run("both 7d out is 1hr or less", func(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker() @@ -59,7 +59,7 @@ func Test_CertExpirationChecker(t *testing.T) { waitTime, err := certChecker.getWaitTime() req.NoError(err) - req.Equal(0*time.Second, waitTime) + req.LessOrEqual(waitTime, 1*time.Hour+1*time.Second) }) t.Run("both 4d out is 0", func(t *testing.T) { @@ -206,7 +206,7 @@ func Test_CertExpirationChecker(t *testing.T) { req.Equal(0*time.Second, waitTime) }) - t.Run("server 7d out returns 0", func(t *testing.T) { + t.Run("server 7d out returns 1h or less", func(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker() @@ -218,7 +218,7 @@ func Test_CertExpirationChecker(t *testing.T) { waitTime, err := certChecker.getWaitTime() req.NoError(err) - req.Equal(0*time.Second, waitTime) + req.LessOrEqual(waitTime, 1*time.Hour+1*time.Second, waitTime) }) t.Run("server 7d30s out returns 0", func(t *testing.T) { diff --git a/tests/addressable_terminators_test.go b/tests/addressable_terminators_test.go index 648250a97..c524ee0f3 100644 --- a/tests/addressable_terminators_test.go +++ b/tests/addressable_terminators_test.go @@ -19,9 +19,9 @@ package tests import ( - "github.com/openziti/ziti/controller/xt_smartrouting" "github.com/openziti/sdk-golang/ziti" "github.com/openziti/sdk-golang/ziti/edge" + "github.com/openziti/ziti/controller/xt_smartrouting" "github.com/pkg/errors" "net" "strings" @@ -142,7 +142,9 @@ func Test_AddressableTerminatorSameIdentity(t *testing.T) { listener.(edge.SessionListener).SetErrorEventHandler(errorHandler) defer func() { _ = listener.Close() }() - context2 := ziti.NewContext(identity.config) + context2, err := ziti.NewContext(identity.config) + ctx.Req.NoError(err) + listener2, err := context2.ListenWithOptions(service.Name, &ziti.ListenOptions{ BindUsingEdgeIdentity: true, ConnectTimeout: 5 * time.Second, diff --git a/tests/data_flow_close_test.go b/tests/data_flow_close_test.go index 20bbb775c..b613169c1 100644 --- a/tests/data_flow_close_test.go +++ b/tests/data_flow_close_test.go @@ -22,8 +22,8 @@ package tests import ( "errors" "fmt" - "github.com/openziti/ziti/common/eid" "github.com/openziti/sdk-golang/ziti" + "github.com/openziti/ziti/common/eid" "io" "testing" "time" @@ -69,7 +69,9 @@ func Test_ServerConnClosePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) conn := ctx.WrapConn(clientContext.Dial(service.Name)) defer conn.Close() @@ -134,7 +136,9 @@ func Test_ServerContextClosePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) conn := ctx.WrapConn(clientContext.Dial(service.Name)) defer conn.Close() @@ -202,7 +206,9 @@ func Test_ServerCloseListenerPropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) conn := ctx.WrapConn(clientContext.Dial(service.Name)) defer conn.Close() @@ -234,7 +240,9 @@ func Test_ClientConnClosePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) errC := make(chan error, 1) @@ -296,7 +304,9 @@ func Test_ClientContextClosePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) errC := make(chan error, 1) @@ -359,7 +369,9 @@ func Test_ServerConnCloseWritePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) errC := make(chan error, 1) @@ -453,7 +465,9 @@ func Test_ClientConnCloseWritePropagation(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) conn := ctx.WrapConn(clientContext.Dial(service.Name)) name := eid.New() diff --git a/tests/data_flow_hs_rotating_test.go b/tests/data_flow_hs_rotating_test.go index d860d4406..6966e37ac 100644 --- a/tests/data_flow_hs_rotating_test.go +++ b/tests/data_flow_hs_rotating_test.go @@ -21,9 +21,9 @@ package tests import ( "github.com/michaelquigley/pfxlog" - "github.com/openziti/ziti/common/eid" "github.com/openziti/sdk-golang/ziti" "github.com/openziti/sdk-golang/ziti/edge" + "github.com/openziti/ziti/common/eid" "github.com/pkg/errors" "math/rand" "sync" @@ -122,7 +122,9 @@ func testClientFirstWithStrategy(t *testing.T, strategy string) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) logger := pfxlog.Logger() @@ -265,7 +267,9 @@ func testServerFirstWithStrategy(t *testing.T, strategy string) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) ticker := time.NewTicker(time.Millisecond * 500) defer ticker.Stop() diff --git a/tests/data_flow_hs_test.go b/tests/data_flow_hs_test.go index 5a8295757..83d43ff5a 100644 --- a/tests/data_flow_hs_test.go +++ b/tests/data_flow_hs_test.go @@ -21,8 +21,8 @@ package tests import ( "github.com/michaelquigley/pfxlog" - "github.com/openziti/ziti/common/eid" "github.com/openziti/sdk-golang/ziti" + "github.com/openziti/ziti/common/eid" "sync/atomic" "testing" "time" @@ -76,7 +76,9 @@ func Test_HSDataflow(t *testing.T) { clientIdentity := ctx.AdminManagementSession.RequireNewIdentityWithOtt(false) clientConfig := ctx.EnrollIdentity(clientIdentity.Id) - clientContext := ziti.NewContext(clientConfig) + + clientContext, err := ziti.NewContext(clientConfig) + ctx.Req.NoError(err) for i := 0; i < 100; i++ { conn := ctx.WrapConn(clientContext.Dial(service.Name)) From 6c0bc85cbefe7768bb62bc3c977efe2010bcc0d3 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Mon, 30 Oct 2023 09:53:42 -0400 Subject: [PATCH 2/3] use UTC to avoid daylight savings time issues --- router/xgress_edge/certchecker_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/router/xgress_edge/certchecker_test.go b/router/xgress_edge/certchecker_test.go index 11e557120..9e693779d 100644 --- a/router/xgress_edge/certchecker_test.go +++ b/router/xgress_edge/certchecker_test.go @@ -50,7 +50,7 @@ func Test_CertExpirationChecker(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker() - now := time.Now() + now := time.Now().UTC() notAfter := now.AddDate(0, 0, 7) certChecker.id.Cert().Leaf.NotAfter = notAfter @@ -59,7 +59,7 @@ func Test_CertExpirationChecker(t *testing.T) { waitTime, err := certChecker.getWaitTime() req.NoError(err) - req.LessOrEqual(waitTime, 1*time.Hour+1*time.Second) + req.Equal(0*time.Second, waitTime) }) t.Run("both 4d out is 0", func(t *testing.T) { @@ -210,7 +210,7 @@ func Test_CertExpirationChecker(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker() - now := time.Now() + now := time.Now().UTC() notAfter := now.AddDate(0, 0, 7) certChecker.id.ServerCert()[0].Leaf.NotAfter = notAfter @@ -218,7 +218,7 @@ func Test_CertExpirationChecker(t *testing.T) { waitTime, err := certChecker.getWaitTime() req.NoError(err) - req.LessOrEqual(waitTime, 1*time.Hour+1*time.Second, waitTime) + req.Equal(0*time.Second, waitTime) }) t.Run("server 7d30s out returns 0", func(t *testing.T) { From 24cfbc601bb60025f6609f5ed023c20958e81add Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Mon, 30 Oct 2023 09:56:20 -0400 Subject: [PATCH 3/3] fix test description lines --- router/xgress_edge/certchecker_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/router/xgress_edge/certchecker_test.go b/router/xgress_edge/certchecker_test.go index 9e693779d..8741666cf 100644 --- a/router/xgress_edge/certchecker_test.go +++ b/router/xgress_edge/certchecker_test.go @@ -46,7 +46,7 @@ func Test_CertExpirationChecker(t *testing.T) { req.LessOrEqual(waitTime, maxWaitTime) }) - t.Run("both 7d out is 1hr or less", func(t *testing.T) { + t.Run("both 7d out is 0", func(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker() @@ -206,7 +206,7 @@ func Test_CertExpirationChecker(t *testing.T) { req.Equal(0*time.Second, waitTime) }) - t.Run("server 7d out returns 1h or less", func(t *testing.T) { + t.Run("server 7d out returns 0", func(t *testing.T) { req := require.New(t) certChecker, _ := newCertChecker()