Path: blob/develop/tests/functional/iam/test_create_virtual_mfa_device.py
1567 views
#!/usr/bin/env python1# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from awscli.testutils import BaseAWSCommandParamsTest14import os151617class TestCreateVirtualMFADevice(BaseAWSCommandParamsTest):1819prefix = 'iam create-virtual-mfa-device'2021def setUp(self):22super(TestCreateVirtualMFADevice, self).setUp()23self.parsed_response = {24'ResponseMetadata': {25'HTTPStatusCode': 200,26'RequestId': 'requset-id'27},28"VirtualMFADevice": {29"Base32StringSeed": (30"VFpYTVc2V1lIUFlFRFczSVhLUlpRUTJRVFdUSFRNRDNTQ0c3"31"TkZDUVdQWDVETlNWM0IyUENaQVpWTEpQTlBOTA=="),32"SerialNumber": "arn:aws:iam::419278470775:mfa/fiebaz",33"QRCodePNG": (34"iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAIAAAAHjs1qAAAFi"35"ElEQVR42u3bQW7jMBAEwPz/07vHvS0QeLpnZFVf7cgyWRTgJv"36"PzR+Q1+TEEgrsI7iK4i+AugrsI7iK4i+AugrsI7iK4C+4iuIv"37"gLoK7CO4iuIvgLoK7CO4iBe4/rfz/c391k7lLffK5v/r6tZu8"38"Ofu444477rjjjjvuuOOOO+6xwcoZ/WTl5D53cNXlZqG2VPpXx"39"h133HHHHXfccccdd9xxD09/rU7ZylZdVnvo5BY/7rjjjjvuuO"40"OOO+64447713H/RFIOZW0944477rjjjjvuuOOOO+64417ZVM8"41"ZPbLHXiOLO+6444477rjjjjvuuOP+fO5bC2lwMeQKoiN/ew0l"42"7rjjjjvuuOOOO+644457uCLYGmivHuxeBmcfd6/ijrtXccfdq"43"7jj7lXcH5han3Bkeedana9SgTvuuOOOO+6444477ri/hXttc7"44"umMLc2tm5ycI4GnzJfWETijjvuuOOOO+6444477s9oZnKDlZv"45"vGp2tnf/BNx8/NYA77rjjjjvuuOOOO+64v5V7rZkZHKzalXOw"46"cg3J1qorFGK444477rjjjjvuuOOO+1u5fwLrSG9T6zEGxyr3F"47"WqPwkeemcEdd9xxxx133HHHHXfcj3Kv4chNUo17rU7ZmtDjax"48"J33HHHHXfccccdd9xxfw33rWYm12McOY/wBQupZgN33HHHHXf"49"ccccdd9xxx/2DwTpy0Pzm2sh9oyOgc+sZd9xxxx133HHHHXfc"50"ccc9liOVSE3SkYIot2KPFES444477rjjjjvuuOOO+/u4DzYzg"51"xoGpyH35q3R2Nrb758awB133HHHHXfccccdd9zfyj23NmpX3j"52"omkBuc3N7+4DIr+MYdd9xxxx133HHHHXfc38q91gkcUZi7jcG"53"d/9xIHnkG4Y477rjjjjvuuOOOO+6430gOR20hbVUTW4cIrg0O"54"7rjjjjvuuOOOO+644/4a7keKi8G+6At273Nv3vpc3HHHHXfcc"55"ccdd9xxxx332LjXyocanUfgqJ0pqNU4uOOOO+6444477rjjjj"56"vuS13E1l53jc5Ndjf144477rjjjjvuuOOOO+64x77Skf352mZ"57"+7VhEbo62DiBE6jvccccdd9xxxx133HHHHffs9A8WNbnprz0a"58"tv7rYPDrP/IQAe6444477rjjjjvuuON+lPvguK//ci+TrS3Rw"59"Z7q5nMEd9xxxx133HHHHXfccce9VSDkippcY5A7nrBVaxyp2n"60"DHHXfccccdd9xxxx133FuTVFs5tUttlVq5pZJ7cCy0arjjjjv"61"uuOOOO+6444477tmd8K0SIDdnNXZHirj+YwV33HHHHXfccccd"62"d9xxfw33mu+bHUiObK4By7E7jgF33HHHHXfccccdd9xxfw33W"63"hcx+Kt/a1Zyn5tbZltkcccdd9xxxx133HHHHXfcb4DOnRp4Yg"64"eSQ/l9jRDuuOOOO+6444477rjjjntM4WCBMGhlcHByt1GrcbZ"65"OSeCOO+6444477rjjjjvuuD8htUMENcFbN1mrcXIfhDvuuOOO"66"O+6444477rjjvvSrP3cbg3NWG7pcMTV4OuPtRSTuuOOOO+644"67"4477rjjfoV7rXvZWjlbVr6+5CkUNbjjjjvuuOOOO+6444477q"68"sacn+7VeMcaYRyVdsjDxHgjjvuuOOOO+6444477rinNNR6myf"69"exlbXpJnBHXfccccdd9xxxx133J/PvbAFPT5nN4upLQy44447"70"7rjjjjvuuOOOO+4t7rWx27pybY/9iLMjvQ3uuOOOO+6444477"71"rjjjvvSfB/Zr86t58H53qpxBpdoYZxxxx133HHHHXfccccd99"72"dwF3lKcBfcRXAXwV0EdxHcRXAXwV0EdxHcRXAXwV1wF8FdBHc"73"R3EVwF8FdBHcR3EVwF8Fd5F/+AgASajf850wfAAAAAElFTkSu"74"QmCC"75),76}77}7879def getpath(self, filename):80return os.path.join(os.path.abspath(os.path.dirname(__file__)),81filename)8283def remove_file_if_exists(self, filename):84if os.path.isfile(filename):85os.remove(filename)8687def test_base32(self):88outfile = self.getpath('fiebaz.b32')89self.addCleanup(self.remove_file_if_exists, outfile)90cmdline = self.prefix91cmdline += ' --virtual-mfa-device-name fiebaz'92cmdline += (93' --outfile %s --bootstrap-method Base32StringSeed' % outfile)94result = {"VirtualMFADeviceName": 'fiebaz'}95self.assert_params_for_cmd(cmdline, result)96self.assertTrue(os.path.exists(outfile))9798def test_qrcode(self):99outfile = self.getpath('fiebaz.png')100self.addCleanup(self.remove_file_if_exists, outfile)101cmdline = self.prefix102cmdline += ' --virtual-mfa-device-name fiebaz'103cmdline += ' --outfile %s --bootstrap-method QRCodePNG' % outfile104result = {"VirtualMFADeviceName": 'fiebaz'}105self.assert_params_for_cmd(cmdline, result)106self.assertTrue(os.path.exists(outfile))107108def test_bad_filename(self):109outfile = '/some/bad/filename.png'110self.addCleanup(self.remove_file_if_exists, outfile)111cmdline = self.prefix112cmdline += ' --virtual-mfa-device-name fiebaz'113cmdline += ' --outfile %s --bootstrap-method QRCodePNG' % outfile114self.assert_params_for_cmd(cmdline, expected_rc=255)115116def test_relative_filename(self):117outfile = 'filename.png'118self.addCleanup(self.remove_file_if_exists, outfile)119cmdline = self.prefix120cmdline += ' --virtual-mfa-device-name fiebaz'121cmdline += ' --outfile %s --bootstrap-method QRCodePNG' % outfile122result = {"VirtualMFADeviceName": 'fiebaz'}123self.assert_params_for_cmd(cmdline, result)124self.assertTrue(os.path.exists(outfile))125126def test_bad_relative_filename(self):127outfile = 'some/bad/filename.png'128self.addCleanup(self.remove_file_if_exists, outfile)129cmdline = self.prefix130cmdline += ' --virtual-mfa-device-name fiebaz'131cmdline += ' --outfile %s --bootstrap-method QRCodePNG' % outfile132self.assert_params_for_cmd(cmdline, expected_rc=255)133134def test_bad_response(self):135# This can happen if you run the create-virtual-mfa-device136# command multiple times with the same name. You'll get137# an "already exists" error and we should handle that case138# gracefully.139self.parsed_response = {140'Error': {141'Code': 'EntityAlreadyExists',142'Message': 'MFADevice entity at the and name already exists.',143'Type': 'Sender',144},145'ResponseMetadata': {146'HTTPStatusCode': 409,147'RequestId': 'requset-id'}148}149self.http_response.status_code = 409150cmdline = self.prefix151cmdline += ' --virtual-mfa-device-name fiebaz'152cmdline += ' --outfile foo --bootstrap-method QRCodePNG'153# The error message should be in the stderr.154self.assert_params_for_cmd(155cmdline,156stderr_contains=self.parsed_response['Error']['Message'],157expected_rc=255)158159160