| 
									
										
										
										
											2018-04-03 13:38:24 -07:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2021-11-05 14:17:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-03 13:38:24 -07:00
										 |  |  | import moto.server as server | 
					
						
							|  |  |  | from moto import mock_cognitoidentity | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | """
 | 
					
						
							| 
									
										
										
										
											2018-04-03 13:38:24 -07:00
										 |  |  | Test the different server responses | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | """
 | 
					
						
							| 
									
										
										
										
											2018-04-03 13:38:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cognitoidentity | 
					
						
							|  |  |  | def test_create_identity_pool(): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     backend = server.create_backend_app("cognito-identity") | 
					
						
							|  |  |  |     test_client = backend.test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							|  |  |  |         data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True}, | 
					
						
							|  |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-04-03 13:38:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     assert json_data["IdentityPoolName"] == "test" | 
					
						
							| 
									
										
										
										
											2018-04-03 16:27:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cognitoidentity | 
					
						
							|  |  |  | def test_get_id(): | 
					
						
							|  |  |  |     backend = server.create_backend_app("cognito-identity") | 
					
						
							|  |  |  |     test_client = backend.test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 14:17:30 +01:00
										 |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							|  |  |  |         data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True}, | 
					
						
							|  |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							|  |  |  |         data=json.dumps( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "AccountId": "someaccount", | 
					
						
							| 
									
										
										
										
											2021-11-05 14:17:30 +01:00
										 |  |  |                 "IdentityPoolId": json_data["IdentityPoolId"], | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Logins": {"someurl": "12345"}, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-04-03 16:27:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     assert ":" in json_data["IdentityId"] | 
					
						
							| 
									
										
										
										
											2021-11-05 14:17:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cognitoidentity | 
					
						
							|  |  |  | def test_list_identities(): | 
					
						
							|  |  |  |     backend = server.create_backend_app("cognito-identity") | 
					
						
							|  |  |  |     test_client = backend.test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							|  |  |  |         data={"IdentityPoolName": "test", "AllowUnauthenticatedIdentities": True}, | 
					
						
							|  |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.CreateIdentityPool" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							|  |  |  |     identity_pool_id = json_data["IdentityPoolId"] | 
					
						
							|  |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							|  |  |  |         data=json.dumps( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "AccountId": "someaccount", | 
					
						
							|  |  |  |                 "IdentityPoolId": identity_pool_id, | 
					
						
							|  |  |  |                 "Logins": {"someurl": "12345"}, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							|  |  |  |     identity_id = json_data["IdentityId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     res = test_client.post( | 
					
						
							|  |  |  |         "/", | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         data=json.dumps({"IdentityPoolId": identity_pool_id}), | 
					
						
							| 
									
										
										
										
											2021-11-05 14:17:30 +01:00
										 |  |  |         headers={ | 
					
						
							|  |  |  |             "X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.ListIdentities" | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     json_data = json.loads(res.data.decode("utf-8")) | 
					
						
							|  |  |  |     assert "IdentityPoolId" in json_data and "Identities" in json_data | 
					
						
							|  |  |  |     assert identity_id in [x["IdentityId"] for x in json_data["Identities"]] |