|
17 | 17 | import io
|
18 | 18 | import json
|
19 | 19 | import os
|
| 20 | +from pprint import pprint |
20 | 21 | import shutil
|
21 | 22 | import tempfile
|
22 | 23 | import unittest
|
@@ -485,6 +486,13 @@ class TestKubeConfigLoader(BaseTestCase):
|
485 | 486 | "user": "expired_oidc"
|
486 | 487 | }
|
487 | 488 | },
|
| 489 | + { |
| 490 | + "name": "expired_oidc_with_idp_ca_file", |
| 491 | + "context": { |
| 492 | + "cluster": "default", |
| 493 | + "user": "expired_oidc_with_idp_ca_file" |
| 494 | + } |
| 495 | + }, |
488 | 496 | {
|
489 | 497 | "name": "expired_oidc_nocert",
|
490 | 498 | "context": {
|
@@ -799,6 +807,23 @@ class TestKubeConfigLoader(BaseTestCase):
|
799 | 807 | }
|
800 | 808 | }
|
801 | 809 | },
|
| 810 | + { |
| 811 | + "name": "expired_oidc_with_idp_ca_file", |
| 812 | + "user": { |
| 813 | + "auth-provider": { |
| 814 | + "name": "oidc", |
| 815 | + "config": { |
| 816 | + "client-id": "tectonic-kubectl", |
| 817 | + "client-secret": "FAKE_SECRET", |
| 818 | + "id-token": TEST_OIDC_EXPIRED_LOGIN, |
| 819 | + "idp-certificate-authority": TEST_CERTIFICATE_AUTH, |
| 820 | + "idp-issuer-url": "https://example.org/identity", |
| 821 | + "refresh-token": |
| 822 | + "lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk" |
| 823 | + } |
| 824 | + } |
| 825 | + } |
| 826 | + }, |
802 | 827 | {
|
803 | 828 | "name": "expired_oidc_nocert",
|
804 | 829 | "user": {
|
@@ -1059,6 +1084,33 @@ def test_oidc_with_refresh(self, mock_ApiClient, mock_OAuth2Session):
|
1059 | 1084 | self.assertTrue(loader._load_auth_provider_token())
|
1060 | 1085 | self.assertEqual("Bearer abc123", loader.token)
|
1061 | 1086 |
|
| 1087 | + @mock.patch('kubernetes.config.kube_config.OAuth2Session.refresh_token') |
| 1088 | + @mock.patch('kubernetes.config.kube_config.ApiClient.request') |
| 1089 | + def test_oidc_with_idp_ca_file_refresh(self, mock_ApiClient, mock_OAuth2Session): |
| 1090 | + mock_response = mock.MagicMock() |
| 1091 | + type(mock_response).status = mock.PropertyMock( |
| 1092 | + return_value=200 |
| 1093 | + ) |
| 1094 | + type(mock_response).data = mock.PropertyMock( |
| 1095 | + return_value=json.dumps({ |
| 1096 | + "token_endpoint": "https://example.org/identity/token" |
| 1097 | + }) |
| 1098 | + ) |
| 1099 | + |
| 1100 | + mock_ApiClient.return_value = mock_response |
| 1101 | + |
| 1102 | + mock_OAuth2Session.return_value = {"id_token": "abc123", |
| 1103 | + "refresh_token": "newtoken123"} |
| 1104 | + |
| 1105 | + loader = KubeConfigLoader( |
| 1106 | + config_dict=self.TEST_KUBE_CONFIG, |
| 1107 | + active_context="expired_oidc_with_idp_ca_file", |
| 1108 | + ) |
| 1109 | + |
| 1110 | + |
| 1111 | + self.assertTrue(loader._load_auth_provider_token()) |
| 1112 | + self.assertEqual("Bearer abc123", loader.token) |
| 1113 | + |
1062 | 1114 | @mock.patch('kubernetes.config.kube_config.OAuth2Session.refresh_token')
|
1063 | 1115 | @mock.patch('kubernetes.config.kube_config.ApiClient.request')
|
1064 | 1116 | def test_oidc_with_refresh_nocert(
|
|
0 commit comments