From 812ece3a8e8504c040d2b09e7768758fd48cd0a1 Mon Sep 17 00:00:00 2001 From: Bartosz Oleaczek Date: Wed, 7 Aug 2024 13:01:27 +0200 Subject: [PATCH] Add state-backend-test command --- build/foss/Cargo.lock | 14 +++++++------- cli/cli.go | 13 +++++++++++++ cli/cli_cities_test.go | 2 +- cli/cli_connect_test.go | 2 +- cli/cli_countries_test.go | 2 +- cli/cli_groups_test.go | 2 +- cli/cli_gui_backend.go | 28 ++++++++++++++++++++++++++++ cli/cli_mesh_peers_test.go | 2 +- cli/cli_set_autoconnect_test.go | 2 +- 9 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 cli/cli_gui_backend.go diff --git a/build/foss/Cargo.lock b/build/foss/Cargo.lock index fb221424..19a9de86 100644 --- a/build/foss/Cargo.lock +++ b/build/foss/Cargo.lock @@ -682,7 +682,7 @@ dependencies = [ [[package]] name = "drop-analytics" version = "1.0.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "anyhow", "serde", @@ -693,7 +693,7 @@ dependencies = [ [[package]] name = "drop-auth" version = "0.1.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "base64 0.21.7", "hmac", @@ -705,12 +705,12 @@ dependencies = [ [[package]] name = "drop-config" version = "1.0.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" [[package]] name = "drop-core" version = "0.1.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "serde", ] @@ -718,7 +718,7 @@ dependencies = [ [[package]] name = "drop-storage" version = "1.0.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "chrono", "include_dir", @@ -736,7 +736,7 @@ dependencies = [ [[package]] name = "drop-transfer" version = "1.0.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "anyhow", "async-trait", @@ -1932,7 +1932,7 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" [[package]] name = "norddrop" version = "0.1.0" -source = "git+https://github.com/NordSecurity/libdrop?tag=v5.4.0_moose_backport#bc7d2cffb9483bc85f501d5725e12cdea0bf48a6" +source = "git+https://github.com/NordSecurity/libdrop?tag=v5.5.0-moose-with-context#b95303810701c225d01ea44c4176701ea5e18c27" dependencies = [ "async-trait", "cc", diff --git a/cli/cli.go b/cli/cli.go index 8fe61575..322185bf 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -21,6 +21,7 @@ import ( meshpb "github.com/NordSecurity/nordvpn-linux/meshnet/pb" "github.com/NordSecurity/nordvpn-linux/snapconf" snappb "github.com/NordSecurity/nordvpn-linux/snapconf/pb" + statepb "github.com/NordSecurity/nordvpn-linux/state/pb" "github.com/fatih/color" "github.com/urfave/cli/v2" @@ -96,6 +97,9 @@ func NewApp(version, environment, hash, salt string, cmd.client = pb.NewDaemonClient(conn) cmd.meshClient = meshpb.NewMeshnetClient(conn) cmd.fileshareClient = filesharepb.NewFileshareClient(fileshareConn) + if internal.IsDevEnv(environment) { + cmd.stateClient = statepb.NewStateClient(conn) + } } cli.AppHelpTemplate = AppHelpTemplate @@ -547,6 +551,14 @@ func NewApp(version, environment, hash, salt string, }, } + if internal.IsDevEnv(environment) { + app.Commands = append(app.Commands, &cli.Command{ + Name: "state-backend-test", + Action: cmd.SubscribeToStatus, + Hidden: true, + }) + } + app.Commands = append(app.Commands, meshnetCommand(cmd)) if pingErr == nil { @@ -928,6 +940,7 @@ type cmd struct { client pb.DaemonClient meshClient meshpb.MeshnetClient fileshareClient filesharepb.FileshareClient + stateClient statepb.StateClient environment internal.Environment loaderInterceptor *LoaderInterceptor } diff --git a/cli/cli_cities_test.go b/cli/cli_cities_test.go index 5160d84e..52cf5602 100644 --- a/cli/cli_cities_test.go +++ b/cli/cli_cities_test.go @@ -15,7 +15,7 @@ import ( func TestCitiesList(t *testing.T) { category.Set(t, category.Unit) mockClient := mockDaemonClient{} - c := cmd{&mockClient, nil, nil, "", nil} + c := cmd{&mockClient, nil, nil, nil, "", nil} tests := []struct { name string diff --git a/cli/cli_connect_test.go b/cli/cli_connect_test.go index 87fbc389..d7ee8645 100644 --- a/cli/cli_connect_test.go +++ b/cli/cli_connect_test.go @@ -92,7 +92,7 @@ func (c mockDaemonClient) Groups(ctx context.Context, in *pb.Empty, opts ...grpc func TestConnectAutoComplete(t *testing.T) { category.Set(t, category.Unit) mockClient := mockDaemonClient{} - c := cmd{&mockClient, nil, nil, "", nil} + c := cmd{&mockClient, nil, nil, nil, "", nil} tests := []struct { name string countries []*pb.ServerGroup diff --git a/cli/cli_countries_test.go b/cli/cli_countries_test.go index 7a6ec722..e4674510 100644 --- a/cli/cli_countries_test.go +++ b/cli/cli_countries_test.go @@ -15,7 +15,7 @@ import ( func TestCountriesList(t *testing.T) { category.Set(t, category.Unit) mockClient := mockDaemonClient{} - c := cmd{&mockClient, nil, nil, "", nil} + c := cmd{&mockClient, nil, nil, nil, "", nil} tests := []struct { name string diff --git a/cli/cli_groups_test.go b/cli/cli_groups_test.go index edbfca50..59289a84 100644 --- a/cli/cli_groups_test.go +++ b/cli/cli_groups_test.go @@ -15,7 +15,7 @@ import ( func TestGroupsList(t *testing.T) { category.Set(t, category.Unit) mockClient := mockDaemonClient{} - c := cmd{&mockClient, nil, nil, "", nil} + c := cmd{&mockClient, nil, nil, nil, "", nil} tests := []struct { name string diff --git a/cli/cli_gui_backend.go b/cli/cli_gui_backend.go new file mode 100644 index 00000000..24a29501 --- /dev/null +++ b/cli/cli_gui_backend.go @@ -0,0 +1,28 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/NordSecurity/nordvpn-linux/state/pb" + "github.com/urfave/cli/v2" +) + +// FileshareSend rpc +func (c *cmd) SubscribeToStatus(ctx *cli.Context) error { + fmt.Println("Subscribing to bakckend state.") + srv, err := c.stateClient.Subscribe(context.Background(), &pb.Empty{}) + if err != nil { + fmt.Println("Failed to subscribe to state changes: ", err) + } + + fmt.Println("Subscribed to bakckend state.") + for { + stateUpdate, err := srv.Recv() + if err != nil { + fmt.Println("Failed to receive state update: ", err) + } else { + fmt.Printf("State update: %+v\n", stateUpdate) + } + } +} diff --git a/cli/cli_mesh_peers_test.go b/cli/cli_mesh_peers_test.go index 82a931be..a13f88fd 100644 --- a/cli/cli_mesh_peers_test.go +++ b/cli/cli_mesh_peers_test.go @@ -67,7 +67,7 @@ func (m mockMeshClient) GetPeers(ctx context.Context, in *pb.Empty, opts ...grpc func TestMeshPeerList(t *testing.T) { category.Set(t, category.Unit) - c := cmd{nil, mockMeshClient{}, nil, "", nil} + c := cmd{nil, mockMeshClient{}, nil, nil, "", nil} tests := []struct { name string expected []string diff --git a/cli/cli_set_autoconnect_test.go b/cli/cli_set_autoconnect_test.go index 0fccc667..78ce340d 100644 --- a/cli/cli_set_autoconnect_test.go +++ b/cli/cli_set_autoconnect_test.go @@ -15,7 +15,7 @@ import ( func TestAutoConnectAutoComplete(t *testing.T) { category.Set(t, category.Unit) mockClient := mockDaemonClient{} - c := cmd{&mockClient, nil, nil, "", nil} + c := cmd{&mockClient, nil, nil, nil, "", nil} tests := []struct { name string countries []*pb.ServerGroup