@@ -12,9 +12,12 @@ import (
1212 "encoding/pem"
1313 "fmt"
1414 "os"
15+ "path/filepath"
1516 "reflect"
1617 "testing"
1718
19+ "github.com/stretchr/testify/assert"
20+
1821 "go.step.sm/crypto/kms/apiv1"
1922 "go.step.sm/crypto/pemutil"
2023 "go.step.sm/crypto/x25519"
@@ -247,6 +250,12 @@ func TestSoftKMS_GetPublicKey(t *testing.T) {
247250 if err != nil {
248251 t .Fatal (err )
249252 }
253+
254+ fullPath := filepath .Join (t .TempDir (), "pub.pem" )
255+ if err := os .WriteFile (fullPath , b , 0o0600 ); err != nil {
256+ t .Fatal (err )
257+ }
258+
250259 block , _ := pem .Decode (b )
251260 pub , err := x509 .ParsePKIXPublicKey (block .Bytes )
252261 if err != nil {
@@ -270,8 +279,11 @@ func TestSoftKMS_GetPublicKey(t *testing.T) {
270279 wantErr bool
271280 }{
272281 {"key" , args {& apiv1.GetPublicKeyRequest {Name : "testdata/pub.pem" }}, pub , false },
282+ {"key full path" , args {& apiv1.GetPublicKeyRequest {Name : fullPath }}, pub , false },
273283 {"key uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:testdata/pub.pem" }}, pub , false },
274284 {"key path uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:path=testdata/pub.pem" }}, pub , false },
285+ {"key full path uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:" + fullPath }}, pub , false },
286+ {"key full path value" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:path=" + fullPath }}, pub , false },
275287 {"cert" , args {& apiv1.GetPublicKeyRequest {Name : "testdata/cert.crt" }}, pub , false },
276288 {"cert uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:testdata/cert.crt" }}, pub , false },
277289 {"cert path uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:path=testdata/cert.crt" }}, pub , false },
@@ -405,3 +417,25 @@ func TestSoftKMS_CreateDecrypter(t *testing.T) {
405417 })
406418 }
407419}
420+
421+ func Test_filename (t * testing.T ) {
422+ type args struct {
423+ s string
424+ }
425+ tests := []struct {
426+ name string
427+ args args
428+ want string
429+ }{
430+ {"ok name" , args {"testdata/pub.pem" }, "testdata/pub.pem" },
431+ {"ok uri value" , args {"softkms:path=testdata/pub.pem" }, "testdata/pub.pem" },
432+ {"ok uri value full" , args {"softkms:path=/testdata/pub.pem" }, "/testdata/pub.pem" },
433+ {"ok uri opaque" , args {"softkms:testdata/pub.pem" }, "testdata/pub.pem" },
434+ {"ok uri path" , args {"softkms:/testdata/pub.pem" }, "/testdata/pub.pem" },
435+ }
436+ for _ , tt := range tests {
437+ t .Run (tt .name , func (t * testing.T ) {
438+ assert .Equal (t , tt .want , filename (tt .args .s ))
439+ })
440+ }
441+ }
0 commit comments