Skip to content

Commit

Permalink
Further work!
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Apr 30, 2024
1 parent 0a38925 commit a790b0a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scheme/cca-realm/corim_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ func (o CorimExtractor) RefValExtractor(
// integrity register
refVals := make([]*handler.Endorsement, 0, len(rv.Measurements))

if len(refVals) == 0 {
return nil, fmt.Errorf("no measurements found")
}

var refVal *handler.Endorsement
for _, m := range rv.Measurements {
var rAttr RealmAttributes
Expand All @@ -55,6 +51,11 @@ func (o CorimExtractor) RefValExtractor(
}
refVals = append(refVals, refVal)
}

if len(refVals) == 0 {
return nil, fmt.Errorf("no measurements found")
}

return refVals, nil
}

Expand Down
87 changes: 87 additions & 0 deletions scheme/cca-realm/endorsement_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package cca_realm

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/veraison/corim/comid"
)

func TestDecoder_Decode_OK(t *testing.T) {
tvs := []string{
unsignedCorimcomidCcaRealm,
}

d := &EndorsementHandler{}

for _, tv := range tvs {
data := comid.MustHexDecode(t, tv)
_, err := d.Decode(data)
assert.NoError(t, err)
}
}

func TestDecoder_GetAttestationScheme(t *testing.T) {
d := &EndorsementHandler{}

expected := SchemeName

actual := d.GetAttestationScheme()

assert.Equal(t, expected, actual)
}

func TestDecoder_GetSupportedMediaTypes(t *testing.T) {
d := &EndorsementHandler{}

expected := EndorsementMediaTypes

actual := d.GetSupportedMediaTypes()

assert.Equal(t, expected, actual)
}

func TestDecoder_Init(t *testing.T) {
d := &EndorsementHandler{}

assert.Nil(t, d.Init(nil))
}

func TestDecoder_Close(t *testing.T) {
d := &EndorsementHandler{}

assert.Nil(t, d.Close())
}

func TestDecoder_GetName_ok(t *testing.T) {
d := &EndorsementHandler{}
expectedName := "unsigned-corim (CCA realm profile)"
name := d.GetName()
assert.Equal(t, name, expectedName)
}

func TestDecoder_Decode_empty_data(t *testing.T) {
d := &EndorsementHandler{}

emptyData := []byte{}

expectedErr := `empty data`

_, err := d.Decode(emptyData)

assert.EqualError(t, err, expectedErr)
}

func TestDecoder_Decode_invalid_data(t *testing.T) {
d := &EndorsementHandler{}

invalidCbor := []byte("invalid CBOR")

expectedErr := `CBOR decoding failed: expected map (CBOR Major Type 5), found Major Type 3`

_, err := d.Decode(invalidCbor)

assert.EqualError(t, err, expectedErr)
}

0 comments on commit a790b0a

Please sign in to comment.