
    1                        S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SK	r	S SK
JrJrJrJrJrJrJr  S SKJrJrJr  S SKJr  S SKJr  S S	KJr  S S
KJrJr  \R<                  (       a  S SKJ r    " S S5      r!g)    )annotationsN)ResponseNotReady)mock)RECENT_DATECertificateErrorHTTPConnectionHTTPSConnection_match_hostname_url_from_connection_wrap_proxy_error)	HTTPError
ProxyErrorSSLError)ssl_)SKIP_HEADER)r   )_dnsname_matchmatch_hostname)_TYPE_PEER_CERT_RET_DICTc                     \ rS rSrSrS-S jrS-S jrS-S jrS-S jrS-S jr	S-S jr
S-S	 jrS-S
 jrS-S jrS-S jrS-S jrS-S jrS-S jr\R&                  R)                  SS// SQ5            S.S j5       rS-S jrS-S jrS-S jrS-S jrS-S jr\R&                  R)                  SSS/5      S/S j5       rS-S jrS-S jrS-S jrS-S  jr\R&                  R)                  S!/ S"Q5      \R&                  R)                  S#/ S$Q5      \R&                  R)                  S%/ S&Q5      \R&                  R)                  S'S(S)/5                S0S* j5       5       5       5       r S+r!g,)1TestConnection    zJ
Tests in this suite should not make any network requests or connections.
c                    S nSn[         R                  " [        5         [        X5        S S S 5        g ! , (       d  f       g = fNfoopytestraises
ValueErrorr
   selfcertasserted_hostnames      ;platform/gsutil/third_party/urllib3/test/test_connection.pytest_match_hostname_no_cert*TestConnection.test_match_hostname_no_cert%   s-    !]]:&D4 '&&	   4
