fix: test suites that never ran, and thirty expectations that assert nothing - #286
Open
awsmadi wants to merge 4 commits into
Open
fix: test suites that never ran, and thirty expectations that assert nothing#286awsmadi wants to merge 4 commits into
awsmadi wants to merge 4 commits into
Conversation
Four test files under rules/aws/**/tests/ matched no rules file stem, so cfn-guard never paired them and not one of them had ever run. Each failed to pair for a different reason. s3_bucket_default_lock_enable_tests.yml dropped the trailing d from S3_BUCKET_DEFAULT_LOCK_ENABLED. No correctly named file existed beside it, so s3_bucket_default_lock_enabled.guard had no test coverage at all. The truncated spelling appeared eight times: once in the header comment, once in each of the six expectations, and once as a Metadata.guard SuppressedRules value inside the sixth case's template. Correcting only the filename and the expectation names leaves that sixth case failing, and the failure is the test data rather than the rule. The rule's filter excludes a bucket that suppresses S3_BUCKET_DEFAULT_LOCK_ENABLED, the template suppressed S3_BUCKET_DEFAULT_LOCK_ENABLE, and a suppression naming a different rule must not suppress this one. All eight occurrences are corrected here and the suite passes six of six. The cloudfront access logs test filename began with a space. Nothing inside it was wrong and its seven cases pass as written, so this is a rename and nothing more. cloudfront_accesslogs_enabled.guard had gone untested for that reason alone. iam_role_no_full_access_on_trust_policy.yml lacked the _tests suffix altogether. Its eight cases also pass unchanged, so it is likewise a rename only, and iam_role_no_full_access_on_trust_policy.guard had gone untested. rds_instance_logging_enabled_tests.yml was named after the rule it exercises, RDS_INSTANCE_LOGGING_ENABLED, rather than after its rules file, rds_logging_enabled.guard, which is why it did not pair. It duplicated rds_logging_enabled_tests.yml, which already pairs and already runs. Both held five cases over the same five scenarios with the same expectations: an empty template, no resources, EnableCloudwatchLogsExports present, that property absent, and that property absent with the rule suppressed. No scenario existed only in the orphan, so deleting it costs no coverage. One case name in the surviving file described the wrong property. It read "RDS Multi AZ property missing but rule is suppressed" while the rule tests only whether EnableCloudwatchLogsExports exists, and the case's template sets no MultiAZ property in either direction. It now says what it tests. Rule and test pairs go from 190 to 193, and all 193 exit 0. Test files living under a tests/ directory go from 194 to 193 once the duplicate is removed, and none of them is left unpaired.
"CodeDeploy DeploymentConfig without static deploymentConfigName, FAIL" and "IAM Group without static groupName, FAIL" both set a static name and both expect FAIL. Each is the with-a-static-name half of a pair whose other half already reads "without", so as written the titles duplicate the PASS cases. Titles only; no input or expectation changes.
Every one of the 33 existing cases declares exactly one resource of exactly one covered type, so nothing in the suite exercised the rule's behaviour when several covered types appear together. Three cases are added: all clean; only the IAM Role statically named; the DynamoDB table and the IAM Role both statically named. The middle one is the case worth having. It is the only shape in the suite where one covered resource violates while another is clean, so it is what pins down that a clean resource of one type does not mask a violation on another. Each verdict was read off cfn-guard validate against the rules file before being written here. Cases go from 33 to 36.
cfn_no_explicit_resource_names_tests.yml carried 63 expectation entries across 33 cases. Thirty of them, spread over 11 distinct names -- no_static_names, static_alarmname, static_dbinstanceidentifier and eight more in the same shape -- name rules that do not exist. cfn_no_explicit_resource_names.guard defines exactly one rule, CFN_NO_EXPLICIT_RESOURCE_NAMES. cfn-guard prints "No rule named X is in this file, so its expectation was not checked" for each and exits 0, so the suite has always reported clean while those thirty assertions ran nothing. They are not a stale rename. Both files were added in the same commit, 5f4a972 (aws-cloudformation#265), and no commit since has renamed a rule. The eleven names are the author's intended decomposition of the rule into per-type checks, written into the test file although the decomposition itself was never written into the rules file. Each name maps onto the property one type block checks: static_name to Name, static_alarmname to AlarmName, and so on. Dropped rather than repointed. Every affected case already carries a CFN_NO_EXPLICIT_RESOURCE_NAMES expectation of its own, so renaming a dead entry onto the rule that exists yields a second copy of an assertion the case already makes. The two operations are equivalent here and deletion is the smaller diff. No test input is removed: all 33 cases still run, against the same templates, asserting the same aggregate verdict as before. What is lost is the granularity the eleven names wanted, and that is worth having -- a per-type verdict says which resource type caused a failure, and lets one type be suppressed without suppressing the rule. Restoring it means adding the per-type rules to the ruleset, which changes the public rule set and needs a cfn-guard that tolerates a rule reference to a rule that did not apply. It is a follow-up, not this change.
Author
|
CI has never executed here — the workflow runs are held at That matters more than usual for this one, since the change is specifically about test suites that never ran and expectations that assert nothing. Without a CI run there is no evidence the newly-armed expectations actually fire. Could a maintainer enable the workflow run? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four test-suite fixes in this repository. Three suites were never run at all, thirty expectations asserted nothing, and two case titles state the opposite of what their case tests. Nothing here changes a rule, and no
.guardfile is touched.Thirty expectations that assert nothing
rules/aws/aws_cloudformation/tests/cfn_no_explicit_resource_names_tests.ymlcarries 63 expectation entries across 33 cases. Thirty of them name rules that do not exist, spread over 11 distinct names:no_static_names,static_alarmname,static_dbinstanceidentifier,static_deploymentconfigname,static_deploymentgroupname,static_domainname,static_groupname,static_managedpolicyname,static_name,static_repositoryname,static_rolenamecfn_no_explicit_resource_names.guarddefines exactly one rule,CFN_NO_EXPLICIT_RESOURCE_NAMES. For each of the thirty,cfn-guard testprintsand exits 0. So the suite has always reported clean while those thirty assertions ran nothing.
They are not a stale rename. Both files were added in the same commit, 5f4a972 (#265), and no commit since renames a rule. The eleven names are the intended decomposition of the rule into per-type checks, written into the test file although the decomposition was never written into the rules file. Each maps onto the property one type block checks —
static_nametoName,static_alarmnametoAlarmName, and so on.Dropped rather than repointed, because every affected case already carries a
CFN_NO_EXPLICIT_RESOURCE_NAMESexpectation of its own. Renaming a dead entry onto the rule that exists produces a second copy of an assertion the case already makes, so the two operations are equivalent here and deletion is the smaller diff. No test input is removed: all 33 cases still run, against the same templates, asserting the same aggregate verdict.What is lost is the granularity those eleven names wanted, and it is worth having — a per-type verdict says which resource type caused a failure, and lets one type be suppressed without suppressing the whole rule. Restoring it means adding per-type rules to the ruleset, which changes the public rule set and needs a
cfn-guardthat tolerates a rule reference to a rule that did not apply. That is a follow-up, not this change.No case covered more than one resource type
Every one of the 33 original cases declares exactly one resource of exactly one covered type. So nothing in the suite ever distinguished the rule's fourteen type checks from each other, and nothing exercised the rule on a template carrying several of them — which is what a real template looks like.
Three cases are added for that: several covered types all clean, several with one violating, and several with more than one violating. The middle one is the shape that matters, because it is the only case in the suite where the aggregate must fail on account of one specific type while the others are fine.
Three suites that never ran
cfn-guard testpairs a test file to a rules file by name. Three test files were named so that no rules file claimed them, so they were silently skipped:cloudfront_accesslogs_enabled_tests.yml— renamed to match its ruleiam_role_no_full_access_on_trust_policy_tests.yml— renamed to match its rules3_bucket_default_lock_enabled_tests.yml— renamed to match its rulerds_instance_logging_enabled_tests.ymlis removed: it duplicatesrds_logging_enabled_tests.yml, which is paired and does run.Two titles that describe the wrong outcome
Two cases in
cfn_no_explicit_resource_names_tests.ymlare titled as the opposite of what they assert. Titles only, no expectation changed.Verification
cfn-guard test -d ./rules/— the invocation.github/workflows/ci.ymluses — before and after, on the releasedcfn-guardand on a build frommain:Exit code is 0 before and after on every
cfn-guardversion tested, so this does not depend on a tool release. The reduction from 63 to 36 is the thirty dead entries plus the deduplication described above; case count goes from 33 to 36 with the three new ones.Every
.guardfile in the repository parses to a byte-identical tree before and after, because none is modified.