Skip to content

Commit 603a275

Browse files
authored
Merge pull request #286 from Kudbettin/fix_issue-249
Fixes a problem where a value of a property can be an empty string (or emtpy list) but still being validated.
2 parents d4a163f + d6faa91 commit 603a275

File tree

16 files changed

+102
-0
lines changed

16 files changed

+102
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## Unreleased
4+
* Fixed a bug where some empty found values would be treated as not found. ([#249](https://github.com/eerkunt/terraform-compliance/issues/249))
5+
36
## 1.2.4 (2020-06-03)
47
* Add ability to reference a git repo by branch name and directory via `<repo>.git//<directory>?ref=<branch-name`. ([#218](https://github.com/eerkunt/terraform-compliance/issues/218))
58

terraform_compliance/steps/then/it_must_contain_something.py

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def it_must_contain_something(_step_obj, something, inherited_values=Null):
4040

4141
if isinstance(found_key, dict):
4242
found_value = jsonify(found_key.get(something, found_key))
43+
found_value = found_value if found_value not in ([], '') else found_key
4344
else:
4445
found_value = found_key
4546
elif isinstance(values, list):
@@ -137,6 +138,7 @@ def it_must_not_contain_something(_step_obj, something, inherited_values=Null):
137138

138139
if isinstance(found_key, dict):
139140
found_value = jsonify(found_key.get(something, found_key))
141+
found_value = found_value if found_value not in ([], '') else found_key
140142
else:
141143
found_value = found_key
142144
elif isinstance(values, list):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Failure: module.alb.aws_alb.alb \(aws_alb\) does not have bad_something_waf_custom property.

tests/functional/test_issue-249-bad_feature/.failure

Whitespace-only changes.

tests/functional/test_issue-249-bad_feature/plan.out.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Fixed version of the features provided on issue 249.
2+
# Bad feature: Last line changed to something that's not in tags
3+
Feature: Resources should be properly tagged
4+
In order to keep track of resource ownership
5+
As engineers
6+
We'll enforce tagging on all resources
7+
8+
# Check required tag for ALB and CF
9+
Scenario: Ensure that waf_policy for ALB/CF tag is defined
10+
Given I have aws_alb defined
11+
When it contains tags
12+
Then it must contain waf_policy
13+
And its value must match the "^(internal|external|custom)$" regex
14+
15+
Scenario: Ensure that waf_custom for ALB/CF tag is defined
16+
Given I have aws_alb defined
17+
When it contains tags
18+
Then it must contain bad_something_waf_custom

tests/functional/test_issue-249-has/plan.out.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Fixed version of the features provided on issue 249
2+
# Has: "when it contains" steps are changed to "when it has"
3+
Feature: Resources should be properly tagged
4+
In order to keep track of resource ownership
5+
As engineers
6+
We'll enforce tagging on all resources
7+
8+
# Check required tag for ALB and CF
9+
Scenario: Ensure that waf_policy for ALB/CF tag is defined
10+
Given I have aws_alb defined
11+
When it has tags
12+
Then it must contain tags
13+
Then it must contain waf_policy
14+
And its value must match the "^(internal|external|custom)$" regex
15+
16+
Scenario: Ensure that waf_custom for ALB/CF tag is defined
17+
Given I have aws_alb defined
18+
When it has tags
19+
Then it must contain waf_custom
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Failure: waf_policy property exists in module.alb.aws_alb.alb \(aws_alb\).
2+
Failure: waf_custom property exists in module.alb.aws_alb.alb \(aws_alb\).

tests/functional/test_issue-249-must_not/.failure

Whitespace-only changes.

tests/functional/test_issue-249-must_not/plan.out.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Fixed version of the features provided on issue 249
2+
# Must not: Testing must not changes
3+
Feature: Resources should be properly tagged
4+
In order to keep track of resource ownership
5+
As engineers
6+
We'll enforce tagging on all resources
7+
8+
# Check required tag for ALB and CF
9+
Scenario: Ensure that waf_policy for ALB/CF tag is defined
10+
Given I have aws_alb defined
11+
When it contains tags
12+
Then it must not contain waf_policy
13+
14+
Scenario: Ensure that waf_custom for ALB/CF tag is defined
15+
Given I have aws_alb defined
16+
When it contains tags
17+
Then it must not contain waf_custom

tests/functional/test_issue-249-must_not_bad_feature/plan.out.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Fixed version of the features provided on issue 249
2+
# Must not: Testing must not changes
3+
# Bad feature: Last line changed to something that's not in tags
4+
Feature: Resources should be properly tagged
5+
In order to keep track of resource ownership
6+
As engineers
7+
We'll enforce tagging on all resources
8+
9+
# Check required tag for ALB and CF
10+
Scenario: Ensure that waf_policy for ALB/CF tag is defined
11+
Given I have aws_alb defined
12+
When it contains tags
13+
Then it must not contain bad_waf_policy
14+
15+
Scenario: Ensure that waf_custom for ALB/CF tag is defined
16+
Given I have aws_alb defined
17+
When it contains tags
18+
Then it must not contain bad_something_waf_custom

tests/functional/test_issue-249/plan.out.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Fixed version of the features provided on issue 249
2+
Feature: Resources should be properly tagged
3+
In order to keep track of resource ownership
4+
As engineers
5+
We'll enforce tagging on all resources
6+
7+
# Check required tag for ALB and CF
8+
Scenario: Ensure that waf_policy for ALB/CF tag is defined
9+
Given I have aws_alb defined
10+
When it contains tags
11+
Then it must contain waf_policy
12+
And its value must match the "^(internal|external|custom)$" regex
13+
14+
Scenario: Ensure that waf_custom for ALB/CF tag is defined
15+
Given I have aws_alb defined
16+
When it contains tags
17+
Then it must contain waf_custom

0 commit comments

Comments
 (0)