Skip to content

Commit cc5dcea

Browse files
dhaiducekopenshift-merge-robot
authored andcommitted
Error when manifest is empty
ref: https://issues.redhat.com/browse/ACM-3617 Signed-off-by: Dale Haiducek <[email protected]>
1 parent db27853 commit cc5dcea

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

internal/plugin_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,38 @@ spec:
909909
assertEqual(t, output, expected)
910910
}
911911

912+
func TestCreatePolicyEmptyManifest(t *testing.T) {
913+
t.Parallel()
914+
tmpDir := t.TempDir()
915+
createConfigMap(t, tmpDir, "configmap.yaml")
916+
917+
err := os.WriteFile(path.Join(tmpDir, "empty.yaml"), []byte{}, 0o666)
918+
if err != nil {
919+
t.Fatalf("Failed to write empty.yaml")
920+
}
921+
922+
p := Plugin{}
923+
p.PolicyDefaults.Namespace = "my-policies"
924+
policyConf := types.PolicyConfig{
925+
Name: "policy-app-config",
926+
Manifests: []types.Manifest{
927+
{
928+
Path: path.Join(tmpDir, "empty.yaml"),
929+
ConfigurationPolicyOptions: types.ConfigurationPolicyOptions{ComplianceType: "mustonlyhave"},
930+
}, {
931+
Path: path.Join(tmpDir, "configmap.yaml"),
932+
ConfigurationPolicyOptions: types.ConfigurationPolicyOptions{ComplianceType: "mustnothave"},
933+
},
934+
},
935+
}
936+
p.Policies = append(p.Policies, policyConf)
937+
p.applyDefaults(map[string]interface{}{})
938+
939+
err = p.createPolicy(&p.Policies[0])
940+
expectedErr := fmt.Sprintf("found empty YAML in the manifest at %s", path.Join(tmpDir, "empty.yaml"))
941+
assertEqual(t, err.Error(), expectedErr)
942+
}
943+
912944
func TestCreatePolicyWithAnnotations(t *testing.T) {
913945
t.Parallel()
914946
tmpDir := t.TempDir()

internal/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
7777
}
7878

7979
if len(manifestFile) == 0 {
80-
continue
80+
return nil, fmt.Errorf("found empty YAML in the manifest at %s", manifest.Path)
8181
}
8282
// Allowing replace the original manifest metadata.name and/or metadata.namespace if it is a single
8383
// yaml structure in the manifest path

0 commit comments

Comments
 (0)