Add new key tests

This commit is contained in:
Aron Wussler 2019-05-09 20:12:28 +02:00
parent c9730189a7
commit 56a73b1532
3 changed files with 42 additions and 4 deletions

4
.gitignore vendored
View file

@ -3,6 +3,6 @@ bin
dist dist
vendor vendor
.vscode .vscode
.out *.out
.html *.html
reports reports

View file

@ -13,8 +13,8 @@ import (
func TestAttachmentGetKey(t *testing.T) { func TestAttachmentGetKey(t *testing.T) {
testKeyPackets, err := ioutil.ReadFile("testdata/attachment_keypacket") testKeyPackets, err := ioutil.ReadFile("testdata/attachment_keypacket")
if err != nil { if err != nil {
t.Error("Expected no error while reading from file, got:", err) t.Error("Expected no error while reading from file, got:", err)
return return
} }
testKeyPacketsDecoded, err := base64.StdEncoding.DecodeString(string(testKeyPackets)) testKeyPacketsDecoded, err := base64.StdEncoding.DecodeString(string(testKeyPackets))

38
crypto/key_test.go Normal file
View file

@ -0,0 +1,38 @@
package crypto
import (
"github.com/stretchr/testify/assert"
// "encoding/base64"
"regexp"
"testing"
)
const name = "richard.stallman"
const domain = "gnu.org"
const passphrase = "I love GNU"
var rsaKey, ecKey string
func TestGenerateRsaKey(t *testing.T) {
var pmCrypto = PmCrypto{}
var err error
rsaKey, err = pmCrypto.generateKey(name, domain, passphrase, "RSA", 1024, nil, nil, nil, nil)
if err != nil {
t.Fatal("Cannot encrypt token:", err)
}
rTest := regexp.MustCompile("(?s)^-----BEGIN PGP PRIVATE KEY BLOCK-----.*-----END PGP PRIVATE KEY BLOCK-----$")
assert.Regexp(t, rTest, rsaKey)
}
func TestGenerateECKey(t *testing.T) {
var pmCrypto = PmCrypto{}
var err error
ecKey, err = pmCrypto.generateKey(name, domain, passphrase, "x25519", 1024, nil, nil, nil, nil)
if err != nil {
t.Fatal("Cannot encrypt token:", err)
}
rTest := regexp.MustCompile("(?s)^-----BEGIN PGP PRIVATE KEY BLOCK-----.*-----END PGP PRIVATE KEY BLOCK-----$")
assert.Regexp(t, rTest, ecKey)
}