o
    M,h\G                     @   s   d dl Z d dlZd dlmZmZmZmZ d dlmZ 	 G dd dej	Z
G dd dej	ZG dd	 d	ej	Zed
kr@e  dS dS )    N)_is_address_in_network_is_no_proxy_hostget_proxy_info	parse_url)WebSocketProxyExceptionc                   @   s   e Zd Zdd Zdd ZdS )UrlTestc                 C   sT   |  tdd |  tdd | tdd |  tdd | tdd d S )N	127.0.0.1127.0.0.0/8	127.1.0.1127.0.0.0/242001:db8::12001:db8::/642001:db8:1::1)
assertTruer   assertFalseself r   d/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/websocket/tests/test_url.pytest_address_in_network#   s
   zUrlTest.test_address_in_networkc                 C   s  t d}| |d d | |d d | |d d | |d d	 t d
}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d t d}| |d d | |d d | |d d | |d d | tt d t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d	 t d}| |d d | |d d | |d d | |d d t d}| |d d | |d d | |d d | |d d d S )Nzws://www.example.com/rr   zwww.example.com   P      z/r   Fzws://www.example.com/r/z/r/zws://www.example.com//zws://www.example.comzws://www.example.com:8080/ri  zws://www.example.com:8080/zws://www.example.com:8080zwss://www.example.com:8080/rTz&wss://www.example.com:8080/r?key=valuez/r?key=valuezhttp://www.example.com/rzws://[2a03:4000:123:83::3]/rz2a03:4000:123:83::3z!ws://[2a03:4000:123:83::3]:8080/rzwss://[2a03:4000:123:83::3]/ri  z"wss://[2a03:4000:123:83::3]:8080/r)r   assertEqualassertRaises
ValueError)r   pr   r   r   test_parse_url*   s   zUrlTest.test_parse_urlN)__name__
__module____qualname__r   r   r   r   r   r   r   "   s    r   c                   @   sD   e 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S )IsNoProxyHostTestc                 C   s*   t jdd | _dt jv rt jd= d S d S Nno_proxy)osenvirongetr%   r   r   r   r   setUp}   s   
zIsNoProxyHostTest.setUpc                 C   s0   | j r| j tjd< d S dtjv rtjd= d S d S r$   )r%   r&   r'   r   r   r   r   tearDown   s
   
zIsNoProxyHostTest.tearDownc                 C   s   |  tddg |  tddg | tddg | tddg |  tdddg dtjd< |  tdd  |  tdd  dtjd< |  tdd  d S )Nany.websocket.org*z192.168.0.1192.168.1.1other.websocket.orgr%   zother.websocket.org, *r   r   r   r&   r'   r   r   r   r   test_match_all   s   


z IsNoProxyHostTest.test_match_allc                 C   s   |  tddg | tddg |  tdddg | tdddg dtjd< |  tdd  | tdd  dtjd< |  tdd  | tdd  d S )Nr   	127.0.0.2r.   r%   zother.websocket.org, 127.0.0.1r/   r   r   r   r   test_ip_address   s   

z!IsNoProxyHostTest.test_ip_addressc                 C   s   |  tddg |  tddg | tddg |  tddg | tddg d	tjd
< |  tdd  |  tdd  |  tdd  | tdd  dtjd
< | tdd  | tdd  d S )Nr   r	   r1   r
   r   r   r   r   z127.0.0.0/8,2001:db8::/64r%   z127.0.0.0/24,2001:db8::/64r/   r   r   r   r   test_ip_address_in_range   s   

z*IsNoProxyHostTest.test_ip_address_in_rangec                 C   s   |  tddg |  tdddg | tddg dtjd< |  tdd  | tdd  dtjd< |  tdd  d S )Nmy.websocket.orgr.   r%   z%other.websocket.org, my.websocket.orgr/   r   r   r   r   test_hostname_match   s   

