This test ensures backwards compatibility. If it breaks, something is very wrong.
(t *testing.T)
| 68 | |
| 69 | // This test ensures backwards compatibility. If it breaks, something is very wrong. |
| 70 | func TestCiphersBackwardCompatibility(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | var ( |
| 73 | msg = "hello world" |
| 74 | key = bytes.Repeat([]byte{'a'}, 32) |
| 75 | //nolint: gosec // The below is the base64-encoded result of encrypting the above message with the above key. |
| 76 | encoded = `YhAz+lE2fFeeiVPH9voKN7UV1xSDrgcnC0LmNXmaAk1Yg0kPFO3x` |
| 77 | ) |
| 78 | |
| 79 | cipher, err := cipherAES256(key) |
| 80 | require.NoError(t, err) |
| 81 | |
| 82 | // This is the code that was used to generate the above. |
| 83 | // Note that the output of this code will change every time it is run. |
| 84 | // encrypted, err := cipher.Encrypt([]byte(msg)) |
| 85 | // require.NoError(t, err) |
| 86 | // t.Logf("encoded: %q", base64.StdEncoding.EncodeToString(encrypted)) |
| 87 | |
| 88 | decoded, err := base64.StdEncoding.DecodeString(encoded) |
| 89 | require.NoError(t, err, "the encoded string should be valid base64") |
| 90 | decrypted, err := cipher.Decrypt(decoded) |
| 91 | require.NoError(t, err, "decryption should succeed") |
| 92 | require.Equal(t, msg, string(decrypted), "decrypted message should match original message") |
| 93 | } |
| 94 | |
| 95 | // If you're looking here, you're probably in trouble. |
| 96 | // Here's what you need to do: |
nothing calls this directly
no test coverage detected