Skip to content

Commit

Permalink
Merge pull request #8 from Amnesic-Systems/fix-nitro-tests
Browse files Browse the repository at this point in the history
Fix unit tests for Nitro attester.
  • Loading branch information
NullHypothesis authored Oct 27, 2024
2 parents 52aa026 + 1adcf6a commit 6a732e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cmd/veil/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func TestReadyHandler(t *testing.T) {
func TestAttestation(t *testing.T) {
defer stopSvc(startSvc(t, withFlags()))

var attester enclave.Attester = enclave.NewNitroAttester()
if !enclave.IsEnclave() {
attester = enclave.NewNoopAttester()
}

cases := []struct {
name string
url string
Expand Down Expand Up @@ -261,7 +266,7 @@ func TestAttestation(t *testing.T) {
require.NoError(t, json.Unmarshal(body, &a))

// "Verify" the attestation document using our noop attester.
aux, err := enclave.NewNoopAttester().Verify(&a, c.nonce)
aux, err := attester.Verify(&a, c.nonce)
require.NoError(t, err, errFromBody(t, resp))

// Ensure that the recovered nonce matches what we sent.
Expand Down
6 changes: 4 additions & 2 deletions internal/nonce/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"net/url"

"github.com/Amnesic-Systems/veil/internal/errs"
Expand Down Expand Up @@ -47,8 +48,9 @@ func New() (*Nonce, error) {

// FromSlice turns a byte slice into a nonce.
func FromSlice(s []byte) (*Nonce, error) {
if len(s) != Len {
return nil, errs.InvalidLength
if len(s) < Len {
return nil, fmt.Errorf("%w: slice len is %d but need at least %d",
errs.InvalidLength, len(s), Len)
}

var n Nonce
Expand Down
6 changes: 3 additions & 3 deletions internal/nonce/nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestFromSlice(t *testing.T) {
wantErr: errs.InvalidLength,
},
{
name: "too long",
in: append(validSlice, 0),
wantErr: errs.InvalidLength,
name: "too long",
in: append(validSlice, 0),
want: Nonce{1},
},
{
name: "valid",
Expand Down

0 comments on commit 6a732e4

Please sign in to comment.