-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rules-to-control mappings to support implementation/require…
…ment specific settings (#30) * feat: add namespace check during rule property search Adding a trestle-defined namespace check ensures Rule properties are only processed from trestle authored documents. Signed-off-by: Jennifer Power <[email protected]> * refactor: updates rules.Store for simplification The All() method is removed from rules.Store to simplify the interface. The rules.Store interface is for more focused queries. Indexing is decoupled from the creation of the MemoryStore to defer indexing until needed. Signed-off-by: Jennifer Power <[email protected]> * test: update testdata for a multi validator use case Signed-off-by: Jennifer Power <[email protected]> * feat(requirements): adds requirements pkg for control implementation This change adds support for processing OSCAL Control Implementations and using that processed data to apply settings and context from requirements to RuleSet results in a rules.Store implementation. The Settings interface is defined to allow settings to be applied at the Implementation and Requirement levels. Signed-off-by: Jennifer Power <[email protected]> --------- Signed-off-by: Jennifer Power <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,137 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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,58 @@ | ||
/* | ||
Copyright 2024 The OSCAL Compass Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package extensions | ||
|
||
import ( | ||
"strings" | ||
|
||
oscalTypes "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2" | ||
) | ||
|
||
// TrestleNameSpace is the generic namespace for trestle-defined property extensions. | ||
const TrestleNameSpace = "https://oscal-compass.github.io/compliance-trestle/schemas/oscal" | ||
|
||
// Below are defined oscal.Property names for compass-based extensions. | ||
const ( | ||
// RuleIdProp represents the property name for Rule ids. | ||
RuleIdProp = "Rule_Id" | ||
// RuleDescriptionProp represents the property name for Rule descriptions. | ||
RuleDescriptionProp = "Rule_Description" | ||
// CheckIdProp represents the property name for Check ids. | ||
CheckIdProp = "Check_Id" | ||
// CheckDescriptionProp represents the property name for Check descriptions. | ||
CheckDescriptionProp = "Check_Description" | ||
// ParameterIdProp represents the property name for Parameter ids. | ||
ParameterIdProp = "Parameter_Id" | ||
// ParameterDescriptionProp represents the property name for Parameter descriptions. | ||
ParameterDescriptionProp = "Parameter_Description" | ||
// ParameterDefaultProp represents the property name for Parameter default selected values. | ||
ParameterDefaultProp = "Parameter_Value_Default" | ||
// FrameworkProp represents the property name for the control source short name. | ||
FrameworkProp = "Framework_Short_Name" | ||
) | ||
|
||
// FindAllProps returns all properties with the given name. If no properties match, nil is returned. | ||
// This function also implicitly checks that the property is a trestle-defined property in the namespace. | ||
func FindAllProps(name string, props []oscalTypes.Property) []oscalTypes.Property { | ||
var matchingProps []oscalTypes.Property | ||
for _, prop := range props { | ||
if prop.Name == name && strings.Contains(prop.Ns, TrestleNameSpace) { | ||
matchingProps = append(matchingProps, prop) | ||
} | ||
} | ||
return matchingProps | ||
} | ||
|
||
// GetTrestleProp returned the first property matching the given name and a match is found. | ||
// This function also implicitly checks that the property is a trestle-defined property in the namespace. | ||
func GetTrestleProp(name string, props []oscalTypes.Property) (oscalTypes.Property, bool) { | ||
for _, prop := range props { | ||
if prop.Name == name && strings.Contains(prop.Ns, TrestleNameSpace) { | ||
return prop, true | ||
} | ||
} | ||
return oscalTypes.Property{}, false | ||
} |
This file contains 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,166 @@ | ||
/* | ||
Copyright 2024 The OSCAL Compass Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package extensions | ||
|
||
import ( | ||
"testing" | ||
|
||
oscalTypes "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetTrestleProp(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputProps []oscalTypes.Property | ||
inputName string | ||
wantProp oscalTypes.Property | ||
wantFound bool | ||
}{ | ||
{ | ||
name: "Valid/PropFound", | ||
inputName: "testProp1", | ||
inputProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue", | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue", | ||
Ns: TrestleNameSpace, | ||
}, | ||
}, | ||
wantProp: oscalTypes.Property{ | ||
Name: "testProp1", | ||
Value: "testValue", | ||
Ns: TrestleNameSpace, | ||
Group: "", | ||
Class: "", | ||
Remarks: "", | ||
}, | ||
wantFound: true, | ||
}, | ||
{ | ||
name: "Valid/PropNotFound", | ||
inputName: "testProp", | ||
inputProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue", | ||
}, | ||
{ | ||
Name: "testProp2", | ||
Value: "testValue", | ||
Ns: TrestleNameSpace, | ||
}, | ||
}, | ||
wantProp: oscalTypes.Property{}, | ||
wantFound: false, | ||
}, | ||
{ | ||
name: "Valid/PropNotFoundNs", | ||
inputName: "testProp1", | ||
inputProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue", | ||
}, | ||
{ | ||
Name: "testProp2", | ||
Value: "testValue", | ||
}, | ||
}, | ||
wantProp: oscalTypes.Property{}, | ||
wantFound: false, | ||
}, | ||
} | ||
|
||
for _, c := range tests { | ||
t.Run(c.name, func(t *testing.T) { | ||
foundProp, found := GetTrestleProp(c.inputName, c.inputProps) | ||
require.Equal(t, c.wantProp, foundProp) | ||
require.Equal(t, c.wantFound, found) | ||
}) | ||
} | ||
} | ||
|
||
func TestFindAllProps(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputName string | ||
inputProps []oscalTypes.Property | ||
wantProps []oscalTypes.Property | ||
}{ | ||
{ | ||
name: "Valid/PropsFound", | ||
inputName: "testProp1", | ||
inputProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue1", | ||
Ns: TrestleNameSpace, | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue2", | ||
Ns: TrestleNameSpace, | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue3", | ||
}, | ||
}, | ||
wantProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue1", | ||
Ns: TrestleNameSpace, | ||
Group: "", | ||
Class: "", | ||
Remarks: "", | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue2", | ||
Ns: TrestleNameSpace, | ||
Group: "", | ||
Class: "", | ||
Remarks: "", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Valid/NoPropsFound", | ||
inputName: "testProp3", | ||
inputProps: []oscalTypes.Property{ | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue1", | ||
Ns: TrestleNameSpace, | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue2", | ||
Ns: TrestleNameSpace, | ||
}, | ||
{ | ||
Name: "testProp1", | ||
Value: "testValue3", | ||
Ns: TrestleNameSpace, | ||
}, | ||
}, | ||
wantProps: []oscalTypes.Property(nil), | ||
}, | ||
} | ||
|
||
for _, c := range tests { | ||
t.Run(c.name, func(t *testing.T) { | ||
foundProps := FindAllProps(c.inputName, c.inputProps) | ||
require.Equal(t, c.wantProps, foundProps) | ||
}) | ||
} | ||
} |
This file contains 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 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 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.