From bbc8baac0a970413bf9ed7447f870cc21d3c602a Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Sat, 13 Jul 2024 10:17:07 +0200 Subject: [PATCH] [MM-59350] Include LDAP vendor errors in Support Packet (#27571) --- server/channels/app/support_packet.go | 15 ++++++++-- server/channels/app/support_packet_test.go | 32 +++++++++++++++++++++- server/einterfaces/ldap.go | 2 +- server/einterfaces/mocks/LdapInterface.go | 13 +++++++-- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/server/channels/app/support_packet.go b/server/channels/app/support_packet.go index 6ea0b1c5aff..f09df4d81e0 100644 --- a/server/channels/app/support_packet.go +++ b/server/channels/app/support_packet.go @@ -123,8 +123,19 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error) /* LDAP */ var vendorName, vendorVersion string - if ldapInterface := a.Ldap(); ldapInterface != nil { - vendorName, vendorVersion = ldapInterface.GetVendorNameAndVendorVersion(c) + ldap := a.Ldap() + if ldap != nil { + vendorName, vendorVersion, err = ldap.GetVendorNameAndVendorVersion(c) + if err != nil { + rErr = multierror.Append(errors.Wrap(err, "error while getting LDAP vendor info")) + } + + if vendorName == "" { + vendorName = "unknown" + } + if vendorVersion == "" { + vendorVersion = "unknown" + } } /* Elastic Search */ diff --git a/server/channels/app/support_packet_test.go b/server/channels/app/support_packet_test.go index d92c19e608c..5d13837d0a9 100644 --- a/server/channels/app/support_packet_test.go +++ b/server/channels/app/support_packet_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" @@ -16,6 +17,7 @@ import ( "github.com/mattermost/mattermost/server/v8/channels/app/platform" smocks "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks" "github.com/mattermost/mattermost/server/v8/config" + emocks "github.com/mattermost/mattermost/server/v8/einterfaces/mocks" fmocks "github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks" ) @@ -46,7 +48,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) { defer th.TearDown() licenseUsers := 100 - license := model.NewTestLicense() + license := model.NewTestLicense("ldap") license.Features.Users = model.NewInt(licenseUsers) th.App.Srv().SetLicense(license) @@ -148,6 +150,34 @@ func TestGenerateSupportPacketYaml(t *testing.T) { assert.Equal(t, "mock", packet.FileDriver) assert.Equal(t, "FAIL: all broken", packet.FileStatus) }) + + t.Run("no LDAP vendor info", func(t *testing.T) { + ldapMock := &emocks.LdapInterface{} + ldapMock.On( + "GetVendorNameAndVendorVersion", + mock.AnythingOfType("*request.Context"), + ).Return("", "", nil) + th.App.Channels().Ldap = ldapMock + + packet := generateSupportPacket(t) + + assert.Equal(t, "unknown", packet.LdapVendorName) + assert.Equal(t, "unknown", packet.LdapVendorVersion) + }) + + t.Run("found LDAP vendor info", func(t *testing.T) { + ldapMock := &emocks.LdapInterface{} + ldapMock.On( + "GetVendorNameAndVendorVersion", + mock.AnythingOfType("*request.Context"), + ).Return("some vendor", "v1.0.0", nil) + th.App.Channels().Ldap = ldapMock + + packet := generateSupportPacket(t) + + assert.Equal(t, "some vendor", packet.LdapVendorName) + assert.Equal(t, "v1.0.0", packet.LdapVendorVersion) + }) } func TestGenerateSupportPacket(t *testing.T) { diff --git a/server/einterfaces/ldap.go b/server/einterfaces/ldap.go index a7369882638..bf4b0420bdd 100644 --- a/server/einterfaces/ldap.go +++ b/server/einterfaces/ldap.go @@ -26,5 +26,5 @@ type LdapInterface interface { UpdateProfilePictureIfNecessary(request.CTX, model.User, model.Session) GetADLdapIdFromSAMLId(c request.CTX, authData string) string GetSAMLIdFromADLdapId(c request.CTX, authData string) string - GetVendorNameAndVendorVersion(rctx request.CTX) (string, string) + GetVendorNameAndVendorVersion(rctx request.CTX) (string, string, error) } diff --git a/server/einterfaces/mocks/LdapInterface.go b/server/einterfaces/mocks/LdapInterface.go index cabdf55035f..e4d54d0cc6c 100644 --- a/server/einterfaces/mocks/LdapInterface.go +++ b/server/einterfaces/mocks/LdapInterface.go @@ -329,7 +329,7 @@ func (_m *LdapInterface) GetUserAttributes(rctx request.CTX, id string, attribut } // GetVendorNameAndVendorVersion provides a mock function with given fields: rctx -func (_m *LdapInterface) GetVendorNameAndVendorVersion(rctx request.CTX) (string, string) { +func (_m *LdapInterface) GetVendorNameAndVendorVersion(rctx request.CTX) (string, string, error) { ret := _m.Called(rctx) if len(ret) == 0 { @@ -338,7 +338,8 @@ func (_m *LdapInterface) GetVendorNameAndVendorVersion(rctx request.CTX) (string var r0 string var r1 string - if rf, ok := ret.Get(0).(func(request.CTX) (string, string)); ok { + var r2 error + if rf, ok := ret.Get(0).(func(request.CTX) (string, string, error)); ok { return rf(rctx) } if rf, ok := ret.Get(0).(func(request.CTX) string); ok { @@ -353,7 +354,13 @@ func (_m *LdapInterface) GetVendorNameAndVendorVersion(rctx request.CTX) (string r1 = ret.Get(1).(string) } - return r0, r1 + if rf, ok := ret.Get(2).(func(request.CTX) error); ok { + r2 = rf(rctx) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // MigrateIDAttribute provides a mock function with given fields: c, toAttribute