[MM-20061] Add System Admin filter to both LDAP and SAML (#13534)
* promote user to admin upon login * Add SAML support for admin accounts * update en.json * update i18n * Add tests as per comments * change function name * fix config.go * invalidate cache so its not checking for cache when roles change * add enable attribute and filter
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5f7ca55b13
Коммит
dc24c9abe8
@@ -171,6 +171,21 @@ func TestConfigOverwriteGuestSettings(t *testing.T) {
|
||||
require.Equal(t, *c1.SamlSettings.GuestAttribute, attribute)
|
||||
}
|
||||
|
||||
func TestConfigOverwriteAdminSettings(t *testing.T) {
|
||||
const attribute = "FakeAttributeName"
|
||||
c1 := Config{
|
||||
SamlSettings: SamlSettings{
|
||||
AdminAttribute: NewString(attribute),
|
||||
},
|
||||
}
|
||||
|
||||
c1.SetDefaults()
|
||||
|
||||
if *c1.SamlSettings.AdminAttribute != attribute {
|
||||
t.Fatal("SamlSettings.AdminAttribute should be overwritten")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
|
||||
c1 := Config{}
|
||||
c1.SetDefaults()
|
||||
@@ -1069,6 +1084,105 @@ func TestLdapSettingsIsValid(t *testing.T) {
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
|
||||
{
|
||||
Name: "valid Admin filter #1",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("(property=value)"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "invalid Admin filter #1",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("("),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "invalid Admin filter #2",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("()"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "valid Admin filter #2",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("(&(property=value)(otherthing=othervalue))"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "valid Admin filter #3",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("(&(property=value)(|(otherthing=othervalue)(other=thing)))"),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
{
|
||||
Name: "invalid Admin filter #3",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("(&(property=value)(|(otherthing=othervalue)(other=thing))"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
{
|
||||
Name: "invalid Admin filter #4",
|
||||
LdapSettings: LdapSettings{
|
||||
Enable: NewBool(true),
|
||||
LdapServer: NewString("server"),
|
||||
BaseDN: NewString("basedn"),
|
||||
EmailAttribute: NewString("email"),
|
||||
UsernameAttribute: NewString("username"),
|
||||
IdAttribute: NewString("id"),
|
||||
LoginIdAttribute: NewString("loginid"),
|
||||
AdminFilter: NewString("(&(property=value)((otherthing=othervalue)(other=thing)))"),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
} {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
test.LdapSettings.SetDefaults()
|
||||
|
||||
Ссылка в новой задаче
Block a user