From 1924ac1c9398c79d751ff9049c0a3db202df1dea Mon Sep 17 00:00:00 2001 From: Savolro Date: Tue, 22 Oct 2024 12:26:31 +0300 Subject: [PATCH] Check if mesh is enabled before reg info check Signed-off-by: Savolro --- cli/cli_mesh_peers.go | 4 + meshnet/server.go | 334 +++++++++++++++++++++++++---------------- meshnet/server_test.go | 33 +++- 3 files changed, 243 insertions(+), 128 deletions(-) diff --git a/cli/cli_mesh_peers.go b/cli/cli_mesh_peers.go index 1a8b0a6a..d5e1168b 100644 --- a/cli/cli_mesh_peers.go +++ b/cli/cli_mesh_peers.go @@ -899,6 +899,8 @@ func allowIncomingResponseToError( resp.AllowIncomingErrorCode, identifier, ) + case *pb.AllowIncomingResponse_MeshnetErrorCode: + return meshnetErrorToError(resp.MeshnetErrorCode) default: return errors.New(AccountInternalError) } @@ -929,6 +931,8 @@ func denyIncomingResponseToError( resp.DenyIncomingErrorCode, identifier, ) + case *pb.DenyIncomingResponse_MeshnetErrorCode: + return meshnetErrorToError(resp.MeshnetErrorCode) default: return errors.New(AccountInternalError) } diff --git a/meshnet/server.go b/meshnet/server.go index a1a3b311..e1512fcd 100644 --- a/meshnet/server.go +++ b/meshnet/server.go @@ -265,7 +265,7 @@ func (s *Server) IsEnabled(context.Context, *pb.Empty) (*pb.IsEnabledResponse, e return &pb.IsEnabledResponse{ Response: &pb.IsEnabledResponse_Status{ Status: &pb.EnabledStatus{ - Value: s.mc.IsRegistrationInfoCorrect() && cfg.Mesh, + Value: cfg.Mesh && s.mc.IsRegistrationInfoCorrect(), Uid: cfg.Meshnet.EnabledByUID, }, }, @@ -470,14 +470,6 @@ func (s *Server) Invite( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.InviteResponse{ - Response: &pb.InviteResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -496,6 +488,14 @@ func (s *Server) Invite( }, nil } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.InviteResponse{ + Response: &pb.InviteResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + }, nil + } + tokenData := cfg.TokensData[cfg.AutoConnectData.ID] err := s.invitationAPI.Invite( tokenData.Token, @@ -583,14 +583,6 @@ func (s *Server) AcceptInvite( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.RespondToInviteResponse{ - Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -609,6 +601,14 @@ func (s *Server) AcceptInvite( }, nil } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.RespondToInviteResponse{ + Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + }, nil + } + tokenData := cfg.TokensData[cfg.AutoConnectData.ID] received, err := s.invitationAPI.Received(tokenData.Token, cfg.MeshDevice.ID) if err != nil { @@ -708,14 +708,6 @@ func (s *Server) DenyInvite( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.RespondToInviteResponse{ - Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -734,6 +726,14 @@ func (s *Server) DenyInvite( }, nil } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.RespondToInviteResponse{ + Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + }, nil + } + tokenData := cfg.TokensData[cfg.AutoConnectData.ID] received, err := s.invitationAPI.Received(tokenData.Token, cfg.MeshDevice.ID) if err != nil { @@ -799,14 +799,6 @@ func (s *Server) RevokeInvite( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.RespondToInviteResponse{ - Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -825,6 +817,14 @@ func (s *Server) RevokeInvite( }, nil } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.RespondToInviteResponse{ + Response: &pb.RespondToInviteResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + }, nil + } + tokenData := cfg.TokensData[cfg.AutoConnectData.ID] sent, err := s.invitationAPI.Sent(tokenData.Token, cfg.MeshDevice.ID) if err != nil { @@ -887,14 +887,6 @@ func (s *Server) GetInvites(context.Context, *pb.Empty) (*pb.GetInvitesResponse, }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.GetInvitesResponse{ - Response: &pb.GetInvitesResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -913,6 +905,14 @@ func (s *Server) GetInvites(context.Context, *pb.Empty) (*pb.GetInvitesResponse, }, nil } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.GetInvitesResponse{ + Response: &pb.GetInvitesResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + }, nil + } + tokenData := cfg.TokensData[cfg.AutoConnectData.ID] resp, err := s.invitationAPI.Received(tokenData.Token, cfg.MeshDevice.ID) if err != nil { @@ -1632,20 +1632,28 @@ func (s *Server) AllowIncoming( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.AllowIncomingResponse{ + Response: &pb.AllowIncomingResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.AllowIncomingResponse{ Response: &pb.AllowIncomingResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.AllowIncomingResponse{ - Response: &pb.AllowIncomingResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.AllowIncomingResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -1748,20 +1756,28 @@ func (s *Server) DenyIncoming( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.DenyIncomingResponse{ + Response: &pb.DenyIncomingResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.DenyIncomingResponse{ Response: &pb.DenyIncomingResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.DenyIncomingResponse{ - Response: &pb.DenyIncomingResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.DenyIncomingResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -1857,14 +1873,6 @@ func (s *Server) AllowRouting( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.AllowRoutingResponse{ - Response: &pb.AllowRoutingResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - }, nil - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -1875,6 +1883,14 @@ func (s *Server) AllowRouting( }, nil } + if !cfg.Mesh { + return &pb.AllowRoutingResponse{ + Response: &pb.AllowRoutingResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, + }, + }, nil + } + token := cfg.TokensData[cfg.AutoConnectData.ID].Token peers, err := s.reg.List(token, cfg.MeshDevice.ID) if err != nil { @@ -1973,20 +1989,28 @@ func (s *Server) DenyRouting( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.DenyRoutingResponse{ + Response: &pb.DenyRoutingResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.DenyRoutingResponse{ Response: &pb.DenyRoutingResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.DenyRoutingResponse{ - Response: &pb.DenyRoutingResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.DenyRoutingResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2089,20 +2113,28 @@ func (s *Server) AllowLocalNetwork( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.AllowLocalNetworkResponse{ + Response: &pb.AllowLocalNetworkResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.AllowLocalNetworkResponse{ Response: &pb.AllowLocalNetworkResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.AllowLocalNetworkResponse{ - Response: &pb.AllowLocalNetworkResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.AllowLocalNetworkResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2205,20 +2237,28 @@ func (s *Server) DenyLocalNetwork( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.DenyLocalNetworkResponse{ + Response: &pb.DenyLocalNetworkResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.DenyLocalNetworkResponse{ Response: &pb.DenyLocalNetworkResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.DenyLocalNetworkResponse{ - Response: &pb.DenyLocalNetworkResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.DenyLocalNetworkResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2321,20 +2361,28 @@ func (s *Server) AllowFileshare( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.AllowFileshareResponse{ + Response: &pb.AllowFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.AllowFileshareResponse{ Response: &pb.AllowFileshareResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.AllowFileshareResponse{ - Response: &pb.AllowFileshareResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.AllowFileshareResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2441,20 +2489,28 @@ func (s *Server) DenyFileshare( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.DenyFileshareResponse{ + Response: &pb.DenyFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.DenyFileshareResponse{ Response: &pb.DenyFileshareResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.DenyFileshareResponse{ - Response: &pb.DenyFileshareResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.DenyFileshareResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2561,20 +2617,28 @@ func (s *Server) EnableAutomaticFileshare( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.EnableAutomaticFileshareResponse{ + Response: &pb.EnableAutomaticFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.EnableAutomaticFileshareResponse{ Response: &pb.EnableAutomaticFileshareResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.EnableAutomaticFileshareResponse{ - Response: &pb.EnableAutomaticFileshareResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.EnableAutomaticFileshareResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2670,20 +2734,28 @@ func (s *Server) DisableAutomaticFileshare( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.DisableAutomaticFileshareResponse{ + Response: &pb.DisableAutomaticFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.DisableAutomaticFileshareResponse{ Response: &pb.DisableAutomaticFileshareResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.DisableAutomaticFileshareResponse{ - Response: &pb.DisableAutomaticFileshareResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.DisableAutomaticFileshareResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2779,20 +2851,28 @@ func (s *Server) NotifyNewTransfer( }, nil } - if !s.mc.IsRegistrationInfoCorrect() { + var cfg config.Config + if err := s.cm.Load(&cfg); err != nil { + s.pub.Publish(err) + return &pb.NotifyNewTransferResponse{ + Response: &pb.NotifyNewTransferResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, nil + } + + if !cfg.Mesh { return &pb.NotifyNewTransferResponse{ Response: &pb.NotifyNewTransferResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_ENABLED, }, }, nil } - var cfg config.Config - if err := s.cm.Load(&cfg); err != nil { - s.pub.Publish(err) + if !s.mc.IsRegistrationInfoCorrect() { return &pb.NotifyNewTransferResponse{ - Response: &pb.NotifyNewTransferResponse_ServiceErrorCode{ - ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + Response: &pb.NotifyNewTransferResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, }, }, nil } @@ -2898,14 +2978,6 @@ func (s *Server) connect( } } - if !s.mc.IsRegistrationInfoCorrect() { - return &pb.ConnectResponse{ - Response: &pb.ConnectResponse_MeshnetErrorCode{ - MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, - }, - } - } - var cfg config.Config if err := s.cm.Load(&cfg); err != nil { s.pub.Publish(err) @@ -2924,6 +2996,14 @@ func (s *Server) connect( } } + if !s.mc.IsRegistrationInfoCorrect() { + return &pb.ConnectResponse{ + Response: &pb.ConnectResponse_MeshnetErrorCode{ + MeshnetErrorCode: pb.MeshnetErrorCode_NOT_REGISTERED, + }, + } + } + if cfg.Technology != config.Technology_NORDLYNX { return &pb.ConnectResponse{ Response: &pb.ConnectResponse_MeshnetErrorCode{ diff --git a/meshnet/server_test.go b/meshnet/server_test.go index 2c52e364..84d8a5c1 100644 --- a/meshnet/server_test.go +++ b/meshnet/server_test.go @@ -175,6 +175,7 @@ func (acceptInvitationsAPI) Received(string, uuid.UUID) (mesh.Invitations, error func newMockedServer( t *testing.T, listErr error, + loadConfigErr error, saveConfigErr error, configureErr error, isMeshOn bool, @@ -188,7 +189,6 @@ func newMockedServer( registryApi.ConfigureErr = configureErr configManager := &mock.ConfigManager{} - configManager.SaveErr = saveConfigErr server := NewServer( meshRenewChecker{}, @@ -209,6 +209,9 @@ func newMockedServer( server.EnableMeshnet(context.Background(), &pb.Empty{}) } + configManager.SaveErr = saveConfigErr + configManager.LoadErr = loadConfigErr + return server } @@ -1114,6 +1117,7 @@ func TestServer_EnableAutomaticFileshare(t *testing.T) { peerUuid string listErr error configureErr error + loadConfigErr error saveConfigErr error isMeshOn bool expectedResponse *pb.EnableAutomaticFileshareResponse @@ -1177,6 +1181,18 @@ func TestServer_EnableAutomaticFileshare(t *testing.T) { }, }, }, + { + name: "failed to load config", + peerUuid: peerValidUuid, + listErr: core.ErrUnauthorized, + loadConfigErr: fmt.Errorf("generic error"), + isMeshOn: true, + expectedResponse: &pb.EnableAutomaticFileshareResponse{ + Response: &pb.EnableAutomaticFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, + }, { name: "failed to save config", peerUuid: peerValidUuid, @@ -1206,6 +1222,7 @@ func TestServer_EnableAutomaticFileshare(t *testing.T) { t.Run(test.name, func(t *testing.T) { server := newMockedServer(t, test.listErr, + test.loadConfigErr, test.saveConfigErr, test.configureErr, test.isMeshOn, @@ -1239,6 +1256,7 @@ func TestServer_DisableAutomaticFileshare(t *testing.T) { peerUuid string isMeshOn bool listErr error + loadConfigErr error saveConfigErr error configureErr error expectedResponse *pb.DisableAutomaticFileshareResponse @@ -1302,6 +1320,18 @@ func TestServer_DisableAutomaticFileshare(t *testing.T) { }, }, }, + { + name: "failed to load config", + peerUuid: peerValidUuid, + listErr: core.ErrUnauthorized, + loadConfigErr: fmt.Errorf("generic error"), + isMeshOn: true, + expectedResponse: &pb.DisableAutomaticFileshareResponse{ + Response: &pb.DisableAutomaticFileshareResponse_ServiceErrorCode{ + ServiceErrorCode: pb.ServiceErrorCode_CONFIG_FAILURE, + }, + }, + }, { name: "failed to save config", peerUuid: peerAleradyDisabledUuid, @@ -1331,6 +1361,7 @@ func TestServer_DisableAutomaticFileshare(t *testing.T) { t.Run(test.name, func(t *testing.T) { server := newMockedServer(t, test.listErr, + test.loadConfigErr, test.saveConfigErr, test.configureErr, test.isMeshOn,