Fix condition filtering bug in elbv2.create_rule() (#3092)
* Fix condition filtering bug * Update test_handle_listener_rules unit test * Run black
This commit is contained in:
parent
80c53d8b5a
commit
73813460b6
@ -158,7 +158,7 @@ class ELBV2Response(BaseResponse):
|
|||||||
condition = {}
|
condition = {}
|
||||||
condition["field"] = _condition["field"]
|
condition["field"] = _condition["field"]
|
||||||
values = sorted(
|
values = sorted(
|
||||||
[e for e in _condition.items() if e[0].startswith("values.member")],
|
[e for e in _condition.items() if "values.member" in e[0]],
|
||||||
key=lambda x: x[0],
|
key=lambda x: x[0],
|
||||||
)
|
)
|
||||||
condition["values"] = [e[1] for e in values]
|
condition["values"] = [e[1] for e in values]
|
||||||
@ -356,7 +356,7 @@ class ELBV2Response(BaseResponse):
|
|||||||
condition = {}
|
condition = {}
|
||||||
condition["field"] = _condition["field"]
|
condition["field"] = _condition["field"]
|
||||||
values = sorted(
|
values = sorted(
|
||||||
[e for e in _condition.items() if e[0].startswith("values.member")],
|
[e for e in _condition.items() if "values.member" in e[0]],
|
||||||
key=lambda x: x[0],
|
key=lambda x: x[0],
|
||||||
)
|
)
|
||||||
condition["values"] = [e[1] for e in values]
|
condition["values"] = [e[1] for e in values]
|
||||||
|
@ -994,12 +994,17 @@ def test_handle_listener_rules():
|
|||||||
priority = 100
|
priority = 100
|
||||||
host = "xxx.example.com"
|
host = "xxx.example.com"
|
||||||
path_pattern = "foobar"
|
path_pattern = "foobar"
|
||||||
|
pathpatternconfig_pattern = "foobar2"
|
||||||
created_rule = conn.create_rule(
|
created_rule = conn.create_rule(
|
||||||
ListenerArn=http_listener_arn,
|
ListenerArn=http_listener_arn,
|
||||||
Priority=priority,
|
Priority=priority,
|
||||||
Conditions=[
|
Conditions=[
|
||||||
{"Field": "host-header", "Values": [host]},
|
{"Field": "host-header", "Values": [host]},
|
||||||
{"Field": "path-pattern", "Values": [path_pattern]},
|
{"Field": "path-pattern", "Values": [path_pattern]},
|
||||||
|
{
|
||||||
|
"Field": "path-pattern",
|
||||||
|
"PathPatternConfig": {"Values": [pathpatternconfig_pattern]},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
Actions=[
|
Actions=[
|
||||||
{"TargetGroupArn": target_group.get("TargetGroupArn"), "Type": "forward"}
|
{"TargetGroupArn": target_group.get("TargetGroupArn"), "Type": "forward"}
|
||||||
@ -1017,6 +1022,10 @@ def test_handle_listener_rules():
|
|||||||
Conditions=[
|
Conditions=[
|
||||||
{"Field": "host-header", "Values": [host]},
|
{"Field": "host-header", "Values": [host]},
|
||||||
{"Field": "path-pattern", "Values": [path_pattern]},
|
{"Field": "path-pattern", "Values": [path_pattern]},
|
||||||
|
{
|
||||||
|
"Field": "path-pattern",
|
||||||
|
"PathPatternConfig": {"Values": [pathpatternconfig_pattern]},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
Actions=[
|
Actions=[
|
||||||
{"TargetGroupArn": target_group.get("TargetGroupArn"), "Type": "forward"}
|
{"TargetGroupArn": target_group.get("TargetGroupArn"), "Type": "forward"}
|
||||||
@ -1031,6 +1040,10 @@ def test_handle_listener_rules():
|
|||||||
Conditions=[
|
Conditions=[
|
||||||
{"Field": "host-header", "Values": [host]},
|
{"Field": "host-header", "Values": [host]},
|
||||||
{"Field": "path-pattern", "Values": [path_pattern]},
|
{"Field": "path-pattern", "Values": [path_pattern]},
|
||||||
|
{
|
||||||
|
"Field": "path-pattern",
|
||||||
|
"PathPatternConfig": {"Values": [pathpatternconfig_pattern]},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
Actions=[
|
Actions=[
|
||||||
{
|
{
|
||||||
@ -1079,11 +1092,16 @@ def test_handle_listener_rules():
|
|||||||
# modify rule partially
|
# modify rule partially
|
||||||
new_host = "new.example.com"
|
new_host = "new.example.com"
|
||||||
new_path_pattern = "new_path"
|
new_path_pattern = "new_path"
|
||||||
|
new_pathpatternconfig_pattern = "new_path2"
|
||||||
modified_rule = conn.modify_rule(
|
modified_rule = conn.modify_rule(
|
||||||
RuleArn=first_rule["RuleArn"],
|
RuleArn=first_rule["RuleArn"],
|
||||||
Conditions=[
|
Conditions=[
|
||||||
{"Field": "host-header", "Values": [new_host]},
|
{"Field": "host-header", "Values": [new_host]},
|
||||||
{"Field": "path-pattern", "Values": [new_path_pattern]},
|
{"Field": "path-pattern", "Values": [new_path_pattern]},
|
||||||
|
{
|
||||||
|
"Field": "path-pattern",
|
||||||
|
"PathPatternConfig": {"Values": [new_pathpatternconfig_pattern]},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)["Rules"][0]
|
)["Rules"][0]
|
||||||
|
|
||||||
@ -1092,6 +1110,9 @@ def test_handle_listener_rules():
|
|||||||
modified_rule.should.equal(obtained_rule)
|
modified_rule.should.equal(obtained_rule)
|
||||||
obtained_rule["Conditions"][0]["Values"][0].should.equal(new_host)
|
obtained_rule["Conditions"][0]["Values"][0].should.equal(new_host)
|
||||||
obtained_rule["Conditions"][1]["Values"][0].should.equal(new_path_pattern)
|
obtained_rule["Conditions"][1]["Values"][0].should.equal(new_path_pattern)
|
||||||
|
obtained_rule["Conditions"][2]["Values"][0].should.equal(
|
||||||
|
new_pathpatternconfig_pattern
|
||||||
|
)
|
||||||
obtained_rule["Actions"][0]["TargetGroupArn"].should.equal(
|
obtained_rule["Actions"][0]["TargetGroupArn"].should.equal(
|
||||||
target_group.get("TargetGroupArn")
|
target_group.get("TargetGroupArn")
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user