Skip to content

Commit

Permalink
[MM-59350] Include LDAP vendor errors in Support Packet (mattermost#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Jul 13, 2024
1 parent 9bb22a3 commit bbc8baa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
15 changes: 13 additions & 2 deletions server/channels/app/support_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
32 changes: 31 additions & 1 deletion server/channels/app/support_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"

"github.com/mattermost/mattermost/server/public/model"
"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"
)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/einterfaces/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 10 additions & 3 deletions server/einterfaces/mocks/LdapInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbc8baa

Please sign in to comment.