MM-24467- Use new ServiceProviderIdentifier in AuthnRequest (#14725)
* add ServiceProviderIdentifier to config * Update config, add unit test * fix unit test, update i18n * add english translation for error Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
124014ad9c
Коммит
938176be3e
@@ -4599,6 +4599,7 @@ func TestLoginErrorMessage(t *testing.T) {
|
|||||||
*cfg.SamlSettings.IdpUrl = "https://localhost/adfs/ls"
|
*cfg.SamlSettings.IdpUrl = "https://localhost/adfs/ls"
|
||||||
*cfg.SamlSettings.IdpDescriptorUrl = "https://localhost/adfs/services/trust"
|
*cfg.SamlSettings.IdpDescriptorUrl = "https://localhost/adfs/services/trust"
|
||||||
*cfg.SamlSettings.IdpMetadataUrl = "https://localhost/adfs/metadata"
|
*cfg.SamlSettings.IdpMetadataUrl = "https://localhost/adfs/metadata"
|
||||||
|
*cfg.SamlSettings.ServiceProviderIdentifier = "https://localhost/login/sso/saml"
|
||||||
*cfg.SamlSettings.AssertionConsumerServiceURL = "https://localhost/login/sso/saml"
|
*cfg.SamlSettings.AssertionConsumerServiceURL = "https://localhost/login/sso/saml"
|
||||||
*cfg.SamlSettings.IdpCertificateFile = app.SamlIdpCertificateName
|
*cfg.SamlSettings.IdpCertificateFile = app.SamlIdpCertificateName
|
||||||
*cfg.SamlSettings.PrivateKeyFile = app.SamlPrivateKeyName
|
*cfg.SamlSettings.PrivateKeyFile = app.SamlPrivateKeyName
|
||||||
|
|||||||
@@ -5350,6 +5350,10 @@
|
|||||||
"id": "model.config.is_valid.saml_signature_algorithm.app_error",
|
"id": "model.config.is_valid.saml_signature_algorithm.app_error",
|
||||||
"translation": "Invalid Signature Algorithm."
|
"translation": "Invalid Signature Algorithm."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.saml_spidentifier_attribute.app_error",
|
||||||
|
"translation": "Service Provider Identifier is required"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "model.config.is_valid.saml_username_attribute.app_error",
|
"id": "model.config.is_valid.saml_username_attribute.app_error",
|
||||||
"translation": "Invalid Username attribute. Must be set."
|
"translation": "Invalid Username attribute. Must be set."
|
||||||
|
|||||||
@@ -2135,6 +2135,7 @@ type SamlSettings struct {
|
|||||||
IdpUrl *string
|
IdpUrl *string
|
||||||
IdpDescriptorUrl *string
|
IdpDescriptorUrl *string
|
||||||
IdpMetadataUrl *string
|
IdpMetadataUrl *string
|
||||||
|
ServiceProviderIdentifier *string
|
||||||
AssertionConsumerServiceURL *string
|
AssertionConsumerServiceURL *string
|
||||||
|
|
||||||
SignatureAlgorithm *string
|
SignatureAlgorithm *string
|
||||||
@@ -2212,6 +2213,14 @@ func (s *SamlSettings) SetDefaults() {
|
|||||||
s.IdpDescriptorUrl = NewString("")
|
s.IdpDescriptorUrl = NewString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.ServiceProviderIdentifier == nil {
|
||||||
|
if s.IdpDescriptorUrl != nil {
|
||||||
|
s.ServiceProviderIdentifier = NewString(*s.IdpDescriptorUrl)
|
||||||
|
} else {
|
||||||
|
s.ServiceProviderIdentifier = NewString("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if s.IdpMetadataUrl == nil {
|
if s.IdpMetadataUrl == nil {
|
||||||
s.IdpMetadataUrl = NewString("")
|
s.IdpMetadataUrl = NewString("")
|
||||||
}
|
}
|
||||||
@@ -3126,6 +3135,10 @@ func (s *SamlSettings) isValid() *AppError {
|
|||||||
return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.saml_username_attribute.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(*s.ServiceProviderIdentifier) == 0 {
|
||||||
|
return NewAppError("Config.IsValid", "model.config.is_valid.saml_spidentifier_attribute.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
if *s.Verify {
|
if *s.Verify {
|
||||||
if len(*s.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*s.AssertionConsumerServiceURL) {
|
if len(*s.AssertionConsumerServiceURL) == 0 || !IsValidHttpUrl(*s.AssertionConsumerServiceURL) {
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.saml_assertion_consumer_service_url.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ func TestConfigIsValidDefaultAlgorithms(t *testing.T) {
|
|||||||
*c1.SamlSettings.IdpUrl = "http://test.url.com"
|
*c1.SamlSettings.IdpUrl = "http://test.url.com"
|
||||||
*c1.SamlSettings.IdpDescriptorUrl = "http://test.url.com"
|
*c1.SamlSettings.IdpDescriptorUrl = "http://test.url.com"
|
||||||
*c1.SamlSettings.IdpCertificateFile = "certificatefile"
|
*c1.SamlSettings.IdpCertificateFile = "certificatefile"
|
||||||
|
*c1.SamlSettings.ServiceProviderIdentifier = "http://test.url.com"
|
||||||
*c1.SamlSettings.EmailAttribute = "Email"
|
*c1.SamlSettings.EmailAttribute = "Email"
|
||||||
*c1.SamlSettings.UsernameAttribute = "Username"
|
*c1.SamlSettings.UsernameAttribute = "Username"
|
||||||
|
|
||||||
@@ -153,6 +154,27 @@ func TestConfigIsValidDefaultAlgorithms(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigServiceProviderDefault(t *testing.T) {
|
||||||
|
c1 := &Config{
|
||||||
|
SamlSettings: *&SamlSettings{
|
||||||
|
Enable: NewBool(true),
|
||||||
|
Verify: NewBool(false),
|
||||||
|
Encrypt: NewBool(false),
|
||||||
|
IdpUrl: NewString("http://test.url.com"),
|
||||||
|
IdpDescriptorUrl: NewString("http://test2.url.com"),
|
||||||
|
IdpCertificateFile: NewString("certificatefile"),
|
||||||
|
EmailAttribute: NewString("Email"),
|
||||||
|
UsernameAttribute: NewString("Username"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c1.SetDefaults()
|
||||||
|
assert.Equal(t, *c1.SamlSettings.ServiceProviderIdentifier, *c1.SamlSettings.IdpDescriptorUrl)
|
||||||
|
|
||||||
|
err := c1.SamlSettings.isValid()
|
||||||
|
require.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigIsValidFakeAlgorithm(t *testing.T) {
|
func TestConfigIsValidFakeAlgorithm(t *testing.T) {
|
||||||
c1 := Config{}
|
c1 := Config{}
|
||||||
c1.SetDefaults()
|
c1.SetDefaults()
|
||||||
@@ -165,6 +187,7 @@ func TestConfigIsValidFakeAlgorithm(t *testing.T) {
|
|||||||
*c1.SamlSettings.IdpDescriptorUrl = "http://test.url.com"
|
*c1.SamlSettings.IdpDescriptorUrl = "http://test.url.com"
|
||||||
*c1.SamlSettings.IdpMetadataUrl = "http://test.url.com"
|
*c1.SamlSettings.IdpMetadataUrl = "http://test.url.com"
|
||||||
*c1.SamlSettings.IdpCertificateFile = "certificatefile"
|
*c1.SamlSettings.IdpCertificateFile = "certificatefile"
|
||||||
|
*c1.SamlSettings.ServiceProviderIdentifier = "http://test.url.com"
|
||||||
*c1.SamlSettings.EmailAttribute = "Email"
|
*c1.SamlSettings.EmailAttribute = "Email"
|
||||||
*c1.SamlSettings.UsernameAttribute = "Username"
|
*c1.SamlSettings.UsernameAttribute = "Username"
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user