outposts/ldap: fix panic in type conversion when value is nil
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
677621989a
commit
9b6e47e6b8
|
@ -29,7 +29,9 @@ func ldapResolveTypeSingle(in interface{}) *string {
|
||||||
s := BoolToString(*t)
|
s := BoolToString(*t)
|
||||||
return &s
|
return &s
|
||||||
default:
|
default:
|
||||||
log.WithField("type", reflect.TypeOf(in).String()).Warning("Type can't be mapped to LDAP yet")
|
if in != nil {
|
||||||
|
log.WithField("type", reflect.TypeOf(in).String()).Warning("Type can't be mapped to LDAP yet")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@ import (
|
||||||
"goauthentik.io/api/v3"
|
"goauthentik.io/api/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Test_ldapResolveTypeSingle_nil(t *testing.T) {
|
||||||
|
var ex *string
|
||||||
|
assert.Equal(t, ex, ldapResolveTypeSingle(nil))
|
||||||
|
}
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_String(t *testing.T) {
|
func TestAKAttrsToLDAP_String(t *testing.T) {
|
||||||
var d *map[string]interface{}
|
var d *map[string]interface{}
|
||||||
|
|
||||||
|
@ -54,7 +59,7 @@ func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||||
// Dicts are currently unsupported, but make sure we don't crash
|
// Dicts are currently unsupported, but make sure we don't crash
|
||||||
// assert.Equal(t, []string{nil}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string([]string(nil)), AKAttrsToLDAP(d)[0].Values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
||||||
|
@ -68,5 +73,5 @@ func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||||
// Dicts are currently unsupported, but make sure we don't crash
|
// Dicts are currently unsupported, but make sure we don't crash
|
||||||
// assert.Equal(t, []string{nil}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string{"foo", ""}, AKAttrsToLDAP(d)[0].Values)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue