mirror of
https://github.com/goauthentik/authentik
synced 2026-04-28 10:28:22 +02:00
* packages/client-go: init Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove mod/sum Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix translate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * no go replace Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update rust makefile with pwd Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix build Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't need a version ig? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude go client from cspell Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix main docker build Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
api "goauthentik.io/packages/client-go"
|
|
)
|
|
|
|
func Test_stringify_nil(t *testing.T) {
|
|
var ex *string
|
|
assert.Equal(t, ex, stringify(nil))
|
|
}
|
|
|
|
func TestAKAttrsToLDAP_String(t *testing.T) {
|
|
u := api.User{}
|
|
|
|
// normal string
|
|
u.Attributes = map[string]any{
|
|
"foo": "bar",
|
|
}
|
|
mapped := AttributesToLDAP(u.Attributes, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"bar"}, mapped[0].Values)
|
|
// pointer string
|
|
u.Attributes = map[string]any{
|
|
"foo": new("bar"),
|
|
}
|
|
mapped = AttributesToLDAP(u.Attributes, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"bar"}, mapped[0].Values)
|
|
}
|
|
|
|
func TestAKAttrsToLDAP_String_List(t *testing.T) {
|
|
u := api.User{}
|
|
// string list
|
|
u.Attributes = map[string]any{
|
|
"foo": []string{"bar"},
|
|
}
|
|
mapped := AttributesToLDAP(u.Attributes, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"bar"}, mapped[0].Values)
|
|
// pointer string list
|
|
u.Attributes = map[string]any{
|
|
"foo": &[]string{"bar"},
|
|
}
|
|
mapped = AttributesToLDAP(u.Attributes, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"bar"}, mapped[0].Values)
|
|
}
|
|
|
|
func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
|
// dict
|
|
d := map[string]any{
|
|
"foo": map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
}
|
|
mapped := AttributesToLDAP(d, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"map[foo:bar]"}, mapped[0].Values)
|
|
}
|
|
|
|
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
|
// dict
|
|
d := map[string]any{
|
|
"foo": []any{
|
|
"foo",
|
|
6,
|
|
},
|
|
}
|
|
mapped := AttributesToLDAP(d, func(key string) string {
|
|
return AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
assert.Equal(t, 1, len(mapped))
|
|
assert.Equal(t, "foo", mapped[0].Name)
|
|
assert.Equal(t, []string{"foo", "6"}, mapped[0].Values)
|
|
}
|