| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2014-10-15 13:43:38 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  | import requests | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | from moto import mock_ec2, settings | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if settings.TEST_SERVER_MODE: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     BASE_URL = "http://localhost:5000" | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     BASE_URL = "http://169.254.169.254" | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_latest_meta_data(): | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     res = requests.get("{0}/latest/meta-data/".format(BASE_URL)) | 
					
						
							| 
									
										
										
										
											2014-08-26 13:25:50 -04:00
										 |  |  |     res.content.should.equal(b"iam") | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_meta_data_iam(): | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     res = requests.get("{0}/latest/meta-data/iam".format(BASE_URL)) | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  |     json_response = res.json() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     default_role = json_response["security-credentials"]["default-role"] | 
					
						
							|  |  |  |     default_role.should.contain("AccessKeyId") | 
					
						
							|  |  |  |     default_role.should.contain("SecretAccessKey") | 
					
						
							|  |  |  |     default_role.should.contain("Token") | 
					
						
							|  |  |  |     default_role.should.contain("Expiration") | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_meta_data_security_credentials(): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     res = requests.get( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "{0}/latest/meta-data/iam/security-credentials/".format(BASE_URL) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-08-26 13:25:50 -04:00
										 |  |  |     res.content.should.equal(b"default-role") | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_meta_data_default_role(): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     res = requests.get( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "{0}/latest/meta-data/iam/security-credentials/default-role".format(BASE_URL) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2013-07-08 19:40:24 -04:00
										 |  |  |     json_response = res.json() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     json_response.should.contain("AccessKeyId") | 
					
						
							|  |  |  |     json_response.should.contain("SecretAccessKey") | 
					
						
							|  |  |  |     json_response.should.contain("Token") | 
					
						
							|  |  |  |     json_response.should.contain("Expiration") |