mirror of
https://github.com/hanzo-fi/auth.git
synced 2026-10-30 20:33:21 +00:00
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package auth_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
auth "github.com/hanzo-fi/auth/pkg"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStaticClientFromEnvironment(t *testing.T) {
|
|
type testCase struct {
|
|
staticClients []auth.StaticClient
|
|
environmentVariables map[string]string
|
|
expectedErr error
|
|
}
|
|
|
|
testCases := []testCase{
|
|
{
|
|
staticClients: []auth.StaticClient{
|
|
{
|
|
Secrets: []string{"$SECRET"},
|
|
},
|
|
},
|
|
environmentVariables: map[string]string{
|
|
"SECRET": "secret",
|
|
},
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
staticClients: []auth.StaticClient{
|
|
{
|
|
Secrets: []string{"$ERROR"},
|
|
},
|
|
},
|
|
environmentVariables: map[string]string{},
|
|
expectedErr: auth.ErrEnvironmentVariableNotFound,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run("TestStaticClientFromEnvironment", func(t *testing.T) {
|
|
for key, value := range tc.environmentVariables {
|
|
_ = os.Setenv(key, value)
|
|
}
|
|
|
|
for _, staticClient := range tc.staticClients {
|
|
loadedClient, err := staticClient.FromEnvironment()
|
|
if tc.expectedErr != nil {
|
|
require.Error(t, err)
|
|
require.ErrorIs(t, err, tc.expectedErr)
|
|
return
|
|
}
|
|
for _, secret := range loadedClient.Secrets {
|
|
require.NotContains(t, secret, "$")
|
|
require.NotEmpty(t, secret)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|