Skip to content

Commit c0b72a0

Browse files
committed
fix: align OSCAL AR mapping for target, aggregate-result, and back-matter
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
1 parent 14a9277 commit c0b72a0

2 files changed

Lines changed: 62 additions & 21 deletions

File tree

gemaraconv/assessment_results.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ func EvaluationLogToOSCALAssessmentResults(log gemara.EvaluationLog, opts ...Eva
3232
}
3333

3434
return oscal.AssessmentResults{
35-
UUID: uuid.NewUUID(),
36-
Metadata: metadata,
37-
ImportAp: oscal.ImportAp{Href: options.importApHref},
38-
Results: []oscal.Result{result},
35+
UUID: uuid.NewUUID(),
36+
Metadata: metadata,
37+
ImportAp: oscal.ImportAp{Href: options.importApHref},
38+
Results: []oscal.Result{result},
39+
BackMatter: mappingToBackMatter(log.Metadata.MappingReferences),
3940
}, nil
4041
}
4142

@@ -82,9 +83,9 @@ func evaluationLogToResult(log gemara.EvaluationLog, catalog *gemara.ControlCata
8283

8384
title := fmt.Sprintf("Evaluation: %s", log.Metadata.Id)
8485

85-
targetComponent := buildTargetComponent(log.Target)
86+
targetItem := buildTargetInventoryItem(log.Target)
8687
localDefs := oscal.LocalDefinitions{
87-
Components: &[]oscal.SystemComponent{targetComponent},
88+
InventoryItems: &[]oscal.InventoryItem{targetItem},
8889
}
8990

9091
result := oscal.Result{
@@ -98,7 +99,7 @@ func evaluationLogToResult(log gemara.EvaluationLog, catalog *gemara.ControlCata
9899
LocalDefinitions: &localDefs,
99100
Props: &[]oscal.Property{
100101
{
101-
Name: "result",
102+
Name: "aggregate-result",
102103
Value: log.Result.String(),
103104
Ns: oscalUtils.GemaraNamespace,
104105
},
@@ -277,26 +278,26 @@ func buildLogEntry(alog *gemara.AssessmentLog, eval *gemara.ControlEvaluation, p
277278
return entry
278279
}
279280

280-
func buildTargetComponent(target gemara.Resource) oscal.SystemComponent {
281+
func buildTargetInventoryItem(target gemara.Resource) oscal.InventoryItem {
281282
description := target.Description
282283
if description == "" {
283284
description = target.Name
284285
}
285286

286-
return oscal.SystemComponent{
287+
return oscal.InventoryItem{
287288
UUID: uuid.NewUUID(),
288-
Type: "this-system",
289-
Title: target.Name,
290289
Description: description,
291-
Status: oscal.SystemComponentStatus{
292-
State: "operational",
293-
},
294290
Props: &[]oscal.Property{
295291
{
296292
Name: "gemara-resource-id",
297293
Value: target.Id,
298294
Ns: oscalUtils.GemaraNamespace,
299295
},
296+
{
297+
Name: "name",
298+
Value: target.Name,
299+
Ns: oscalUtils.GemaraNamespace,
300+
},
300301
},
301302
}
302303
}

gemaraconv/assessment_results_test.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestEvaluationLogToOSCALAssessmentResults_AssessmentLogEntries(t *testing.T
142142
assert.Contains(t, result.AssessmentLog.Entries[1].Title, "REQ-2")
143143
}
144144

145-
func TestEvaluationLogToOSCALAssessmentResults_TargetComponent(t *testing.T) {
145+
func TestEvaluationLogToOSCALAssessmentResults_TargetInventoryItem(t *testing.T) {
146146
log := makeEvaluationLog(gemara.Actor{Name: "tool", Type: gemara.Software}, []*gemara.AssessmentLog{
147147
makeAssessmentLog("REQ-1", "check", gemara.Passed, "", nil),
148148
})
@@ -153,12 +153,15 @@ func TestEvaluationLogToOSCALAssessmentResults_TargetComponent(t *testing.T) {
153153

154154
result := ar.Results[0]
155155
require.NotNil(t, result.LocalDefinitions)
156-
require.NotNil(t, result.LocalDefinitions.Components)
157-
require.Len(t, *result.LocalDefinitions.Components, 1)
158-
159-
comp := (*result.LocalDefinitions.Components)[0]
160-
assert.Equal(t, "Production System", comp.Title)
161-
assert.Equal(t, "The prod system", comp.Description)
156+
require.NotNil(t, result.LocalDefinitions.InventoryItems)
157+
require.Len(t, *result.LocalDefinitions.InventoryItems, 1)
158+
159+
item := (*result.LocalDefinitions.InventoryItems)[0]
160+
assert.Equal(t, "The prod system", item.Description)
161+
require.NotNil(t, item.Props)
162+
props := *item.Props
163+
assert.Equal(t, "my-sys", props[0].Value)
164+
assert.Equal(t, "Production System", props[1].Value)
162165
}
163166

164167
func TestEvaluationLogConverter_ToOSCALAssessmentResults(t *testing.T) {
@@ -173,6 +176,43 @@ func TestEvaluationLogConverter_ToOSCALAssessmentResults(t *testing.T) {
173176
assert.Contains(t, ar.Results[0].Title, "eval-converter")
174177
}
175178

179+
func TestEvaluationLogToOSCALAssessmentResults_BackMatter(t *testing.T) {
180+
log := makeEvaluationLog(gemara.Actor{Name: "tool", Type: gemara.Software}, []*gemara.AssessmentLog{
181+
makeAssessmentLog("REQ-1", "check", gemara.Passed, "", nil),
182+
})
183+
log.Metadata.MappingReferences = []gemara.MappingReference{
184+
{
185+
Id: "CNSC",
186+
Title: "Cloud Native Security Controls",
187+
Version: "1.0.0",
188+
Description: "CNCF security controls catalog",
189+
Url: "https://example.com/cnsc",
190+
},
191+
}
192+
193+
ar, err := EvaluationLogToOSCALAssessmentResults(log)
194+
require.NoError(t, err)
195+
196+
require.NotNil(t, ar.BackMatter)
197+
require.NotNil(t, ar.BackMatter.Resources)
198+
require.Len(t, *ar.BackMatter.Resources, 1)
199+
200+
resource := (*ar.BackMatter.Resources)[0]
201+
assert.Equal(t, "Cloud Native Security Controls", resource.Title)
202+
assert.NotEmpty(t, resource.UUID)
203+
assertValidJSON(t, ar)
204+
}
205+
206+
func TestEvaluationLogToOSCALAssessmentResults_NoBackMatterWhenEmpty(t *testing.T) {
207+
log := makeEvaluationLog(gemara.Actor{Name: "tool", Type: gemara.Software}, []*gemara.AssessmentLog{
208+
makeAssessmentLog("REQ-1", "check", gemara.Passed, "", nil),
209+
})
210+
211+
ar, err := EvaluationLogToOSCALAssessmentResults(log)
212+
require.NoError(t, err)
213+
assert.Nil(t, ar.BackMatter)
214+
}
215+
176216
func TestMapActorType(t *testing.T) {
177217
assert.Equal(t, "person", mapActorType(gemara.Human))
178218
assert.Equal(t, "tool", mapActorType(gemara.Software))

0 commit comments

Comments
 (0)