Skip to content

Commit

Permalink
Rework sandbox to use custom tokens/credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Apr 9, 2021
1 parent 458da5f commit eaa739f
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 178 deletions.
32 changes: 16 additions & 16 deletions pkg/networkservice/chains/nsmgr/server_heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int, restored bool) {
nseCtx, nseCtxCancel := context.WithTimeout(context.Background(), time.Second)
defer nseCtxCancel()

nse := domain.Nodes[nodeNum].NewEndpoint(nseCtx, nseReg, sandbox.GenerateExpiringToken(time.Second), counter)
nse := domain.Nodes[nodeNum].NewEndpoint(nseCtx, nseReg, time.Second, counter)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand All @@ -113,7 +113,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int, restored bool) {
},
}

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -134,7 +134,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int, restored bool) {
nseReg2.Name = nse.Name
nseReg2.Url = nse.URL.String()
}
domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken, counter)
domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg2, sandbox.DefaultTokenTimeout, counter)

if restored {
require.Eventually(t, checkSecondRequestsReceived(func() int {
Expand Down Expand Up @@ -225,7 +225,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int, restored bool) {
}

counter := &counterServer{}
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand All @@ -238,7 +238,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int, restored bool) {
},
}

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -258,7 +258,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int, restored bool) {
forwarderReg.Name = forwarder.Name
forwarderReg.Url = forwarder.URL.String()
}
domain.Nodes[nodeNum].NewForwarder(ctx, forwarderReg, sandbox.GenerateTestToken)
domain.Nodes[nodeNum].NewForwarder(ctx, forwarderReg, sandbox.DefaultTokenTimeout)

if restored {
require.Eventually(t, checkSecondRequestsReceived(func() int {
Expand Down Expand Up @@ -291,13 +291,13 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int, restored bool) {
}

func setupCancelableForwarderNode(ctx context.Context, node *sandbox.Node) (context.CancelFunc, *sandbox.EndpointEntry) {
node.NewNSMgr(ctx, sandbox.Name("nsmgr"), nil, sandbox.GenerateTestToken, nsmgr.NewServer)
node.NewNSMgr(ctx, sandbox.Name("nsmgr"), nil, sandbox.DefaultTokenTimeout, nsmgr.NewServer)

forwarderCtx, forwarderCtxCancel := context.WithTimeout(ctx, time.Second)

forwarder := node.NewForwarder(forwarderCtx, &registry.NetworkServiceEndpoint{
Name: sandbox.Name("forwarder"),
}, sandbox.GenerateExpiringToken(time.Second))
}, time.Second)

return forwarderCtxCancel, forwarder
}
Expand Down Expand Up @@ -363,7 +363,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
}

counter := &counterServer{}
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand All @@ -376,7 +376,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
},
}

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -390,7 +390,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
mgr := domain.Nodes[nodeNum].NSMgr
require.Eventually(t, checkURLFree(mgr.URL), timeout, tick)

domain.Nodes[nodeNum].NewNSMgr(ctx, mgr.Name, mgr.URL, sandbox.GenerateTestToken, nsmgr.NewServer)
domain.Nodes[nodeNum].NewNSMgr(ctx, mgr.Name, mgr.URL, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
// TODO: https://github.com/networkservicemesh/sdk/issues/713
domain.Nodes[nodeNum].RegisterForwarder(ctx, forwarderReg)
if nodeNum == 1 {
Expand All @@ -401,7 +401,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
Name: "nse-2",
NetworkServiceNames: []string{"ns"},
}
domain.Nodes[2].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken, counter)
domain.Nodes[2].NewEndpoint(ctx, nseReg2, sandbox.DefaultTokenTimeout, counter)
}

