Path: blob/develop/tests/unit/customizations/eks/test_get_token.py
1569 views
# Copyright 2018 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 base6414import botocore15import json16from datetime import datetime1718from awscli.testutils import mock, unittest, capture_output19from awscli.customizations.eks.get_token import (20GetTokenCommand,21TokenGenerator22)232425class BaseTokenTest(unittest.TestCase):26def setUp(self):27self._session = botocore.session.get_session()28self._access_key = 'ABCDEFGHIJKLMNOPQRST'29self._secret_key = 'TSRQPONMLKJUHGFEDCBA'30self._region = 'us-west-2'31self._cluster_name = 'MyCluster'32self._session.set_credentials(self._access_key, self._secret_key)33self._sts_client = self._session.create_client('sts', self._region)343536class TestTokenGenerator(BaseTokenTest):37@mock.patch.object(TokenGenerator, '_get_presigned_url', return_value='aHR0cHM6Ly9zdHMuYW1hem9uYXdzLmNvbS8=')38def test_token_no_padding(self, mock_presigned_url):39generator = TokenGenerator(self._sts_client)40tok = generator.get_token(self._cluster_name)41self.assertTrue('=' not in tok)424344class TestGetTokenCommand(BaseTokenTest):45def test_get_expiration_time(self):46cmd = GetTokenCommand(self._session)47timestamp = cmd.get_expiration_time()48try:49datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')50except ValueError:51raise ValueError("Incorrect data format, should be %Y-%m-%dT%H:%M:%SZ")525354