| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  | # Ensure 'pytest.raises' context manager support for Python 2.6 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2014-08-25 15:09:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | from boto.exception import EC2ResponseError | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | from moto import mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | from .helpers import rsa_check_private_key | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSA_PUBLIC_KEY_OPENSSH = b"""\
 | 
					
						
							|  |  |  | ssh-rsa \ | 
					
						
							|  |  |  | AAAAB3NzaC1yc2EAAAADAQABAAABAQDusXfgTE4eBP50NglSzCSEGnIL6+cr6m3H\ | 
					
						
							| 
									
										
										
										
											2020-09-10 13:50:26 +05:30
										 |  |  | 6cZANOQ+P1o/W4BdtcAL3sor4iGi7SOeJgo\\8kweyMQrhrt6HaKGgromRiz37LQx\ | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 4YIAcBi4Zd023mO/V7Rc2Chh18mWgLSmA6ng+j37ip6452zxtv0jHAz9pJolbKBp\ | 
					
						
							|  |  |  | JzbZlPN45ZCTk9ck0fSVHRl6VRSSPQcpqi65XpRf+35zNOCGCc1mAOOTmw59Q2a6\ | 
					
						
							|  |  |  | A3t8mL7r91aM5q6QOQm219lctFM8O7HRJnDgmhGpnjRwE1LyKktWTbgFZ4SNWU2X\ | 
					
						
							|  |  |  | qusUO07jKuSxzPumXBeU+JEtx0J1tqZwJlpGt2R+0qN7nKnPl2+hx \ | 
					
						
							|  |  |  | moto@github.com"""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSA_PUBLIC_KEY_RFC4716 = b"""\
 | 
					
						
							|  |  |  | ---- BEGIN SSH2 PUBLIC KEY ---- | 
					
						
							|  |  |  | AAAAB3NzaC1yc2EAAAADAQABAAABAQDusXfgTE4eBP50NglSzCSEGnIL6+cr6m3H6cZANO | 
					
						
							|  |  |  | Q+P1o/W4BdtcAL3sor4iGi7SOeJgo8kweyMQrhrt6HaKGgromRiz37LQx4YIAcBi4Zd023 | 
					
						
							|  |  |  | mO/V7Rc2Chh18mWgLSmA6ng+j37ip6452zxtv0jHAz9pJolbKBpJzbZlPN45ZCTk9ck0fS | 
					
						
							|  |  |  | VHRl6VRSSPQcpqi65XpRf+35zNOCGCc1mAOOTmw59Q2a6A3t8mL7r91aM5q6QOQm219lct | 
					
						
							|  |  |  | FM8O7HRJnDgmhGpnjRwE1LyKktWTbgFZ4SNWU2XqusUO07jKuSxzPumXBeU+JEtx0J1tqZ | 
					
						
							|  |  |  | wJlpGt2R+0qN7nKnPl2+hx | 
					
						
							|  |  |  | ---- END SSH2 PUBLIC KEY ---- | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSA_PUBLIC_KEY_FINGERPRINT = "6a:49:07:1c:7e:bd:d2:bd:96:25:fe:b5:74:83:ae:fd" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DSA_PUBLIC_KEY_OPENSSH = b"""ssh-dss \
 | 
					
						
							|  |  |  | AAAAB3NzaC1kc3MAAACBAJ0aXctVwbN6VB81gpo8R7DUk8zXRjZvrkg8Y8vEGt63gklpNJNsLXtEUXkl5D4c0nD2FZO1rJNqFoe\ | 
					
						
							|  |  |  | OQOCoGSfclHvt9w4yPl/lUEtb3Qtj1j80MInETHr19vaSunRk5R+M+8YH+LLcdYdz7MijuGey02mbi0H9K5nUIcuLMArVAAAAFQ\ | 
					
						
							|  |  |  | D0RDvsObRWBlnaW8645obZBM86jwAAAIBNZwf3B4krIzAwVfkMHLDSdAvs7lOWE7o8SJLzr9t4a9HhYp9SLbMzJ815KWfidEYV2\ | 
					
						
							|  |  |  | +s4ZaPCfcZ1GENFRbE8rixz5eMAjEUXEPMJkblDZTHzMsH96z2cOCQZ0vfOmgznsf18Uf725pqo9OqAioEsTJjX8jtI2qNPEBU0\ | 
					
						
							|  |  |  | uhMSZQAAAIBBMGhDu5CWPUlS2QG7vzmzw81XasmHE/s2YPDRbolkriwlunpgwZhCscoQP8HFHY+DLUVvUb+GZwBmFt4l1uHl03b\ | 
					
						
							|  |  |  | ffsm7UIHtCBYERr9Nx0u20ldfhkgB1lhaJb5o0ZJ3pmJ38KChfyHe5EUcqRdEFo89Mp72VI2Z6UHyL175RA== \ | 
					
						
							|  |  |  | moto@github.com"""
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 12:08:00 +02:00
										 |  |  | def test_key_pairs_empty(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-02-24 12:08:00 +02:00
										 |  |  |     assert len(conn.get_all_key_pairs()) == 0 | 
					
						
							| 
									
										
										
										
											2014-02-24 12:24:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | def test_key_pairs_invalid_id(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.get_all_key_pairs("foo") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidKeyPair.NotFound") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 12:24:46 +02:00
										 |  |  | def test_key_pairs_create(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.create_key_pair("foo", dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the CreateKeyPair operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp = conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     rsa_check_private_key(kp.material) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 13:20:47 +02:00
										 |  |  |     kps = conn.get_all_key_pairs() | 
					
						
							|  |  |  |     assert len(kps) == 1 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     assert kps[0].name == "foo" | 
					
						
							| 
									
										
										
										
											2014-02-24 13:20:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 13:20:47 +02:00
										 |  |  | def test_key_pairs_create_two(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp1 = conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     rsa_check_private_key(kp1.material) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp2 = conn.create_key_pair("bar") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     rsa_check_private_key(kp2.material) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert kp1.material != kp2.material | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 13:20:47 +02:00
										 |  |  |     kps = conn.get_all_key_pairs() | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     kps.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     assert {i.name for i in kps} == {"foo", "bar"} | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kps = conn.get_all_key_pairs("foo") | 
					
						
							| 
									
										
										
										
											2017-01-11 17:37:57 -08:00
										 |  |  |     kps.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kps[0].name.should.equal("foo") | 
					
						
							| 
									
										
										
										
											2014-02-24 13:06:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 13:06:53 +02:00
										 |  |  | def test_key_pairs_create_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							|  |  |  |     conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2014-02-24 13:20:47 +02:00
										 |  |  |     assert len(conn.get_all_key_pairs()) == 1 | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidKeyPair.Duplicate") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-02-24 13:34:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 13:34:39 +02:00
										 |  |  | def test_key_pairs_delete_no_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-02-24 13:34:39 +02:00
										 |  |  |     assert len(conn.get_all_key_pairs()) == 0 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     r = conn.delete_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2014-02-24 13:34:39 +02:00
										 |  |  |     r.should.be.ok | 
					
						
							| 
									
										
										
										
											2014-02-24 13:35:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-02-24 13:35:42 +02:00
										 |  |  | def test_key_pairs_delete_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							|  |  |  |     conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         r = conn.delete_key_pair("foo", dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the DeleteKeyPair operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     r = conn.delete_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2014-02-24 13:35:42 +02:00
										 |  |  |     r.should.be.ok | 
					
						
							|  |  |  |     assert len(conn.get_all_key_pairs()) == 0 | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  | def test_key_pairs_import(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.import_key_pair("foo", RSA_PUBLIC_KEY_OPENSSH, dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the ImportKeyPair operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp1 = conn.import_key_pair("foo", RSA_PUBLIC_KEY_OPENSSH) | 
					
						
							|  |  |  |     assert kp1.name == "foo" | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     assert kp1.fingerprint == RSA_PUBLIC_KEY_FINGERPRINT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp2 = conn.import_key_pair("foo2", RSA_PUBLIC_KEY_RFC4716) | 
					
						
							|  |  |  |     assert kp2.name == "foo2" | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     assert kp2.fingerprint == RSA_PUBLIC_KEY_FINGERPRINT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  |     kps = conn.get_all_key_pairs() | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  |     assert len(kps) == 2 | 
					
						
							|  |  |  |     assert kps[0].name == kp1.name | 
					
						
							|  |  |  |     assert kps[1].name == kp2.name | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  | def test_key_pairs_import_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							|  |  |  |     kp = conn.import_key_pair("foo", RSA_PUBLIC_KEY_OPENSSH) | 
					
						
							|  |  |  |     assert kp.name == "foo" | 
					
						
							| 
									
										
										
										
											2015-09-24 17:25:49 +02:00
										 |  |  |     assert len(conn.get_all_key_pairs()) == 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.create_key_pair("foo") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidKeyPair.Duplicate") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2017-09-14 14:59:13 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							|  |  |  | def test_key_pairs_invalid(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.import_key_pair("foo", b"") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("InvalidKeyPair.Format") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal("Key is not in valid OpenSSH public key format") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.import_key_pair("foo", b"garbage") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("InvalidKeyPair.Format") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal("Key is not in valid OpenSSH public key format") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         conn.import_key_pair("foo", DSA_PUBLIC_KEY_OPENSSH) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("InvalidKeyPair.Format") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal("Key is not in valid OpenSSH public key format") | 
					
						
							| 
									
										
										
										
											2019-05-25 07:17:52 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 14:59:13 +05:30
										 |  |  | @mock_ec2_deprecated | 
					
						
							|  |  |  | def test_key_pair_filters(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_ec2("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2017-09-14 14:59:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     _ = conn.create_key_pair("kpfltr1") | 
					
						
							|  |  |  |     kp2 = conn.create_key_pair("kpfltr2") | 
					
						
							|  |  |  |     kp3 = conn.create_key_pair("kpfltr3") | 
					
						
							| 
									
										
										
										
											2017-09-14 14:59:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp_by_name = conn.get_all_key_pairs(filters={"key-name": "kpfltr2"}) | 
					
						
							|  |  |  |     set([kp.name for kp in kp_by_name]).should.equal(set([kp2.name])) | 
					
						
							| 
									
										
										
										
											2017-09-14 14:59:13 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     kp_by_name = conn.get_all_key_pairs(filters={"fingerprint": kp3.fingerprint}) | 
					
						
							|  |  |  |     set([kp.name for kp in kp_by_name]).should.equal(set([kp3.name])) |