if restored {
Expand Down Expand Up @@ -437,12 +437,12 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
func setupCancellableNSMgrNode(ctx context.Context, node *sandbox.Node) (context.CancelFunc, *registry.NetworkServiceEndpoint) {
nsmgrCtx, nsmgrCtxCancel := context.WithTimeout(ctx, time.Second)

node.NewNSMgr(nsmgrCtx, sandbox.Name("nsmgr"), nil, sandbox.GenerateExpiringToken(time.Second), nsmgr.NewServer)
node.NewNSMgr(nsmgrCtx, sandbox.Name("nsmgr"), nil, time.Second, nsmgr.NewServer)

forwarderReg := &registry.NetworkServiceEndpoint{
Name: sandbox.Name("forwarder"),
}
node.NewForwarder(ctx, forwarderReg, sandbox.GenerateTestToken)
node.NewForwarder(ctx, forwarderReg, sandbox.DefaultTokenTimeout)

return nsmgrCtxCancel, forwarderReg
}
Expand All @@ -466,7 +466,7 @@ func TestNSMGR_CloseHeal(t *testing.T) {

nseCtx, nseCtxCancel := context.WithCancel(ctx)

domain.Nodes[0].NewEndpoint(nseCtx, nseReg, sandbox.GenerateTestToken)
domain.Nodes[0].NewEndpoint(nseCtx, nseReg, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand All @@ -481,7 +481,7 @@ func TestNSMGR_CloseHeal(t *testing.T) {

nscCtx, nscCtxCancel := context.WithCancel(ctx)

nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.DefaultTokenTimeout)

// 1. Request
conn, err := nsc.Request(ctx, request.Clone())
Expand Down
58 changes: 29 additions & 29 deletions pkg/networkservice/chains/nsmgr/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func TestNSMGR_RemoteUsecase_Parallel(t *testing.T) {
Name: "final-endpoint",
NetworkServiceNames: []string{"my-service-remote"},
}
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)
}()
nsc := domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[1].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestNSMGR_SelectsRestartingEndpoint(t *testing.T) {
})

// 3. Create client and request endpoint
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestNSMGR_RemoteUsecase_BusyEndpoints(t *testing.T) {
Name: "final-endpoint-" + strconv.Itoa(id),
NetworkServiceNames: []string{"my-service-remote"},
}
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, newBusyEndpoint())
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, newBusyEndpoint())
wg.Done()
}(i)
}
Expand All @@ -209,9 +209,9 @@ func TestNSMGR_RemoteUsecase_BusyEndpoints(t *testing.T) {
Name: "final-endpoint-3",
NetworkServiceNames: []string{"my-service-remote"},
}
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)
}()
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestNSMGR_RemoteUsecase(t *testing.T) {
}

counter := &counterServer{}
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand All @@ -261,7 +261,7 @@ func TestNSMGR_RemoteUsecase(t *testing.T) {
},
}

nsc := domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[1].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -306,9 +306,9 @@ func TestNSMGR_ConnectToDeadNSE(t *testing.T) {
counter := &counterServer{}

nseCtx, killNse := context.WithCancel(ctx)
domain.Nodes[0].NewEndpoint(nseCtx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[0].NewEndpoint(nseCtx, nseReg, sandbox.DefaultTokenTimeout, counter)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -355,9 +355,9 @@ func TestNSMGR_LocalUsecase(t *testing.T) {
}

counter := &counterServer{}
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestNSMGR_PassThroughRemote(t *testing.T) {
sandbox.NewCrossConnectClientFactory(
newPassTroughClient(fmt.Sprintf("my-service-remote-%v", i-1)),
kernel.NewClient()),
connect.WithDialOptions(sandbox.DefaultDialOptions(sandbox.GenerateTestToken)...),
connect.WithDialOptions(sandbox.DefaultDialOptions(sandbox.DefaultTokenTimeout)...),
),
),
}
Expand All @@ -426,10 +426,10 @@ func TestNSMGR_PassThroughRemote(t *testing.T) {
Name: fmt.Sprintf("endpoint-%v", i),
NetworkServiceNames: []string{fmt.Sprintf("my-service-remote-%v", i)},
}
domain.Nodes[i].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, additionalFunctionality...)
domain.Nodes[i].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, additionalFunctionality...)
}

