From 8a88e896bf7334363b8faaef1c1df21bcc473927 Mon Sep 17 00:00:00 2001 From: Bartosz Oleaczek Date: Thu, 16 Jan 2025 12:06:29 +0200 Subject: [PATCH] Remove mesh private key on logout --- daemon/rpc_logout.go | 1 + daemon/rpc_logout_test.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/daemon/rpc_logout.go b/daemon/rpc_logout.go index e94433d7..370220c8 100644 --- a/daemon/rpc_logout.go +++ b/daemon/rpc_logout.go @@ -103,6 +103,7 @@ func (r *RPC) Logout(ctx context.Context, in *pb.LogoutRequest) (payload *pb.Pay delete(c.TokensData, c.AutoConnectData.ID) c.AutoConnectData.ID = 0 c.Mesh = false + c.MeshPrivateKey = "" return c }); err != nil { return nil, err diff --git a/daemon/rpc_logout_test.go b/daemon/rpc_logout_test.go index c791b8c9..187414c5 100644 --- a/daemon/rpc_logout_test.go +++ b/daemon/rpc_logout_test.go @@ -34,9 +34,11 @@ func (mockApi) DeleteToken(token string) error { return nil } func (mockApi) Logout(token string) error { return nil } func TestLogout_Token(t *testing.T) { + cfgManagerMock := newMockConfigManager() + rpc := RPC{ ac: &workingLoginChecker{}, - cm: newMockConfigManager(), + cm: cfgManagerMock, norduser: &testnorduser.MockNorduserCombinedService{}, netw: &networker.Mock{}, ncClient: mockNC{}, @@ -84,12 +86,14 @@ func TestLogout_Token(t *testing.T) { } tokenData.Token = "1234" c.TokensData[c.AutoConnectData.ID] = tokenData + c.MeshPrivateKey = "key" return c }) assert.NoError(t, err) resp, err := rpc.Logout(context.Background(), &pb.LogoutRequest{PersistToken: test.persistToken}) assert.NoError(t, err) assert.Equal(t, test.result, resp.Type) + assert.Equal(t, "", cfgManagerMock.c.MeshPrivateKey, "Mesh private key not removed after logout.") }) } }