o
    j]                     @   st   d dl mZ d dlmZ edgd d dlmZ G dd deZG dd	 d	eZG d
d deZG dd deZdS )    )TestCase)set_address_parser_settingsz177.139.233.100trusted_proxies)address_parserc                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBS )CIPv4TestCaseIP address Testc                 C      i }t |}| | d S N)r   get_real_ipassertIsNoneselfrequestip r   \/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/test/util/test_address.pytest_meta_none8      
zIPv4TestCase.test_meta_nonec                 C   &   dddd}t |}| |d d S )NE192.168.255.182, 10.0.0.0, 127.0.0.1, 198.84.193.157, 177.139.233.139177.139.233.132177.139.233.133HTTP_X_FORWARDED_FORHTTP_X_REAL_IPREMOTE_ADDR198.84.193.157r   r   assertEqualr   r   r   r   "test_http_x_forwarded_for_multiple>      
z/IPv4TestCase.test_http_x_forwarded_for_multiplec                 C   r   )NE192.168.255.182, 198.84.193.157, 10.0.0.0, 127.0.0.1, 177.139.233.139r   r   r   r   r   r   r   r   r   /test_http_x_forwarded_for_multiple_left_most_ipG   r!   z<IPv4TestCase.test_http_x_forwarded_for_multiple_left_most_ipc                 C   *   dddd}t j|dd}| |d d S Nr"   r   r   r   Tright_most_proxy177.139.233.139r   r   r   r   r   0test_http_x_forwarded_for_multiple_right_most_ipP      z=IPv4TestCase.test_http_x_forwarded_for_multiple_right_most_ipc                 C   r$   r%   r   r   r   r   r   8test_http_x_forwarded_for_multiple_right_most_ip_privateY   r*   zEIPv4TestCase.test_http_x_forwarded_for_multiple_right_most_ip_privatec                 C   r   )NNunknown, 192.168.255.182, 10.0.0.0, 127.0.0.1, 198.84.193.157, 177.139.233.139r   r   r   r   r   r   r   r   r   .test_http_x_forwarded_for_multiple_bad_addressb   r!   z;IPv4TestCase.test_http_x_forwarded_for_multiple_bad_addressc                 C   s&   dddd}t |}| |d d S )Nr(   r   r   r   r   r   r   r   r   #test_http_x_forwarded_for_singletonk   r!   z0IPv4TestCase.test_http_x_forwarded_for_singletonc                 C   &   dddd}t |}| |d d S )N192.168.255.182r   r   r   r   r   r   r   r   3test_http_x_forwarded_for_singleton_private_addresst   r!   z@IPv4TestCase.test_http_x_forwarded_for_singleton_private_addressc                 C   r/   )Nunknown 177.139.233.139r   r   r   r   r   r   r   r   3test_bad_http_x_forwarded_for_fallback_on_x_real_ip}   r!   z@IPv4TestCase.test_bad_http_x_forwarded_for_fallback_on_x_real_ipc                 C   r/   )N r   r   r   r   r   r   r   r   5test_empty_http_x_forwarded_for_fallback_on_x_real_ip   r!   zBIPv4TestCase.test_empty_http_x_forwarded_for_fallback_on_x_real_ipc                 C   &   dddd}t |}| |d d S )Nr4   r   r   r   r   r   r   r   Gtest_empty_http_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addr   r!   zTIPv4TestCase.test_empty_http_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addrc                 C   &   dddd}t |}| |d d S )Nr4   r0   r   r   r   r   r   r   r   Itest_empty_http_x_forwarded_for_private_x_real_ip_fallback_on_remote_addr   r!   zVIPv4TestCase.test_empty_http_x_forwarded_for_private_x_real_ip_fallback_on_remote_addrc                 C   &   dddd}t |}| |d  d S )N	127.0.0.1r4   r   r   r   r   r   r   'test_private_http_x_forward_for_ip_addr   r!   z4IPv4TestCase.test_private_http_x_forward_for_ip_addrc                 C   $   ddd}t |}| |d  d S )Nr4   r;   )r   r   r   r   r   r   r   $test_private_remote_addr_for_ip_addr   
   
