outposts/ldap: fix type assertion after upgrading to new API Client
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
987f03c4be
commit
88a8b7d2fa
|
@ -16,7 +16,7 @@ type LDAPGroup struct {
|
|||
Member []string
|
||||
IsSuperuser bool
|
||||
IsVirtualGroup bool
|
||||
AKAttributes interface{}
|
||||
AKAttributes map[string]interface{}
|
||||
}
|
||||
|
||||
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
||||
|
|
|
@ -36,13 +36,12 @@ func ldapResolveTypeSingle(in interface{}) *string {
|
|||
}
|
||||
}
|
||||
|
||||
func AKAttrsToLDAP(attrs interface{}) []*ldap.EntryAttribute {
|
||||
func AKAttrsToLDAP(attrs map[string]interface{}) []*ldap.EntryAttribute {
|
||||
attrList := []*ldap.EntryAttribute{}
|
||||
if attrs == nil {
|
||||
return attrList
|
||||
}
|
||||
a := attrs.(*map[string]interface{})
|
||||
for attrKey, attrValue := range *a {
|
||||
for attrKey, attrValue := range attrs {
|
||||
entry := &ldap.EntryAttribute{Name: attrKey}
|
||||
switch t := attrValue.(type) {
|
||||
case []string:
|
||||
|
|
|
@ -13,45 +13,45 @@ func Test_ldapResolveTypeSingle_nil(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAKAttrsToLDAP_String(t *testing.T) {
|
||||
var d *map[string]interface{}
|
||||
u := api.User{}
|
||||
|
||||
// normal string
|
||||
d = &map[string]interface{}{
|
||||
u.Attributes = map[string]interface{}{
|
||||
"foo": "bar",
|
||||
}
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||
// pointer string
|
||||
d = &map[string]interface{}{
|
||||
u.Attributes = map[string]interface{}{
|
||||
"foo": api.PtrString("bar"),
|
||||
}
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||
}
|
||||
|
||||
func TestAKAttrsToLDAP_String_List(t *testing.T) {
|
||||
var d *map[string]interface{}
|
||||
u := api.User{}
|
||||
// string list
|
||||
d = &map[string]interface{}{
|
||||
u.Attributes = map[string]interface{}{
|
||||
"foo": []string{"bar"},
|
||||
}
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||
// pointer string list
|
||||
d = &map[string]interface{}{
|
||||
u.Attributes = map[string]interface{}{
|
||||
"foo": &[]string{"bar"},
|
||||
}
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
||||
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||
}
|
||||
|
||||
func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
||||
// dict
|
||||
d := &map[string]interface{}{
|
||||
d := map[string]interface{}{
|
||||
"foo": map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
@ -64,7 +64,7 @@ func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
|||
|
||||
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
||||
// dict
|
||||
d := &map[string]interface{}{
|
||||
d := map[string]interface{}{
|
||||
"foo": []interface{}{
|
||||
"foo",
|
||||
6,
|
||||
|
|
Reference in a new issue