Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/config/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ func (s *SecretManagement) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(g.Config, s.GCPKMS)
}
default:
err = fmt.Errorf("unsupported secret management type: %s", s.Type)
err = fmt.Errorf("unsupported secret management type: %s", g.Type)
}
return err
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/config/piped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
"encoding/json"
"errors"
"testing"
"time"
Expand Down Expand Up @@ -1626,3 +1627,51 @@ func TestPipeGitValidate(t *testing.T) {
})
}
}

func TestSecretManagementUnmarshalJSON(t *testing.T) {
testcases := []struct {
name string
data string
want *SecretManagement
wantError string
}{
{
name: "unsupported type",
data: `{"type":"UNKNOWN_TYPE","config":{}}`,
wantError: "unsupported secret management type: UNKNOWN_TYPE",
},
{
name: "key pair type",
data: `{"type":"KEY_PAIR","config":{"privateKeyFile":"/tmp/private.pem","publicKeyFile":"/tmp/public.pem"}}`,
want: &SecretManagement{
Type: model.SecretManagementTypeKeyPair,
KeyPair: &SecretManagementKeyPair{
PrivateKeyFile: "/tmp/private.pem",
PublicKeyFile: "/tmp/public.pem",
},
},
},
{
name: "gcp kms type",
data: `{"type":"GCP_KMS","config":{"keyName":"projects/p/secret"}}`,
want: &SecretManagement{
Type: model.SecretManagementTypeGCPKMS,
GCPKMS: &SecretManagementGCPKMS{
KeyName: "projects/p/secret",
},
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
var got SecretManagement
err := json.Unmarshal([]byte(tc.data), &got)
if tc.wantError != "" {
assert.EqualError(t, err, tc.wantError)
return
}
require.NoError(t, err)
assert.Equal(t, tc.want, &got)
})
}
}
2 changes: 1 addition & 1 deletion pkg/configv1/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (s *SecretManagement) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(g.Config, s.GCPKMS)
}
default:
err = fmt.Errorf("unsupported secret management type: %s", s.Type)
err = fmt.Errorf("unsupported secret management type: %s", g.Type)
}
return err
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/configv1/piped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
"encoding/json"
"errors"
"testing"
"time"
Expand Down Expand Up @@ -1054,3 +1055,51 @@ func TestPipeGitValidate(t *testing.T) {
})
}
}

func TestSecretManagementUnmarshalJSON(t *testing.T) {
testcases := []struct {
name string
data string
want *SecretManagement
wantError string
}{
{
name: "unsupported type",
data: `{"type":"UNKNOWN_TYPE","config":{}}`,
wantError: "unsupported secret management type: UNKNOWN_TYPE",
},
{
name: "key pair type",
data: `{"type":"KEY_PAIR","config":{"privateKeyFile":"/tmp/private.pem","publicKeyFile":"/tmp/public.pem"}}`,
want: &SecretManagement{
Type: model.SecretManagementTypeKeyPair,
KeyPair: &SecretManagementKeyPair{
PrivateKeyFile: "/tmp/private.pem",
PublicKeyFile: "/tmp/public.pem",
},
},
},
{
name: "gcp kms type",
data: `{"type":"GCP_KMS","config":{"keyName":"projects/p/secret"}}`,
want: &SecretManagement{
Type: model.SecretManagementTypeGCPKMS,
GCPKMS: &SecretManagementGCPKMS{
KeyName: "projects/p/secret",
},
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
var got SecretManagement
err := json.Unmarshal([]byte(tc.data), &got)
if tc.wantError != "" {
assert.EqualError(t, err, tc.wantError)
return
}
require.NoError(t, err)
assert.Equal(t, tc.want, &got)
})
}
}