fix: handle type string for oauth groups

This commit is contained in:
Stavros
2025-07-15 00:17:41 +03:00
parent 736f65b7b2
commit 6519644fc1
4 changed files with 52 additions and 5 deletions

View File

@@ -327,3 +327,15 @@ func DeriveKey(secret string, info string) (string, error) {
encodedKey := base64.StdEncoding.EncodeToString(key)
return encodedKey, nil
}
func CoalesceToString(value any) string {
switch v := value.(type) {
case []string:
return strings.Join(v, ",")
case string:
return v
default:
log.Warn().Interface("value", value).Msg("Unsupported type, returning empty string")
return ""
}
}

View File

@@ -511,3 +511,38 @@ func TestDeriveKey(t *testing.T) {
t.Fatalf("Expected %v, got %v", expected, result)
}
}
func TestCoalesceToString(t *testing.T) {
t.Log("Testing coalesce to string with a string")
value := "test"
expected := "test"
result := utils.CoalesceToString(value)
if result != expected {
t.Fatalf("Expected %v, got %v", expected, result)
}
t.Log("Testing coalesce to string with a slice of strings")
valueSlice := []string{"test1", "test2"}
expected = "test1,test2"
result = utils.CoalesceToString(valueSlice)
if result != expected {
t.Fatalf("Expected %v, got %v", expected, result)
}
t.Log("Testing coalesce to string with an unsupported type")
valueUnsupported := 12345
expected = ""
result = utils.CoalesceToString(valueUnsupported)
if result != expected {
t.Fatalf("Expected %v, got %v", expected, result)
}
}