Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/eks/test_get_token.py
1569 views
1
# Copyright 2018 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.0/
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
14
import base64
15
import botocore
16
import json
17
from datetime import datetime
18
19
from awscli.testutils import mock, unittest, capture_output
20
from awscli.customizations.eks.get_token import (
21
GetTokenCommand,
22
TokenGenerator
23
)
24
25
26
class BaseTokenTest(unittest.TestCase):
27
def setUp(self):
28
self._session = botocore.session.get_session()
29
self._access_key = 'ABCDEFGHIJKLMNOPQRST'
30
self._secret_key = 'TSRQPONMLKJUHGFEDCBA'
31
self._region = 'us-west-2'
32
self._cluster_name = 'MyCluster'
33
self._session.set_credentials(self._access_key, self._secret_key)
34
self._sts_client = self._session.create_client('sts', self._region)
35
36
37
class TestTokenGenerator(BaseTokenTest):
38
@mock.patch.object(TokenGenerator, '_get_presigned_url', return_value='aHR0cHM6Ly9zdHMuYW1hem9uYXdzLmNvbS8=')
39
def test_token_no_padding(self, mock_presigned_url):
40
generator = TokenGenerator(self._sts_client)
41
tok = generator.get_token(self._cluster_name)
42
self.assertTrue('=' not in tok)
43
44
45
class TestGetTokenCommand(BaseTokenTest):
46
def test_get_expiration_time(self):
47
cmd = GetTokenCommand(self._session)
48
timestamp = cmd.get_expiration_time()
49
try:
50
datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')
51
except ValueError:
52
raise ValueError("Incorrect data format, should be %Y-%m-%dT%H:%M:%SZ")
53
54