MCPcopy Index your code
hub / github.com/coder/coder / TestCiphersBackwardCompatibility

Function TestCiphersBackwardCompatibility

enterprise/dbcrypt/cipher_internal_test.go:70–93  ·  view source on GitHub ↗

This test ensures backwards compatibility. If it breaks, something is very wrong.

(t *testing.T)

Source from the content-addressed store, hash-verified

68
69// This test ensures backwards compatibility. If it breaks, something is very wrong.
70func 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:

Callers

nothing calls this directly

Calls 4

cipherAES256Function · 0.85
DecodeStringMethod · 0.80
DecryptMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected