MCPcopy Index your code
hub / github.com/getsops/sops / Test_dataKeyFromSecret

Function Test_dataKeyFromSecret

hcvault/keysource_test.go:355–381  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

353}
354
355func Test_dataKeyFromSecret(t *testing.T) {
356 tests := []struct {
357 name string
358 secret *api.Secret
359 want []byte
360 wantErr bool
361 }{
362 {name: "nil secret", secret: nil, wantErr: true},
363 {name: "secret with nil data", secret: &api.Secret{Data: nil}, wantErr: true},
364 {name: "secret without plaintext data", secret: &api.Secret{Data: map[string]interface{}{"other": true}}, wantErr: true},
365 {name: "plaintext non string", secret: &api.Secret{Data: map[string]interface{}{"plaintext": 123}}, wantErr: true},
366 {name: "plaintext non base64", secret: &api.Secret{Data: map[string]interface{}{"plaintext": "notbase64"}}, wantErr: true},
367 {name: "plaintext base64 data", secret: &api.Secret{Data: map[string]interface{}{"plaintext": "Zm9v"}}, want: []byte("foo")},
368 }
369 for _, tt := range tests {
370 t.Run(tt.name, func(t *testing.T) {
371 got, err := dataKeyFromSecret(tt.secret)
372 if tt.wantErr {
373 assert.Error(t, err)
374 assert.Empty(t, got)
375 return
376 }
377 assert.NoError(t, err)
378 assert.Equal(t, tt.want, got)
379 })
380 }
381}
382
383func Test_vaultClient(t *testing.T) {
384 t.Run("client", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

dataKeyFromSecretFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected