
    hT                     f    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
y)    N)replace_loop)patchMock)ApplicationRunnerc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestApplicationRunnerzA
    Test the autobahn.asyncio.wamp.ApplicationRunner class.
    c                     	 | j                    | j                   } |||g|i | y # t        $ r | j                  }Y %w xY w)N)assertRaisesRegexAttributeErrorassertRaisesRegexp)self	exceptionerrorargskwfs         b/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/asyncio/test/test_wamp_runner.py_assertRaisesRegexz(TestApplicationRunner._assertRaisesRegex(   sM    	'"" &&A	)U(T(R(	  	(''A	(s   ( A A c                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        i }t        dd|      }|j                  d       | j                  ||j                  j                  d   d          d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
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 O*.TVTV<L*M'*+CW/24

:&c4#9#9#C#CA#Fu#MNO	O 	OO O	O 	Os#   B?A1B3"B?3B<	8B??Cc                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        t        dd      }|j                  d       | j                  d|j                  j                  d   d          d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
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@   s     $&! 	QTg'7dK Q*.TVTV<L*M'*+CWM

:&eT%;%;%E%Ea%H%OP	Q	Q 	QQ Q	Q 	Qs#   B;A-B/B;/B8	4B;;Cc                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        t        dd      }|j                  | j                         | j                  d|j                  j                  d   d          ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	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   s     $&! 	PTg'7dK P*.TVTV<L*M'*+EwO

499%dD$:$:$D$DQ$G$NO	P	P 	PP P	P 	Ps#   CA7B9(C9C	>CCc                     t        t                     5 }t        t               t               f      |_        t        ddd      }d}| j	                  t
        ||j                  d       ddd       y# 1 sw Y   yxY w)	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   ss    
 $&! 	NT&*8H&ID#&'@'+/1FAE ##Iufjj*M	N 	N 	Ns   AA33A<c                 b   ddl }	 |j                   |j                         }t        t	                     5 }t	        t	               t	               f      |_        t        dd|      }d}| j                  t        ||j                  d	       ddd       y# t        $ r d}Y w xY w# 1 sw Y   yxY w)
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   s    
 		3 && 002G$&! 	NT&*8H&ID#&'@'+24FAE ##Iufjj*M	N 	N  	G	
	N 	Ns   B AB%B"!B"%B.N)
__name__
__module____qualname____doc__r   r)   r,   r/   r4   r8        r   r   r   $   s*    )OQPNNr>   r   )unittesttxaio.testutilr   r!   unittest.mockr   r   autobahn.asyncio.wampr   TestCaser   r=   r>   r   <module>rD      s,   6  '  % 3bNH-- bNr>   