-
Notifications
You must be signed in to change notification settings - Fork 33
Add Evidence validation using swid.Evidence.Valid() method #224
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
Merged
+258
−7
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7eb8bed
Add Evidence validation using swid.Evidence.Valid() method
Sukuna0007Abhi 6364ae7
Update coev/coswid_evidence.go
Sukuna0007Abhi f651356
Fix linting issues and update dependencies
Sukuna0007Abhi dd5e798
fix: resolve gocritic and goimports linting issues
Sukuna0007Abhi b28d6a2
Further refinement
yogeshbdeshpande f064f8f
Apply suggestions from code review
yogeshbdeshpande d22cd64
Fix import formatting in coswid_evidence.go
Sukuna0007Abhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,123 @@ | ||
| // Copyright 2025 Contributors to the Veraison project. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package coev | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/veraison/swid" | ||
| ) | ||
|
|
||
| func TestCoSWIDEvidenceMap_Valid_Success(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| evidenceMap := CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-123", | ||
| Date: validDate, | ||
| }, | ||
| } | ||
|
|
||
| err := evidenceMap.Valid() | ||
| assert.NoError(t, err, "Valid evidence map should pass validation") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidenceMap_Valid_WithTagID(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| evidenceMap := CoSWIDEvidenceMap{ | ||
| TagID: swid.NewTagID("test-tag-id"), | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-123", | ||
| Date: validDate, | ||
| }, | ||
| } | ||
|
|
||
| err := evidenceMap.Valid() | ||
| assert.NoError(t, err, "Valid evidence map with TagID should pass validation") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidenceMap_Valid_InvalidEvidence(t *testing.T) { | ||
| evidenceMap := CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| // Missing required DeviceID and Date | ||
| }, | ||
| } | ||
|
|
||
| err := evidenceMap.Valid() | ||
| assert.Error(t, err, "Invalid evidence should fail validation") | ||
| assert.Contains(t, err.Error(), "evidence validation failed") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidenceMap_Valid_InvalidTagID(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
| emptyTagID := &swid.TagID{} // Empty TagID - should be invalid | ||
|
|
||
| evidenceMap := CoSWIDEvidenceMap{ | ||
| TagID: emptyTagID, | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-123", | ||
| Date: validDate, | ||
| }, | ||
| } | ||
|
|
||
| err := evidenceMap.Valid() | ||
| assert.Error(t, err, "Invalid TagID should fail validation") | ||
| assert.Contains(t, err.Error(), "tagId validation failed") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidence_Valid_Success(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| evidence := CoSWIDEvidence{ | ||
| CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-1", | ||
| Date: validDate, | ||
| }, | ||
| }, | ||
| CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-2", | ||
| Date: validDate, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err := evidence.Valid() | ||
| assert.NoError(t, err, "Valid evidence slice should pass validation") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidence_Valid_EmptySlice(t *testing.T) { | ||
| evidence := CoSWIDEvidence{} | ||
|
|
||
| err := evidence.Valid() | ||
| assert.Error(t, err, "Empty evidence slice should fail validation") | ||
| assert.Contains(t, err.Error(), "must contain at least one entry") | ||
| } | ||
|
|
||
| func TestCoSWIDEvidence_Valid_InvalidEntry(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| evidence := CoSWIDEvidence{ | ||
| CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| DeviceID: "test-device-1", | ||
| Date: validDate, | ||
| }, | ||
| }, | ||
| CoSWIDEvidenceMap{ | ||
| Evidence: swid.Evidence{ | ||
| // Missing required DeviceID - should fail | ||
| Date: validDate, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err := evidence.Valid() | ||
| assert.Error(t, err, "Evidence slice with invalid entry should fail validation") | ||
| assert.Contains(t, err.Error(), "evidence[1] validation failed") | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
| // Copyright 2025 Contributors to the Veraison project. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cots | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/veraison/swid" | ||
| ) | ||
|
|
||
| func TestAbbreviatedSwidTag_Valid_WithEvidence_Success(t *testing.T) { | ||
| validDate := time.Date(2023, time.January, 1, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| tag, err := NewTag("test-tag-id", "Test Software", "1.0.0") | ||
| assert.NoError(t, err) | ||
|
|
||
| // Add required entity | ||
| entity := swid.Entity{ | ||
| EntityName: "Test Inc.", | ||
| } | ||
| err = entity.SetRoles(swid.RoleTagCreator) | ||
| assert.NoError(t, err) | ||
| tag.Entities = append(tag.Entities, entity) | ||
|
|
||
| // Add valid Evidence | ||
| evidence := &swid.Evidence{ | ||
| DeviceID: "test-device-123", | ||
| Date: validDate, | ||
| } | ||
| tag.Evidence = evidence | ||
|
|
||
| err = tag.Valid() | ||
| assert.NoError(t, err, "Tag with valid Evidence should pass validation") | ||
| } | ||
|
|
||
| func TestAbbreviatedSwidTag_Valid_WithInvalidEvidence(t *testing.T) { | ||
| tag, err := NewTag("test-tag-id", "Test Software", "1.0.0") | ||
| assert.NoError(t, err) | ||
|
|
||
| // Add required entity | ||
| entity := swid.Entity{ | ||
| EntityName: "Test Inc.", | ||
| } | ||
| err = entity.SetRoles(swid.RoleTagCreator) | ||
| assert.NoError(t, err) | ||
| tag.Entities = append(tag.Entities, entity) | ||
|
|
||
| // Add invalid Evidence (missing required fields) | ||
| evidence := &swid.Evidence{ | ||
| // Missing DeviceID and Date | ||
| } | ||
| tag.Evidence = evidence | ||
|
|
||
| err = tag.Valid() | ||
| assert.Error(t, err, "Tag with invalid Evidence should fail validation") | ||
| assert.Contains(t, err.Error(), "evidence validation failed") | ||
| } | ||
|
|
||
| func TestAbbreviatedSwidTag_Valid_WithoutEvidence(t *testing.T) { | ||
| tag, err := NewTag("test-tag-id", "Test Software", "1.0.0") | ||
| assert.NoError(t, err) | ||
|
|
||
| // Add required entity | ||
| entity := swid.Entity{ | ||
| EntityName: "Test Inc.", | ||
| } | ||
| err = entity.SetRoles(swid.RoleTagCreator) | ||
| assert.NoError(t, err) | ||
| tag.Entities = append(tag.Entities, entity) | ||
|
|
||
| // Evidence is nil - should still pass validation | ||
| err = tag.Valid() | ||
| assert.NoError(t, err, "Tag without Evidence should pass validation") | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.