(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestEncryptedStringPositive(t *testing.T) { |
| 81 | id := uuid.Must(uuid.NewV4()).String() |
| 82 | |
| 83 | es, err := NewEncryptedString(id, []byte("data"), "key-id", "pwFoiPyybQMqNmYVN0gUnpbfpGQV2sDv9vp0ZAxi_Y4") |
| 84 | assert.NoError(t, err) |
| 85 | |
| 86 | assert.Equal(t, es.KeyID, "key-id") |
| 87 | assert.Equal(t, es.Algorithm, "aes-gcm-hkdf") |
| 88 | assert.Len(t, es.Data, 20) |
| 89 | assert.Len(t, es.Nonce, 12) |
| 90 | |
| 91 | dec := ParseEncryptedString(es.String()) |
| 92 | |
| 93 | assert.NotNil(t, dec) |
| 94 | assert.Equal(t, dec.Algorithm, "aes-gcm-hkdf") |
| 95 | assert.Len(t, dec.Data, 20) |
| 96 | assert.Len(t, dec.Nonce, 12) |
| 97 | |
| 98 | decrypted, err := dec.Decrypt(id, map[string]string{ |
| 99 | "key-id": "pwFoiPyybQMqNmYVN0gUnpbfpGQV2sDv9vp0ZAxi_Y4", |
| 100 | }) |
| 101 | |
| 102 | assert.NoError(t, err) |
| 103 | assert.Equal(t, []byte("data"), decrypted) |
| 104 | } |
| 105 | |
| 106 | func TestParseEncryptedStringNegative(t *testing.T) { |
| 107 | negativeExamples := []string{ |
nothing calls this directly
no test coverage detected