z1IPv4TestCase.test_private_remote_addr_for_ip_addrc                 C   "   ddi}t |}| |d d S Nr   r   r   r   r   r   r   test_missing_x_forwarded      
z%IPv4TestCase.test_missing_x_forwardedc                 C   r@   rA   r   r   r   r   r   (test_missing_x_forwarded_missing_real_ip   rC   z5IPv4TestCase.test_missing_x_forwarded_missing_real_ipc                 C   $   ddd}t |}| |d d S )Nr;   z172.31.233.133r   r   r   get_ipr   r   r   r   r   test_best_matched_real_ip   r?   z&IPv4TestCase.test_best_matched_real_ipc                 C   rE   )Nr;   192.31.233.133rF   rG   r   r   r   r   test_best_matched_private_ip   r?   z)IPv4TestCase.test_best_matched_private_ipc                 C   $   ddd}t |}| |d d S )NrJ   r;   rF   rG   r   r   r   r   test_best_matched_private_ip_2   r?   z+IPv4TestCase.test_best_matched_private_ip_2c                 C   $   ddd}t |}| |d d S )Nr   r   X_FORWARDED_FORr   r   r   r   r   r   r   test_x_forwarded_for_multiple   r?   z*IPv4TestCase.test_x_forwarded_for_multiplec                 C   rN   )Nr"   r   rO   r   r   r   r   r   r   *test_x_forwarded_for_multiple_left_most_ip   r?   z7IPv4TestCase.test_x_forwarded_for_multiple_left_most_ipc                 C   (   ddd}t j|dd}| |d d S Nr"   r   rO   Tr&   r(   r   r   r   r   r   +test_x_forwarded_for_multiple_right_most_ip   
   z8IPv4TestCase.test_x_forwarded_for_multiple_right_most_ipc                 C   rS   rT   r   r   r   r   r   3test_x_forwarded_for_multiple_right_most_ip_private   rV   z@IPv4TestCase.test_x_forwarded_for_multiple_right_most_ip_privatec                 C   rN   )Nr,   r   rO   r   r   r   r   r   r   )test_x_forwarded_for_multiple_bad_address   r?   z6IPv4TestCase.test_x_forwarded_for_multiple_bad_addressc                 C   rL   )Nr(   r   rO   r   r   r   r   r   test_x_forwarded_for_singleton   r?   z+IPv4TestCase.test_x_forwarded_for_singletonc                 C   rE   )Nr0   r   rO   r   r   r   r   r   .test_x_forwarded_for_singleton_private_address  r?   z;IPv4TestCase.test_x_forwarded_for_singleton_private_addressc                 C   rE   )Nr2   r   rO   r   r   r   r   r   .test_bad_x_forwarded_for_fallback_on_x_real_ip  r?   z;IPv4TestCase.test_bad_x_forwarded_for_fallback_on_x_real_ipc                 C   rE   Nr4   r   rO   r   r   r   r   r   0test_empty_x_forwarded_for_fallback_on_x_real_ip  r?   z=IPv4TestCase.test_empty_x_forwarded_for_fallback_on_x_real_ipc                 C   rE   r\   r   r   r   r   r   Btest_empty_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addr   r?   zOIPv4TestCase.test_empty_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addrc                 C   rE   r\   r   r   r   r   r   Dtest_empty_x_forwarded_for_private_x_real_ip_fallback_on_remote_addr(  r?   zQIPv4TestCase.test_empty_x_forwarded_for_private_x_real_ip_fallback_on_remote_addrc                 C   r=   )Nr;   r4   rO   r   r   r   r   r   "test_private_x_forward_for_ip_addr0  r?   z/IPv4TestCase.test_private_x_forward_for_ip_addrc                 C   rL   )Nr(   r   X-FORWARDED-FORzREMOTE-ADDRr   r   r   r   r   2test_x_forwarded_for_singleton_hyphen_as_delimiter8  r?   z?IPv4TestCase.test_x_forwarded_for_singleton_hyphen_as_delimiterN)$__name__
__module____qualname____doc__r   r    r#   r)   r+   r-   r.   r1   r3   r5   r7   r9   r<   r>   rB   rD   rI   rK   rM   rQ   rR   rU   rW   rX   rY   rZ   r[   r]   r^   r_   r`   rc   r   r   r   r   r   5   sD    												r   c                   @   sh   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )IPv4TrustedProxiesTestCase!Trusted Proxies - IP address Testc                 C   r	   r
   r   get_trusted_ipr   r   r   r   r   r   D  r   z)IPv4TrustedProxiesTestCase.test_meta_nonec                 C   "   ddi}t |}| |d d S )Nr   z0198.84.193.157, 177.139.200.139, 177.139.233.100r   r   rk   r   r   r   r   r   'test_http_x_forwarded_for_conf_settingsJ  s   
zBIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_conf_settingsc                 C   $   ddi}t j|g d}| | d S )Nr   0198.84.193.157, 177.139.200.139, 177.139.233.139r   rj   r   r   r   r   "test_http_x_forwarded_for_no_proxyR     z=IPv4TrustedProxiesTestCase.test_http_x_forwarded_for_no_proxyc                 C   (   ddi}t j|dgd}| |d d S )Nr   rp   r(   r   r   rm   r   r   r   r   &test_http_x_forwarded_for_single_proxyY     zAIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_single_proxyc                 C   s*   ddi}t j|ddgd}| |d d S )Nr   z0177.139.233.139, 177.139.200.139, 198.84.193.157Tr(   )r'   r   r   rm   r   r   r   r   6test_http_x_forwarded_for_single_proxy_with_right_most`     zQIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_single_proxy_with_right_mostc                 C   s*   ddi}t j|ddgd}| |d d S )Nr   rp   z177.139.233.138r(   r   r   rm   r   r   r   r   %test_http_x_forwarded_for_multi_proxyg  rw   z@IPv4TrustedProxiesTestCase.test_http_x_forwarded_for_multi_proxyc                 C   rs   )Nr   rp   z177.139.233r   r   rm   r   r   r   r   /test_http_x_forwarded_for_all_proxies_in_subnetn  ru   zJIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_all_proxies_in_subnetc                 C   rs   )Nr   rp   z177.139r   r   rm   r   r   r   r   1test_http_x_forwarded_for_all_proxies_in_subnet_2u  ru   zLIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_all_proxies_in_subnet_2c                 C   rs   )NrP   rp   r(   r   r   rm   r   r   r   r   !test_x_forwarded_for_single_proxy|  ru   z<IPv4TrustedProxiesTestCase.test_x_forwarded_for_single_proxyc                 C   rs   )Nrb   rp   r(   r   r   rm   r   r   r   r   )test_x_forwarded_for_single_proxy_hyphens  ru   zDIPv4TrustedProxiesTestCase.test_x_forwarded_for_single_proxy_hyphensc                 C   s*   ddd}t j|dgd}| |d d S )Nz0198.84.193.156, 177.139.200.139, 177.139.233.139rp   )r   rP   r(   r   z198.84.193.156rm   r   r   r   r   8test_http_x_forwarded_for_and_x_forward_for_single_proxy  s
   zSIPv4TrustedProxiesTestCase.test_http_x_forwarded_for_and_x_forward_for_single_proxyN)rd   re   rf   rg   r   rn   rq   rt   rv   rx   ry   rz   r{   r|   r}   r   r   r   r   rh   A  s    rh   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6S )7IPv6TestCaser   c                 C   &   dddd}t |}| |d d S )N/3ffe:1900:4545:3:200:f8ff:fe21:67cf, 74dc::02ba
