Skip to content

Commit

Permalink
ELBV2 - Fix elbv2 modify_rule expects Conditions (#4677) (#4681)
Browse files Browse the repository at this point in the history
  • Loading branch information
hudelgado committed Dec 12, 2021
1 parent 2b37a60 commit 7b06d74
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moto/elbv2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def delete_listener(self):
def modify_rule(self):
rule_arn = self._get_param("RuleArn")
params = self._get_params()
conditions = params["Conditions"]
conditions = params.get("Conditions", [])
actions = params.get("Actions", [])
rules = self.elbv2_backend.modify_rule(
rule_arn=rule_arn, conditions=conditions, actions=actions
Expand Down
58 changes: 58 additions & 0 deletions tests/test_elbv2/test_elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,64 @@ def test_create_rule_priority_in_use():
err["Message"].should.equal("The specified priority is in use.")


@mock_elbv2
@mock_ec2
def test_modify_rule_conditions():
response, _, _, _, _, elbv2 = create_load_balancer()
load_balancer_arn = response.get("LoadBalancers")[0].get("LoadBalancerArn")

action = {
"Type": "redirect",
"RedirectConfig": {
"Protocol": "HTTPS",
"Port": "443",
"StatusCode": "HTTP_301",
},
}
condition = {
"Field": "path-pattern",
"PathPatternConfig": {"Values": [f"/sth*",]},
}

response = elbv2.create_listener(
LoadBalancerArn=load_balancer_arn,
Protocol="HTTP",
Port=80,
DefaultActions=[action],
)
http_listener_arn = response.get("Listeners")[0]["ListenerArn"]

response = elbv2.create_rule(
ListenerArn=http_listener_arn, Priority=100, Conditions=[], Actions=[],
)
rule = response["Rules"][0]

assert len(rule["Actions"]) == 0
assert len(rule["Conditions"]) == 0

response = elbv2.modify_rule(RuleArn=rule["RuleArn"], Actions=[action],)
rule = response["Rules"][0]

assert len(rule["Actions"]) == 1
assert len(rule["Conditions"]) == 0

response = elbv2.modify_rule(RuleArn=rule["RuleArn"], Conditions=[condition])
rule = response["Rules"][0]

assert len(rule["Actions"]) == 1
assert len(rule["Conditions"]) == 1

response = elbv2.modify_rule(
RuleArn=rule["RuleArn"],
Conditions=[condition, condition],
Actions=[action, action],
)
rule = response["Rules"][0]

assert len(rule["Actions"]) == 2
assert len(rule["Conditions"]) == 2


@mock_elbv2
@mock_ec2
def test_handle_listener_rules():
Expand Down

0 comments on commit 7b06d74

Please sign in to comment.