Ac                    0 nSn[         R                  " [        5         [        X5        S S S 5        g ! , (       d  f       g = fr   r   r   s      r#   test_match_hostname_empty_cert-TestConnection.test_match_hostname_empty_cert+   s-    )+!]]:&D4 '&&r&   c                &    SS0nSn[        X5        g )NsubjectAltName)DNSr   r   r
   r   s      r#   test_match_hostname_match(TestConnection.test_match_hostname_match1   s    *:<M)N!0    c                &   SS0nSn [         R                  " S5       n[        X5        S S S 5        g ! , (       d  f       g = f! [         aB  nS[	        U5      ;   d   eWR                  SSSS05        UR                  U:X  d   e S nAg S nAff = f)Nr+   r,   barurllib3.connection.log.warningz"hostname 'bar' doesn't match 'foo'@Certificate did not match expected hostname: %s. Certificate: %sr   patchr
   r   strassert_called_once_with
_peer_certr    r!   r"   mock_loges        r#   test_match_hostname_mismatch+TestConnection.test_match_hostname_mismatch6   s    *:<M)N!
	(<=8 >== 	(73q6AAA,,R!#45
 <<4'''	(0   A 3A 
AA A 
B8BBc                &   SS0nSn [         R                  " S5       n[        X5        S S S 5        g ! , (       d  f       g = f! [         aB  nS[	        U5      ;   d   eWR                  SSSS05        UR                  U:X  d   e S nAg S nAff = f)Nr+   ))r-    r3   r4   zhostname 'bar' doesn't match ''r5   r6   r;   s        r#   test_match_hostname_no_dns)TestConnection.test_match_hostname_no_dnsE   s    *:N)K!
	(<=8 >== 	(4A>>>,,R!>2
 <<4'''	(r@   c                &    SS0nSn[        X5        g )Nr+   ))r-   *r   r.   r   s      r#   &test_match_hostname_startwith_wildcard5TestConnection.test_match_hostname_startwith_wildcardT   s    *:O)L!0r1   c                &    SS0nSn[        X5        g )Nr+   ))r-   xn--p1b6ci4b4b3a*.xn--11b5bs8drJ   r.   r   s      r#   test_match_hostname_dnsname*TestConnection.test_match_hostname_dnsnameY   s    J*
 =0r1   c                &    SS0nSn[        X5        g )Nr+   )r-   zfoo*foobarr.   r   s      r#   $test_match_hostname_include_wildcard3TestConnection.test_match_hostname_include_wildcard`   s    *:<N)O$0r1   c                    SS0nSn[         R                  " [        SS9   [        X5        S S S 5        g ! , (       d  f       g = f)Nr+   )rN   )r-   zfo*r3   zdoesn't match either ofmatch)r   r   r   r
   r   s      r#   /test_match_hostname_more_than_one_dnsname_error>TestConnection.test_match_hostname_more_than_one_dnsname_errore   s<    ?*
 "]]+3LMD4 NMM	   5
Ac                    [         R                  " [        SS9   [        SS5        S S S 5        g ! , (       d  f       g = f)Nz!too many wildcards in certificaterS   zfoo**rO   )r   r   r   r   )r    s    r#   7test_dnsname_match_include_more_than_one_wildcard_errorFTestConnection.test_dnsname_match_include_more_than_one_wildcard_errorm   s)    ]]+3VW7H- XWWs   0
>c                    SS0nSn[         R                  " [        SS9   [        X5        S S S 5        g ! , (       d  f       g = f)Nsubject))
commonNamer   r   z/no appropriate subjectAltName fields were foundrS   )r   r   ImplementationCertificateErrorr   r   s      r#   &test_match_hostname_ignore_common_name5TestConnection.test_match_hostname_ignore_common_nameq   s?    *35P)Q!]]*C
 43	
 
 
rW   c                (    SS0nSn[        XS5        g )Nr\   r]   r   Tr   r   s      r#   %test_match_hostname_check_common_name4TestConnection.test_match_hostname_check_common_namez   s    *35P)Q!t5r1   c                &   SS0nSn [         R                  " S5       n[        X5        S S S 5        g ! , (       d  f       g = f! [         aB  nS[	        U5      ;   d   eWR                  SSSS05        UR                  U:X  d   e S nAg S nAff = f)Nr+   ))
IP Addressz1.1.1.1z1.1.1.2r4   z*hostname '1.1.1.2' doesn't match '1.1.1.1'r5   r6   r;   s        r#   test_match_hostname_ip_address-TestConnection.test_match_hostname_ip_address   s    :*
 &
	(<=8 >== 	(?3q6III,,R!#?@
 <<4'''	(r@   r"   san_ip))z1:2::3:41:2:0:0:0:0:3:4)z1:2:0:0::3:4rk   )z	::0.1.0.2z0:0:0:0:0:0:1:2)z::1%42z0:0:0:0:0:0:0:1)z	::2%ifacez0:0:0:0:0:0:0:2c                (    SSU440n[        X15        g)z;Check that hostname matches follow RFC 9110 rules for IPv6.r+   rg   Nrc   )r    r"   rj   r!   s       r#   #test_match_hostname_ip_address_ipv62TestConnection.test_match_hostname_ip_address_ipv6   s     +;lF=S<U)Vt/r1   c                &   SS0nSn [         R                  " S5       n[        X5        S S S 5        g ! , (       d  f       g = f! [         aB  nS[	        U5      ;   d   eWR                  SSSS05        UR                  U:X  d   e S nAg S nAff = f)Nr+   )rg   z1:2::2:1z1:2::2:2r4   z,hostname '1:2::2:2' doesn't match '1:2::2:1'r5   r6   r;   s        r#   0test_match_hostname_ip_address_ipv6_doesnt_match?TestConnection.test_match_hostname_ip_address_ipv6_doesnt_match   s    ;*
 '
	(<=8 >== 	(ASVKKK,,R!#@A
 <<4'''	(r@   c                    SS0nSn[         R                  " [        5       n[        X5        S S S 5        S[	        WR
                  5      ;   d   eg ! , (       d  f       N*= f)Nr+   ))r-   	localhost)rg   rt   z[localhost]zGhostname '[localhost]' doesn't match either of 'localhost', 'localhost')r   r   r   r
   r8   value)r    r!   r"   r=   s       r#   2test_match_hostname_dns_with_brackets_doesnt_matchATestConnection.test_match_hostname_dns_with_brackets_doesnt_match   s^     *
 *]]+,D4 - V177|	
 -,s   A
Ac                &    SS0nSn[        X5        g )Nr+   rp   z
[1:2::2:1]r.   r   s      r#   ,test_match_hostname_ip_address_ipv6_brackets;TestConnection.test_match_hostname_ip_address_ipv6_brackets   s    ;*
 )0r1   c                    [         R                  " SS9n[        [         R                   R                  5       U-
  R	                  5       :  d   eg )Ni  )days)datetime	timedeltar   todaydate)r    	two_yearss     r#   test_recent_dateTestConnection.test_recent_date   s?    
 &&G4	h//557)CIIKKKKr1   c                |    [        SSS9nUR                  [        R                  [        R                  S4/:X  d   eg )Nznot.a.real.host  port   )r	   socket_optionssocketIPPROTO_TCPTCP_NODELAYr    conns     r#   +test_HTTPSConnection_default_socket_options:TestConnection.test_HTTPSConnection_default_socket_options   s:    0s;""(:(:F<N<NPQ'R&SSSSr1   zproxy_scheme, err_part)httpzUnable to connect to proxy)httpszMUnable to connect to proxy. Your proxy appears to only use HTTP and not HTTPSc                    [        [        S5      U5      n[        U[        5      SL d   eX#R                  S   ;   d   eg )Nzunknown protocolTr   )r   r   
