
    ZiS                         d dl Z d dlZd dlZd dlZd dlZd dlmZ ddlmZ ddl	m
Z
mZmZmZ dZdZdZd	Zd
ZdZdZdZe
eeeiZe
eeeiZ G d dej                  Zedk    r ej                     dS dS )    N)Configuration   )ConfigException)SERVICE_HOST_ENV_NAMESERVICE_PORT_ENV_NAMEInClusterConfigLoader_join_host_port
temp_tokentemp_new_token	temp_certz	127.0.0.180z127.0.0.1:80z::1z[::1]:80c                   x    e Zd Zd Zd ZddZddefdZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd ZdS )InClusterConfigTestc                     g | _         d S N)_temp_filesselfs    b/root/projects/butler/venv/lib/python3.11/site-packages/kubernetes/config/incluster_config_test.pysetUpzInClusterConfigTest.setUp/   s        c                 B    | j         D ]}t          j        |           d S r   )r   osremove)r   fs     r   tearDownzInClusterConfigTest.tearDown2   s-    ! 	 	AIaLLLL	 	r    c                     t          j                    \  }}| j                            |           t	          j        |t                              |                     t	          j        |           |S r   )	tempfilemkstempr   appendr   writestrencodeclose)r   contenthandlernames       r   _create_file_with_temp_contentz2InClusterConfigTest._create_file_with_temp_content6   s^     (**%%%
#**W--...
r   Nc                     |s|                      t                    }|s|                      t                    }t          ||d|          S )NT)token_filenamecert_filenametry_refresh_tokenenviron)r)   _TEST_TOKEN
_TEST_CERTr   )r   r+   r,   r.   s       r   get_test_loaderz#InClusterConfigTest.get_test_loader=   s^      	N!@@MMN 	L ??
KKM$N3@7;-46 6 6 	6r   c                     |                      t          t          t          t                               |                      t
          t          t          t                               d S r   )assertEqual_TEST_HOST_PORTr	   
_TEST_HOST
_TEST_PORT_TEST_IPV6_HOST_PORT_TEST_IPV6_HOSTr   s    r   test_join_host_portz'InClusterConfigTest.test_join_host_portJ   sc    (Z@@	B 	B 	B-(*EE	G 	G 	G 	G 	Gr   c                 P   |                      t                    }|                     |          }|                                 |                     dt
          z   |j                   |                     ||j                   |                     dt          z   |j	                   d S )Nr,   zhttps://bearer )
r)   r0   r1   _load_configr3   r4   hostssl_ca_certr/   token)r   r,   loaders      r   test_load_configz$InClusterConfigTest.test_load_configP   s    ;;JGG%%M%BBo5v{CCC(:;;;[0&,?????r   c                 0   |                                  }t                      }|                    |           |                     dt          z   |                    d                     |                     dt          z   |j                   |                     |j                   |j        }|j        }| 	                    t                    |_        |                     dt          z   |                    d                     t          j                                        |_        |                     dt          z   |                    d                     |                     dt          z   |j                   |                     |j        |           d S )Nr<   authorization)r1   r   load_and_setr3   r/   get_api_key_with_prefixr@   assertIsNotNonetoken_expires_atr)   _TEST_NEW_TOKEN_token_filenamedatetimenowassertGreater)r   rA   config	old_tokenold_token_expires_ats        r   test_refresh_tokenz&InClusterConfigTest.test_refresh_tokenX   s~   %%''F###[077HH	J 	J 	J[0&,???V4555L	%6!%!D!D" "[077HH	J 	J 	J #+"3"7"7"9"9_477HH	J 	J 	J_4flCCC624HIIIIIr   c                     	 |                                  |                     d|z             d S # t          $ r Y d S w xY w)NzShould fail because %s)rE   failr   )r   config_loaderreasons      r   _should_fail_loadz%InClusterConfigTest._should_fail_loado   sY    	&&(((II.788888 	 	 	DD	s   ,0 
>>c                 v    |                      t          t          i          }|                     |d           d S )Nr.   zno port specified)r1   r   r5   rV   r   rA   s     r   test_no_portz InClusterConfigTest.test_no_portw   A    %%*J7 & 9 9v':;;;;;r   c                     |                      t          t          t          di          }|                     |d           d S )Nr   rX   zempty port specified)r1   r   r5   r   rV   rY   s     r   test_empty_portz#InClusterConfigTest.test_empty_port|   sH    %%!:!2/
%   	v'=>>>>>r   c                 v    |                      t          t          i          }|                     |d           d S )NrX   zno host specified)r1   r   r6   rV   rY   s     r   test_no_hostz InClusterConfigTest.test_no_host   r[   r   c                     |                      t          dt          t          i          }|                     |d           d S )Nr   rX   zempty host specified)r1   r   r   r6   rV   rY   s     r   test_empty_hostz#InClusterConfigTest.test_empty_host   sH    %%!2!:/
%   	v'=>>>>>r   c                 ^    |                      d          }|                     |d           d S )Nnot_exists_file_1123r;   zcert file does not existr1   rV   rY   s     r   test_no_cert_filez%InClusterConfigTest.test_no_cert_file   s6    %%4J%KKv'ABBBBBr   c                     |                      |                                           }|                     |d           d S )Nr;   zempty cert file providedr1   r)   rV   rY   s     r   test_empty_cert_filez(InClusterConfigTest.test_empty_cert_file   sJ    %%==?? & A Av'ABBBBBr   c                 ^    |                      d          }|                     |d           d S )Nrc   r+   ztoken file does not existrd   rY   s     r   test_no_token_filez&InClusterConfigTest.test_no_token_file   s6    %%5K%LLv'BCCCCCr   c                     |                      |                                           }|                     |d           d S )Nrj   zempty token file providedrg   rY   s     r   test_empty_token_filez)InClusterConfigTest.test_empty_token_file   sJ    %%>>@@ & B Bv'BCCCCCr   )r   )__name__
__module____qualname__r   r   r)   _TEST_ENVIRONr1   r9   rB   rQ   rV   rZ   r]   r_   ra   re   rh   rk   rm    r   r   r   r   .   s0               (,&* -6 6 6 6G G G@ @ @J J J.  < < <
? ? ?< < <
? ? ?C C CC C C
D D DD D D D Dr   r   __main__)rK   r   r   timeunittestkubernetes.clientr   config_exceptionr   incluster_configr   r   r   r	   r/   rI   r0   r5   r6   r4   r8   r7   rq   _TEST_IPV6_ENVIRONTestCaser   rn   mainrr   r   r   <module>r|      sV    				    + + + + + + - - - - - -G G G G G G G G G G G G "


 !  ::
 ?: qD qD qD qD qD(+ qD qD qDh zHMOOOOO r   