Skip to content

Commit

Permalink
Look at OriginGroups too for rule E3057 (#3607)
Browse files Browse the repository at this point in the history
* Look at OriginGroups too for rule E3057

* Add one more test
  • Loading branch information
kddejong authored Aug 16, 2024
1 parent efe911f commit 68ac3a6
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ def validate(
break
origin_ids.append(origin_id)
else:
yield ValidationError(
message=f"{cache_origin_id!r} is not one of {origin_ids!r}",
rule=self,
path_override=cache_validator.context.path.path,
validator="enum",
)
for origin_id, _ in get_value_from_path(
cache_validator,
instance,
path=deque(["OriginGroups", "Items", "*", "Id"]),
):
if origin_id is None:
continue
if not validator.is_type(origin_id, "string"):
break
if origin_id == cache_origin_id:
break
origin_ids.append(origin_id)
else:
yield ValidationError(
message=f"{cache_origin_id!r} is not one of {origin_ids!r}",
rule=self,
path_override=cache_validator.context.path.path,
validator="enum",
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def rule():
},
[
ValidationError(
("'origin-id' is not one of " "['foo', 'bar']"),
("'origin-id' is not one of ['foo', 'bar']"),
rule=DistributionTargetOriginId(),
path=deque([]),
validator="enum",
Expand Down Expand Up @@ -117,6 +117,95 @@ def rule():
},
[],
),
(
{
"DefaultCacheBehavior": {
"TargetOriginId": "origin-id",
},
"Origins": [
{
"Id": "foo",
},
{
"Id": "bar",
},
],
"OriginGroups": {
"Items": [
{
"Id": "group-1",
},
{
"Id": "group-2",
},
]
},
},
[
ValidationError(
(
"'origin-id' is not one of "
"['foo', 'bar', 'group-1', 'group-2']"
),
rule=DistributionTargetOriginId(),
path=deque([]),
validator="enum",
path_override=deque(["DefaultCacheBehavior", "TargetOriginId"]),
)
],
),
(
{
"DefaultCacheBehavior": {
"TargetOriginId": "origin-id",
},
"Origins": [
{
"Id": "foo",
},
{
"Id": "bar",
},
],
"OriginGroups": {
"Items": [
{
"Id": "group-1",
},
{
"Id": "origin-id",
},
]
},
},
[],
),
(
{
"DefaultCacheBehavior": {
"TargetOriginId": "origin-id",
},
"Origins": [
{
"Id": "foo",
},
{
"Id": "bar",
},
],
"OriginGroups": {
"Items": [
{
"Id": "group-1",
},
{
"Id": {"Ref": "MyParameter"},
},
]
},
},
[],
),
],
)
def test_validate(instance, expected, rule, validator):
Expand Down

0 comments on commit 68ac3a6

Please sign in to comment.