mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 20:55:42 +00:00
refactor: handle oauth groups response as an any array of any
This commit is contained in:
@@ -330,12 +330,21 @@ func DeriveKey(secret string, info string) (string, error) {
|
|||||||
|
|
||||||
func CoalesceToString(value any) string {
|
func CoalesceToString(value any) string {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case []string:
|
case []any:
|
||||||
return strings.Join(v, ",")
|
log.Debug().Msg("Coalescing []any to string")
|
||||||
|
strs := make([]string, 0, len(v))
|
||||||
|
for _, item := range v {
|
||||||
|
if str, ok := item.(string); ok {
|
||||||
|
strs = append(strs, str)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Warn().Interface("item", item).Msg("Item in []any is not a string, skipping")
|
||||||
|
}
|
||||||
|
return strings.Join(strs, ",")
|
||||||
case string:
|
case string:
|
||||||
return v
|
return v
|
||||||
default:
|
default:
|
||||||
log.Warn().Interface("value", value).Msg("Unsupported type, returning empty string")
|
log.Warn().Interface("value", value).Interface("type", v).Msg("Unsupported type, returning empty string")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ func TestDeriveKey(t *testing.T) {
|
|||||||
func TestCoalesceToString(t *testing.T) {
|
func TestCoalesceToString(t *testing.T) {
|
||||||
t.Log("Testing coalesce to string with a string")
|
t.Log("Testing coalesce to string with a string")
|
||||||
|
|
||||||
value := "test"
|
value := any("test")
|
||||||
expected := "test"
|
expected := "test"
|
||||||
|
|
||||||
result := utils.CoalesceToString(value)
|
result := utils.CoalesceToString(value)
|
||||||
@@ -526,10 +526,10 @@ func TestCoalesceToString(t *testing.T) {
|
|||||||
|
|
||||||
t.Log("Testing coalesce to string with a slice of strings")
|
t.Log("Testing coalesce to string with a slice of strings")
|
||||||
|
|
||||||
valueSlice := []string{"test1", "test2"}
|
value = []any{any("test1"), any("test2"), any(123)}
|
||||||
expected = "test1,test2"
|
expected = "test1,test2"
|
||||||
|
|
||||||
result = utils.CoalesceToString(valueSlice)
|
result = utils.CoalesceToString(value)
|
||||||
|
|
||||||
if result != expected {
|
if result != expected {
|
||||||
t.Fatalf("Expected %v, got %v", expected, result)
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
@@ -537,10 +537,10 @@ func TestCoalesceToString(t *testing.T) {
|
|||||||
|
|
||||||
t.Log("Testing coalesce to string with an unsupported type")
|
t.Log("Testing coalesce to string with an unsupported type")
|
||||||
|
|
||||||
valueUnsupported := 12345
|
value = 12345
|
||||||
expected = ""
|
expected = ""
|
||||||
|
|
||||||
result = utils.CoalesceToString(valueUnsupported)
|
result = utils.CoalesceToString(value)
|
||||||
|
|
||||||
if result != expected {
|
if result != expected {
|
||||||
t.Fatalf("Expected %v, got %v", expected, result)
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user