Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
30f8487a5c
15
moto/sts/exceptions.py
Normal file
15
moto/sts/exceptions.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
from moto.core.exceptions import RESTError
|
||||||
|
|
||||||
|
|
||||||
|
class STSClientError(RESTError):
|
||||||
|
code = 400
|
||||||
|
|
||||||
|
|
||||||
|
class STSValidationError(STSClientError):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(STSValidationError, self).__init__(
|
||||||
|
"ValidationError",
|
||||||
|
*args, **kwargs
|
||||||
|
)
|
@ -1,8 +1,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
|
from .exceptions import STSValidationError
|
||||||
from .models import sts_backend
|
from .models import sts_backend
|
||||||
|
|
||||||
|
MAX_FEDERATION_TOKEN_POLICY_LENGTH = 2048
|
||||||
|
|
||||||
|
|
||||||
class TokenResponse(BaseResponse):
|
class TokenResponse(BaseResponse):
|
||||||
|
|
||||||
@ -15,6 +18,15 @@ class TokenResponse(BaseResponse):
|
|||||||
def get_federation_token(self):
|
def get_federation_token(self):
|
||||||
duration = int(self.querystring.get('DurationSeconds', [43200])[0])
|
duration = int(self.querystring.get('DurationSeconds', [43200])[0])
|
||||||
policy = self.querystring.get('Policy', [None])[0]
|
policy = self.querystring.get('Policy', [None])[0]
|
||||||
|
|
||||||
|
if policy is not None and len(policy) > MAX_FEDERATION_TOKEN_POLICY_LENGTH:
|
||||||
|
raise STSValidationError(
|
||||||
|
"1 validation error detected: Value "
|
||||||
|
"'{\"Version\": \"2012-10-17\", \"Statement\": [...]}' "
|
||||||
|
"at 'policy' failed to satisfy constraint: Member must have length less than or "
|
||||||
|
" equal to %s" % MAX_FEDERATION_TOKEN_POLICY_LENGTH
|
||||||
|
)
|
||||||
|
|
||||||
name = self.querystring.get('Name')[0]
|
name = self.querystring.get('Name')[0]
|
||||||
token = sts_backend.get_federation_token(
|
token = sts_backend.get_federation_token(
|
||||||
duration=duration, name=name, policy=policy)
|
duration=duration, name=name, policy=policy)
|
||||||
|
@ -1683,7 +1683,7 @@ def test_boto3_multipart_part_size():
|
|||||||
parts = []
|
parts = []
|
||||||
n_parts = 10
|
n_parts = 10
|
||||||
for i in range(1, n_parts + 1):
|
for i in range(1, n_parts + 1):
|
||||||
part_size = 5 * 1024 * 1024
|
part_size = REDUCED_PART_SIZE + i
|
||||||
body = b'1' * part_size
|
body = b'1' * part_size
|
||||||
part = s3.upload_part(
|
part = s3.upload_part(
|
||||||
Bucket='mybucket',
|
Bucket='mybucket',
|
||||||
@ -1704,7 +1704,7 @@ def test_boto3_multipart_part_size():
|
|||||||
|
|
||||||
for i in range(1, n_parts + 1):
|
for i in range(1, n_parts + 1):
|
||||||
obj = s3.head_object(Bucket='mybucket', Key='the-key', PartNumber=i)
|
obj = s3.head_object(Bucket='mybucket', Key='the-key', PartNumber=i)
|
||||||
assert obj["ContentLength"] == part_size
|
assert obj["ContentLength"] == REDUCED_PART_SIZE + i
|
||||||
|
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
|
@ -3,10 +3,13 @@ import json
|
|||||||
|
|
||||||
import boto
|
import boto
|
||||||
import boto3
|
import boto3
|
||||||
|
from botocore.client import ClientError
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
from nose.tools import assert_raises
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
from moto import mock_sts, mock_sts_deprecated
|
from moto import mock_sts, mock_sts_deprecated
|
||||||
|
from moto.sts.responses import MAX_FEDERATION_TOKEN_POLICY_LENGTH
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2012-01-01 12:00:00")
|
@freeze_time("2012-01-01 12:00:00")
|
||||||
@ -117,3 +120,32 @@ def test_get_caller_identity():
|
|||||||
identity['Arn'].should.equal('arn:aws:sts::123456789012:user/moto')
|
identity['Arn'].should.equal('arn:aws:sts::123456789012:user/moto')
|
||||||
identity['UserId'].should.equal('AKIAIOSFODNN7EXAMPLE')
|
identity['UserId'].should.equal('AKIAIOSFODNN7EXAMPLE')
|
||||||
identity['Account'].should.equal('123456789012')
|
identity['Account'].should.equal('123456789012')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sts
|
||||||
|
def test_federation_token_with_too_long_policy():
|
||||||
|
"Trying to get a federation token with a policy longer than 2048 character should fail"
|
||||||
|
cli = boto3.client("sts", region_name='us-east-1')
|
||||||
|
resource_tmpl = 'arn:aws:s3:::yyyy-xxxxx-cloud-default/my_default_folder/folder-name-%s/*'
|
||||||
|
statements = []
|
||||||
|
for num in range(30):
|
||||||
|
statements.append(
|
||||||
|
{
|
||||||
|
'Effect': 'Allow',
|
||||||
|
'Action': ['s3:*'],
|
||||||
|
'Resource': resource_tmpl % str(num)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
policy = {
|
||||||
|
'Version': '2012-10-17',
|
||||||
|
'Statement': statements
|
||||||
|
}
|
||||||
|
json_policy = json.dumps(policy)
|
||||||
|
assert len(json_policy) > MAX_FEDERATION_TOKEN_POLICY_LENGTH
|
||||||
|
|
||||||
|
with assert_raises(ClientError) as exc:
|
||||||
|
cli.get_federation_token(Name='foo', DurationSeconds=3600, Policy=json_policy)
|
||||||
|
exc.exception.response['Error']['Code'].should.equal('ValidationError')
|
||||||
|
exc.exception.response['Error']['Message'].should.contain(
|
||||||
|
str(MAX_FEDERATION_TOKEN_POLICY_LENGTH)
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user