Skip to content

Commit 04989c4

Browse files
authored
Adding tests around tagProperty (#53)
1 parent ac3eae8 commit 04989c4

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

docs/BASIC_LINTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
| | `TAG009` | `"Resource MUST provide 'cloudFormationSystemTags' {true\|false} if 'tagging.taggable' is true"` |
4848
| | `TAG010` | `"Resource MUST provide 'tagProperty' {/properties/Tags} if 'tagging.taggable' is true"` |
4949
| | `TAG011` | `"Resource MUST implement Tags property if 'tagging.taggable' is true"` |
50+
| | `TAG013` | `"'tagProperty' MUST specify property defined in the schema"` |
51+
| | `TAG014` | `"'tagProperty' MUST NOT be a part of 'writeOnlyProperties'"` |
5052

5153
#### Permissions
5254
| Rule Name | Check Id | Message |

src/rpdk/guard_rail/rule_library/tags/schema-linter-core-tagging-rules.guard

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ rule ensure_property_tags_exists_v2 when tagging exists {
112112
}
113113
>>
114114

115+
when tagging.tagProperty exists {
116+
let paths = paths
117+
tagging.tagProperty IN %paths
118+
<<
119+
{
120+
"result": "NON_COMPLIANT",
121+
"check_id": "TAG013",
122+
"message": "`tagProperty` MUST specify property defined in the schema"
123+
}
124+
>>
125+
126+
when writeOnlyProperties exists {
127+
tagging.tagProperty !IN writeOnlyProperties
128+
<<
129+
{
130+
"result": "NON_COMPLIANT",
131+
"check_id": "TAG014",
132+
"message": "`tagProperty` MUST NOT be a part of `writeOnlyProperties`"
133+
}
134+
>>
135+
}
136+
}
115137
tagging.permission exists
116138
<<
117139
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"properties": {
3+
"Tags": {},
4+
"Arn": {}
5+
},
6+
"tagging": {
7+
"taggable": true,
8+
"tagOnCreate": true,
9+
"tagUpdatable": true,
10+
"cloudFormationSystemTags": false,
11+
"tagProperty": "/properties/Tags2"
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties": {
3+
"Tags": {},
4+
"Arn": {}
5+
},
6+
"writeOnlyProperties": [
7+
"/properties/Tags"
8+
],
9+
"tagging": {
10+
"taggable": true,
11+
"tagOnCreate": true,
12+
"tagUpdatable": true,
13+
"cloudFormationSystemTags": false,
14+
"tagProperty": "/properties/Tags"
15+
}
16+
}

tests/integ/runner/test_integ_runner.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,52 @@
168168
},
169169
{},
170170
),
171+
(
172+
collect_schemas(
173+
schemas=[
174+
"file:/"
175+
+ str(
176+
Path(os.path.dirname(os.path.realpath(__file__))).joinpath(
177+
"../data/schema-malformed-tag-property.json"
178+
)
179+
)
180+
]
181+
),
182+
[],
183+
{
184+
"ensure_property_tags_exists_v2": {
185+
GuardRuleResult(
186+
check_id="TAG013",
187+
message="`tagProperty` MUST specify property defined in the schema",
188+
path="/tagging/tagProperty",
189+
)
190+
},
191+
},
192+
{},
193+
),
194+
(
195+
collect_schemas(
196+
schemas=[
197+
"file:/"
198+
+ str(
199+
Path(os.path.dirname(os.path.realpath(__file__))).joinpath(
200+
"../data/schema-tag-property-writeonly.json"
201+
)
202+
)
203+
]
204+
),
205+
[],
206+
{
207+
"ensure_property_tags_exists_v2": {
208+
GuardRuleResult(
209+
check_id="TAG014",
210+
message="`tagProperty` MUST NOT be a part of `writeOnlyProperties`",
211+
path="/tagging/tagProperty",
212+
)
213+
},
214+
},
215+
{},
216+
),
171217
(
172218
collect_schemas(
173219
schemas=[

0 commit comments

Comments
 (0)