74dc::02bar   #3ffe:1900:4545:3:200:f8ff:fe21:67cfr   r   r   r   r   r      r!   z/IPv6TestCase.test_http_x_forwarded_for_multiplec                 C   r   )Nunknown, ::1/128, 74dc::02bar   r   r   r   r   r   r   r   r-     r!   z;IPv6TestCase.test_http_x_forwarded_for_multiple_bad_addressc                 C   s&   dddd}t |}| |d d S )Nr   r   r   r   r   r   r   r   r.     r!   z0IPv6TestCase.test_http_x_forwarded_for_singletonc                 C   r/   )N::1/128r   r   r   r   r   r   r   r   r1     r!   z@IPv6TestCase.test_http_x_forwarded_for_singleton_private_addressc                 C   r/   )Nunknown ::1/128r   r   r   r   r   r   r   r   r3     r!   z@IPv6TestCase.test_bad_http_x_forwarded_for_fallback_on_x_real_ipc                 C   r/   )Nr4   r   r   r   r   r   r   r   r   r5     r!   zBIPv6TestCase.test_empty_http_x_forwarded_for_fallback_on_x_real_ipc                 C   r6   )Nr4   r   r   r   r   r   r   r   r7     r!   zTIPv6TestCase.test_empty_http_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addrc                 C   r8   )Nr4   r   r   r   r   r   r   r   r   r9     r!   zVIPv6TestCase.test_empty_http_x_forwarded_for_private_x_real_ip_fallback_on_remote_addrc                 C   r:   )Nr   r4   r   r   r   r   r   r   r<     r!   z4IPv6TestCase.test_private_http_x_forward_for_ip_addrc                 C   s&   dddd}t |}| |d  d S Nr4   r   r   r   r   r   r   r    test_private_real_ip_for_ip_addr  r!   z-IPv6TestCase.test_private_real_ip_for_ip_addrc                 C   s&   dddd}t |}| |d  d S r   r   r   r   r   r   r>     r!   z1IPv6TestCase.test_private_remote_addr_for_ip_addrc                 C   s$   ddd}t |}| |d d S )Nr   rF   r   r   r   r   r   rB     r?   z%IPv6TestCase.test_missing_x_forwardedc                 C   r@   )Nr   r   r   r   r   r   r   rD     rC   z5IPv6TestCase.test_missing_x_forwarded_missing_real_ipc                 C   rl   )Nr   z
74DC::02BAr   r   r   r   r   r   1test_missing_x_forwarded_missing_real_ip_mix_case  rC   z>IPv6TestCase.test_missing_x_forwarded_missing_real_ip_mix_casec                 C   s"   ddi}t |}| |d  d S )Nr   
fe80::02bar   r   r   r   r   test_private_remote_address  rC   z(IPv6TestCase.test_private_remote_addressc                 C   rE   )Nz::1r   rF   rG   r   r   r   r   rI     r?   z&IPv6TestCase.test_best_matched_real_ipc                 C   rN   )Nr   r   rO   r   r   r   r   r   r   rQ     r?   z*IPv6TestCase.test_x_forwarded_for_multiplec                 C   rN   )Nr   r   rO   r   r   r   r   r   r   rX   &  r?   z6IPv6TestCase.test_x_forwarded_for_multiple_bad_addressc                 C   rL   )Nr   r   rO   r   r   r   r   r   rY   .  r?   z+IPv6TestCase.test_x_forwarded_for_singletonc                 C   r/   )Nr   r   r   )rP   r   r   r   r   r   r   r   rZ   6  r!   z;IPv6TestCase.test_x_forwarded_for_singleton_private_addressc                 C   rE   )Nr   r   rO   r   r   r   r   r   r[   ?  r?   z;IPv6TestCase.test_bad_x_forwarded_for_fallback_on_x_real_ipc                 C   rE   )Nr4   r   rO   r   r   r   r   r   r]   G  r?   z=IPv6TestCase.test_empty_x_forwarded_for_fallback_on_x_real_ipc                 C   rE   Nr4   r   rO   r   r   r   r   r   r^   O  r?   zOIPv6TestCase.test_empty_x_forwarded_for_empty_x_real_ip_fallback_on_remote_addrc                 C   rE   r   r   r   r   r   r   r_   W  r?   zQIPv6TestCase.test_empty_x_forwarded_for_private_x_real_ip_fallback_on_remote_addrc                 C   r=   )Nr   r4   rO   r   r   r   r   r   r`   _  r?   z/IPv6TestCase.test_private_x_forward_for_ip_addrc                 C   rL   )Nr   r   ra   r   r   r   r   r   rc   g  r?   z?IPv6TestCase.test_x_forwarded_for_singleton_hyphen_as_delimiterN)rd   re   rf   rg   r    r-   r.   r1   r3   r5   r7   r9   r<   r   r>   rB   rD   r   r   rI   rQ   rX   rY   rZ   r[   r]   r^   r_   r`   rc   r   r   r   r   r~     s8    												r~   c                   @   s    e Zd ZdZdd Zdd ZdS )IPv6TrustedProxiesTestCaseri   c                 C   ro   )Nr   r   r   rj   r   r   r   r   rq   s  rr   z=IPv6TrustedProxiesTestCase.test_http_x_forwarded_for_no_proxyc                 C   rs   )Nr   r   r   r   r   rm   r   r   r   r   rt   z  ru   zAIPv6TrustedProxiesTestCase.test_http_x_forwarded_for_single_proxyN)rd   re   rf   rg   rq   rt   r   r   r   r   r   p  s    r   N)	unittestr   spyne.util.addressr   r   r   rh   r~   r   r   r   r   r   <module>   s   *  R ^