File: //lib/python3.6/site-packages/ndg/httpsclient/test/__pycache__/test_https.cpython-36.pyc
3
��Z� � @ s� d Z dZdZdZdZdZdZddlZejej d � ej
e�Zddl
Z
ddlZdd
lmZ ddlmZ ddlmZ dd
lmZ G dd� de
j�Zedkr�e
j� dS )z�unit tests module for ndg.httpsclient.https.HTTPSconnection class
PyOpenSSL utility to make a httplib-like interface suitable for use with
urllib2
zP J Kershaw (STFC)z06/01/12z2(C) 2012 Science and Technology Facilities Councilz-BSD - see LICENSE file in top-level directoryzPhilip.Kershaw@stfc.ac.ukz$Id$� N)�level)�SSL)� Constants)�HTTPSConnection)�ServerSSLCertVerificationc @ s@ e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dS )�TestHTTPSConnectionz+Test ndg HTTPS client HTTPSConnection classc C sH t tjtjd�}|j� |jdd� |j� }td|j� � |j � d S )N)�port�GET�/z
Response = %s)
r r �HOSTNAME�PORT�connect�request�getresponse�print�read�close)�self�conn�resp� r � /usr/lib/python3.6/test_https.py�test01_open s zTestHTTPSConnection.test01_openc C s$ t tjtjd�}| jtj|j� d S )N)r )r r r ZPORT2�assertRaises�socket�errorr
)r r r r r �test02_open_fails$ s z%TestHTTPSConnection.test02_open_failsc C sl t jt j�}dd� }|jt j|� |jd� |jd tj� t tj
tj|d�}|j� | j
t j|jdd� d S )Nc S s t jd|j� � |S )Nz/SSL peer certificate verification failed for %r)�log�debugZget_subject)r �x509�errnum�errdepth�preverify_okr r r �verify_callback+ s
zRTestHTTPSConnection.test03_ssl_verification_of_peer_fails.<locals>.verify_callback� )r �ssl_contextr r
)r �Context�TLSv1_2_METHOD�
set_verify�VERIFY_PEER�set_verify_depth�load_verify_locationsr ZUNITTEST_DIRr r r r
r �Errorr )r �ctxr# r r r r �%test03_ssl_verification_of_peer_fails( s
z9TestHTTPSConnection.test03_ssl_verification_of_peer_failsc C s| t jt j�}dd� }|jt j|� |jd� |jd tj� t tj
tj|d�}|j� |j
dd� |j� }td|j� � d S )Nc S s |S )Nr )r r r r! r"