Skip to content

Commit

Permalink
Ensure NewAttestationResult() returns a valid result
Browse files Browse the repository at this point in the history
NewAttestationResult() has to initialize the VerifierID, is it is a
mandatory filed. There is no reasonable default that can be supplied for
it, so pass its values as parameters.

Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Feb 20, 2023
1 parent 99b28b2 commit 37395a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion ear.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func (o B64Url) MarshalJSON() ([]byte, error) {

// NewAttestationResult returns a pointer to a new fully-initialized
// AttestationResult.
func NewAttestationResult(submodName string) *AttestationResult {
func NewAttestationResult(
submodName string,
verifierBuild string,
verifierDeveloper string,
) *AttestationResult {
status := TrustTierNone
iat := time.Now().Unix()
profile := EatProfile
Expand All @@ -56,6 +60,10 @@ func NewAttestationResult(submodName string) *AttestationResult {
Status: &status,
},
},
VerifierID: &VerifierIdentity{
Build: &verifierBuild,
Developer: &verifierDeveloper,
},
}
}

Expand Down
14 changes: 12 additions & 2 deletions ear_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestRoundTrip_tampering(t *testing.T) {
}

func TestUpdateStatusFromTrustVector(t *testing.T) {
ar := NewAttestationResult("test")
ar := NewAttestationResult("test", "test", "test")

ar.UpdateStatusFromTrustVector()
assert.Equal(t, TrustTierNone, *ar.Submods["test"].Status)
Expand All @@ -293,7 +293,7 @@ func TestUpdateStatusFromTrustVector(t *testing.T) {
func TestAsMap(t *testing.T) {
policyID := "foo"

ar := NewAttestationResult("someScheme")
ar := NewAttestationResult("someScheme", "test", "test")
status := NewTrustTier(TrustTierAffirming)
ar.Submods["someScheme"].Status = status
ar.Submods["someScheme"].TrustVector.Executables = ApprovedRuntimeClaim
Expand Down Expand Up @@ -371,3 +371,13 @@ func TestTrustTier_ColorString(t *testing.T) {
assert.Equal(t, "\\033[43mwarning\\033[0m", TrustTierWarning.ColorString())
assert.Equal(t, "\\033[41mcontraindicated\\033[0m", TrustTierContraindicated.ColorString())
}

func TestNewAttestationResult(t *testing.T) {
ar := NewAttestationResult("test", "testBuild", "testDev")

_, err := ar.MarshalJSON()
assert.NoError(t, err)

assert.Equal(t, "testBuild", *ar.VerifierID.Build)
assert.Equal(t, "testDev", *ar.VerifierID.Developer)
}

0 comments on commit 37395a1

Please sign in to comment.