MCPcopy Create free account
hub / github.com/supabase/auth / TestEncryptedStringDecryptNegative

Function TestEncryptedStringDecryptNegative

internal/crypto/crypto_test.go:127–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

125}
126
127func TestEncryptedStringDecryptNegative(t *testing.T) {
128 id := uuid.Must(uuid.NewV4()).String()
129
130 // short key
131 _, err := NewEncryptedString(id, []byte("data"), "key-id", "short_key")
132 assert.Error(t, err)
133
134 // not base64
135 _, err = NewEncryptedString(id, []byte("data"), "key-id", "!!!")
136 assert.Error(t, err)
137
138 es, err := NewEncryptedString(id, []byte("data"), "key-id", "pwFoiPyybQMqNmYVN0gUnpbfpGQV2sDv9vp0ZAxi_Y4")
139 assert.NoError(t, err)
140
141 dec := ParseEncryptedString(es.String())
142 assert.NotNil(t, dec)
143
144 _, err = dec.Decrypt(id, map[string]string{
145 // empty map
146 })
147 assert.Error(t, err)
148
149 // short key
150 _, err = dec.Decrypt(id, map[string]string{
151 "key-id": "AQAB",
152 })
153 assert.Error(t, err)
154
155 // key not base64
156 _, err = dec.Decrypt(id, map[string]string{
157 "key-id": "!!!",
158 })
159 assert.Error(t, err)
160
161 // bad key
162 _, err = dec.Decrypt(id, map[string]string{
163 "key-id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
164 })
165 assert.Error(t, err)
166
167 // bad tag for AEAD failure
168 dec.Data[len(dec.Data)-1] += 1
169
170 _, err = dec.Decrypt(id, map[string]string{
171 "key-id": "pwFoiPyybQMqNmYVN0gUnpbfpGQV2sDv9vp0ZAxi_Y4",
172 })
173 assert.Error(t, err)
174}
175
176func TestSecureToken(t *testing.T) {
177 assert.Equal(t, len(SecureAlphanumeric(22)), 22)

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
NewEncryptedStringFunction · 0.85
ParseEncryptedStringFunction · 0.85
DecryptMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected