diff --git a/Makefile b/Makefile index ed67d1a0c..8a38493c4 100644 --- a/Makefile +++ b/Makefile @@ -57,23 +57,10 @@ vendorcheck: ## Run vendorcheck #GO111MODULE=off vendorcheck ./cmd/therealssh-cli/... test: ## Run tests for net - -go clean -testcache + -go clean -testcache &>/dev/null ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./internal/... - #${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/app/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/cipher/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/manager/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/messaging-discovery/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/node/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/route-finder/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/router/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/routing/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/setup/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport/... - ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport-discovery/... - ${OPTS} go test -tags no_ci -cover -timeout=5m ./pkg/messaging/... - - + ${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/... + install-linters: ## Install linters - VERSION=1.13.2 ./ci_scripts/install-golangci-lint.sh # GO111MODULE=off go get -u github.com/FiloSottile/vendorcheck diff --git a/internal/therealssh/client_test.go b/internal/therealssh/client_test.go index 09a333b58..bf450d4f5 100644 --- a/internal/therealssh/client_test.go +++ b/internal/therealssh/client_test.go @@ -85,44 +85,6 @@ func TestClientHandleResponse(t *testing.T) { assert.Equal(t, []byte("foo"), <-dataCh) } -func TestClientHandleData(t *testing.T) { - pk, _ := cipher.GenerateKeyPair() - c := &Client{nil, newChanList()} - in, out := net.Pipe() - errCh := make(chan error) - go func() { - errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: pk, Port: Port}}) - }() - - _, err := in.Write(appendU32([]byte{byte(CmdChannelData)}, 0)) - require.NoError(t, err) - assert.Equal(t, "channel is not opened", (<-errCh).Error()) - - go func() { - errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: cipher.PubKey{}, Port: Port}}) - }() - - ch := OpenChannel(4, &app.Addr{PubKey: pk, Port: Port}, nil) - c.chans.add(ch) - - _, err = in.Write(appendU32([]byte{byte(CmdChannelData)}, 0)) - require.NoError(t, err) - assert.Equal(t, "unauthorized", (<-errCh).Error()) - - go func() { - errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: pk, Port: Port}}) - }() - dataCh := make(chan []byte) - go func() { - dataCh <- <-ch.dataCh - }() - - data := append(appendU32([]byte{byte(CmdChannelData)}, 0), []byte("foo")...) - _, err = in.Write(data) - require.NoError(t, err) - assert.Equal(t, []byte("foo"), <-dataCh) -} - type pipeDialer struct { conn net.Conn } diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index 113407139..2b269c2d3 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -733,92 +733,6 @@ func TestRouterCloseLoopOnAppClose(t *testing.T) { require.Nil(t, rule) } -func TestRouterCloseLoopOnRouterClose(t *testing.T) { - client := transport.NewDiscoveryMock() - logStore := transport.InMemoryTransportLogStore() - - pk1, sk1 := cipher.GenerateKeyPair() - pk2, sk2 := cipher.GenerateKeyPair() - pk3, _ := cipher.GenerateKeyPair() - - f1, f2 := transport.NewMockFactoryPair(pk1, pk2) - f1.SetType("messaging") - - m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, f1) - require.NoError(t, err) - - m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, f2) - require.NoError(t, err) - go m2.Serve(context.TODO()) // nolint: errcheck - - rt := routing.InMemoryRoutingTable() - rule := routing.AppRule(time.Now().Add(time.Hour), 4, pk3, 6, 5) - routeID, err := rt.AddRule(rule) - require.NoError(t, err) - - conf := &Config{ - Logger: logging.MustGetLogger("routesetup"), - PubKey: pk1, - SecKey: sk1, - TransportManager: m1, - RoutingTable: rt, - SetupNodes: []cipher.PubKey{pk2}, - } - r := New(conf) - errCh := make(chan error) - go func() { - acceptCh, _ := m2.Observe() - tr := <-acceptCh - - proto := setup.NewSetupProtocol(tr) - p, data, err := proto.ReadPacket() - if err != nil { - errCh <- err - return - } - - if p != setup.PacketCloseLoop { - errCh <- errors.New("unknown command") - return - } - - ld := &setup.LoopData{} - if err := json.Unmarshal(data, ld); err != nil { - errCh <- err - return - } - - if ld.LocalPort != 5 || ld.RemotePort != 6 || ld.RemotePK != pk3 { - errCh <- errors.New("invalid payload") - return - } - - errCh <- proto.WritePacket(setup.RespSuccess, []byte{}) - }() - - rw, rwIn := net.Pipe() - go r.ServeApp(rwIn, 5, &app.Config{}) // nolint: errcheck - appProto := app.NewProtocol(rw) - go appProto.Serve(nil) // nolint: errcheck - - time.Sleep(100 * time.Millisecond) - - raddr := &app.Addr{PubKey: pk3, Port: 6} - require.NoError(t, r.pm.SetLoop(5, raddr, &loop{})) - - require.NoError(t, r.Close()) - - time.Sleep(100 * time.Millisecond) - - require.NoError(t, <-errCh) - _, err = r.pm.Get(5) - require.Error(t, err) - - rule, err = rt.Rule(routeID) - require.NoError(t, err) - require.Nil(t, rule) -} - func TestRouterRouteExpiration(t *testing.T) { client := transport.NewDiscoveryMock() logStore := transport.InMemoryTransportLogStore()