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

Function TestEncryptAndDecrypt

pkg/encryption/cipher_test.go:50–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

48}
49
50func TestEncryptAndDecrypt(t *testing.T) {
51 // Test our 2 cipher types
52 cipherInits := map[string]func([]byte) (Cipher, error){
53 "CFB": NewCFBCipher,
54 "GCM": NewGCMCipher,
55 }
56 for name, initCipher := range cipherInits {
57 t.Run(name, func(t *testing.T) {
58 // Test all 3 valid AES sizes
59 for _, secretSize := range []int{16, 24, 32} {
60 t.Run(fmt.Sprintf("%d", secretSize), func(t *testing.T) {
61 secret := make([]byte, secretSize)
62 _, err := io.ReadFull(rand.Reader, secret)
63 assert.Equal(t, nil, err)
64
65 // Test Standard & Base64 wrapped
66 cstd, err := initCipher(secret)
67 assert.Equal(t, nil, err)
68
69 cb64 := NewBase64Cipher(cstd)
70
71 ciphers := map[string]Cipher{
72 "Standard": cstd,
73 "Base64": cb64,
74 }
75
76 for cName, c := range ciphers {
77 t.Run(cName, func(t *testing.T) {
78 // Test various sizes sessions might be
79 for _, dataSize := range []int{10, 100, 1000, 5000, 10000} {
80 t.Run(fmt.Sprintf("%d", dataSize), func(t *testing.T) {
81 runEncryptAndDecrypt(t, c, dataSize)
82 })
83 }
84 })
85 }
86 })
87 }
88 })
89 }
90}
91
92func runEncryptAndDecrypt(t *testing.T, c Cipher, dataSize int) {
93 data := make([]byte, dataSize)

Callers

nothing calls this directly

Calls 2

NewBase64CipherFunction · 0.85
runEncryptAndDecryptFunction · 0.85

Tested by

no test coverage detected