
    Bfi                         d Z dZdZdZdZdZdZddlZej                  d   d	kD  rdd
l	m
Z
 ndd
lm
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j0                          yy)zunit tests module for ndg.httpsclient.urllib2_build_opener module

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   )URLError)SSL)	Constants)build_opener)ServerSSLCertVerificationc                   t    e Zd ZdZd Zd Z ej                  ej                  dk7  d      d        Z
d Zd Zy	)
Urllib2TestCasez$Unit tests for urllib2 functionalityc                 :    t               }| j                  |       y N)r   
assertTrueselfopeners     s/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/ndg/httpsclient/test/test_urllib2.pytest01_urllib2_build_openerz+Urllib2TestCase.test01_urllib2_build_opener   s        c                     t               }|j                  t        j                        }| j	                  |       t        d|j                         z         y )Nres = %s)r   openr   TEST_URIr   printread)r   r   ress      r   test02_openzUrllib2TestCase.test02_open"   s<    kk),,-j388:%&r   	localhostzSkip non-local hostc                 v    t               }| j                  t        |j                  t        j
                         y r   )r   assertRaisesr   r   r   	TEST_URI2r   s     r   test03_open_fails_unknown_locz-Urllib2TestCase.test03_open_fails_unknown_loc)   s%    (FKK1D1DEr   c                 >   t        j                  t         j                        }d }|j                  t         j                  |       |j                  d d       t        |      }| j                  t         j                  |j                  t        j                         y )Nc                     |S r    )connx509errnumerrdepthpreverify_oks        r   <lambda>zJUrllib2TestCase.test04_open_peer_cert_verification_fails.<locals>.<lambda>1   s
     r   z./ssl_context)r   ContextTLSv1_2_METHOD
set_verifyVERIFY_PEERload_verify_locationsr   r   Errorr   r   r   )r   ctxverify_callbackr   s       r   (test04_open_peer_cert_verification_failsz8Urllib2TestCase.test04_open_peer_cert_verification_fails.   sk    kk#,,- 	s8!!$-#.#))V[[)2D2DEr   c                 b   t        j                  t         j                        }t        j                  j                  dd      }t        |      dkD  r	d|d   z   }nt        j                  }t        |      }|j                         }|j                  t         j                  |       |j                  d       |j                  d t        j                         t        |      }|j                  t        j                         }| j#                  |       t%        d|j'                         z         y )	N.   z*.)hostname	   r*   r   )r   r,   r-   r   HOSTNAMEsplitlenr   get_verify_server_cert_funcr.   r/   set_verify_depthr0   
CACERT_DIRr   r   r   r   r   r   )r   r2   split_hostname	_hostnameserver_ssl_verifyverify_callback_r   r   s           r   ,test05_open_with_subj_alt_names_verificationz<Urllib2TestCase.test05_open_with_subj_alt_names_verification9   s    kk#,,- #++11#q9~"~b11I!**I5yI,HHJs(89 	Q 	!!$	(<(<=#.kk),,-j388:%&r   N)__name__
__module____qualname____doc__r   r   unittestskipIfr   r;   r    r4   rE   r#   r   r   r
   r
      sJ    . ' X__Y'';68MNF OF	F'r   r
   __main__)rI   
__author____date____copyright____license____contact____revision__sysversion_infourllib.errorr   urllib2rJ   OpenSSLr   ndg.httpsclient.testr   $ndg.httpsclient.urllib2_build_openerr   %ndg.httpsclient.ssl_peer_verificationr   TestCaser
   rF   mainr#   r   r   <module>r]      s   
 "
D=) 
A1,   * = K:'h'' :'z zHMMO r   