Path: blob/develop/tests/unit/customizations/test_s3errormsg.py
1567 views
# Copyright 2014 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.0e7#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 copy1314from awscli.testutils import unittest15from awscli.customizations import s3errormsg161718class TestGetRegionFromEndpoint(unittest.TestCase):1920def test_sigv4_error_message(self):21parsed = {22'Error': {23'Message': 'Please use AWS4-HMAC-SHA256'24}25}26s3errormsg.enhance_error_msg(parsed)27# We should say how to fix the issue.28self.assertIn('You can fix this issue',29parsed['Error']['Message'])30# We should mention the --region argument.31self.assertIn('--region', parsed['Error']['Message'])32# We should mention get-bucket-location33self.assertIn('get-bucket-location', parsed['Error']['Message'])3435def test_301_error_message(self):36parsed = {37'Error': {38'Code': 'PermanentRedirect',39'Message': "Please use the correct endpoint.",40'Endpoint': "myendpoint",41}42}43s3errormsg.enhance_error_msg(parsed)44# We should include the endpoint in the error message.45error_message = parsed['Error']['Message']46self.assertIn('myendpoint', error_message)4748def test_kms_sigv4_error_message(self):49parsed = {50'Error': {51'Message': (52'Requests specifying Server Side Encryption with '53'AWS KMS managed keys require AWS Signature Version 4.')54}55}56s3errormsg.enhance_error_msg(parsed)57# We should say how you enable it.58self.assertIn('You can enable AWS Signature Version 4',59parsed['Error']['Message'])60# We should mention the command that needs to be run.61self.assertIn(62'aws configure set s3.signature_version s3v4',63parsed['Error']['Message'])6465def test_error_message_not_enhanced(self):66parsed = {67'Error': {68'Message': 'This is a different error message.',69'Code': 'Other Message'70}71}72expected = copy.deepcopy(parsed)73s3errormsg.enhance_error_msg(parsed)74# Nothing should have changed75self.assertEqual(parsed, expected)7677def test_not_an_error_message(self):78parsed = {79'Success': 'response',80'ResponseMetadata': {}81}82expected = copy.deepcopy(parsed)83s3errormsg.enhance_error_msg(parsed)84# Nothing should have changed85self.assertEqual(parsed, expected)868788