kubernetes.config.kube_config_test module¶
- class kubernetes.config.kube_config_test.BaseTestCase(methodName='runTest')¶
Bases:
TestCase- expect_exception(func, message_part, *args, **kwargs)¶
- setUp()¶
Hook method for setting up the test fixture before exercising it.
- tearDown()¶
Hook method for deconstructing the test fixture after testing it.
- class kubernetes.config.kube_config_test.FakeConfig(token=None, **kwargs)¶
Bases:
object- FILE_KEYS = ['ssl_ca_cert', 'key_file', 'cert_file']¶
- IGNORE_KEYS = ['refresh_api_key_hook']¶
- class kubernetes.config.kube_config_test.TestConfigNode(methodName='runTest')¶
Bases:
BaseTestCase- setUp()¶
Hook method for setting up the test fixture before exercising it.
- test_get_with_name()¶
- test_get_with_name_on_duplicate_name()¶
- test_get_with_name_on_invalid_object()¶
- test_get_with_name_on_name_does_not_exists()¶
- test_get_with_name_on_non_list_object()¶
- test_key_does_not_exists()¶
- test_normal_map_array_operations()¶
- test_obj = {'key1': 'test', 'key2': ['a', 'b', 'c'], 'key3': {'inner_key': 'inner_value'}, 'with_names': [{'name': 'test_name', 'value': 'test_value'}, {'name': 'test_name2', 'value': {'key1', 'test'}}, {'name': 'test_name3', 'value': [1, 2, 3]}], 'with_names_dup': [{'name': 'test_name', 'value': 'test_value'}, {'name': 'test_name', 'value': {'key1', 'test'}}, {'name': 'test_name3', 'value': [1, 2, 3]}]}¶
- class kubernetes.config.kube_config_test.TestFileOrData(methodName='runTest')¶
Bases:
BaseTestCase- static get_file_content(filename)¶
- test_create_temp_file_with_content()¶
- test_data_given_data()¶
- test_data_given_file()¶
- test_data_given_file_and_data()¶
- test_data_given_file_no_base64()¶
- test_file_given_data()¶
- test_file_given_data_bytes()¶
- test_file_given_data_bytes_no_base64()¶
- test_file_given_data_no_base64()¶
- test_file_given_file()¶
- test_file_given_file_and_data()¶
- test_file_given_no_object()¶
- test_file_given_no_object_data()¶
- test_file_given_non_existing_file()¶
- test_file_recreation()¶
- test_file_with_custom_dirname()¶
- class kubernetes.config.kube_config_test.TestKubeConfigLoader(methodName='runTest')¶
Bases:
BaseTestCase- TEST_KUBE_CONFIG = {'clusters': [{'cluster': {'server': 'test-host'}, 'name': 'default'}, {'cluster': {'certificate-authority': 'cert-auth', 'server': 'https://test-host'}, 'name': 'ssl-no_file'}, {'cluster': {'certificate-authority': 'cert_test', 'server': 'https://test-host'}, 'name': 'ssl-local-file'}, {'cluster': {'certificate-authority-data': 'Y2VydC1hdXRo', 'insecure-skip-tls-verify': False, 'server': 'https://test-host'}, 'name': 'ssl'}, {'cluster': {'insecure-skip-tls-verify': True, 'server': 'https://test-host'}, 'name': 'no_ssl_verification'}, {'cluster': {}, 'name': 'clustertestcmdpath'}, {'cluster': {'certificate-authority-data': 'Y2VydC1hdXRo', 'insecure-skip-tls-verify': False, 'server': 'https://test-host', 'tls-server-name': 'kubernetes.io'}, 'name': 'tls-server-name'}, {'cluster': {'proxy-url': 'http://proxy.example.com:3128', 'server': 'test-host'}, 'name': 'proxy_cluster'}], 'contexts': [{'context': {'cluster': 'default'}, 'name': 'no_user'}, {'context': {'cluster': 'default', 'user': 'simple_token'}, 'name': 'simple_token'}, {'context': {'cluster': 'default', 'user': 'gcp'}, 'name': 'gcp'}, {'context': {'cluster': 'default', 'user': 'expired_gcp'}, 'name': 'expired_gcp'}, {'context': {'cluster': 'default', 'user': 'expired_gcp_refresh'}, 'name': 'expired_gcp_refresh'}, {'context': {'cluster': 'default', 'user': 'oidc'}, 'name': 'oidc'}, {'context': {'cluster': 'default', 'user': 'expired_oidc'}, 'name': 'expired_oidc'}, {'context': {'cluster': 'default', 'user': 'expired_oidc_with_idp_ca_file'}, 'name': 'expired_oidc_with_idp_ca_file'}, {'context': {'cluster': 'default', 'user': 'expired_oidc_nocert'}, 'name': 'expired_oidc_nocert'}, {'context': {'cluster': 'default', 'user': 'oidc_contains_reserved_character'}, 'name': 'oidc_contains_reserved_character'}, {'context': {'cluster': 'default', 'user': 'oidc_invalid_padding_length'}, 'name': 'oidc_invalid_padding_length'}, {'context': {'cluster': 'default', 'user': 'user_pass'}, 'name': 'user_pass'}, {'context': {'cluster': 'ssl', 'user': 'ssl'}, 'name': 'ssl'}, {'context': {'cluster': 'no_ssl_verification', 'user': 'ssl'}, 'name': 'no_ssl_verification'}, {'context': {'cluster': 'ssl-no_file', 'user': 'ssl-no_file'}, 'name': 'ssl-no_file'}, {'context': {'cluster': 'ssl-local-file', 'user': 'ssl-local-file'}, 'name': 'ssl-local-file'}, {'context': {'cluster': 'default', 'user': 'non_existing_user'}, 'name': 'non_existing_user'}, {'context': {'cluster': 'default', 'user': 'exec_cred_user'}, 'name': 'exec_cred_user'}, {'context': {'cluster': 'ssl', 'user': 'exec_cred_user_certificate'}, 'name': 'exec_cred_user_certificate'}, {'context': {'cluster': 'clustertestcmdpath', 'user': 'usertestcmdpath'}, 'name': 'contexttestcmdpath'}, {'context': {'cluster': 'clustertestcmdpath', 'user': 'usertestcmdpathempty'}, 'name': 'contexttestcmdpathempty'}, {'context': {'cluster': 'clustertestcmdpath', 'user': 'usertestcmdpathscope'}, 'name': 'contexttestcmdpathscope'}, {'context': {'cluster': 'tls-server-name', 'user': 'ssl'}, 'name': 'tls-server-name'}, {'context': {'cluster': 'proxy_cluster', 'user': 'simple_token'}, 'name': 'proxy_cluster_context'}], 'current-context': 'no_user', 'users': [{'name': 'simple_token', 'user': {'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}, {'name': 'gcp', 'user': {'auth-provider': {'config': {'access-token': 'dGVzdC1kYXRh'}, 'name': 'gcp'}, 'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}, {'name': 'expired_gcp', 'user': {'auth-provider': {'config': {'access-token': 'dGVzdC1kYXRh', 'expiry': '2026-10-23T21:44:06Z'}, 'name': 'gcp'}, 'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}, {'name': 'expired_gcp_refresh', 'user': {'auth-provider': {'config': {'access-token': 'dGVzdC1kYXRh', 'expiry': '2026-10-23T21:44:06Z'}, 'name': 'gcp'}, 'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}, {'name': 'oidc', 'user': {'auth-provider': {'config': {'id-token': 'dGVzdC1vaWRjLXRva2Vu.eyJuYW1lIjogInRlc3QifQ.WTJ4cFpXNTBMV05sY25RPQ'}, 'name': 'oidc'}}}, {'name': 'expired_oidc', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.eyJuYW1lIjogInRlc3QiLCJleHAiOiA1MzY0NTc2MDB9.Y2xpZW50LWNlcnQ', 'idp-certificate-authority-data': 'Y2VydC1hdXRo', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'expired_oidc_with_idp_ca_file', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.eyJuYW1lIjogInRlc3QiLCJleHAiOiA1MzY0NTc2MDB9.Y2xpZW50LWNlcnQ', 'idp-certificate-authority': 'cert-auth', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'expired_oidc_nocert', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.eyJuYW1lIjogInRlc3QiLCJleHAiOiA1MzY0NTc2MDB9.Y2xpZW50LWNlcnQ', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'oidc_contains_reserved_character', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.eyJuYW1lIjogInRlc3QifQ.Y2xpZW50LWNlcnQ', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'oidc_invalid_padding_length', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.aaaaa.Y2xpZW50LWNlcnQ', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'user_pass', 'user': {'password': 'pass', 'username': 'me'}}, {'name': 'ssl-no_file', 'user': {'client-certificate': 'client-cert', 'client-key': 'client-key', 'token': 'dGVzdC1kYXRh'}}, {'name': 'ssl-local-file', 'user': {'client-certificate': 'client_cert', 'client-key': 'client_key', 'tokenFile': 'token_file'}}, {'name': 'ssl', 'user': {'client-certificate-data': 'Y2xpZW50LWNlcnQ=', 'client-key-data': 'Y2xpZW50LWtleQ==', 'token': 'dGVzdC1kYXRh'}}, {'name': 'exec_cred_user', 'user': {'exec': {'apiVersion': 'client.authentication.k8s.io/v1beta1', 'args': ['token', '-i', 'dummy-cluster'], 'command': 'aws-iam-authenticator'}}}, {'name': 'exec_cred_user_certificate', 'user': {'exec': {'apiVersion': 'client.authentication.k8s.io/v1beta1', 'args': [], 'command': 'custom-certificate-authenticator'}}}, {'name': 'usertestcmdpath', 'user': {'auth-provider': {'config': {'cmd-path': 'cmdtorun'}, 'name': 'gcp'}}}, {'name': 'usertestcmdpathempty', 'user': {'auth-provider': {'config': {'cmd-path': ''}, 'name': 'gcp'}}}, {'name': 'usertestcmdpathscope', 'user': {'auth-provider': {'config': {'cmd-path': 'cmd', 'scopes': 'scope'}, 'name': 'gcp'}}}]}¶
- test__get_kube_config_loader_dict_no_persist()¶
- test__get_kube_config_loader_file_no_persist()¶
- test__get_kube_config_loader_file_persist()¶
- test__get_kube_config_loader_for_yaml_file_no_persist()¶
- test__get_kube_config_loader_for_yaml_file_persist()¶
- test_current_context()¶
- test_gcp_no_refresh()¶
- test_gcp_refresh_api_key_hook()¶
- test_list_contexts()¶
- test_list_kube_config_contexts()¶
- test_load_gcp_token_no_refresh()¶
- test_load_gcp_token_with_refresh()¶
- test_load_kube_config_from_dict()¶
- test_load_kube_config_from_dict_with_temp_file_path()¶
- test_load_kube_config_from_empty_file()¶
- test_load_kube_config_from_empty_file_like_object()¶
- test_load_kube_config_from_file_like_object()¶
- test_load_kube_config_from_file_path()¶
- test_load_user_pass_token()¶
- test_load_user_token()¶
- test_new_client_from_config()¶
- test_new_client_from_config_dict()¶
- test_new_client_from_config_proxy()¶
- test_no_user_context()¶
- test_no_users_section()¶
- test_non_existing_user()¶
- test_oidc_fails_if_contains_reserved_chars()¶
- test_oidc_fails_if_invalid_padding_length()¶
- test_oidc_no_refresh()¶
- test_oidc_with_idp_ca_file_refresh(mock_ApiClient, mock_OAuth2Session)¶
- test_oidc_with_refresh(mock_ApiClient, mock_OAuth2Session)¶
- test_oidc_with_refresh_nocert(mock_ApiClient, mock_OAuth2Session)¶
- test_proxy_url_from_cluster()¶
- test_set_active_context()¶
- test_simple_token()¶
- test_ssl()¶
- test_ssl_no_cert_files()¶
- test_ssl_no_verification()¶
- test_ssl_with_relative_ssl_files()¶
- test_tls_server_name()¶
- test_user_cmd_path()¶
- test_user_cmd_path_empty()¶
- test_user_cmd_path_with_scope()¶
- test_user_exec_auth(mock)¶
- test_user_exec_auth_certificates(mock)¶
- test_user_exec_auth_with_expiry(mock)¶
- test_user_exec_cwd(mock)¶
- test_user_pass()¶
- class kubernetes.config.kube_config_test.TestKubeConfigMerger(methodName='runTest')¶
Bases:
BaseTestCase- TEST_KUBE_CONFIG_SET1 = [{'clusters': [{'cluster': {'server': 'test-host'}, 'name': 'default'}], 'contexts': [{'context': {'cluster': 'default'}, 'name': 'no_user'}], 'current-context': 'no_user', 'users': []}, {'clusters': [{'cluster': {'certificate-authority-data': 'Y2VydC1hdXRo', 'server': 'https://test-host'}, 'name': 'ssl'}], 'contexts': [{'context': {'cluster': 'ssl', 'user': 'ssl'}, 'name': 'ssl'}, {'context': {'cluster': 'default', 'user': 'simple_token'}, 'name': 'simple_token'}], 'current-context': '', 'users': [{'name': 'ssl', 'user': {'client-certificate-data': 'Y2xpZW50LWNlcnQ=', 'client-key-data': 'Y2xpZW50LWtleQ==', 'token': 'dGVzdC1kYXRh'}}]}, {'clusters': [], 'contexts': [{'context': {'cluster': 'default', 'user': 'expired_oidc'}, 'name': 'expired_oidc'}, {'context': {'cluster': 'skipped-part2-defined-this-context', 'user': 'skipped'}, 'name': 'ssl'}], 'current-context': 'no_user', 'users': [{'name': 'expired_oidc', 'user': {'auth-provider': {'config': {'client-id': 'tectonic-kubectl', 'client-secret': 'FAKE_SECRET', 'id-token': 'QmVhcmVyIGRHVnpkQzF2YVdSakxYUnZhMlZ1LmV5SnVZVzFsSWpvZ0luUmxjM1FpZlEuV1RKNGNGcFhOVEJNVjA1c1kyNVJQUQ.eyJuYW1lIjogInRlc3QiLCJleHAiOiA1MzY0NTc2MDB9.Y2xpZW50LWNlcnQ', 'idp-certificate-authority-data': 'Y2VydC1hdXRo', 'idp-issuer-url': 'https://example.org/identity', 'refresh-token': 'lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk'}, 'name': 'oidc'}}}, {'name': 'simple_token', 'user': {'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}]}, {'current-context': 'no_user'}, {'clusters': [{'cluster': {}, 'name': 'clustertestcmdpath'}], 'contexts': [{'context': {'cluster': 'clustertestcmdpath', 'user': 'usertestcmdpath'}, 'name': 'contexttestcmdpath'}], 'users': [{'name': 'usertestcmdpath', 'user': {'auth-provider': {'config': {'cmd-path': 'cmdtorun'}, 'name': 'gcp'}}}]}, {'clusters': [{'cluster': {'server': 'test-host'}, 'name': 'default'}], 'contexts': [{'context': {'cluster': 'default'}, 'name': 'no_user'}], 'current-context': 'no_user', 'users': None}]¶
- TEST_KUBE_CONFIG_SET2 = [{'clusters': [{'cluster': {'server': 'test-host'}, 'name': 'default'}]}, {'contexts': [{'context': {'cluster': 'default', 'user': 'simple_token'}, 'name': 'simple_token'}], 'current-context': 'simple_token'}, {'users': [{'name': 'simple_token', 'user': {'password': 'pass', 'token': 'dGVzdC1kYXRh', 'username': 'me'}}]}]¶
- test_list_kube_config_contexts()¶
- test_merge_with_context_in_different_file()¶
- test_new_client_from_config()¶
- test_save_changes()¶
- class kubernetes.config.kube_config_test.TestKubernetesClientConfiguration(methodName='runTest')¶
Bases:
BaseTestCase- test_get_api_key_calls_refresh_api_key_hook()¶
- test_refresh_api_key_hook_exists()¶