mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
feat: multiple oauth providers (#355)
* feat: add flag decoder (candidate) * refactor: finalize flags decoder * feat: add env decoder * feat: add oauth config parsing logic * feat: implement backend logic for multiple oauth providers * feat: implement multiple oauth providers in the frontend * feat: add some default icons * chore: add credits for parser * feat: style oauth auto redirect screen * fix: bot suggestions * refactor: rework decoders using simpler and more efficient pattern * refactor: rework oauth name database migration
This commit is contained in:
44
internal/utils/decoders/decoders_test.go
Normal file
44
internal/utils/decoders/decoders_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package decoders_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"tinyauth/internal/utils/decoders"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestNormalizeKeys(t *testing.T) {
|
||||
// Test with env
|
||||
test := map[string]string{
|
||||
"PROVIDERS_CLIENT1_CLIENT_ID": "my-client-id",
|
||||
"PROVIDERS_CLIENT1_CLIENT_SECRET": "my-client-secret",
|
||||
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_ID": "my-awesome-client-id",
|
||||
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_SECRET_FILE": "/path/to/secret",
|
||||
}
|
||||
expected := map[string]string{
|
||||
"tinyauth.providers.client1.clientId": "my-client-id",
|
||||
"tinyauth.providers.client1.clientSecret": "my-client-secret",
|
||||
"tinyauth.providers.myAwesomeClient.clientId": "my-awesome-client-id",
|
||||
"tinyauth.providers.myAwesomeClient.clientSecretFile": "/path/to/secret",
|
||||
}
|
||||
|
||||
normalized := decoders.NormalizeKeys(test, "tinyauth", "_")
|
||||
assert.DeepEqual(t, normalized, expected)
|
||||
|
||||
// Test with flags (assume -- is already stripped)
|
||||
test = map[string]string{
|
||||
"providers-client1-client-id": "my-client-id",
|
||||
"providers-client1-client-secret": "my-client-secret",
|
||||
"providers-my-awesome-client-client-id": "my-awesome-client-id",
|
||||
"providers-my-awesome-client-client-secret-file": "/path/to/secret",
|
||||
}
|
||||
expected = map[string]string{
|
||||
"tinyauth.providers.client1.clientId": "my-client-id",
|
||||
"tinyauth.providers.client1.clientSecret": "my-client-secret",
|
||||
"tinyauth.providers.myAwesomeClient.clientId": "my-awesome-client-id",
|
||||
"tinyauth.providers.myAwesomeClient.clientSecretFile": "/path/to/secret",
|
||||
}
|
||||
|
||||
normalized = decoders.NormalizeKeys(test, "tinyauth", "-")
|
||||
assert.DeepEqual(t, normalized, expected)
|
||||
}
|
||||
Reference in New Issue
Block a user