Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/test_s3errormsg.py
1567 views
1
# Copyright 2014 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.0e
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 copy
14
15
from awscli.testutils import unittest
16
from awscli.customizations import s3errormsg
17
18
19
class TestGetRegionFromEndpoint(unittest.TestCase):
20
21
def test_sigv4_error_message(self):
22
parsed = {
23
'Error': {
24
'Message': 'Please use AWS4-HMAC-SHA256'
25
}
26
}
27
s3errormsg.enhance_error_msg(parsed)
28
# We should say how to fix the issue.
29
self.assertIn('You can fix this issue',
30
parsed['Error']['Message'])
31
# We should mention the --region argument.
32
self.assertIn('--region', parsed['Error']['Message'])
33
# We should mention get-bucket-location
34
self.assertIn('get-bucket-location', parsed['Error']['Message'])
35
36
def test_301_error_message(self):
37
parsed = {
38
'Error': {
39
'Code': 'PermanentRedirect',
40
'Message': "Please use the correct endpoint.",
41
'Endpoint': "myendpoint",
42
}
43
}
44
s3errormsg.enhance_error_msg(parsed)
45
# We should include the endpoint in the error message.
46
error_message = parsed['Error']['Message']
47
self.assertIn('myendpoint', error_message)
48
49
def test_kms_sigv4_error_message(self):
50
parsed = {
51
'Error': {
52
'Message': (
53
'Requests specifying Server Side Encryption with '
54
'AWS KMS managed keys require AWS Signature Version 4.')
55
}
56
}
57
s3errormsg.enhance_error_msg(parsed)
58
# We should say how you enable it.
59
self.assertIn('You can enable AWS Signature Version 4',
60
parsed['Error']['Message'])
61
# We should mention the command that needs to be run.
62
self.assertIn(
63
'aws configure set s3.signature_version s3v4',
64
parsed['Error']['Message'])
65
66
def test_error_message_not_enhanced(self):
67
parsed = {
68
'Error': {
69
'Message': 'This is a different error message.',
70
'Code': 'Other Message'
71
}
72
}
73
expected = copy.deepcopy(parsed)
74
s3errormsg.enhance_error_msg(parsed)
75
# Nothing should have changed
76
self.assertEqual(parsed, expected)
77
78
def test_not_an_error_message(self):
79
parsed = {
80
'Success': 'response',
81
'ResponseMetadata': {}
82
}
83
expected = copy.deepcopy(parsed)
84
s3errormsg.enhance_error_msg(parsed)
85
# Nothing should have changed
86
self.assertEqual(parsed, expected)
87
88