Run black on moto & test directories.
This commit is contained in:
parent
c820395dbf
commit
96e5b1993d
507 changed files with 52541 additions and 47814 deletions
|
|
@ -10,132 +10,136 @@ from moto.cognitoidentity.utils import get_random_identity_id
|
|||
|
||||
@mock_cognitoidentity
|
||||
def test_create_identity_pool():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
|
||||
result = conn.create_identity_pool(IdentityPoolName='TestPool',
|
||||
result = conn.create_identity_pool(
|
||||
IdentityPoolName="TestPool",
|
||||
AllowUnauthenticatedIdentities=False,
|
||||
SupportedLoginProviders={'graph.facebook.com': '123456789012345'},
|
||||
DeveloperProviderName='devname',
|
||||
OpenIdConnectProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'],
|
||||
SupportedLoginProviders={"graph.facebook.com": "123456789012345"},
|
||||
DeveloperProviderName="devname",
|
||||
OpenIdConnectProviderARNs=["arn:aws:rds:eu-west-2:123456789012:db:mysql-db"],
|
||||
CognitoIdentityProviders=[
|
||||
{
|
||||
'ProviderName': 'testprovider',
|
||||
'ClientId': 'CLIENT12345',
|
||||
'ServerSideTokenCheck': True
|
||||
},
|
||||
"ProviderName": "testprovider",
|
||||
"ClientId": "CLIENT12345",
|
||||
"ServerSideTokenCheck": True,
|
||||
}
|
||||
],
|
||||
SamlProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'])
|
||||
assert result['IdentityPoolId'] != ''
|
||||
SamlProviderARNs=["arn:aws:rds:eu-west-2:123456789012:db:mysql-db"],
|
||||
)
|
||||
assert result["IdentityPoolId"] != ""
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_describe_identity_pool():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
|
||||
res = conn.create_identity_pool(IdentityPoolName='TestPool',
|
||||
res = conn.create_identity_pool(
|
||||
IdentityPoolName="TestPool",
|
||||
AllowUnauthenticatedIdentities=False,
|
||||
SupportedLoginProviders={'graph.facebook.com': '123456789012345'},
|
||||
DeveloperProviderName='devname',
|
||||
OpenIdConnectProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'],
|
||||
SupportedLoginProviders={"graph.facebook.com": "123456789012345"},
|
||||
DeveloperProviderName="devname",
|
||||
OpenIdConnectProviderARNs=["arn:aws:rds:eu-west-2:123456789012:db:mysql-db"],
|
||||
CognitoIdentityProviders=[
|
||||
{
|
||||
'ProviderName': 'testprovider',
|
||||
'ClientId': 'CLIENT12345',
|
||||
'ServerSideTokenCheck': True
|
||||
},
|
||||
"ProviderName": "testprovider",
|
||||
"ClientId": "CLIENT12345",
|
||||
"ServerSideTokenCheck": True,
|
||||
}
|
||||
],
|
||||
SamlProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'])
|
||||
SamlProviderARNs=["arn:aws:rds:eu-west-2:123456789012:db:mysql-db"],
|
||||
)
|
||||
|
||||
result = conn.describe_identity_pool(IdentityPoolId=res['IdentityPoolId'])
|
||||
result = conn.describe_identity_pool(IdentityPoolId=res["IdentityPoolId"])
|
||||
|
||||
assert result['IdentityPoolId'] == res['IdentityPoolId']
|
||||
assert result['AllowUnauthenticatedIdentities'] == res['AllowUnauthenticatedIdentities']
|
||||
assert result['SupportedLoginProviders'] == res['SupportedLoginProviders']
|
||||
assert result['DeveloperProviderName'] == res['DeveloperProviderName']
|
||||
assert result['OpenIdConnectProviderARNs'] == res['OpenIdConnectProviderARNs']
|
||||
assert result['CognitoIdentityProviders'] == res['CognitoIdentityProviders']
|
||||
assert result['SamlProviderARNs'] == res['SamlProviderARNs']
|
||||
assert result["IdentityPoolId"] == res["IdentityPoolId"]
|
||||
assert (
|
||||
result["AllowUnauthenticatedIdentities"]
|
||||
== res["AllowUnauthenticatedIdentities"]
|
||||
)
|
||||
assert result["SupportedLoginProviders"] == res["SupportedLoginProviders"]
|
||||
assert result["DeveloperProviderName"] == res["DeveloperProviderName"]
|
||||
assert result["OpenIdConnectProviderARNs"] == res["OpenIdConnectProviderARNs"]
|
||||
assert result["CognitoIdentityProviders"] == res["CognitoIdentityProviders"]
|
||||
assert result["SamlProviderARNs"] == res["SamlProviderARNs"]
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_describe_identity_pool_with_invalid_id_raises_error():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
|
||||
with assert_raises(ClientError) as cm:
|
||||
conn.describe_identity_pool(IdentityPoolId='us-west-2_non-existent')
|
||||
conn.describe_identity_pool(IdentityPoolId="us-west-2_non-existent")
|
||||
|
||||
cm.exception.operation_name.should.equal('DescribeIdentityPool')
|
||||
cm.exception.response['Error']['Code'].should.equal('ResourceNotFoundException')
|
||||
cm.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
|
||||
cm.exception.operation_name.should.equal("DescribeIdentityPool")
|
||||
cm.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
cm.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
||||
|
||||
# testing a helper function
|
||||
def test_get_random_identity_id():
|
||||
assert len(get_random_identity_id('us-west-2')) > 0
|
||||
assert len(get_random_identity_id('us-west-2').split(':')[1]) == 19
|
||||
assert len(get_random_identity_id("us-west-2")) > 0
|
||||
assert len(get_random_identity_id("us-west-2").split(":")[1]) == 19
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_id():
|
||||
# These two do NOT work in server mode. They just don't return the data from the model.
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
result = conn.get_id(AccountId='someaccount',
|
||||
IdentityPoolId='us-west-2:12345',
|
||||
Logins={
|
||||
'someurl': '12345'
|
||||
})
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_id(
|
||||
AccountId="someaccount",
|
||||
IdentityPoolId="us-west-2:12345",
|
||||
Logins={"someurl": "12345"},
|
||||
)
|
||||
print(result)
|
||||
assert result.get('IdentityId', "").startswith('us-west-2') or result.get('ResponseMetadata').get(
|
||||
'HTTPStatusCode') == 200
|
||||
assert (
|
||||
result.get("IdentityId", "").startswith("us-west-2")
|
||||
or result.get("ResponseMetadata").get("HTTPStatusCode") == 200
|
||||
)
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_credentials_for_identity():
|
||||
# These two do NOT work in server mode. They just don't return the data from the model.
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
result = conn.get_credentials_for_identity(IdentityId='12345')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_credentials_for_identity(IdentityId="12345")
|
||||
|
||||
assert result.get('Expiration', 0) > 0 or result.get('ResponseMetadata').get('HTTPStatusCode') == 200
|
||||
assert result.get('IdentityId') == '12345' or result.get('ResponseMetadata').get('HTTPStatusCode') == 200
|
||||
assert (
|
||||
result.get("Expiration", 0) > 0
|
||||
or result.get("ResponseMetadata").get("HTTPStatusCode") == 200
|
||||
)
|
||||
assert (
|
||||
result.get("IdentityId") == "12345"
|
||||
or result.get("ResponseMetadata").get("HTTPStatusCode") == 200
|
||||
)
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_open_id_token_for_developer_identity():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_open_id_token_for_developer_identity(
|
||||
IdentityPoolId='us-west-2:12345',
|
||||
IdentityId='12345',
|
||||
Logins={
|
||||
'someurl': '12345'
|
||||
},
|
||||
TokenDuration=123
|
||||
IdentityPoolId="us-west-2:12345",
|
||||
IdentityId="12345",
|
||||
Logins={"someurl": "12345"},
|
||||
TokenDuration=123,
|
||||
)
|
||||
assert len(result['Token']) > 0
|
||||
assert result['IdentityId'] == '12345'
|
||||
assert len(result["Token"]) > 0
|
||||
assert result["IdentityId"] == "12345"
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_open_id_token_for_developer_identity_when_no_explicit_identity_id():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_open_id_token_for_developer_identity(
|
||||
IdentityPoolId='us-west-2:12345',
|
||||
Logins={
|
||||
'someurl': '12345'
|
||||
},
|
||||
TokenDuration=123
|
||||
IdentityPoolId="us-west-2:12345", Logins={"someurl": "12345"}, TokenDuration=123
|
||||
)
|
||||
assert len(result['Token']) > 0
|
||||
assert len(result['IdentityId']) > 0
|
||||
assert len(result["Token"]) > 0
|
||||
assert len(result["IdentityId"]) > 0
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_open_id_token():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
result = conn.get_open_id_token(
|
||||
IdentityId='12345',
|
||||
Logins={
|
||||
'someurl': '12345'
|
||||
}
|
||||
)
|
||||
assert len(result['Token']) > 0
|
||||
assert result['IdentityId'] == '12345'
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
result = conn.get_open_id_token(IdentityId="12345", Logins={"someurl": "12345"})
|
||||
assert len(result["Token"]) > 0
|
||||
assert result["IdentityId"] == "12345"
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import sure # noqa
|
|||
import moto.server as server
|
||||
from moto import mock_cognitoidentity
|
||||
|
||||
'''
|
||||
"""
|
||||
Test the different server responses
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
|
|
@ -17,14 +17,16 @@ def test_create_identity_pool():
|
|||
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"},
|
||||
)
|
||||
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"))
|
||||
assert json_data['IdentityPoolName'] == "test"
|
||||
assert json_data["IdentityPoolName"] == "test"
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
|
|
@ -32,14 +34,20 @@ def test_get_id():
|
|||
backend = server.create_backend_app("cognito-identity")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.post('/',
|
||||
data=json.dumps({'AccountId': 'someaccount',
|
||||
'IdentityPoolId': 'us-west-2:12345',
|
||||
'Logins': {'someurl': '12345'}}),
|
||||
headers={
|
||||
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId"},
|
||||
)
|
||||
res = test_client.post(
|
||||
"/",
|
||||
data=json.dumps(
|
||||
{
|
||||
"AccountId": "someaccount",
|
||||
"IdentityPoolId": "us-west-2:12345",
|
||||
"Logins": {"someurl": "12345"},
|
||||
}
|
||||
),
|
||||
headers={
|
||||
"X-Amz-Target": "com.amazonaws.cognito.identity.model.AWSCognitoIdentityService.GetId"
|
||||
},
|
||||
)
|
||||
|
||||
print(res.data)
|
||||
json_data = json.loads(res.data.decode("utf-8"))
|
||||
assert ':' in json_data['IdentityId']
|
||||
assert ":" in json_data["IdentityId"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue