� �/Oc@s�dZdZdZdZdZdZdZddlZejd ej �ej e �Z ddl Z ddlZdd lmZdd lmZdd lmZdd lmZde jfd��YZe dkr�e j�ndS(s�unit tests module for ndg.httpsclient.https.HTTPSconnection class PyOpenSSL utility to make a httplib-like interface suitable for use with urllib2 sP J Kershaw (STFC)s06/01/12s2(C) 2012 Science and Technology Facilities Councils-BSD - see LICENSE file in top-level directorysPhilip.Kershaw@stfc.ac.uks$Id$i����Ntlevel(tSSL(t Constants(tHTTPSConnection(tServerSSLCertVerificationtTestHTTPSConnectioncBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(s+Test ndg HTTPS client HTTPSConnection classcCs[ttjdtj�}|j�|jdd�|j�}d|j�GH|j�dS(NtporttGETt/s Response = %s( RRtHOSTNAMEtPORTtconnecttrequestt getresponsetreadtclose(tselftconntresp((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt test01_opens   cCs2ttjdtj�}|jtj|j�dS(NR(RRR tPORT2tfailUnlessRaisestsocketterrorR (RR((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyttest02_open_fails$scCs�tjtj�}d�}|jtj|�|jd�|jdtj �t tj dtj d|�}|j �|jtj|jdd�dS(NcSstjd|j��|S(Ns/SSL peer certificate verification failed for %r(tlogtdebugt get_subject(Rtx509terrnumterrdeptht preverify_ok((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pytverify_callback+s  i Rt ssl_contextRR(RtContextt SSLv3_METHODt set_verifyt VERIFY_PEERtset_verify_depthtload_verify_locationstNoneRt UNITTEST_DIRRR R R RtErrorR (RtctxR R((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt%test03_ssl_verification_of_peer_fails(s    cCs�tjtj�}d�}|jtj|�|jd�|jdtj �t tj dtj d|�}|j �|jdd�|j�}d|j�GHdS(NcSs|S(N((RRRRR((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt<lambda>>si RR!RRs Response = %s(RR"R#R$R%R&R'R(Rt CACERT_DIRRR R R R R R(RR+R RR((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt(test03_ssl_verification_of_peer_succeeds;s     cCs�tjtj�}tdd�}|jtj|�|jd�|jdt j �t t j dt j d|�}|j�|jdd�|j�}d|j�GHdS( Nthostnamet localhosti RR!RRs Response = %s(RR"R#RR$R%R&R'R(RR.RR R R R R R(RR+R RR((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt*test04_ssl_verification_with_subj_alt_nameNs    cCs�tjtj�}tdddt�}|jtj|�|jd�|jdt j �t t j dt jd|�}|j�|jdd�|j�}d |j�GHdS( NR0R1tsubj_alt_name_matchi RR!RRs Response = %s(RR"R#RtFalseR$R%R&R'R(RR.RR R R R R R(RR+R RR((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt-test04_ssl_verification_with_subj_common_name`s      ( t__name__t __module__t__doc__RRR,R/R2R5(((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyRs     t__main__(R8t __author__t__date__t __copyright__t __license__t __contact__t __revision__tloggingt basicConfigtDEBUGt getLoggerR6RtunittestRtOpenSSLRtndg.httpsclient.testRtndg.httpsclient.httpsRt%ndg.httpsclient.ssl_peer_verificationRtTestCaseRtmain(((sC/usr/lib/python2.7/site-packages/ndg/httpsclient/test/test_https.pyt<module>s$   ]