
    Bfi                        d Z dZdZdZdZdZdZddlZ ej                  ej                  	        ej                  e      ZddlZddlZdd
lmZ ddlmZ ddlmZ ddlmZ  G d dej.                        Zedk(  r ej2                          yy)zunit tests module for ndg.httpsclient.https.HTTPSconnection class

PyOpenSSL utility to make a httplib-like interface suitable for use with 
urllib2
zP J Kershaw (STFC)z06/01/12z2(C) 2012 Science and Technology Facilities Councilz-BSD - see LICENSE file in top-level directoryzPhilip.Kershaw@stfc.ac.ukz$Id$    N)level)SSL)	Constants)HTTPSConnection)ServerSSLCertVerificationc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestHTTPSConnectionz+Test ndg HTTPS client HTTPSConnection classc                    t        t        j                  t        j                        }|j	                          |j                  dd       |j                         }t        d|j                         z         |j                          y )NportGET/Response = %s)
r   r   HOSTNAMEPORTconnectrequestgetresponseprintreadclose)selfconnresps      q/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/ndg/httpsclient/test/test_https.pytest01_openzTestHTTPSConnection.test01_open   sY    y11	GUC !o		+,

    c                     t        t        j                  t        j                        }| j	                  t
        j                  |j                         y )Nr   )r   r   r   PORT2assertRaisessocketerrorr   )r   r   s     r   test02_open_failsz%TestHTTPSConnection.test02_open_fails$   s0    y11	H&,,5r   c                    t        j                  t         j                        }d }|j                  t         j                  |       |j                  d       |j                  d t        j                         t        t        j                  t        j                  |      }|j                          | j                  t         j                  |j                  dd       y )Nc                 N    t         j                  d|j                                |S )Nz/SSL peer certificate verification failed for %r)logdebugget_subjectr   x509errnumerrdepthpreverify_oks        r   verify_callbackzRTestHTTPSConnection.test03_ssl_verification_of_peer_fails.<locals>.verify_callback+   s#    IIG&&(*r   	   r   ssl_contextr   r   )r   ContextTLSv1_2_METHOD
set_verifyVERIFY_PEERset_verify_depthload_verify_locationsr   UNITTEST_DIRr   r   r   r   r    Errorr   )r   ctxr.   r   s       r   %test03_ssl_verification_of_peer_failsz9TestHTTPSConnection.test03_ssl_verification_of_peer_fails(   s    kk#,,-	 
 	s8Q 	!!$	(>(>?y11	+.0#))T\\5#>r   c                    t        j                  t         j                        }d }|j                  t         j                  |       |j                  d       |j                  d t        j                         t        t        j                  t        j                  |      }|j                          |j                  dd       |j                         }t        d|j!                         z         y )Nc                     |S )N r)   s        r   <lambda>zNTestHTTPSConnection.test03_ssl_verification_of_peer_succeeds.<locals>.<lambda>>   s
     r   r/   r0   r   r   r   )r   r2   r3   r4   r5   r6   r7   r   
CACERT_DIRr   r   r   r   r   r   r   r   )r   r:   r.   r   r   s        r   (test03_ssl_verification_of_peer_succeedsz<TestHTTPSConnection.test03_ssl_verification_of_peer_succeeds;   s    kk#,,- 	s8Q 	!!$	(<(<=y11	+.0UC !o		+,r   c                    t        j                  t         j                        }t        d      }|j	                         }|j                  t         j                  |       |j                  d       |j                  d t        j                         t        t        j                  t        j                  |      }|j                          |j                  dd       |j!                         }t#        d|j%                         z         y )N	localhost)hostnamer/   r0   r   r   r   r   r2   r3   r   get_verify_server_cert_funcr4   r5   r6   r7   r   r@   r   r   r   r   r   r   r   r   r   r:   verificationr.   r   r   s         r   *test04_ssl_verification_with_subj_alt_namez>TestHTTPSConnection.test04_ssl_verification_with_subj_alt_nameN   s    kk#,,-0+F&BBDs8Q 	!!$	(<(<=y11	+.0UC !o		+,r   c                    t        j                  t         j                        }t        dd      }|j	                         }|j                  t         j                  |       |j                  d       |j                  d t        j                         t        t        j                  t        j                  |      }|j                          |j                  dd       |j!                         }t#        d|j%                         z         y )	NrC   F)rD   subj_alt_name_matchr/   r0   r   r   r   rE   rG   s         r   -test04_ssl_verification_with_subj_common_namezATestHTTPSConnection.test04_ssl_verification_with_subj_common_namea   s    kk#,,- 1+EJL 'BBDs8Q 	!!$	(<(<=y11	+.0UC !o		+,r   N)
__name__
__module____qualname____doc__r   r#   r;   rA   rI   rL   r>   r   r   r	   r	      s#    56?&-&-&-r   r	   __main__)rP   
__author____date____copyright____license____contact____revision__loggingbasicConfigDEBUG	getLoggerrM   r&   unittestr!   OpenSSLr   ndg.httpsclient.testr   ndg.httpsclient.httpsr   %ndg.httpsclient.ssl_peer_verificationr   TestCaser	   mainr>   r   r   <module>rc      s   
 "
D=)    '-- (g!    * 1 K]-(++ ]-@ zHMMO r   