How to use the moto.mock_sts function in moto

To help you get started, we’ve selected a few moto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Scout24 / afp-core / src / unittest / python / api_endpoint_tests.py View on Github external
    @mock_sts
    @patch("aws_federation_proxy.aws_federation_proxy.requests.get")
    def test_get_credentials_and_consoleurl(self, mock_get):
        token = "abcdefg123"
        callbackurl = ""
        mock_get.return_value = Mock(text=u'{"SigninToken": "%s"}' % token,
                                     status_code=200,
                                     reason="Ok")
        url_template = (u"https://signin.aws.amazon.com/federation?"
                        u"Action=login&"
                        u"Issuer={callbackurl}&"
                        u"Destination=https%3A%2F%2Fconsole.aws.amazon.com%2F&"
                        u"SigninToken={token}")
        expected_url = url_template.format(callbackurl=callbackurl,
                                           token=token)
        expected_credentials = dict(CREDENTIALS)
        expected_credentials['ConsoleUrl'] = expected_url
github spulec / moto / tests / test_stepfunctions / test_stepfunctions.py View on Github external
@mock_sts
def test_state_machine_creation_can_be_described():
    client = boto3.client("stepfunctions", region_name=region)
    #
    sm = client.create_state_machine(
        name="name", definition=str(simple_definition), roleArn=_get_default_role()
    )
    desc = client.describe_state_machine(stateMachineArn=sm["stateMachineArn"])
    desc["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
    desc["creationDate"].should.equal(sm["creationDate"])
    desc["definition"].should.equal(str(simple_definition))
    desc["name"].should.equal("name")
    desc["roleArn"].should.equal(_get_default_role())
    desc["stateMachineArn"].should.equal(sm["stateMachineArn"])
    desc["status"].should.equal("ACTIVE")
github rackerlabs / ebs_snapper / tests / test_clean.py View on Github external
@mock_sts
def test_clean_tagged_snapshots_ignore_volume(mocker):
    """Test for method of the same name."""
    # default settings
    region = 'us-east-1'
    mocks.create_dynamodb(region)

    # create an instance and record the id
    instance_id = mocks.create_instances(region, count=1)[0]
    ctx = utils.MockContext()

    # setup the min # snaps for the instance
    config_data = {
        "match": {"instance-id": instance_id},
        "snapshot": {
            "retention": "6 days", "minimum": 0, "frequency": "13 hours"
        },
github rackerlabs / ebs_snapper / tests / test_utils.py View on Github external
@mock_sts
def test_get_regions_with_instances_or_snapshots():
    """Test for method of the same name."""
    client_uswest2 = boto3.client('ec2', region_name='us-west-2')

    # toss an instance in us-west-2
    client_uswest2.run_instances(ImageId='ami-123abc', MinCount=1, MaxCount=5)

    # be sure we get us-west-2 *only*
    assert ['us-west-2'] == utils.get_regions(
        must_contain_instances=True,
        must_contain_snapshots=False)

    # now say we don't filter by instances, be sure we get a lot of regions
    found_regions = utils.get_regions(
        must_contain_instances=False,
        must_contain_snapshots=False)
github Skyscanner / cfripper / tests / test_boto3_client.py View on Github external
def boto3_client():
    with mock_sts():
        yield Boto3Client("123456789", "eu-west-1", "stack-id")
github spulec / moto / tests / test_sts / test_sts.py View on Github external
@mock_sts
@mock_iam
def test_get_caller_identity_with_iam_user_credentials():
    iam_client = boto3.client("iam", region_name="us-east-1")
    iam_user_name = "new-user"
    iam_user = iam_client.create_user(UserName=iam_user_name)["User"]
    access_key = iam_client.create_access_key(UserName=iam_user_name)["AccessKey"]

    identity = boto3.client(
        "sts",
        region_name="us-east-1",
        aws_access_key_id=access_key["AccessKeyId"],
        aws_secret_access_key=access_key["SecretAccessKey"],
    ).get_caller_identity()

    identity["Arn"].should.equal(iam_user["Arn"])
    identity["UserId"].should.equal(iam_user["UserId"])
github spulec / moto / tests / test_stepfunctions / test_stepfunctions.py View on Github external
@mock_sts
def test_state_machine_start_execution_with_custom_name():
    client = boto3.client("stepfunctions", region_name=region)
    #
    sm = client.create_state_machine(
        name="name", definition=str(simple_definition), roleArn=_get_default_role()
    )
    execution = client.start_execution(
        stateMachineArn=sm["stateMachineArn"], name="execution_name"
    )
    #
    execution["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
    expected_exec_name = (
        "arn:aws:states:"
        + region
        + ":"
        + _get_account_id()
github spulec / moto / tests / test_core / test_auth.py View on Github external
@mock_sts
@mock_ec2
@mock_elbv2
def test_allowed_with_temporary_credentials():
    role_name = "test-role"
    trust_policy_document = {
        "Version": "2012-10-17",
        "Statement": {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::{account_id}:root".format(account_id=ACCOUNT_ID)
            },
            "Action": "sts:AssumeRole",
        },
    }
    attached_policy_document = {
        "Version": "2012-10-17",
github Yipit / awslimits / tests / unit / test_limits.py View on Github external
from unittest import TestCase
from mock import patch
import os

mock_env = {
    'ROLE_ARN': 'arn:aws:iam::212311232123:role/test',
    'SENDGRID_API_KEY': '1231231231231231231',
    'AWS_ACCESS_KEY_ID': 'awskey',
    'AWS_SECRET_ACCESS_KEY': 'awssecret',
}
with patch.dict(os.environ, mock_env):
    from awslimits.support import create_or_get_table


@moto.mock_dynamodb2
@moto.mock_sts
class TestDynamo(TestCase):
    def test_create_or_get_new_table(self):
        dynamodb = boto3.client('dynamodb', region_name="us-east-1")
        table_name = 'awslimits_limits'
        initial_table_list = dynamodb.list_tables()
        assert table_name not in initial_table_list["TableNames"]
        table = create_or_get_table(
            table_name='awslimits_limits',
            attribute_definitions=[
                {
                    'AttributeName': 'limit_name',
                    'AttributeType': 'S',
                },
            ],
            key_schema=[
                {
github rackerlabs / ebs_snapper / tests / test_snapshot.py View on Github external
@mock_ec2
@mock_dynamodb2
@mock_sns
@mock_iam
@mock_sts
def test_perform_snapshot_ignore_volume(mocker):
    """Test for method of the same name."""
    # some default settings for this test
    region = 'us-west-2'

    snapshot_settings = {
        'snapshot': {'minimum': 5, 'frequency': '2 hours', 'retention': '5 days'},
        'match': {'tag:backup': 'yes'},
        'ignore': []
    }

    # create an instance and record the id
    instance_id = mocks.create_instances(region, count=1)[0]

    # need to filter instances, so need dynamodb present
    mocks.create_dynamodb('us-east-1')