Skip to content

Commit d9593c5

Browse files
authored
Merge pull request #29 from jhrozek/fixes
Fixes to catch changes to versioned rules as well as rules going NOT-APPLICABLE
2 parents c5328c8 + 053e80a commit d9593c5

File tree

212 files changed

+18861
-9241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+18861
-9241
lines changed

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ require (
99
github.com/googleapis/gnostic v0.5.5 // indirect
1010
github.com/imdario/mergo v0.3.12 // indirect
1111
github.com/json-iterator/go v1.1.11 // indirect
12+
github.com/onsi/gomega v1.19.0 // indirect
1213
github.com/openshift/cluster-authentication-operator v0.0.3-0.20210603131321-6b9c13549b48
13-
github.com/openshift/compliance-operator v0.1.34
14+
github.com/openshift/compliance-operator v0.1.46
1415
github.com/openshift/library-go v0.0.0-20210611143017-0d0ef669a361 // indirect
1516
github.com/openshift/machine-config-operator v0.0.1-0.20200913004441-7eba765c69c9
16-
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
17-
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
17+
github.com/stretchr/testify v1.7.2 // indirect
18+
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
1819
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
19-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
20-
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
20+
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
2121
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
22+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
2223
google.golang.org/appengine v1.6.7 // indirect
2324
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
2425
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 36 additions & 15 deletions
Large diffs are not rendered by default.

helpers.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func (ctx *e2econtext) ensureTestSettings(t *testing.T) {
394394
}
395395
autoApplySettings.AutoApplyRemediations = true
396396
autoApplySettings.Debug = true
397+
autoApplySettings.ShowNotApplicable = true // so that we can test if a setting goes from PASS/FAIL to N/A
397398
err = backoff.RetryNotify(func() error {
398399
found := &cmpv1alpha1.ScanSetting{}
399400
if err := ctx.dynclient.Get(goctx.TODO(), key, found); err != nil {
@@ -883,10 +884,17 @@ func (ctx *e2econtext) verifyRule(
883884

884885
// getTestDefinition attempts to use a versioned test (<version>.yml)
885886
// definition, if it fails it'll try to use the standard test
886-
// definition (e2e.yml).
887+
// definition (e2e.yml). If that does not exist either, the function checks
888+
// if other files (presumably versioned tests) exist in that file and if
889+
// they do, it would fail. This is better than just silently ignoring the
890+
// files because:
891+
// 1) we catch rules that have versioned results but no result for the
892+
// current version more easily
893+
// 2) with each version, this forces us to think if we can already retire
894+
// certain rules
887895
func (ctx *e2econtext) getTestDefinition(rulePath string) ([]byte, error) {
888896
versionedManifest := fmt.Sprintf("%s.yml", ctx.version)
889-
versionedRuleTestFilePath := path.Join(ruleTestDir, versionedManifest)
897+
versionedRuleTestFilePath := path.Join(rulePath, ruleTestDir, versionedManifest)
890898
vbuf, verr := ioutil.ReadFile(versionedRuleTestFilePath)
891899

892900
if verr == nil {
@@ -897,8 +905,23 @@ func (ctx *e2econtext) getTestDefinition(rulePath string) ([]byte, error) {
897905
return nil, verr
898906
}
899907

908+
// the error is now os.IsNotExist, let's try the global file
900909
testFilePath := path.Join(rulePath, ruleTestFilePath)
901-
return ioutil.ReadFile(testFilePath)
910+
gbuf, gerr := ioutil.ReadFile(testFilePath)
911+
if os.IsNotExist(gerr) {
912+
// let's check for other files and fail if they don't exist
913+
files, err := os.ReadDir(ruleTestDir)
914+
if err != nil {
915+
return nil, err
916+
}
917+
if len(files) > 0 {
918+
return nil, fmt.Errorf("E2E-FAILURE: the rule directory %s contains versioned files, but none for %s", ruleTestDir, ctx.version)
919+
}
920+
} else if gerr != nil {
921+
return nil, gerr
922+
}
923+
924+
return gbuf, nil
902925
}
903926

904927
// getManualRemediationPath attempts to get a versioned remediation

vendor/github.com/openshift/cluster-authentication-operator/test/library/keycloakidp.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/compliance-operator/pkg/apis/compliance/v1alpha1/compliancecheckresult_types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/compliance-operator/pkg/apis/compliance/v1alpha1/complianceremediation_types.go

Lines changed: 141 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/compliance-operator/pkg/apis/compliance/v1alpha1/compliancescan_types.go

Lines changed: 54 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/compliance-operator/pkg/apis/compliance/v1alpha1/rule_types.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)