-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathattester_test.go
46 lines (38 loc) · 1.04 KB
/
attester_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bytes"
"errors"
"testing"
"github.com/hf/nitrite"
)
func TestDummyAttestation(t *testing.T) {
var (
d = newDummyAttester()
workersNonce = nonce{1, 2, 3}
hashOfEncrypted = []byte("this is a hash")
)
attstn, err := d.createAttstn(&leaderAuxInfo{
WorkersNonce: workersNonce,
HashOfEncrypted: hashOfEncrypted,
})
failOnErr(t, err)
aux, err := d.verifyAttstn(attstn, workersNonce)
failOnErr(t, err)
leaderAux := aux.(*leaderAuxInfo)
if leaderAux.WorkersNonce != workersNonce {
t.Fatal("Extracted unexpected workers nonce.")
}
if !bytes.Equal(leaderAux.HashOfEncrypted, hashOfEncrypted) {
t.Fatalf("Extracted unexpected hash over encrypted keys.")
}
}
func TestVerifyNitroAttstn(t *testing.T) {
var n = newNitroAttester()
_, err := n.verifyAttstn([]byte("foobar"), nonce{})
assertEqual(t, errors.Is(err, nitrite.ErrBadCOSESign1Structure), true)
}
func TestCreateNitroAttstn(t *testing.T) {
var n = newNitroAttester()
_, err := n.createAttstn(nil)
assertEqual(t, err != nil, true)
}