Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyc

ó
ê=Nc@sõdZddlZddlZddlmZddlmZddlmZm	Z	m
Z
ddlmZddl
mZdejfd	„ƒYZd
dd„ƒYZdejfd
„ƒYZdejfd„ƒYZdejfd„ƒYZdS(s_
Tests for L{twisted.protocol.socks}, an implementation of the SOCKSv4 and
SOCKSv4a protocols.
iÿÿÿÿN(tunittest(t
proto_helpers(tdefertaddresstreactor(tDNSLookupError(tsockstStringTCPTransportcBs/eZeZdZd„Zd„Zd„ZRS(cCs|jS(N(tpeer(tself((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytgetPeerscCstjdddƒS(NtTCPs2.3.4.5i*(RtIPv4Address(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytgetHostscCs
t|_dS(N(tTruetstringTCPTransport_closing(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytloseConnectionsN(	t__name__t
__module__tFalseRtNoneRR
R
R(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRs
		tFakeResolverReactorcBs eZdZd„Zd„ZRS(sP
    Bare-bones reactor with deterministic behavior for the resolve method.
    cCs
||_dS(sÃ
        @type names: C{dict} containing C{str} keys and C{str} values.
        @param names: A hostname to IP address mapping. The IP addresses are
            stringified dotted quads.
        N(tnames(R	R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyt__init__%scCsDytj|j|ƒSWn%tk
r?tjtd|ƒƒSXdS(sQ
        Resolve a hostname by looking it up in the C{names} dictionary.
        s"FakeResolverReactor couldn't find N(RtsucceedRtKeyErrortfailR(R	thostname((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytresolve.s

(RRt__doc__RR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyR!s		t
SOCKSv4DrivercBs&eZdZdZd„Zd„ZRS(cGsS||Œ}tƒ|_tjd||ƒ|j_|jƒ||_tj|ƒS(NR(	Rt	transportRRRtconnectionMadetdriver_outgoingRR(R	thosttporttklasstargstproto((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytconnectClassAs
	cGs=||Œ}||_|dkr*d}ntjd|fƒS(NiiÒs6.7.8.9(t
driver_listenRR(R	R#R$R%tfactory((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytlistenClassJs
		N(RRRR!R(R'R*(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyR:s		tConnectcBsVeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
RS(	sV
    Tests for SOCKS and SOCKSv4a connect requests using the L{SOCKSv4} protocol.
    cCsEtƒ|_tƒ|j_|jjƒtidd6ƒ|j_dS(Ns	127.0.0.1t	localhost(RtsockRRR RR(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pytsetUpXs
cCs5|jj}|dk	r1|j|jjdƒndS(Ns-Outgoing SOCKS connections need to be closed.(R-R!Rtassert_RR(R	toutgoing((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttearDown_scCs*|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|j	|tjddd	dƒtjdƒƒ|j
|jjjƒ|j
|jjdk	ƒ|jjd
ƒ|j	|jjjjƒd
ƒ|jjjdƒ|j	|jjjƒdƒ|jjdƒdS(
Ns!BBHiii"s1.2.3.4tfooBARtiiZshello, worldshi theresfake reason(R-tdataReceivedtstructtpacktsockett	inet_atonRtvaluetcleartassertEqualR/RR!RtconnectionLost(R	tsent((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_simplefs	.	cCs=tjddddƒtjdƒdd}x|D]}|jj|ƒq4W|jjjƒ}|jjjƒ|j	|tjddd	dƒtjd
ƒƒ|j
|jjjƒ|j|jj
dƒ|jjdƒ|j	|jj
jjƒdƒ|jj
jdƒ|j	|jjjƒdƒ|jjd
ƒdS(su
        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}
        s!BBHiii"s0.0.0.1tfooBAZt
localhostiiZs	127.0.0.1shello, worldshi theresfake reasonN(R5R6R7R8R-R4RR9R:R;tassertFalseRtassertNotIdenticalR!RR<(R	t
clientRequesttbyteR=((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyt test_socks4aSuccessfulResolution€s -
&cCs¿tjddddƒtjdƒdd}x|D]}|jj|ƒq4W|jjjƒ}|j|tjddd	dƒtjd
ƒƒ|j	|jjj
ƒ|j|jjdƒdS(s‹
        Failed hostname resolution on a SOCKSv4a packet results in a 91 error
        response and the connection getting closed.
        s!BBHiii"s0.0.0.1R?tfailinghostii[s0.0.0.0N(R5R6R7R8R-R4RR9R;t
assertTrueRtassertIdenticalR!R(R	RCRDR=((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_socks4aFailedResolution¯s
-
&cCs±d„|j_|jjtjddddƒtjdƒddƒ|j|jjj	ƒtjdd	d
d	ƒtjdƒƒ|j
|jjjƒ|j|jj
dƒdS(NcSsdS(Ni((tcodetserverR#tuser((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyt<lambda>Íss!BBHiii’s10.2.3.4R2R3ii[s0.0.0.0(R-t	authorizeR4R5R6R7R8R;RR9R/RRHR!R(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_accessDeniedÌs	.cCs²|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|jjdƒ|j	|jj
jjƒdƒ|jj
jjƒ|jj
jd	ƒdS(
Ns!BBHiii"s1.2.3.4R2R3shello, worldsfake reason(
R-R4R5R6R7R8RR9R:R;R!RR<(R	R=((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_eofRemoteÚs	.cCsœ|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|jjdƒ|j	|jj
jjƒdƒ|jjd	ƒdS(
Ns!BBHiii"s1.2.3.4R2R3shello, worldsfake reason(R-R4R5R6R7R8RR9R:R;R!R<(R	R=((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyt
test_eofLocalís	.(RRRR.R1R>RERIRORPRQ(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyR+Ts				/			tBindcBsVeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
RS(	sS
    Tests for SOCKS and SOCKSv4a bind requests using the L{SOCKSv4} protocol.
    cCsEtƒ|_tƒ|j_|jjƒtidd6ƒ|j_dS(Ns	127.0.0.1R,(RR-RRR RR(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyR.s
cCsÁ|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|j	|tjddd	d
ƒtjdƒƒ|j
|jjjƒ|j
|jjdk	ƒ|jjjdƒ}|j|dƒtƒ|_|jƒ|jjjƒ}|jjjƒ|j	|tjddd	dƒtjd
ƒƒ|j
|jjjƒ|jjdƒ|j	|jjƒdƒ|jdƒ|j	|jjjƒdƒ|jjdƒdS(Ns!BBHiii"s1.2.3.4R2R3iiZiÒs6.7.8.9iás0.0.0.0shello, worldshi theresfake reason(s1.2.3.4iá(R-R4R5R6R7R8RR9R:R;R/RR(Rt
buildProtocolRBRR R<(R	R=tincoming((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyR>s2	.	
	
cCsÖtjddddƒtjdƒdd}x|D]}|jj|ƒq4W|jjjƒ}|jjjƒ|j	|tjddd	d
ƒtjdƒƒ|j
|jjjƒ|j|jj
dƒ|jj
jdƒ}|j|dƒtƒ|_|jƒ|jjjƒ}|jjjƒ|j	|tjddd	dƒtjdƒƒ|j|jjjdƒ|jjdƒ|j	|jjƒdƒ|jdƒ|j	|jjjƒdƒ|jjdƒdS(su
        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}
        s!BBHiii"s0.0.0.1R?R@iiZiÒs6.7.8.9s	127.0.0.1iás0.0.0.0shi theresfake reasonN(s	127.0.0.1iá(R5R6R7R8R-R4RR9R:R;RARRBR(RRSRR R<(R	RCRDR=RT((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_socks4a9s4-
&
	
cCs¿tjddddƒtjdƒdd}x|D]}|jj|ƒq4W|jjjƒ}|j|tjddd	dƒtjd
ƒƒ|j	|jjj
ƒ|j|jjdƒdS(s‹
        Failed hostname resolution on a SOCKSv4a packet results in a 91 error
        response and the connection getting closed.
        s!BBHiii"s0.0.0.1R?RFii[s0.0.0.0N(R5R6R7R8R-R4RR9R;RGRRHR!R(R	RCRDR=((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRIus
-
&cCs±d„|j_|jjtjddddƒtjdƒddƒ|j|jjj	ƒtjdd	d
d	ƒtjdƒƒ|j
|jjjƒ|j|jj
dƒdS(NcSsdS(Ni((RJRKR#RL((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRM“ss!BBHiii’s10.2.3.4R2R3ii[s0.0.0.0(R-RNR4R5R6R7R8R;RR9R/RRHR(R(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRO’s	.cCsC|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|jj	j
dƒ}|j|dƒt
ƒ|_|jƒ|jjjƒ}|jjjƒ|j|tjdd	d
d	ƒtjdƒƒ|j|jjjƒ|jjdƒ|j|jjƒdƒ|jjƒ|jd
ƒdS(Ns!BBHiii"s1.2.3.4R2R3iáiiZs0.0.0.0shello, worldsfake reason(s1.2.3.4iá(R-R4R5R6R7R8RR9R:R(RSRBRRR R;R/RRR<(R	R=RT((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRPŸs&	.
	
cCs9|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|jj	j
dƒ}|j|dƒt
ƒ|_|jƒ|jjjƒ}|jjjƒ|j|tjdd	d
d	ƒtjdƒƒ|j|jjjƒ|jjdƒ|j|jjƒdƒ|jjd
ƒdS(Ns!BBHiii"s1.2.3.4R2R3iáiiZs0.0.0.0shello, worldsfake reason(s1.2.3.4iá(R-R4R5R6R7R8RR9R:R(RSRBRRR R;R/RR<(R	R=RT((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRQ¿s$	.
	cCsé|jjtjddddƒtjdƒddƒ|jjjƒ}|jjjƒ|jj	j
d
ƒ}|j|dƒ|jjjƒ}|jjjƒ|j
|tjdd
dd
ƒtjdƒƒ|j|jjjƒdS(Ns!BBHiii"s1.2.3.4R2R3s1.6.6.6išii[s0.0.0.0(s1.6.6.6iš(R-R4R5R6R7R8RR9R:R(RSRHRR;R/R(R	R=RT((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyttest_badSourceÞs	.	(RRRR.R>RURIRORPRQRV(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyRRs	
	(	<		
	 	((RR5R7t
twisted.trialRttwisted.testRttwisted.internetRRRttwisted.internet.errorRttwisted.protocolsRtStringTransportRRtSOCKSv4RtTestCaseR+RR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_socks.pyt<module>s¬