%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_socks.cpython-312.pyc

�

Ϫ�fXD�� �dZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZGd	�d
e
j �ZGd�d�ZGd
�de	j&�ZGd�dej*�ZGd�dej*�Zy)z_
Tests for L{twisted.protocol.socks}, an implementation of the SOCKSv4 and
SOCKSv4a protocols.
�N)�address�defer)�DNSLookupError)�socks)�	iterbytes)�
proto_helpers)�unittestc�&�eZdZdZdZd�Zd�Zd�Zy)�StringTCPTransportFNc��|jS)N)�peer��selfs �9/usr/lib/python3/dist-packages/twisted/test/test_socks.py�getPeerzStringTCPTransport.getPeers���y�y��c�0�tjddd�S)N�TCPz2.3.4.5�*)r�IPv4Addressrs r�getHostzStringTCPTransport.getHosts���"�"�5�)�R�8�8rc��d|_y)NT)�stringTCPTransport_closingrs r�loseConnectionz!StringTCPTransport.loseConnections
��*.��'r)�__name__�
__module__�__qualname__rr
rrr�rrrrs��!&���D��9�/rrc��eZdZdZd�Zd�Zy)�FakeResolverReactorzP
    Bare-bones reactor with deterministic behavior for the resolve method.
    c��||_y)z�
        @type names: L{dict} containing L{str} keys and L{str} values.
        @param names: A hostname to IP address mapping. The IP addresses are
            stringified dotted quads.
        N)�names)rr"s  r�__init__zFakeResolverReactor.__init__'s����
rc	���	tj|j|�S#t$r3tjtd|j
d�z��cYSwxYw)zQ
        Resolve a hostname by looking it up in the C{names} dictionary.
        z"FakeResolverReactor couldn't find zutf-8)r�succeedr"�KeyError�failr�decode)r�hostnames  r�resolvezFakeResolverReactor.resolve/sX��	��=�=����H�!5�6�6���	��:�:��8�8�?�?�7�;S�S���
