MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / runEncryptAndDecrypt

Function runEncryptAndDecrypt

pkg/encryption/cipher_test.go:92–119  ·  view source on GitHub ↗
(t *testing.T, c Cipher, dataSize int)

Source from the content-addressed store, hash-verified

90}
91
92func runEncryptAndDecrypt(t *testing.T, c Cipher, dataSize int) {
93 data := make([]byte, dataSize)
94 _, err := io.ReadFull(rand.Reader, data)
95 assert.Equal(t, nil, err)
96
97 // Ensure our Encrypt function doesn't encrypt in place
98 immutableData := make([]byte, len(data))
99 copy(immutableData, data)
100
101 encrypted, err := c.Encrypt(data)
102 assert.Equal(t, nil, err)
103 assert.NotEqual(t, encrypted, data)
104 // Encrypt didn't operate in-place on []byte
105 assert.Equal(t, data, immutableData)
106
107 // Ensure our Decrypt function doesn't decrypt in place
108 immutableEnc := make([]byte, len(encrypted))
109 copy(immutableEnc, encrypted)
110
111 decrypted, err := c.Decrypt(encrypted)
112 assert.Equal(t, nil, err)
113 // Original data back
114 assert.Equal(t, data, decrypted)
115 // Decrypt didn't operate in-place on []byte
116 assert.Equal(t, encrypted, immutableEnc)
117 // Encrypt/Decrypt actually did something
118 assert.NotEqual(t, encrypted, decrypted)
119}
120
121func TestDecryptCFBWrongSecret(t *testing.T) {
122 secret1 := []byte("0123456789abcdefghijklmnopqrstuv")

Callers 1

TestEncryptAndDecryptFunction · 0.85

Calls 2

EncryptMethod · 0.65
DecryptMethod · 0.65

Tested by

no test coverage detected