-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CloudTrail customization fix to use built-in session #496
Changes from 3 commits
488e5b3
e5abfb8
03d23c1
defa40f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,15 @@ | |
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
import botocore.session | ||
import io | ||
import os | ||
|
||
from awscli.clidriver import create_clidriver | ||
from awscli.customizations.cloudtrail import CloudTrailSubscribe | ||
from awscli.customizations.service import Service | ||
from mock import Mock | ||
from tests.unit.customizations.test_configure import FakeSession | ||
from mock import Mock, patch | ||
from tests.unit.test_clidriver import FakeSession | ||
from tests import unittest | ||
|
||
|
||
|
@@ -104,3 +107,40 @@ def test_sns_create(self): | |
def test_sns_create_already_exists(self): | ||
with self.assertRaises(Exception): | ||
self.subscribe.setup_new_topic('test2') | ||
|
||
|
||
class TestCloudTrailSessions(unittest.TestCase): | ||
def test_sessions(self): | ||
""" | ||
Make sure that the session passed to our custom command | ||
is the same session used when making service calls. | ||
""" | ||
# awscli/__init__.py injects AWS_DATA_PATH at import time | ||
# so that we can find cli.json. This might be fixed in the | ||
# future, but for now we just grab that value out of the real | ||
# os.environ so the patched os.environ has this data and | ||
# the CLI works. | ||
self.environ = { | ||
'AWS_DATA_PATH': os.environ['AWS_DATA_PATH'], | ||
'AWS_DEFAULT_REGION': 'us-east-1', | ||
'AWS_ACCESS_KEY_ID': 'access_key', | ||
'AWS_SECRET_ACCESS_KEY': 'secret_key', | ||
} | ||
self.environ_patch = patch('os.environ', self.environ) | ||
self.environ_patch.start() | ||
|
||
# Get a new session we will use to test | ||
driver = create_clidriver() | ||
|
||
def _mock_call(self, *args, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're shadowing the |
||
# Make sure every service uses the same session | ||
assert driver.session == self.iam.session | ||
assert driver.session == self.s3.session | ||
assert driver.session == self.sns.session | ||
assert driver.session == self.cloudtrail.session | ||
|
||
with patch.object(CloudTrailSubscribe, '_call', _mock_call): | ||
rc = driver.main('cloudtrail create-subscription --name test --s3-use-bucket test'.split()) | ||
# If any assert above fails, then rc will be set to a | ||
# non-zero value and this will cause the test to fail | ||
self.assertEqual(rc, None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this would have a difficult to debug error message, wouldn't it just say: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like duplicate code from
tests/unit/__init__.py
. Was there a reason we can't just use that code?