nsc := domain.Nodes[nodesCount-1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[nodesCount-1].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -473,7 +473,7 @@ func TestNSMGR_PassThroughLocal(t *testing.T) {
sandbox.NewCrossConnectClientFactory(
newPassTroughClient(fmt.Sprintf("my-service-remote-%v", i-1)),
kernel.NewClient()),
connect.WithDialOptions(sandbox.DefaultDialOptions(sandbox.GenerateTestToken)...),
connect.WithDialOptions(sandbox.DefaultDialOptions(sandbox.DefaultTokenTimeout)...),
),
),
}
Expand All @@ -482,10 +482,10 @@ func TestNSMGR_PassThroughLocal(t *testing.T) {
Name: fmt.Sprintf("endpoint-%v", i),
NetworkServiceNames: []string{fmt.Sprintf("my-service-remote-%v", i)},
}
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, additionalFunctionality...)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, additionalFunctionality...)
}

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestNSMGR_ShouldCorrectlyAddForwardersWithSameNames(t *testing.T) {
SetNodesCount(1).
SetRegistryProxySupplier(nil).
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, _ int) {
node.NewNSMgr(ctx, sandbox.Name("nsmgr"), nil, sandbox.GenerateTestToken, nsmgr.NewServer)
node.NewNSMgr(ctx, sandbox.Name("nsmgr"), nil, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
}).
SetRegistryExpiryDuration(sandbox.RegistryExpiryDuration).
Build()
Expand All @@ -533,13 +533,13 @@ func TestNSMGR_ShouldCorrectlyAddForwardersWithSameNames(t *testing.T) {

// 1. Add forwarders
forwarder1Reg := forwarderReg.Clone()
domain.Nodes[0].NewForwarder(ctx, forwarder1Reg, sandbox.GenerateTestToken)
domain.Nodes[0].NewForwarder(ctx, forwarder1Reg, sandbox.DefaultTokenTimeout)

forwarder2Reg := forwarderReg.Clone()
domain.Nodes[0].NewForwarder(ctx, forwarder2Reg, sandbox.GenerateTestToken)
domain.Nodes[0].NewForwarder(ctx, forwarder2Reg, sandbox.DefaultTokenTimeout)

forwarder3Reg := forwarderReg.Clone()
domain.Nodes[0].NewForwarder(ctx, forwarder3Reg, sandbox.GenerateTestToken)
domain.Nodes[0].NewForwarder(ctx, forwarder3Reg, sandbox.DefaultTokenTimeout)

// 2. Wait for refresh
<-time.After(sandbox.RegistryExpiryDuration)
Expand Down Expand Up @@ -578,16 +578,16 @@ func TestNSMGR_ShouldCorrectlyAddEndpointsWithSameNames(t *testing.T) {
Name: "endpoint",
}

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

// 1. Add endpoints
nse1Reg := nseReg.Clone()
nse1Reg.NetworkServiceNames = []string{"service-1"}
domain.Nodes[0].NewEndpoint(ctx, nse1Reg, sandbox.GenerateTestToken)
domain.Nodes[0].NewEndpoint(ctx, nse1Reg, sandbox.DefaultTokenTimeout)

nse2Reg := nseReg.Clone()
nse2Reg.NetworkServiceNames = []string{"service-2"}
domain.Nodes[0].NewEndpoint(ctx, nse2Reg, sandbox.GenerateTestToken)
domain.Nodes[0].NewEndpoint(ctx, nse2Reg, sandbox.DefaultTokenTimeout)

// 2. Wait for refresh
<-time.After(sandbox.RegistryExpiryDuration)
Expand Down Expand Up @@ -653,9 +653,9 @@ func testNSEAndClient(
ctx, cancel := context.WithCancel(ctx)
defer cancel()

domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

conn, err := nsc.Request(ctx, &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -799,9 +799,9 @@ func TestNSMGR_LocalUsecaseNoURL(t *testing.T) {
}

counter := &counterServer{}
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/nsmgrproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func TestNSMGR_InterdomainUseCase(t *testing.T) {
NetworkServiceNames: []string{"my-service-interdomain"},
}

domain2.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)
domain2.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout)

nsc := domain1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain1.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down
6 changes: 2 additions & 4 deletions pkg/networkservice/common/refresh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func TestRefreshClient_Sandbox(t *testing.T) {
domain := sandbox.NewBuilder(ctx, t).
SetNodesCount(2).
SetRegistryProxySupplier(nil).
SetTokenGenerateFunc(sandbox.GenerateTestToken).
Build()

nseReg := &registry.NetworkServiceEndpoint{
Expand All @@ -215,10 +214,9 @@ func TestRefreshClient_Sandbox(t *testing.T) {
}

refreshSrv := newRefreshTesterServer(t, sandboxMinDuration, sandboxExpireTimeout)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, refreshSrv)
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, refreshSrv)

nscTokenGenerator := sandbox.GenerateExpiringToken(sandboxExpireTimeout)
nsc := domain.Nodes[1].NewClient(ctx, nscTokenGenerator)
nsc := domain.Nodes[1].NewClient(ctx, sandboxExpireTimeout)

refreshSrv.beforeRequest("test-conn")
_, err := nsc.Request(ctx, mkRequest("test-conn", nil))
Expand Down
Loading

0 comments on commit eaa739f

Please sign in to comment.