z%IsNoProxyHostTest.test_hostname_matchc                 C   s   |  tddg |  tddg |  tdddg | tddg dtjd< |  tdd  |  tdd  | tdd  dtjd< |  tdd  d S )Nr+   z.websocket.orgzmy.other.websocket.orgr4   zany.websocket.comr%   z my.websocket.org, .websocket.orgr/   r   r   r   r   test_hostname_match_domain   s   

z,IsNoProxyHostTest.test_hostname_match_domainN)
r    r!   r"   r)   r*   r0   r2   r3   r5   r6   r   r   r   r   r#   |   s    r#   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ProxyInfoTestc                 C   sn   t jdd | _t jdd | _t jdd | _dt jv r!t jd= dt jv r*t jd= dt jv r5t jd= d S d S N
http_proxyhttps_proxyr%   )r&   r'   r(   r9   r:   r%   r   r   r   r   r)      s   


zProxyInfoTest.setUpc                 C   s|   | j r
| j tjd< n	dtjv rtjd= | jr| jtjd< n	dtjv r&tjd= | jr1| jtjd< d S dtjv r<tjd= d S d S r8   )r9   r&   r'   r:   r%   r   r   r   r   r*      s   


zProxyInfoTest.tearDownc              
   C   s  | j ttdddd | tdddddd | tdddddd | tdddd	d
dd | tddddd
dd | tddddd
dd | tddddd
dd | tdddddgd
dd | tdddddgd
dd | tdddddgdd d S )Necho.websocket.eventsF	localhost)
proxy_host8  )r=   
proxy_portr<   r>   NT)#  ab)r=   r?   
proxy_auth)r<   rA   rB   r<   r>   rB   ="  )r<   rG   rB   zexample.com)r=   r?   r%   rE   Nr   Nz.websocket.events)r=   r?   r%   )r   r   r   r   r   r   r   r   test_proxy_from_args   s   


z"ProxyInfoTest.test_proxy_from_argsc                 C   s|  dt jd< | tddd dt jd< | tddd dt jd< dt jd	< | tddd dt jd< d
t jd	< | tddd dt jd< dt jd	< | tddd dt jd< d
t jd	< | tddd dt jd< dt jd	< | tddd | tddd dt jd< d
t jd	< | tddd | tddd dt jd< dt jd	< | tddd | tddd dt jd< dt jd	< | tddd | tddd dt jd< | tddd dt jd< | tddd dt jd< dt jd	< | tddd dt jd< dt jd	< | tddd dt jd< dt jd	< | tddd dt jd< dt jd	< | tddd dt jd< dt jd	< | tddd dt jd< dt jd	< dt jd< | tddd dt jd< dt jd	< dt jd< | tddd dt jd< dt jd	< dt jd< | tddd dt jd< dt jd	< d t jd< | td!dd | td"dd d S )#Nzhttp://localhost/r9   r;   F)r<   NNzhttp://localhost:3128/r@   zhttp://localhost2/r:   zhttp://localhost2:3128/T)
localhost2NN)rJ   r>   N rH   zhttp://a:b@localhost/)r<   NrB   zhttp://a:b@localhost:3128/rF   zhttp://a:b@localhost2/zhttp://a:b@localhost2:3128/)rJ   NrB   )rJ   r>   rB   z4http://john%40example.com:P%40SSWORD@localhost:3128/z5http://john%40example.com:P%40SSWORD@localhost2:3128/)rJ   r>   )zjohn@example.comzP@SSWORDzexample1.com,example2.comr%   zexample.1.comz0example1.com,example2.com, echo.websocket.eventsz,example1.com,example2.com, .websocket.eventsz127.0.0.0/8, 192.168.0.0/16r   r-   )r&   r'   r   r   r   r   r   r   test_proxy_from_envR  s   




















































z!ProxyInfoTest.test_proxy_from_envN)r    r!   r"   r)   r*   rI   rL   r   r   r   r   r7      s
    `r7   __main__)r&   unittestwebsocket._urlr   r   r   r   websocket._exceptionsr   TestCaser   r#   r7   r    mainr   r   r   r   <module>   s   ZZ  