Fix bug 4073

This commit is contained in:
stonezdj 2018-01-19 11:46:24 +08:00
parent 69fa18c881
commit b99a13cfa8
2 changed files with 12 additions and 1 deletions

View File

@ -365,7 +365,13 @@ func GetDatabaseFromCfg(cfg map[string]interface{}) *models.Database {
// Valid LDAP Scope
func validLdapScope(cfg map[string]interface{}, isMigrate bool) {
ldapScope := cfg[ldapScopeKey].(int)
ldapScope, ok := cfg[ldapScopeKey].(int)
if !ok {
ldapScopeFloat, ok := cfg[ldapScopeKey].(float64)
if ok {
ldapScope = int(ldapScopeFloat)
}
}
if isMigrate && ldapScope > 0 && ldapScope < 3 {
ldapScope = ldapScope - 1
}

View File

@ -143,6 +143,8 @@ func TestGetDatabaseFromCfg(t *testing.T) {
}
func TestValidLdapScope(t *testing.T) {
var dbValue float64
dbValue = 2
ldapScopeKey := "ldap_scope"
testCfgs := []struct {
config map[string]interface{}
@ -167,6 +169,9 @@ func TestValidLdapScope(t *testing.T) {
{map[string]interface{}{
ldapScopeKey: -100,
}, false, 0},
{map[string]interface{}{
ldapScopeKey: dbValue,
}, false, 2},
}
for i, item := range testCfgs {