You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-08-15 20:23:13 +02:00
Ensure Cipher.Encrypt doesn't mangle input data []byte
This commit is contained in:
@@ -80,20 +80,26 @@ func TestEncryptAndDecrypt(t *testing.T) {
|
|||||||
_, err := io.ReadFull(rand.Reader, data)
|
_, err := io.ReadFull(rand.Reader, data)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
|
|
||||||
|
// Ensure our Encrypt function doesn't encrypt in place
|
||||||
|
immutableData := make([]byte, len(data))
|
||||||
|
copy(immutableData, data)
|
||||||
|
|
||||||
encrypted, err := c.Encrypt(data)
|
encrypted, err := c.Encrypt(data)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.NotEqual(t, encrypted, data)
|
assert.NotEqual(t, encrypted, data)
|
||||||
|
// Encrypt didn't operate in-place on []byte
|
||||||
|
assert.Equal(t, data, immutableData)
|
||||||
|
|
||||||
// Ensure our Decrypt function doesn't decrypt in place
|
// Ensure our Decrypt function doesn't decrypt in place
|
||||||
immutable := make([]byte, len(encrypted))
|
immutableEnc := make([]byte, len(encrypted))
|
||||||
copy(immutable, encrypted)
|
copy(immutableEnc, encrypted)
|
||||||
|
|
||||||
decrypted, err := c.Decrypt(encrypted)
|
decrypted, err := c.Decrypt(encrypted)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
// Original data back
|
// Original data back
|
||||||
assert.Equal(t, data, decrypted)
|
assert.Equal(t, data, decrypted)
|
||||||
// Decrypt didn't operate in-place on []byte
|
// Decrypt didn't operate in-place on []byte
|
||||||
assert.Equal(t, encrypted, immutable)
|
assert.Equal(t, encrypted, immutableEnc)
|
||||||
// Encrypt/Decrypt actually did something
|
// Encrypt/Decrypt actually did something
|
||||||
assert.NotEqual(t, encrypted, decrypted)
|
assert.NotEqual(t, encrypted, decrypted)
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user