mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-02 20:06:03 +02:00
Fixes #1354 Co-authored-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
c05a686205
commit
3fd66c1401
2 changed files with 28 additions and 3 deletions
|
@ -291,9 +291,8 @@ func ParseServiceAccount(rawServiceAccount string) (*ServiceAccount, error) {
|
|||
}
|
||||
|
||||
var serviceAccount ServiceAccount
|
||||
err = json.Unmarshal(bs, &serviceAccount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err := json.Unmarshal(bs, &serviceAccount); err != nil {
|
||||
serviceAccount.APIKey = string(bs)
|
||||
}
|
||||
|
||||
if serviceAccount.APIKey == "" {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tomnomnom/linkheader"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/directory"
|
||||
|
@ -207,3 +208,28 @@ func mustParseURL(rawurl string) *url.URL {
|
|||
}
|
||||
return u
|
||||
}
|
||||
|
||||
func TestParseServiceAccount(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
rawServiceAccount string
|
||||
apiKey string
|
||||
wantErr bool
|
||||
}{
|
||||
{"json", "ewogICAgImFwaV9rZXkiOiAiZm9vIgp9Cg==", "foo", false},
|
||||
{"value", "Zm9v", "foo", false},
|
||||
{"empty", "", "", true},
|
||||
{"invalid", "Zm9v---", "", 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)
|
||||
if tc.apiKey != "" {
|
||||
assert.Equal(t, tc.apiKey, got.APIKey)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue