@@ -12,9 +12,12 @@ import (
12
12
"encoding/pem"
13
13
"fmt"
14
14
"os"
15
+ "path/filepath"
15
16
"reflect"
16
17
"testing"
17
18
19
+ "github.com/stretchr/testify/assert"
20
+
18
21
"go.step.sm/crypto/kms/apiv1"
19
22
"go.step.sm/crypto/pemutil"
20
23
"go.step.sm/crypto/x25519"
@@ -247,6 +250,12 @@ func TestSoftKMS_GetPublicKey(t *testing.T) {
247
250
if err != nil {
248
251
t .Fatal (err )
249
252
}
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
+
250
259
block , _ := pem .Decode (b )
251
260
pub , err := x509 .ParsePKIXPublicKey (block .Bytes )
252
261
if err != nil {
@@ -270,8 +279,11 @@ func TestSoftKMS_GetPublicKey(t *testing.T) {
270
279
wantErr bool
271
280
}{
272
281
{"key" , args {& apiv1.GetPublicKeyRequest {Name : "testdata/pub.pem" }}, pub , false },
282
+ {"key full path" , args {& apiv1.GetPublicKeyRequest {Name : fullPath }}, pub , false },
273
283
{"key uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:testdata/pub.pem" }}, pub , false },
274
284
{"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 },
275
287
{"cert" , args {& apiv1.GetPublicKeyRequest {Name : "testdata/cert.crt" }}, pub , false },
276
288
{"cert uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:testdata/cert.crt" }}, pub , false },
277
289
{"cert path uri" , args {& apiv1.GetPublicKeyRequest {Name : "softkms:path=testdata/cert.crt" }}, pub , false },
@@ -405,3 +417,25 @@ func TestSoftKMS_CreateDecrypter(t *testing.T) {
405
417
})
406
418
}
407
419
}
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