Add support for AWS::ElasticLoadBalancingV2::ListenerRule (#3969)
* Add ssm parsing support for cloudformation stacks * Start adding unit tests for ssm parameter parsing * Add tests for code update * Add tests to parse ssm parameters code * Fix black lint errors * Fix bug. * Need to specify region_name * region needs to be same * Use ssm_backends[region] instead of ssm_backend * StringList -> string * Linting * check if servermode tests are on * Typo * Added support for ListenerRule. Will remove cruft * Pushing latest * Something works * Put back ripped out code * Save point. Incase I need more validations * Revert "Save point. Incase I need more validations" This reverts commit dac4953335dd9335eddb7a91a63667bc3c17104c. * Fixed validations and some refactor * Fix formatting * Linting * Cannot refactor if I have to fix all tests * Remove exceptions for now. Will do in another PR * Remove validations. Will add in next PR * Fix broken tests. Almost.: * Fix all tests. Some sneaky for now. * Python2 making me write bad code * OrderedDict.move_to_end() does not work in python2 * Linting * Add more checks to field in conditions later. * Unwnated change in FakeListener * Revert "Unwnated change in FakeListener" This reverts commit 962c2fdfd76fce999de9feccf1dd1c3ec48c459f. * Add back default listener rule * Linting fix * Fix priority sorting * Add cloudformation test for edge case Co-authored-by: Bert Blommers <bblommers@users.noreply.github.com>
This commit is contained in:
parent
a281f9d4a6
commit
b82096ba37
4 changed files with 295 additions and 121 deletions
|
|
@ -345,6 +345,7 @@ def test_create_target_group_and_listeners():
|
|||
response.get("TargetGroups").should.have.length_of(1)
|
||||
|
||||
# And another with SSL
|
||||
actions = {"Type": "forward", "TargetGroupArn": target_group.get("TargetGroupArn")}
|
||||
response = conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTPS",
|
||||
|
|
@ -356,9 +357,7 @@ def test_create_target_group_and_listeners():
|
|||
)
|
||||
}
|
||||
],
|
||||
DefaultActions=[
|
||||
{"Type": "forward", "TargetGroupArn": target_group.get("TargetGroupArn")}
|
||||
],
|
||||
DefaultActions=[actions],
|
||||
)
|
||||
listener = response.get("Listeners")[0]
|
||||
listener.get("Port").should.equal(443)
|
||||
|
|
@ -391,6 +390,12 @@ def test_create_target_group_and_listeners():
|
|||
)
|
||||
response.get("Listeners").should.have.length_of(2)
|
||||
|
||||
listener_response = conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Conditions=[{"Field": "path-pattern", "Values": ["/*"]},],
|
||||
Priority=3,
|
||||
Actions=[actions],
|
||||
)
|
||||
# Try to delete the target group and it fails because there's a
|
||||
# listener referencing it
|
||||
with pytest.raises(ClientError) as e:
|
||||
|
|
@ -1011,11 +1016,12 @@ def test_handle_listener_rules():
|
|||
Actions=[
|
||||
{"TargetGroupArn": target_group.get("TargetGroupArn"), "Type": "forward"}
|
||||
],
|
||||
)["Rules"][0]
|
||||
created_rule["Priority"].should.equal("100")
|
||||
)
|
||||
rule = created_rule.get("Rules")[0]
|
||||
rule["Priority"].should.equal("100")
|
||||
|
||||
# check if rules is sorted by priority
|
||||
priority = 50
|
||||
priority = 500
|
||||
host = "yyy.example.com"
|
||||
path_pattern = "foobar"
|
||||
rules = conn.create_rule(
|
||||
|
|
@ -1059,7 +1065,7 @@ def test_handle_listener_rules():
|
|||
obtained_rules = conn.describe_rules(ListenerArn=http_listener_arn)
|
||||
len(obtained_rules["Rules"]).should.equal(3)
|
||||
priorities = [rule["Priority"] for rule in obtained_rules["Rules"]]
|
||||
priorities.should.equal(["50", "100", "default"])
|
||||
priorities.should.equal(["100", "500", "default"])
|
||||
|
||||
first_rule = obtained_rules["Rules"][0]
|
||||
second_rule = obtained_rules["Rules"][1]
|
||||
|
|
@ -1076,7 +1082,6 @@ def test_handle_listener_rules():
|
|||
ListenerArn=http_listener_arn, PageSize=1, Marker=next_marker
|
||||
)
|
||||
len(following_rules["Rules"]).should.equal(1)
|
||||
following_rules.should.have.key("NextMarker")
|
||||
following_rules["Rules"][0]["RuleArn"].should_not.equal(
|
||||
obtained_rules["Rules"][0]["RuleArn"]
|
||||
)
|
||||
|
|
@ -1105,11 +1110,10 @@ def test_handle_listener_rules():
|
|||
"PathPatternConfig": {"Values": [new_pathpatternconfig_pattern]},
|
||||
},
|
||||
],
|
||||
)["Rules"][0]
|
||||
)
|
||||
|
||||
rules = conn.describe_rules(ListenerArn=http_listener_arn)
|
||||
obtained_rule = rules["Rules"][0]
|
||||
modified_rule.should.equal(obtained_rule)
|
||||
obtained_rule["Conditions"][0]["Values"][0].should.equal(new_host)
|
||||
obtained_rule["Conditions"][1]["Values"][0].should.equal(new_path_pattern)
|
||||
obtained_rule["Conditions"][2]["Values"][0].should.equal(
|
||||
|
|
@ -1696,20 +1700,20 @@ def test_redirect_action_listener_rule():
|
|||
|
||||
load_balancer_arn = response.get("LoadBalancers")[0].get("LoadBalancerArn")
|
||||
|
||||
action = {
|
||||
"Type": "redirect",
|
||||
"RedirectConfig": {
|
||||
"Protocol": "HTTPS",
|
||||
"Port": "443",
|
||||
"StatusCode": "HTTP_301",
|
||||
},
|
||||
}
|
||||
|
||||
response = conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTP",
|
||||
Port=80,
|
||||
DefaultActions=[
|
||||
{
|
||||
"Type": "redirect",
|
||||
"RedirectConfig": {
|
||||
"Protocol": "HTTPS",
|
||||
"Port": "443",
|
||||
"StatusCode": "HTTP_301",
|
||||
},
|
||||
}
|
||||
],
|
||||
DefaultActions=[action],
|
||||
)
|
||||
|
||||
listener = response.get("Listeners")[0]
|
||||
|
|
@ -1726,6 +1730,12 @@ def test_redirect_action_listener_rule():
|
|||
listener.get("DefaultActions").should.equal(expected_default_actions)
|
||||
listener_arn = listener.get("ListenerArn")
|
||||
|
||||
listener_response = conn.create_rule(
|
||||
ListenerArn=listener_arn,
|
||||
Conditions=[{"Field": "path-pattern", "Values": ["/*"]},],
|
||||
Priority=3,
|
||||
Actions=[action],
|
||||
)
|
||||
describe_rules_response = conn.describe_rules(ListenerArn=listener_arn)
|
||||
describe_rules_response["Rules"][0]["Actions"].should.equal(
|
||||
expected_default_actions
|
||||
|
|
@ -1789,6 +1799,12 @@ def test_cognito_action_listener_rule():
|
|||
listener.get("DefaultActions")[0].should.equal(action)
|
||||
listener_arn = listener.get("ListenerArn")
|
||||
|
||||
listener_response = conn.create_rule(
|
||||
ListenerArn=listener_arn,
|
||||
Conditions=[{"Field": "path-pattern", "Values": ["/*"]},],
|
||||
Priority=3,
|
||||
Actions=[action],
|
||||
)
|
||||
describe_rules_response = conn.describe_rules(ListenerArn=listener_arn)
|
||||
describe_rules_response["Rules"][0]["Actions"][0].should.equal(action)
|
||||
|
||||
|
|
@ -1844,6 +1860,12 @@ def test_fixed_response_action_listener_rule():
|
|||
listener.get("DefaultActions")[0].should.equal(action)
|
||||
listener_arn = listener.get("ListenerArn")
|
||||
|
||||
listener_response = conn.create_rule(
|
||||
ListenerArn=listener_arn,
|
||||
Conditions=[{"Field": "path-pattern", "Values": ["/*"]},],
|
||||
Priority=3,
|
||||
Actions=[action],
|
||||
)
|
||||
describe_rules_response = conn.describe_rules(ListenerArn=listener_arn)
|
||||
describe_rules_response["Rules"][0]["Actions"][0].should.equal(action)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue