gogs/internal/cryptoutil/aes_test.go
ᴜɴᴋɴᴡᴏɴ cb439a126a
db: add tests for two factors (#6099)
* Rename to TwoFactors.Create

* Use GORM to execute queries

* TwoFactor.GetByUserID

* Add tests

* Fix failing tests

* Add MD5 tests

* Add tests for RandomChars
2020-04-14 09:41:54 +08:00

35 lines
648 B
Go

// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package cryptoutil
import (
"crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAESGCM(t *testing.T) {
key := make([]byte, 16) // AES-128
_, err := rand.Read(key)
if err != nil {
t.Fatal(err)
}
plaintext := []byte("this will be encrypted")
encrypted, err := AESGCMEncrypt(key, plaintext)
if err != nil {
t.Fatal(err)
}
decrypted, err := AESGCMDecrypt(key, encrypted)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, plaintext, decrypted)
}