Path: blob/develop/tests/integration/customizations/history/test_show.py
1567 views
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import os13import re1415from awscli.testutils import aws, unittest, FileCreator161718class TestShow(unittest.TestCase):19def setUp(self):20self.files = FileCreator()21self.environ = os.environ.copy()22self.environ['AWS_CONFIG_FILE'] = self.files.create_file(23'config', (24'[default]\n'25'cli_history = enabled'26)27)28self.environ['AWS_DEFAULT_PROFILE'] = 'default'29self.environ['AWS_DEFAULT_REGION'] = 'us-west-2'30self.environ['AWS_STS_REGIONAL_ENDPOINTS'] = 'regional'31self.environ['AWS_CLI_HISTORY_FILE'] = os.path.join(32self.files.rootdir, 'history.db')3334def tearDown(self):35self.files.remove_all()3637def remove_color(self, output):38return re.compile(r'\x1b[^m]*m').sub('', output)3940def assert_contains_in_order(self, lines, contents):41current_pos = 042prev_line = None43for line in lines:44self.assertIn(line, contents)45new_pos = contents.find(line)46if new_pos < current_pos:47self.fail('Line: "%s" should have came after line: "%s"' % (48line, prev_line))49prev_line = line50current_pos = new_pos5152def test_show(self):53# Make a call that does not require credentials just in case the54# user was using the config file to provide credentials.55cmd = 'sts assume-role-with-saml '56cmd += '--role-arn arn:aws:iam::...:invalid '57cmd += '--principal-arn arn:aws:iam::...:invalid '58cmd += '--saml-assertion fake-assertion'59aws(cmd, env_vars=self.environ)60# Now run the show command and make sure the general output is all61# there.62result = aws('history show', env_vars=self.environ)63uncolored_content = self.remove_color(result.stdout)6465self.assert_contains_in_order(66[67'AWS CLI command entered',68'with AWS CLI version: aws-cli/',69"with arguments: [",70"'sts', ",71"'assume-role-with-saml',",72'[0] API call made',73'to service: sts',74'using operation: AssumeRoleWithSAML',75'with parameters: {',76' "PrincipalArn": "arn:aws:iam::...:invalid",',77' "RoleArn": "arn:aws:iam::...:invalid",',78' "SAMLAssertion": "fake-assertion"',79'[0] HTTP request sent',80'to URL: https://sts.us-west-2.amazonaws.com/',81'with method: POST',82'with body: ',83'Action=AssumeRoleWithSAML',84'Version=2011-06-15',85'[0] HTTP response received',86'with status code: 400',87'with body: <?xml version="1.0" ?>',88'[0] HTTP response parsed',89'parsed to: {',90' "Error": {',91'AWS CLI command exited',92'with return code: 255'93],94uncolored_content95)969798