-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yogesh Deshpande <[email protected]>
- Loading branch information
1 parent
0a38925
commit a790b0a
Showing
2 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |