Skip to content

Commit

Permalink
fix(validate): fix order of assessment-results results (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller authored May 24, 2024
1 parent 9c51d56 commit a8db208
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/pkg/common/oscal/assessment-results.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func GenerateAssessmentResults(findingMap map[string]oscalTypes_1_1_2.Finding, o
func MergeAssessmentResults(original *oscalTypes_1_1_2.AssessmentResults, latest *oscalTypes_1_1_2.AssessmentResults) (*oscalTypes_1_1_2.AssessmentResults, error) {

results := make([]oscalTypes_1_1_2.Result, 0)
// append new results first - unfurl so as to allow multiple results in the future
results = append(results, original.Results...)
// append newest to oldest results
results = append(results, latest.Results...)
results = append(results, original.Results...)
original.Results = results

original.Metadata.LastModified = time.Now()
Expand Down
12 changes: 10 additions & 2 deletions src/test/e2e/pod_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con
AssessmentResults: report,
}

// Write the component definition to file
// Write the assessment results to file
err = oscal.WriteOscalModel("sar-test.yaml", &model)
if err != nil {
message.Fatalf(err, "error writing component to file")
Expand All @@ -193,11 +193,15 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con
if err != nil {
t.Fatal("Failed generation of Assessment Results object with: ", err)
}

// Get the UUID of the report results - there should only be one
resultId := report.Results[0].UUID

model = oscalTypes_1_1_2.OscalModels{
AssessmentResults: report,
}

// Write the component definition to file
// Write the assessment results to file
err = oscal.WriteOscalModel("sar-test.yaml", &model)
if err != nil {
message.Fatalf(err, "error writing component to file")
Expand All @@ -218,6 +222,10 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con
t.Fatal("Failed to append results to existing report")
}

if resultId != tempAssessment.Results[0].UUID {
t.Fatal("Failed to prepend results to existing report")
}

validatorResponse, err := validation.ValidationCommand("sar-test.yaml")
if err != nil {
t.Fatal("File failed linting")
Expand Down

0 comments on commit a8db208

Please sign in to comment.