mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
directory: support non-base64 encoded service accounts (#3150)
This commit is contained in:
parent
925fc29ab8
commit
f894205d08
14 changed files with 267 additions and 51 deletions
51
internal/directory/ping/config_test.go
Normal file
51
internal/directory/ping/config_test.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package ping
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseServiceAccount(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
rawServiceAccount string
|
||||
serviceAccount *ServiceAccount
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"json",
|
||||
`{"client_id":"CLIENT_ID","client_secret":"CLIENT_SECRET","environment_id":"ENVIRONMENT_ID"}`,
|
||||
&ServiceAccount{ClientID: "CLIENT_ID", ClientSecret: "CLIENT_SECRET", EnvironmentID: "ENVIRONMENT_ID"},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"base64 json",
|
||||
`eyJjbGllbnRfaWQiOiJDTElFTlRfSUQiLCJjbGllbnRfc2VjcmV0IjoiQ0xJRU5UX1NFQ1JFVCIsImVudmlyb25tZW50X2lkIjoiRU5WSVJPTk1FTlRfSUQifQ==`,
|
||||
&ServiceAccount{ClientID: "CLIENT_ID", ClientSecret: "CLIENT_SECRET", EnvironmentID: "ENVIRONMENT_ID"},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"empty",
|
||||
"",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"invalid",
|
||||
"Zm9v---",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := ParseServiceAccount(tc.rawServiceAccount)
|
||||
require.True(t, (err != nil) == tc.wantErr)
|
||||
assert.Equal(t, tc.serviceAccount, got)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue