diff --git a/moto/elb/models.py b/moto/elb/models.py index 36f6eef2a..6a6bc6f6f 100644 --- a/moto/elb/models.py +++ b/moto/elb/models.py @@ -91,11 +91,10 @@ class ELBBackend(BaseBackend): if balancer: for lb_port in ports: for listener in balancer.listeners: - if lb_port == listener.load_balancer_port: + if int(lb_port) == int(listener.load_balancer_port): continue else: listeners.append(listener) - balancer.listeners = listeners return balancer diff --git a/moto/elb/responses.py b/moto/elb/responses.py index 1c3e1f0d5..8f92a9142 100644 --- a/moto/elb/responses.py +++ b/moto/elb/responses.py @@ -65,9 +65,13 @@ class ELBResponse(BaseResponse): port_index = 1 while True: try: - ports.append(self.querystring['Listeners.member.{0}.LoadBalancerPort'.format(port_index)][0]) + port = self.querystring['LoadBalancerPorts.member.{0}'.format(port_index)][0] except KeyError: break + + port_index += 1 + ports.append(int(port)) + elb_backend.delete_load_balancer_listeners(load_balancer_name, ports) template = Template(DELETE_LOAD_BALANCER_LISTENERS) return template.render() diff --git a/tests/test_elb/test_elb.py b/tests/test_elb/test_elb.py index cd4e449e1..4e74701da 100644 --- a/tests/test_elb/test_elb.py +++ b/tests/test_elb/test_elb.py @@ -27,6 +27,60 @@ def test_create_load_balancer(): listener2.protocol.should.equal("TCP") +@mock_elb +def test_add_listener(): + conn = boto.connect_elb() + zones = ['us-east-1a', 'us-east-1b'] + ports = [(80, 8080, 'http')] + conn.create_load_balancer('my-lb', zones, ports) + new_listener = (443, 8443, 'tcp') + conn.create_load_balancer_listeners('my-lb', [new_listener]) + balancers = conn.get_all_load_balancers() + balancer = balancers[0] + listener1 = balancer.listeners[0] + listener1.load_balancer_port.should.equal(80) + listener1.instance_port.should.equal(8080) + listener1.protocol.should.equal("HTTP") + listener2 = balancer.listeners[1] + listener2.load_balancer_port.should.equal(443) + listener2.instance_port.should.equal(8443) + listener2.protocol.should.equal("TCP") + + +@mock_elb +def test_delete_listener(): + conn = boto.connect_elb() + + zones = ['us-east-1a', 'us-east-1b'] + ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] + conn.create_load_balancer('my-lb', zones, ports) + conn.delete_load_balancer_listeners('my-lb', [443]) + balancers = conn.get_all_load_balancers() + balancer = balancers[0] + listener1 = balancer.listeners[0] + listener1.load_balancer_port.should.equal(80) + listener1.instance_port.should.equal(8080) + listener1.protocol.should.equal("HTTP") + balancer.listeners.should.have.length_of(1) + + +@mock_elb +def test_set_sslcertificate(): + conn = boto.connect_elb() + + zones = ['us-east-1a', 'us-east-1b'] + ports = [(443, 8443, 'tcp')] + conn.create_load_balancer('my-lb', zones, ports) + conn.set_lb_listener_SSL_certificate('my-lb', '443', 'arn:certificate') + balancers = conn.get_all_load_balancers() + balancer = balancers[0] + listener1 = balancer.listeners[0] + listener1.load_balancer_port.should.equal(443) + listener1.instance_port.should.equal(8443) + listener1.protocol.should.equal("TCP") + listener1.ssl_certificate_id.should.equal("arn:certificate") + + @mock_elb def test_get_load_balancers_by_name(): conn = boto.connect_elb() diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index 73d548e64..2cbb0ba57 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -5,6 +5,39 @@ import sure # noqa from moto import mock_iam +@mock_iam() +def test_get_all_server_certs(): + conn = boto.connect_iam() + + conn = boto.connect_iam() + conn.upload_server_cert("certname", "certbody", "privatekey") + certs = conn.get_all_server_certs()['list_server_certificates_response']['list_server_certificates_result']['server_certificate_metadata_list'] + certs.should.have.length_of(1) + cert1 = certs[0] + cert1.server_certificate_name.should.equal("certname") + cert1.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") + + +@mock_iam() +def test_get_server_cert(): + conn = boto.connect_iam() + + conn.upload_server_cert("certname", "certbody", "privatekey") + cert = conn.get_server_certificate("certname") + cert.server_certificate_name.should.equal("certname") + cert.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") + + +@mock_iam() +def test_upload_server_cert(): + conn = boto.connect_iam() + + conn.upload_server_cert("certname", "certbody", "privatekey") + cert = conn.get_server_certificate("certname") + cert.server_certificate_name.should.equal("certname") + cert.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") + + @mock_iam() def test_create_role_and_instance_profile(): conn = boto.connect_iam()