| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2020-10-27 00:41:01 -07:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | from boto.exception import EC2ResponseError | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | from moto import mock_ec2, mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | def test_create_vpn_connections(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     vpn_connection = conn.create_vpn_connection( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "ipsec.1", "vgw-0123abcd", "cgw-0123abcd" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  |     vpn_connection.should_not.be.none | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpn_connection.id.should.match(r"vpn-\w+") | 
					
						
							|  |  |  |     vpn_connection.type.should.equal("ipsec.1") | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | def test_delete_vpn_connections(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     vpn_connection = conn.create_vpn_connection( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "ipsec.1", "vgw-0123abcd", "cgw-0123abcd" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections() | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(1) | 
					
						
							|  |  |  |     conn.delete_vpn_connection(vpn_connection.id) | 
					
						
							|  |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections() | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | def test_delete_vpn_connections_bad_id(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.delete_vpn_connection("vpn-0123abcd") | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  | def test_describe_vpn_connections(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections() | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_vpn_connection("ipsec.1", "vgw-0123abcd", "cgw-0123abcd") | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections() | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vpn = conn.create_vpn_connection("ipsec.1", "vgw-1234abcd", "cgw-1234abcd") | 
					
						
							| 
									
										
										
										
											2015-12-03 13:19:10 +02:00
										 |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections() | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(2) | 
					
						
							|  |  |  |     list_of_vpn_connections = conn.get_all_vpn_connections(vpn.id) | 
					
						
							|  |  |  |     list_of_vpn_connections.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2020-10-27 00:41:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_create_vpn_connection_with_vpn_gateway(): | 
					
						
							|  |  |  |     client = boto3.client("ec2", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vpn_gateway = client.create_vpn_gateway(Type="ipsec.1").get("VpnGateway", {}) | 
					
						
							|  |  |  |     customer_gateway = client.create_customer_gateway( | 
					
						
							| 
									
										
										
										
											2020-11-11 15:55:37 +00:00
										 |  |  |         Type="ipsec.1", PublicIp="205.251.242.54", BgpAsn=65534, | 
					
						
							| 
									
										
										
										
											2020-10-27 00:41:01 -07:00
										 |  |  |     ).get("CustomerGateway", {}) | 
					
						
							|  |  |  |     vpn_connection = client.create_vpn_connection( | 
					
						
							|  |  |  |         Type="ipsec.1", | 
					
						
							|  |  |  |         VpnGatewayId=vpn_gateway["VpnGatewayId"], | 
					
						
							|  |  |  |         CustomerGatewayId=customer_gateway["CustomerGatewayId"], | 
					
						
							|  |  |  |     ).get("VpnConnection", {}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vpn_connection["Type"].should.equal("ipsec.1") | 
					
						
							|  |  |  |     vpn_connection["VpnGatewayId"].should.equal(vpn_gateway["VpnGatewayId"]) | 
					
						
							|  |  |  |     vpn_connection["CustomerGatewayId"].should.equal( | 
					
						
							|  |  |  |         customer_gateway["CustomerGatewayId"] | 
					
						
							|  |  |  |     ) |