-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from jkeifer/null-bucket-location
Handle us-east-1 null bucket location
- Loading branch information
Showing
6 changed files
with
135 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
import moto | ||
import boto3 | ||
import pytest | ||
|
||
if 'AWS_DEFAULT_REGION' not in os.environ: | ||
os.environ['AWS_DEFAULT_REGION'] = 'us-east-1' | ||
|
||
|
||
@pytest.fixture | ||
def aws_credentials(): | ||
"""Mocked AWS Credentials for moto.""" | ||
os.environ['AWS_ACCESS_KEY_ID'] = 'testing' | ||
os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing' | ||
os.environ['AWS_SECURITY_TOKEN'] = 'testing' | ||
os.environ['AWS_SESSION_TOKEN'] = 'testing' | ||
os.environ['AWS_DEFAULT_REGION'] = 'us-east-1' | ||
os.environ['AWS_REGION'] = 'us-east-1' | ||
|
||
|
||
@pytest.fixture | ||
def s3(aws_credentials): | ||
with moto.mock_s3(): | ||
yield boto3.client('s3', region_name='us-east-1') | ||
|
||
|
||
@pytest.fixture | ||
def s3_west(aws_credentials): | ||
with moto.mock_s3(): | ||
yield boto3.client('s3', region_name='us-west-2') | ||
|
||
|
||
@pytest.fixture | ||
def secretsmanager(aws_credentials): | ||
with moto.mock_secretsmanager(): | ||
yield boto3.client('secretsmanager', region_name='us-east-1') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
# this must be imported before any boto3 module | ||
from moto import mock_secretsmanager | ||
|
||
import os | ||
import boto3 | ||
import pytest | ||
import json | ||
import base64 | ||
|
||
from boto3utils import secrets | ||
from botocore.exceptions import ClientError | ||
|
||
testpath = os.path.dirname(__file__) | ||
|
||
SECRET_NAME = 'secret' | ||
SECRET = {'mock_key': 'mock_val'} | ||
SECRET_STRING = json.dumps(SECRET) | ||
SECRET_BINARY = base64.b64encode(SECRET_STRING.encode()) | ||
|
||
|
||
@mock_secretsmanager | ||
def test_get_secret_string(): | ||
boto3.session.Session().client('secretsmanager', | ||
region_name='us-west-2').create_secret( | ||
Name=SECRET_NAME, | ||
SecretString=SECRET_STRING) | ||
@pytest.fixture | ||
def secret(secretsmanager): | ||
secretsmanager.create_secret( | ||
Name=SECRET_NAME, | ||
SecretString=SECRET_STRING, | ||
) | ||
return secretsmanager | ||
|
||
|
||
@pytest.fixture | ||
def binary_secret(secretsmanager): | ||
secretsmanager.create_secret( | ||
Name=SECRET_NAME, | ||
SecretBinary=SECRET_BINARY, | ||
) | ||
return secretsmanager | ||
|
||
|
||
def test_get_secret_string(secret): | ||
secret = secrets.get_secret(SECRET_NAME) | ||
assert (secret == SECRET) | ||
|
||
|
||
@mock_secretsmanager | ||
def test_get_secret_undef(): | ||
def test_get_secret_undef(secretsmanager): | ||
with pytest.raises(ClientError): | ||
secrets.get_secret(SECRET_NAME) | ||
|
||
|
||
@mock_secretsmanager | ||
def test_get_secret_binary(): | ||
boto3.session.Session().client('secretsmanager', | ||
region_name='us-west-2').create_secret( | ||
Name=SECRET_NAME, | ||
SecretBinary=SECRET_BINARY) | ||
def test_get_secret_binary(binary_secret): | ||
secret = secrets.get_secret(SECRET_NAME) | ||
assert (secret == SECRET) | ||
# client.create_secret(Name=SECRET_NAME, SecretBinary=SECRET_BINARY) |