Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests for Nitro attester. #8

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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