46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package interactions_test
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestVerify(t *testing.T) {
|
|
i, _, key := makeInteractions(t)
|
|
|
|
// TODO: make this into a real interaction
|
|
body, _ := json.Marshal(map[string]string{
|
|
"test": "test",
|
|
})
|
|
|
|
sig, ts := sign(t, key, body)
|
|
|
|
assert.NoError(t, i.Verify(sig, ts, body), "verification errored")
|
|
}
|
|
|
|
func TestVerifyFailures(t *testing.T) {
|
|
i, _, key := makeInteractions(t)
|
|
badPub, _, _ := ed25519.GenerateKey(nil)
|
|
|
|
// TODO: make this into a real interaction
|
|
body, _ := json.Marshal(map[string]string{
|
|
"test": "test",
|
|
})
|
|
|
|
sig, ts := sign(t, key, body)
|
|
|
|
assert.Error(t, i.Verify(sig, "", body), "erroneously allowed no timestamp")
|
|
assert.Error(t, i.Verify("", ts, body), "erroneously allowed no signature")
|
|
assert.Error(t, i.Verify(hex.EncodeToString(badPub), ts, body), "signature passed erroneously")
|
|
assert.Error(t, i.Verify(string(badPub), ts, body), "accepted an incorrectly encoded key")
|
|
assert.Error(t, i.Verify(sig+"aaaa", ts, body), "length of signature was not checked")
|
|
|
|
body, _ = json.Marshal(map[string]string{
|
|
"test": "test2",
|
|
})
|
|
assert.Error(t, i.Verify(sig, ts, body), "verified against different data")
|
|
}
|