
    tfT                     d    d dl Z d dlmZ d dlZd dlmZmZ d dlmZ  G d de j	                  Z
dS )    N)replace_loop)patchMock)ApplicationRunnerc                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	TestApplicationRunnerzA
    Test the autobahn.asyncio.wamp.ApplicationRunner class.
    c                 n    	 | j          | j         }n# t          $ r
 | j        }Y nw xY w |||g|R i | d S )N)assertRaisesRegexAttributeErrorassertRaisesRegexp)self	exceptionerrorargskwfs         e/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/asyncio/test/test_wamp_runner.py_assertRaisesRegexz(TestApplicationRunner._assertRaisesRegex(   so    	'"" &AA  	( 	( 	('AAA	( 	
)U(T(((R(((((s    %%c                    t          t                                5 }t          j        t          d|          5  t          t                      t                      f          |_        i }t          dd|          }|                    d           |                     ||j	        j
        d         d                    d	d	d	           n# 1 swxY w Y   d	d	d	           d	S # 1 swxY w Y   d	S )
z
        Ensure that loop.create_connection is called with the exact SSL
        context object that is passed (as ssl) to the __init__ method of
        ApplicationRunner.
        get_event_loopreturn_valuews://127.0.0.1:8080/wsrealmssl_unused_   r   Nr   r   r   objectasynciorun_until_completer   runassertIscreate_connection	call_args)r   loopr   runners       r   test_explicit_SSLContextz.TestApplicationRunner.test_explicit_SSLContext1   s    $&&!! 	OTg'7dKKK O O*.TVVTVV<L*M*M*M'*+CW/24 4 4

:&&&c4#9#CA#Fu#MNNNO O O O O O O O O O O O O O O	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	Os5   C"BC
>C"
C	C"C	C""C&)C&c                    t          t                                5 }t          j        t          d|          5  t          t                      t                      f          |_        t          dd          }|                    d           |                     d|j	        j
        d         d                    d	d	d	           n# 1 swxY w Y   d	d	d	           d	S # 1 swxY w Y   d	S )
z
        Ensure that loop.create_connection is called with ssl=False
        if no ssl argument is passed to the __init__ method of
        ApplicationRunner and the websocket URL starts with "ws:".
        r   r   r   r   r   Fr   r   Nr   r   r'   r(   s      r    test_omitted_SSLContext_insecurez6TestApplicationRunner.test_omitted_SSLContext_insecure@   sn    $&&!! 	QTg'7dKKK Q Q*.TVVTVV<L*M*M*M'*+CWMM

:&&&eT%;%Ea%H%OPPP	Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Qs5   CBC:CC
	
CC
	CC"%C"c                    t          t                                5 }t          j        t          d|          5  t          t                      t                      f          |_        t          dd          }|                    | j                   | 	                    d|j
        j        d         d                    ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	z
        Ensure that loop.create_connection is called with ssl=True
        if no ssl argument is passed to the __init__ method of
        ApplicationRunner and the websocket URL starts with "wss:".
        r   r   zwss://127.0.0.1:8080/wssr   Tr   r   N)r   r   r   r    r!   r"   r   r#   failr$   r%   r&   r+   s      r   test_omitted_SSLContext_securez4TestApplicationRunner.test_omitted_SSLContext_secureM   sp    $&&!! 	PTg'7dKKK P P*.TVVTVV<L*M*M*M'*+EwOO

49%%%dD$:$DQ$G$NOOO	P P P P P P P P P P P P P P P	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps5   C#BC?C#C	C#C	C##C'*C'c                 8   t          t                                5 }t          t                      t                      f          |_        t          ddd          }d}|                     t
          ||j        d           ddd           dS # 1 swxY w Y   dS )	zw
        ApplicationRunner must raise an exception if given an ssl value of True
        but only a "ws:" URL.
        r   ws://127.0.0.1:8080/wssr   Tr   ^ssl argument value passed to ApplicationRunner conflicts with the "ws:" prefix of the url argument\. Did you mean to use "wss:"\?$r   N)r   r   r"   r   r   	Exceptionr#   )r   r'   r(   r   s       r   "test_conflict_SSL_True_with_ws_urlz8TestApplicationRunner.test_conflict_SSL_True_with_ws_urlZ   s    
 $&&!! 	NT&*8H&I&I&ID#&'@'+/1 1 1FAE ##Iufj*MMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   A&BBBc                    ddl }	 |j         |                                }n# t          $ r d}Y nw xY wt          t	                                5 }t	          t	                      t	                      f          |_        t          dd|          }d}|                     t          ||j	        d	           ddd           dS # 1 swxY w Y   dS )
z
        ApplicationRunner must raise an exception if given an ssl value that is
        an instance of SSLContext, but only a "ws:" URL.
        r   NTr   r1   r   r   r2   r   )
r   create_default_contextr   r   r   r"   r   r   r3   r#   )r   r   contextr'   r(   r   s         r   $test_conflict_SSLContext_with_ws_urlz:TestApplicationRunner.test_conflict_SSLContext_with_ws_urlh   sB   
 	


	3 && 0022GG  	 	 	GGG	
 $&&!! 	NT&*8H&I&I&ID#&'@'+24 4 4FAE ##Iufj*MMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   " 11A&CC	CN)
__name__
__module____qualname____doc__r   r)   r,   r/   r4   r8        r   r   r   $   s         ) ) )O O OQ Q QP P PN N NN N N N Nr>   r   )unittesttxaio.testutilr   r!   unittest.mockr   r   autobahn.asyncio.wampr   TestCaser   r=   r>   r   <module>rD      s   6  ' ' ' ' ' '  % % % % % % % % 3 3 3 3 3 3bN bN bN bN bNH- bN bN bN bN bNr>   