
    ?gS                         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j0                        Zedk(  r ej6                          yy)    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                   v    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y)InClusterConfigTestc                     g | _         y N)_temp_filesselfs    \/var/www/openai/venv/lib/python3.12/site-packages/kubernetes/config/incluster_config_test.pysetUpzInClusterConfigTest.setUp/   s
        c                 P    | j                   D ]  }t        j                  |        y r   )r   osremove)r   fs     r   tearDownzInClusterConfigTest.tearDown2   s    !!AIIaL "r   c                     t        j                         \  }}| j                  j                  |       t	        j
                  |t        j                  |             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   sP     ((*%
#**W-.
r   Nc                 |    |s| j                  t              }|s| j                  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=   sB     !@@MN ??
KM$N3@7;-46 	6r   c                     | j                  t        t        t        t                     | j                  t
        t        t        t                     y 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   s9    (Z@	B-(*E	Gr   c                 6   | j                  t              }| j                  |      }|j                          | j	                  dt
        z   |j                         | j	                  ||j                         | j	                  dt        z   |j                         y )Nr+   zhttps://bearer )
r(   r/   r0   _load_configr2   r3   hostssl_ca_certr.   token)r   r+   loaders      r   test_load_configz$InClusterConfigTest.test_load_configP   sy    ;;JG%%M%Bo5v{{C(:(:;[0&,,?r   c                    | j                         }t               }|j                  |       | j                  dt        z   |j                  d             | j                  dt        z   |j                         | j                  |j                         |j                  }|j                  }| j                  t              |_        | j                  dt        z   |j                  d             t        j                  j                         |_        | j                  dt        z   |j                  d             | j                  dt        z   |j                         | j                  |j                  |       y )Nr;   authorization)r0   r   load_and_setr2   r.   get_api_key_with_prefixr?   assertIsNotNonetoken_expires_atr(   _TEST_NEW_TOKEN_token_filenamedatetimenowassertGreater)r   r@   config	old_tokenold_token_expires_ats        r   test_refresh_tokenz&InClusterConfigTest.test_refresh_tokenX   s2   %%'F#[077H	J[0&,,?V445LL	%66!%!D!D"[077H	J #+"3"3"7"7"9_477H	J_4fllC6224HIr   c                 l    	 |j                          | j                  d|z         y # t        $ r Y y w xY w)NzShould fail because %s)rD   failr   )r   config_loaderreasons      r   _should_fail_loadz%InClusterConfigTest._should_fail_loado   s7    	&&(II.78 		s   $' 	33c                 `    | j                  t        t        i      }| j                  |d       y )Nr-   zno port specified)r0   r   r4   rU   r   r@   s     r   test_no_portz InClusterConfigTest.test_no_portw   0    %%*J7 & 9v':;r   c                 l    | j                  t        t        t        di      }| j	                  |d       y )N rW   zempty port specified)r0   r   r4   r   rU   rX   s     r   test_empty_portz#InClusterConfigTest.test_empty_port|   s7    %%!:!2/
%  	v'=>r   c                 `    | j                  t        t        i      }| j                  |d       y )NrW   zno host specified)r0   r   r5   rU   rX   s     r   test_no_hostz InClusterConfigTest.test_no_host   rZ   r   c                 l    | j                  t        dt        t        i      }| j	                  |d       y )Nr\   rW   zempty host specified)r0   r   r   r5   rU   rX   s     r   test_empty_hostz#InClusterConfigTest.test_empty_host   s7    %%!2!:/
%  	v'=>r   c                 L    | j                  d      }| j                  |d       y )Nnot_exists_file_1123r:   zcert file does not existr0   rU   rX   s     r   test_no_cert_filez%InClusterConfigTest.test_no_cert_file   s'    %%4J%Kv'ABr   c                 h    | j                  | j                               }| j                  |d       y )Nr:   zempty cert file providedr0   r(   rU   rX   s     r   test_empty_cert_filez(InClusterConfigTest.test_empty_cert_file   s5    %%==? & Av'ABr   c                 L    | j                  d      }| j                  |d       y )Nrc   r*   ztoken file does not existrd   rX   s     r   test_no_token_filez&InClusterConfigTest.test_no_token_file   s'    %%5K%Lv'BCr   c                 h    | j                  | j                               }| j                  |d       y )Nrj   zempty token file providedrg   rX   s     r   test_empty_token_filez)InClusterConfigTest.test_empty_token_file   s5    %%>>@ & Bv'BCr   )r\   )__name__
__module____qualname__r   r   r(   _TEST_ENVIRONr0   r8   rA   rP   rU   rY   r]   r_   ra   re   rh   rk   rm    r   r   r   r   .   sd     (,&* -6G@J.<
?<
?CC
DDr   r   __main__)rJ   r   r   timeunittestkubernetes.clientr   config_exceptionr   incluster_configr   r   r   r	   r.   rH   r/   r4   r5   r3   r7   r6   rq   _TEST_IPV6_ENVIRONTestCaser   rn   mainrr   r   r   <module>r|      s     	    + -G G "


 !  ::
 ?: qD(++ qDh zHMMO r   