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