isinstancer   args)r    proxy_schemeerr_partnew_errs       r#   test_wrap_proxy_error$TestConnection.test_wrap_proxy_error   s?     $I.@$A<P':.$666<<?***r1   c                D    [        SSS9nSnSU 3[        X5      :X  d   eg )N
google.comP   r   zpath?query=foozhttp://google.com:80/)r   r   )r    r   paths      r#   test_url_from_pool!TestConnection.test_url_from_pool   s.    l4&tf-1Ed1QQQQr1   c                    [        SSS9n[        R                  " [        5         UR	                  5         S S S 5        g ! , (       d  f       g = f)Nr   r   r   )r   r   r   r   getresponser   s     r#   (test_getresponse_requires_reponseoptions7TestConnection.test_getresponse_requires_reponseoptions   s5    l4 ]]+, -,,s	   ?
Ac                   [         R                  " [        R                  5      nSUR                  R
                  R                  l        [        SSSUS9n[         R                  R                  US5         [        R                  " [        5         UR                  5         S S S 5        S S S 5        UR                  R
                  R                  R                  5         g ! , (       d  f       NE= f! , (       d  f       NN= f)Ns	   fake certr   r   z;AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA)r   assert_fingerprintssl_context	_new_conn)r   create_autospecr   
SSLContextwrap_socketreturn_valuegetpeercertr	   r7   objectr   r   r   connectcloser9   r    contextr   s      r#   %test_assert_fingerprint_closes_socket4TestConnection.test_assert_fingerprint_closes_socket   s    &&t7DP((44A\	
 ZZt[1x( ) 2 	((..FFH )( 21s$   6C2C!"C2!
C/	+C22
D c                
   [         R                  " [        R                  5      nSS0UR                  R
                  R                  l        [        SSSUS9n[         R                  R                  US5         [        R                  " [        5         UR                  5         S S S 5        S S S 5        UR                  R
                  R                  R                  5         g ! , (       d  f       NE= f! , (       d  f       NN= f)Nr+   ))r-   r   r   r   zexample.com)r   assert_hostnamer   r   )r   r   r   r   r   r   r   r	   r7   r   r   r   r_   r   r   r9   r   s      r#   "test_assert_hostname_closes_socket1TestConnection.test_assert_hostname_closes_socket   s    &&t76E
((44A sMw
 ZZt[1=> ? 2 	((..FFH ?> 21s$   8C4C#$C4#
C1	-C44
Daccept_encoding)Accept-Encodingzaccept-encodings   Accept-Encodings   accept-encodingNhost)Hostr   s   Hosts   hostN
user_agent)
User-Agentz
user-agents
   User-Agents
   user-agentNchunkedTFc           	        0 nUb  [         XQ'   Ub  [         XR'   Ub  [         XS'   [        R                  " S5         [        R                  " S5       n[        S5      nUR	                  SSXTS9  S S S 5        S S S 5        0 nWR
                   H  n	U	R                  u  pXU
'   M     Uc	  SU;   d   eOX;  d   eUc	  SU;   d   eOX(;  d   eUc	  S	U;   d   eg X8;  d   eg ! , (       d  f       Nw= f! , (       d  f       N= f)
Nz)urllib3.util.connection.create_connectionz,urllib3.connection._HTTPConnection.putheaderrB   GETz/headers)headersr   r   r   r   )r   r   r7   r   requestcall_args_listr   )r    r   r   r   r   r   http_client_putheaderr   request_headerscallheaderru   s               r#   test_skip_headerTestConnection.test_skip_header  s   , &'2G$'GM!"-G ZZCD>&%b)UJQ	 E )88D IIMF&+F# 9 "$777"999<_,,,...?222444-  EDs#   C0C.C0
C-	)C00
C> N)returnNone)r"   r8   rj   r8   r   r   )r   r8   r   r8   r   r   )
r   
str | Noner   r   r   r   r   boolr   r   )"__name__
__module____qualname____firstlineno____doc__r$   r(   r/   r>   rC   rG   rK   rP   rU   rY   r`   rd   rh   r   markparametrizerm   rq   rv   ry   r   r   r   r   r   r   r   r   __static_attributes__r   r1   r#   r   r       s   551
((1
11
5.46
(" [[	h'	
	0!$0.10	0	0("
1LT [[ 2	
	+	+
RII [[	
	 [[V%MN[[V [[Yu6(5#(5 (5 	(5
 (5 
(5 7 O	(5r1   r   )"
__future__r   r}   r   typinghttp.clientr   unittestr   r   urllib3.connectionr   r   r   r	   r
   r   r   urllib3.exceptionsr   r   r   urllib3.utilr   urllib3.util.requestr   urllib3.util.ssl_match_hostnamer_   r   r   TYPE_CHECKINGurllib3.util.ssl_r   r   r   r1   r#   <module>r      sZ    "    (     ? >  , K	:e5 e5r1   