�	�s�!$�9A �A N)rrr�__doc__r#r*rrrr r "s����rr c� �eZdZdZdZd�Zd�Zy)�
SOCKSv4DriverNc���||�}t�|_tjd||�|j_|j�||_tj|�S)Nr)	r�	transportrrr
�connectionMade�driver_outgoingrr%)r�host�port�klass�args�protos      r�connectClasszSOCKSv4Driver.connectClassDsS���t���,�.���&�2�2�5�$��E�����
����$����}�}�U�#�#rc�V�||�}||_|dk(rd}tjd|f�S)Nr���6.7.8.9)�
driver_listenrr%)rr3r4r5�factorys     r�listenClasszSOCKSv4Driver.listenClassMs3����,��$����1�9��D��}�}�i��.�/�/r)rrrr1r;r7r=rrrr-r-=s���O��M�$�0rr-c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�ConnectTestszV
    Tests for SOCKS and SOCKSv4a connect requests using the L{SOCKSv4} protocol.
    c��t�|_t�|j_|jj	�tddi�|j_y�Ns	localhost�	127.0.0.1�r-�sockrr/r0r �reactorrs r�setUpzConnectTests.setUp[�@��!�O��	�0�2��	�	���	�	� � �"�/��{�0K�L��	�	�rc��|jj}|�'|j|jjd�yy)Nz-Outgoing SOCKS connections need to be closed.)rDr1�
assertTruer/r)r�outgoings  r�tearDownzConnectTests.tearDownas:���9�9�,�,�����O�O��"�"�=�=�?�
� rc	���|jjtjdddd�t	j
d�zdzdz�|jjj�}|jjj�|j|tjddd	d�t	j
d�z�|j|jjj�|j|jj�|jjd
�|j|jjjj�d
�|jjjd�|j|jjj�d�|jjd�y)
N�!BBH���"�1.2.3.4�fooBAR�r�Z�hello, world�hi there�fake reason)rD�dataReceived�struct�pack�socket�	inet_atonr/�value�clear�assertEqual�assertFalser�assertIsNotNoner1�connectionLost)r�sents  r�test_simplezConnectTests.test_simpleisq���	�	����K�K���1�b�)����y�)�
*��
��
�	
��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��R�0�6�3C�3C�I�3N�N�	
�	
������,�,�G�G�H����T�Y�Y�6�6�7�	
�	�	����/�������2�2�<�<�B�B�D�o�V�	
�	�	�!�!�.�.�{�;�������,�,�2�2�4�k�B��	�	� � ��/rc	��tjdddd�tjd�zdzdz}t	|�D]}|j
j
|��|j
jj�}|j
jj�|j|tjddd	d�tjd
�z�|j|j
jj�|j|j
j�|j
j
d�|j|j
jjj�d�|j
jj
d�|j|j
jj�d�|j
jd
�y)�u
        If the destination IP address has zeros for the first three octets and
        non-zero for the fourth octet, the client is attempting a v4a
        connection.  A hostname is specified after the user ID string and the
        server connects to the address that hostname resolves to.

        @see: U{http://en.wikipedia.org/wiki/SOCKS#SOCKS_4a_protocol}
        rMrNrOrP�0.0.0.1�fooBAZ�
localhostrrTrBrUrVrWN)rYrZr[r\rrDrXr/r]r^r_r`rrar1rb�r�
clientRequest�bytercs    r� test_socks4aSuccessfulResolutionz-ConnectTests.test_socks4aSuccessfulResolution�s���
�K�K���1�b�)����y�)�
*��
��
�	��m�,�	)�D��I�I�"�"�4�(�	)��y�y�"�"�(�(�*���	�	���!�!�#�	
����&�+�+�f�a��R�0�6�3C�3C�K�3P�P�	
�	
������,�,�G�G�H����T�Y�Y�6�6�7�	
�	�	����/�������2�2�<�<�B�B�D�o�V�	
�	�	�!�!�.�.�{�;�������,�,�2�2�4�k�B��	�	� � ��/rc	�.�tjdddd�tjd�zdzdz}t	|�D]}|j
j
|��|j
jj�}|j|tjddd	d�tjd
�z�|j|j
jj�|j|j
j�y)��
        Failed hostname resolution on a SOCKSv4a packet results in a 91 error
        response and the connection getting closed.
        rMrNrOrPrgrh�failinghostr�[�0.0.0.0N�rYrZr[r\rrDrXr/r]r_rIr�assertIsNoner1rjs    r�test_socks4aFailedResolutionz)ConnectTests.test_socks4aFailedResolution�����
�K�K���1�b�)����y�)�
*��
��
�	��m�,�	)�D��I�I�"�"�4�(�	)��y�y�"�"�(�(�*������&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�
	
����	�	�+�+�F�F�G����$�)�)�3�3�4rc	�*�d�|j_|jjtjdddd�tjd�zdzdz�|j|jjj�tjdd	d
d	�tjd�z�|j|jjj�|j|jj�y)Nc��y�Nrr��code�serverr3�users    r�<lambda>z0ConnectTests.test_accessDenied.<locals>.<lambda>���rrMrNrO��10.2.3.4rRrSrrqrr)rD�	authorizerXrYrZr[r\r_r/r]rIrrtr1rs r�test_accessDeniedzConnectTests.test_accessDenied�s���@��	�	���	�	����K�K���1�d�+����z�*�
+��
��
�	
�	
����I�I���%�%�'��K�K���2�q�)�F�,<�,<�Y�,G�G�	
�	
����	�	�+�+�F�F�G����$�)�)�3�3�4rc�>�|jjtjdddd�t	j
d�zdzdz�|jjj�|jjd�|j|jjjj�d�|jjjj�|jjjd	�y�
NrMrNrOrPrQrRrSrUrW)
rDrXrYrZr[r\r/r^r_r1r]rrbrs r�test_eofRemotezConnectTests.test_eofRemote�s����	�	����K�K���1�b�)����y�)�
*��
��
�	
�	
�	�	���!�!�#�	
�	�	����/�������2�2�<�<�B�B�D�o�V�	
�	�	�!�!�+�+�:�:�<��	�	�!�!�0�0��?rc���|jjtjdddd�t	j
d�zdzdz�|jjj�|jjd�|j|jjjj�d�|jjd	�yr�)rDrXrYrZr[r\r/r^r_r1r]rbrs r�
test_eofLocalzConnectTests.test_eofLocal�s����	�	����K�K���1�b�)����y�)�
*��
��
�	
�	
�	�	���!�!�#�	
�	�	����/�������2�2�<�<�B�B�D�o�V�	
�	�	� � ��/rN)rrrr+rFrKrdrmrur�r�r�rrrr?r?Vs2���M��0�2,0�\5�:
5�@�"0rr?c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�	BindTestszS
    Tests for SOCKS and SOCKSv4a bind requests using the L{SOCKSv4} protocol.
    c��t�|_t�|j_|jj	�tddi�|j_yrArCrs rrFzBindTests.setUprGrc	��|jjtjdddd�t	j
d�zdzdz�|jjj�}|jjj�|j|tjddd	d
�t	j
d�z�|j|jjj�|j|jj�|jjjd�}|j|�t�|_|j!�|jjj�}|jjj�|j|tjddd	d�t	j
d
�z�|j|jjj�|jjd�|j|jj�d�|jd�|j|jjj�d�|jj#d�y)NrMrN�rPrQrRrSrrTr9r:�rQ��rrrUrVrW)rDrXrYrZr[r\r/r]r^r_r`rrar;�
buildProtocolrr0rb�rrc�incomings   rrdzBindTests.test_simples!���	�	����K�K���1�b�)����y�)�
*��
��
�	
��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��T�2�V�5E�5E�i�5P�P�	
�	
������,�,�G�G�H����T�Y�Y�4�4�5��9�9�*�*�8�8�9J�K�����X�&�/�1������!��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�	
������,�,�G�G�H�	
�	�	����/�����+�+�1�1�3�_�E�	���k�*�������,�,�2�2�4�k�B��	�	� � ��/rc	���tjdddd�tjd�zdzdz}t	|�D]}|j
j
|��|j
jj�}|j
jj�|j|tjddd	d
�tjd�z�|j|j
jj�|j|j
j�|j
jjd�}|j|�t!�|_|j#�|j
jj�}|j
jj�|j|tjddd	d�tjd
�z�|j%|j
jjd�|j
j
d�|j|jj�d�|j
d�|j|j
jj�d�|j
j'd�y)rfrMrNr�rPrgrhrirrTr9r:)rBr�rrNrVrW)rYrZr[r\rrDrXr/r]r^r_r`rrar;r�rr0�assertIsNotrb)rrkrlrcr�s     r�test_socks4azBindTests.test_socks4a7sB��
�K�K���1�b�)����y�)�
*��
��
�	��m�,�	)�D��I�I�"�"�4�(�	)��y�y�"�"�(�(�*���	�	���!�!�#�	
����&�+�+�f�a��T�2�V�5E�5E�i�5P�P�	
�	
������,�,�G�G�H����T�Y�Y�4�4�5��9�9�*�*�8�8�9L�M�����X�&�/�1������!��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�	
������,�,�G�G��N�	
�	�	���{�+�����+�+�1�1�3�[�A�	���k�*�������,�,�2�2�4�k�B��	�	� � ��/rc	�.�tjdddd�tjd�zdzdz}t	|�D]}|j
j
|��|j
jj�}|j|tjddd	d�tjd
�z�|j|j
jj�|j|j
j�y)rorMrNr�rPrgrhrprrqrrNrsrjs    rruz&BindTests.test_socks4aFailedResolutionrrvrc	�*�d�|j_|jjtjdddd�tjd�zdzdz�|j|jjj�tjdd	d
d	�tjd�z�|j|jjj�|j|jj�y)Nc��yryrrzs    rr~z-BindTests.test_accessDenied.<locals>.<lambda>�rrrMrNr�r�r�rRrSrrqrr)rDr�rXrYrZr[r\r_r/r]rIrrtr;rs rr�zBindTests.test_accessDenied�s���@��	�	���	�	����K�K���1�d�+����z�*�
+��
��
�	
�	
����I�I���%�%�'��K�K���2�q�)�F�,<�,<�Y�,G�G�	
�	
����	�	�+�+�F�F�G����$�)�)�1�1�2rc	�"�|jjtjdddd�t	j
d�zdzdz�|jjj�}|jjj�|jjjd�}|j|�t�|_|j�|jjj�}|jjj�|j|tjdd	d
d	�t	j
d�z�|j|jjj �|jjd�|j|jj�d�|jj#�|j%d
�y�NrMrNr�rPrQrRrSr�rrTrrrUrW)rDrXrYrZr[r\r/r]r^r;r�rarr0r_r`rrrbr�s   rr�zBindTests.test_eofRemote�s����	�	����K�K���1�b�)����y�)�
*��
��
�	
��y�y�"�"�(�(�*���	�	���!�!�#��9�9�*�*�8�8�9J�K�����X�&�/�1������!��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�	
������,�,�G�G�H�	
�	�	����/�����+�+�1�1�3�_�E�	���)�)�+����
�.rc	��|jjtjdddd�t	j
d�zdzdz�|jjj�}|jjj�|jjjd�}|j|�t�|_|j�|jjj�}|jjj�|j|tjdd	d
d	�t	j
d�z�|j|jjj �|jjd�|j|jj�d�|jj#d
�yr�)rDrXrYrZr[r\r/r]r^r;r�rarr0r_r`rrbr�s   rr�zBindTests.test_eofLocal�s����	�	����K�K���1�b�)����y�)�
*��
��
�	
��y�y�"�"�(�(�*���	�	���!�!�#��9�9�*�*�8�8�9J�K�����X�&�/�1������!��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�	
������,�,�G�G�H�	
�	�	����/�����+�+�1�1�3�_�E�	
�	�	� � ��/rc	��|jjtjdddd�t	j
d�zdzdz�|jjj�}|jjj�|jjjd�}|j|�|jjj�}|jjj�|j|tjdd	d
d	�t	j
d�z�|j|jjj�y)NrMrNr�rPrQrRrS)z1.6.6.6i�rrqrr)rDrXrYrZr[r\r/r]r^r;r�rtr_rIrr�s   r�test_badSourcezBindTests.test_badSource�s&���	�	����K�K���1�b�)����y�)�
*��
��
�	
��y�y�"�"�(�(�*���	�	���!�!�#��9�9�*�*�8�8�9I�J�����(�#��y�y�"�"�(�(�*���	�	���!�!�#�����&�+�+�f�a��Q�/�&�2B�2B�9�2M�M�	
�	
����	�	�+�+�F�F�GrN)rrrr+rFrdr�rur�r�r�r�rrrr�r��s4���M�%0�N90�v5�:
3�/�@0�>Hrr�)r+r[rY�twisted.internetrr�twisted.internet.errorr�twisted.protocolsr�twisted.python.compatr�twisted.testr�
twisted.trialr	�StringTransportrr �SOCKSv4r-�TestCaser?r�rrr�<module>r�s{���
�
�+�1�#�+�&�"�/��6�6�/���60�E�M�M�0�2e0�8�$�$�e0�PtH��!�!�tHr

Zerion Mini Shell 1.0