Skip to content

Commit

Permalink
fix(composition): nil pointer in composition (#733)
Browse files Browse the repository at this point in the history
* fix(composition): nil pointer in composition

* fix(validate): testing for required error with no control implementations
  • Loading branch information
brandtkeller authored Oct 11, 2024
1 parent 3f5a110 commit 8ad4209
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/pkg/common/composition/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,41 +152,41 @@ func (c *Composer) ComposeComponentValidations(ctx context.Context, compDef *osc

for componentIndex, component := range *compDef.Components {
// If there are no control-implementations, skip to the next component
controlImplementations := *component.ControlImplementations
if controlImplementations == nil {
continue
}
for controlImplementationIndex, controlImplementation := range controlImplementations {
for implementedRequirementIndex, implementedRequirement := range controlImplementation.ImplementedRequirements {
if implementedRequirement.Links != nil {
compiledLinks := []oscalTypes_1_1_2.Link{}

for _, link := range *implementedRequirement.Links {
if common.IsLulaLink(link) {
ids, err := resourceMap.AddFromLink(&link, baseDir)
if err != nil {
// return err
newId := uuid.NewUUID()
message.Debugf("Error adding validation %s from link %s: %v", newId, link.Href, err)
ids = []string{newId}
}
for _, id := range ids {
link := oscalTypes_1_1_2.Link{
Rel: link.Rel,
Href: common.AddIdPrefix(id),
Text: link.Text,
if component.ControlImplementations != nil {
controlImplementations := *component.ControlImplementations
for controlImplementationIndex, controlImplementation := range controlImplementations {
for implementedRequirementIndex, implementedRequirement := range controlImplementation.ImplementedRequirements {
if implementedRequirement.Links != nil {
compiledLinks := []oscalTypes_1_1_2.Link{}

for _, link := range *implementedRequirement.Links {
if common.IsLulaLink(link) {
ids, err := resourceMap.AddFromLink(&link, baseDir)
if err != nil {
// return err
newId := uuid.NewUUID()
message.Debugf("Error adding validation %s from link %s: %v", newId, link.Href, err)
ids = []string{newId}
}
for _, id := range ids {
link := oscalTypes_1_1_2.Link{
Rel: link.Rel,
Href: common.AddIdPrefix(id),
Text: link.Text,
}
compiledLinks = append(compiledLinks, link)
}
} else {
compiledLinks = append(compiledLinks, link)
}
} else {
compiledLinks = append(compiledLinks, link)
}
(*component.ControlImplementations)[controlImplementationIndex].ImplementedRequirements[implementedRequirementIndex].Links = &compiledLinks
(*compDef.Components)[componentIndex] = component
}
(*component.ControlImplementations)[controlImplementationIndex].ImplementedRequirements[implementedRequirementIndex].Links = &compiledLinks
(*compDef.Components)[componentIndex] = component
}
}
}

}
allFetched := resourceMap.AllFetched()
if compDef.BackMatter != nil && compDef.BackMatter.Resources != nil {
Expand Down
5 changes: 5 additions & 0 deletions src/test/e2e/cmd/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func TestValidateCommand(t *testing.T) {
require.ErrorContains(t, err, "error validating on path")
})

t.Run("Validate with valid oscal containing no control implementations - error", func(t *testing.T) {
err := test(t, "-f", "../../unit/common/oscal/valid-component-no-implementations.yaml")
require.ErrorContains(t, err, "no control implementations found in component definition")
})

t.Run("Test help", func(t *testing.T) {
err := testAgainstGolden(t, "help", "--help")
require.NoError(t, err)
Expand Down
14 changes: 14 additions & 0 deletions src/test/unit/common/oscal/valid-component-no-implementations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
component-definition:
uuid: ea3e8daf-a055-4593-95f4-fa1b10eab448
metadata:
title: example no implementations
last-modified: "2023-11-29T17:48:16Z"
version: "20231129"
oscal-version: 1.1.2
components:
- uuid: b87ba90e-86db-4980-9600-fbfc8bf3c4f1
type: software
title: Test
description: |
this represents a component without any control implementations
purpose: Provides a testing

0 comments on commit 8ad4209

Please sign in to comment.