1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-12-01 22:51:45 +02:00

Ensure Cipher.Decrypt doesn't mangle input ciphertext []byte

This commit is contained in:
Nick Meves
2020-05-11 12:27:27 -07:00
parent e823d874b0
commit 7bb5fc0a81
2 changed files with 16 additions and 6 deletions

View File

@@ -84,9 +84,17 @@ func TestEncryptAndDecrypt(t *testing.T) {
assert.Equal(t, nil, err)
assert.NotEqual(t, encrypted, data)
// Ensure our Decrypt function doesn't decrypt in place
immutable := make([]byte, len(encrypted))
copy(immutable, encrypted)
decrypted, err := c.Decrypt(encrypted)
assert.Equal(t, nil, err)
// Original data back
assert.Equal(t, data, decrypted)
// Decrypt didn't operate in-place on []byte
assert.Equal(t, encrypted, immutable)
// Encrypt/Decrypt actually did something
assert.NotEqual(t, encrypted, decrypted)
})
}