mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-11 13:58:20 +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
|
var serviceAccount ServiceAccount
|
||||||
err = json.Unmarshal(bs, &serviceAccount)
|
if err := json.Unmarshal(bs, &serviceAccount); err != nil {
|
||||||
if err != nil {
|
serviceAccount.APIKey = string(bs)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if serviceAccount.APIKey == "" {
|
if serviceAccount.APIKey == "" {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
"github.com/go-chi/chi/middleware"
|
"github.com/go-chi/chi/middleware"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tomnomnom/linkheader"
|
"github.com/tomnomnom/linkheader"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/pkg/grpc/directory"
|
"github.com/pomerium/pomerium/pkg/grpc/directory"
|
||||||
|
@ -207,3 +208,28 @@ func mustParseURL(rawurl string) *url.URL {
|
||||||
}
|
}
|
||||||
return u
|
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
Add a link
Reference in a new issue