Path: blob/develop/tests/integration/customizations/test_codecommit.py
1567 views
# Copyright 2015 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.1213import awscli14import os1516from datetime import datetime1718import awscli.compat19from awscli.compat import StringIO20from botocore.session import Session21from botocore.credentials import Credentials22from awscli.customizations.codecommit import CodeCommitGetCommand23from awscli.testutils import mock, unittest, StringIOWithFileNo24from botocore.awsrequest import AWSRequest25from awscli.clidriver import create_clidriver262728class TestCodeCommitCredentialHelper(unittest.TestCase):2930PROTOCOL_HOST_PATH = ('protocol=https\n'31'host=git-codecommit.us-east-1.amazonaws.com\n'32'path=/v1/repos/myrepo')3334FIPS_PROTOCOL_HOST_PATH = ('protocol=https\n'35'host=git-codecommit-fips.us-east-1.amazonaws.com\n'36'path=/v1/repos/myrepo')3738VPC_PROTOCOL_HOST_PATH = ('protocol=https\n'39'host=vpce-0b47ea360adebf88a-jkl88hez.git-codecommit.us-east-1.vpce.amazonaws.com\n'40'path=/v1/repos/myrepo')4142def setUp(self):43self.orig_id = os.environ.get('AWS_ACCESS_KEY_ID')44self.orig_key = os.environ.get('AWS_SECRET_ACCESS_KEY')45os.environ['AWS_ACCESS_KEY_ID'] = 'foo'46os.environ['AWS_SECRET_ACCESS_KEY'] = 'bar'4748def tearDown(self):49if self.orig_id:50os.environ['AWS_ACCESS_KEY_ID'] = self.orig_id51else:52del os.environ['AWS_ACCESS_KEY_ID']53if self.orig_key:54os.environ['AWS_SECRET_ACCESS_KEY'] = self.orig_key55else:56del os.environ['AWS_SECRET_ACCESS_KEY']5758@mock.patch('sys.stdin', StringIO(PROTOCOL_HOST_PATH))59@mock.patch('sys.stdout', new_callable=StringIOWithFileNo)60@mock.patch.object(awscli.compat.datetime, 'datetime', wraps=datetime)61def test_integration_using_cli_driver(self, dt_mock, stdout_mock):62dt_mock.now.return_value = datetime(2010, 10, 8)63driver = create_clidriver()64rc = driver.main('codecommit credential-helper get'.split())65output = stdout_mock.getvalue().strip()66self.assertEqual(67('username=foo\n'68'password=20101008T000000Z'69'7dc259e2d505af354a1219b9bcd784bd384dc706efa0d9aefc571f214be4c89c'),70output)71self.assertEqual(0, rc)7273@mock.patch('sys.stdin', StringIO(FIPS_PROTOCOL_HOST_PATH))74@mock.patch('sys.stdout', new_callable=StringIOWithFileNo)75@mock.patch.object(awscli.compat.datetime, 'datetime', wraps=datetime)76def test_integration_fips_using_cli_driver(self, dt_mock, stdout_mock):77dt_mock.now.return_value = datetime(2010, 10, 8)78driver = create_clidriver()79rc = driver.main('codecommit credential-helper get'.split())80output = stdout_mock.getvalue().strip()81self.assertEqual(82('username=foo\n'83'password=20101008T000000Z'84'500037cb3514b3fe01ebcda7c80973f5b4c0d8199a7a6563b85fd6edf272d460'),85output)86self.assertEqual(0, rc)8788@mock.patch('sys.stdin', StringIO(VPC_PROTOCOL_HOST_PATH))89@mock.patch('sys.stdout', new_callable=StringIOWithFileNo)90@mock.patch.object(awscli.compat.datetime, 'datetime', wraps=datetime)91def test_integration_vpc_using_cli_driver(self, dt_mock, stdout_mock):92dt_mock.now.return_value = datetime(2010, 10, 8)93driver = create_clidriver()94rc = driver.main('codecommit credential-helper get'.split())95output = stdout_mock.getvalue().strip()96self.assertEqual(97('username=foo\n'98'password=20101008T000000Z'99'9ed987cc6336c3de2d9f06b9236c7a9fd76b660b080db15983290e636dbfbd6b'),100output)101self.assertEqual(0, rc)102103104if __name__ == "__main__":105unittest.main()106107108