MM-30802: Enable GoSAML2 library support (#16361)
* update saml to always use new library * remove unused variable * Update tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3323b886f1
Коммит
e014de0a65
@@ -138,12 +138,6 @@ func RegisterMetricsInterface(f func(*Server) einterfaces.MetricsInterface) {
|
|||||||
metricsInterface = f
|
metricsInterface = f
|
||||||
}
|
}
|
||||||
|
|
||||||
var samlInterface func(*App) einterfaces.SamlInterface
|
|
||||||
|
|
||||||
func RegisterSamlInterface(f func(*App) einterfaces.SamlInterface) {
|
|
||||||
samlInterface = f
|
|
||||||
}
|
|
||||||
|
|
||||||
var samlInterfaceNew func(*App) einterfaces.SamlInterface
|
var samlInterfaceNew func(*App) einterfaces.SamlInterface
|
||||||
|
|
||||||
func RegisterNewSamlInterface(f func(*App) einterfaces.SamlInterface) {
|
func RegisterNewSamlInterface(f func(*App) einterfaces.SamlInterface) {
|
||||||
@@ -187,17 +181,9 @@ func (a *App) initEnterprise() {
|
|||||||
if notificationInterface != nil {
|
if notificationInterface != nil {
|
||||||
a.srv.Notification = notificationInterface(a)
|
a.srv.Notification = notificationInterface(a)
|
||||||
}
|
}
|
||||||
if samlInterface != nil {
|
if samlInterfaceNew != nil {
|
||||||
if *a.Config().ExperimentalSettings.UseNewSAMLLibrary && samlInterfaceNew != nil {
|
mlog.Debug("Loading SAML2 library")
|
||||||
mlog.Debug("Loading new SAML2 library")
|
a.srv.Saml = samlInterfaceNew(a)
|
||||||
a.srv.Saml = samlInterfaceNew(a)
|
|
||||||
} else if *a.Config().ExperimentalSettings.UseNewSAMLLibrary && samlInterfaceNew == nil {
|
|
||||||
mlog.Debug("Ignoring configuration setting to use the Experimental SAML library")
|
|
||||||
a.srv.Saml = samlInterface(a)
|
|
||||||
} else {
|
|
||||||
mlog.Debug("Loading original SAML library")
|
|
||||||
a.srv.Saml = samlInterface(a)
|
|
||||||
}
|
|
||||||
if err := a.srv.Saml.ConfigureSP(); err != nil {
|
if err := a.srv.Saml.ConfigureSP(); err != nil {
|
||||||
mlog.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
mlog.Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
func TestSAMLSettings(t *testing.T) {
|
func TestSAMLSettings(t *testing.T) {
|
||||||
tt := []struct {
|
tt := []struct {
|
||||||
name string
|
name string
|
||||||
setSAMLInterface bool
|
|
||||||
setNewInterface bool
|
setNewInterface bool
|
||||||
useNewSAMLLibrary bool
|
useNewSAMLLibrary bool
|
||||||
isNil bool
|
isNil bool
|
||||||
@@ -25,45 +24,25 @@ func TestSAMLSettings(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "No SAML Interfaces, default setting",
|
name: "No SAML Interfaces, default setting",
|
||||||
setSAMLInterface: false,
|
|
||||||
setNewInterface: false,
|
setNewInterface: false,
|
||||||
useNewSAMLLibrary: false,
|
useNewSAMLLibrary: false,
|
||||||
isNil: true,
|
isNil: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "No SAML Interfaces, set config true",
|
name: "No SAML Interfaces, set config true",
|
||||||
setSAMLInterface: false,
|
|
||||||
setNewInterface: false,
|
setNewInterface: false,
|
||||||
useNewSAMLLibrary: true,
|
useNewSAMLLibrary: true,
|
||||||
isNil: true,
|
isNil: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "Orignal SAML Interface, default setting",
|
|
||||||
setSAMLInterface: true,
|
|
||||||
setNewInterface: false,
|
|
||||||
useNewSAMLLibrary: false,
|
|
||||||
isNil: false,
|
|
||||||
metadata: "samlOne",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Orignal SAML Interface, config true",
|
|
||||||
setSAMLInterface: true,
|
|
||||||
setNewInterface: false,
|
|
||||||
useNewSAMLLibrary: true,
|
|
||||||
isNil: false,
|
|
||||||
metadata: "samlOne",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "Both SAML Interfaces, default setting",
|
name: "Both SAML Interfaces, default setting",
|
||||||
setSAMLInterface: true,
|
|
||||||
setNewInterface: true,
|
setNewInterface: true,
|
||||||
useNewSAMLLibrary: false,
|
useNewSAMLLibrary: false,
|
||||||
isNil: false,
|
isNil: false,
|
||||||
metadata: "samlOne",
|
metadata: "samlTwo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Both SAML Interfaces, config true",
|
name: "Both SAML Interfaces, config true",
|
||||||
setSAMLInterface: true,
|
|
||||||
setNewInterface: true,
|
setNewInterface: true,
|
||||||
useNewSAMLLibrary: true,
|
useNewSAMLLibrary: true,
|
||||||
isNil: false,
|
isNil: false,
|
||||||
@@ -73,17 +52,6 @@ func TestSAMLSettings(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range tt {
|
for _, tc := range tt {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
saml := &mocks.SamlInterface{}
|
|
||||||
saml.Mock.On("ConfigureSP").Return(nil)
|
|
||||||
saml.Mock.On("GetMetadata").Return("samlOne", nil)
|
|
||||||
if tc.setSAMLInterface {
|
|
||||||
RegisterSamlInterface(func(a *App) einterfaces.SamlInterface {
|
|
||||||
return saml
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
RegisterSamlInterface(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
saml2 := &mocks.SamlInterface{}
|
saml2 := &mocks.SamlInterface{}
|
||||||
saml2.Mock.On("ConfigureSP").Return(nil)
|
saml2.Mock.On("ConfigureSP").Return(nil)
|
||||||
saml2.Mock.On("GetMetadata").Return("samlTwo", nil)
|
saml2.Mock.On("GetMetadata").Return("samlTwo", nil)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user