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_newcred.pyc


=Nc@sdZddlZddlmZmZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZydd	lmZWnek
rdZnXydd
lmZWnek
rdZnXddlmZdefd
YZdd0dYZde
jfdYZe
jeeede
j fdYZ!de"fdYZ#dd1dYZ$dej%fdYZ&dej%fdYZ'dej%fdYZ(dej%fdYZ)d ej%fd!YZ*d"d2d#YZ+d$d3d%YZ,d&e,fd'YZ-d(e,fd)YZ.d*e,e+ej%fd+YZ/d,e-e+ej%fd-YZ0d.e.e+ej%fd/YZ1dS(4s6
Tests for L{twisted.cred}, now with 30% more starch.
iN(t
implementst	Interface(tunittest(tportaltcheckerstcredentialsterror(t
components(tdefer(tdeferredGeneratortwaitForDeferred(tcrypt(tcallIntoPAM(tpamautht	ITestablecBseZRS((t__name__t
__module__(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRst
TestAvatarcBs#eZdZdZdZRS(cCs||_t|_t|_dS(N(tnametFalsetloggedInt	loggedOut(tselfR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt__init__#s		cCs|jstt|_dS(N(RtAssertionErrortTrue(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pytlogin(scCs
t|_dS(N(RR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pytlogout,s(RRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR"s		tTestablecBseZeeRS((RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR/stIDerivedCredentialscBseZRS((RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR6stDerivedCredentialscBs'eZeeedZdZRS(cCs||_||_dS(N(tusernametpassword(RRR ((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR<s	cCs
||jkS(N(R (RR ((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt
checkPassword@s(RRRRRRR!(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR9s
	t	TestRealmcBs'eZeejdZdZRS(cCs
i|_dS(N(tavatars(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRFscGsc|jj|r"|j|}nt|}||j|<|j|d|d||jfS(Ni(R#thas_keyRRR(RtavatarIdtmindt
interfacestavatar((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt
requestAvatarIs

(RRRRtIRealmRR)(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR"Ds
	tNewCredTestcBs>eZdZdZdZdZdZdZRS(cCsZt}|_tj|}|_tj}|_|jdd|j|dS(Ntbobthello(	R"trealmRtPortalRt'InMemoryUsernamePasswordDatabaseDontUsetcheckertaddUsertregisterChecker(Rtrtptup((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pytsetUpTs
cCsItjtjg}|jj}|j|j|j||dS(N(RtIUsernamePasswordtIUsernameHashedPasswordRtlistCredentialsInterfacestsorttassertEqual(Rtexpectedtgot((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestListCheckers[s


cCsg}g}|jjtjdd|tj|jj|j|rY|dn|d\}}}|j|t|j	|j
|d||f|j	|jj|j	|jj
||j	|jj
dS(NR,R-is%s does not implement %s(RRRtUsernamePasswordRtaddCallbacktappendt
addErrbackR<t
failUnlesst
providedBytoriginalRR(RtltftifacetimplR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestBasicLoginbs
cCsg}g}|jjtdd|tj|jj|j|rV|dn|d\}}}|j|t|j|j	|d||f|j|j
j|j|j
j||j|j
jdS(s
        Login with credentials implementing an interface inheriting from an
        interface registered with a checker (but not itself registered).
        R,R-is%s does not implement %sN(
RRRRRARBRCR<RDRERFRR(RRGRHRIRJR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttest_derivedInterfaceus!

cCshg}|jjtjdd|tjdj|j|j||j	t
j|ddS(NR,th3llocSs|jtjS(N(ttrapRtUnauthorizedLogin(tx((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt<lambda>si(RRRR@RRCRARBRDR<RRO(RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestFailedLogins
cCshg}|jjtjdd|tjdj|j|j||j	t
j|ddS(NtjayR-cSs|jtjS(N(RNRRO(RP((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQsi(RRRR@RRCRARBRDR<RRO(RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestFailedLoginNames
(RRR7R?RKRLRRRT(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR+Ss					tCramMD5CredentialsTestCasecBs#eZdZdZdZRS(cCs2tj}|j}|j||jdS(N(RtCramMD5CredentialstgetChallengeR<(Rtctchal((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestIdempotentChallengescCsMtj}|j}tjd|j|_|j|jddS(Ntsecret(	RRVRWthmactHMACt	hexdigesttresponseRDR!(RRXRY((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestCheckPasswordscCs&tj}|j|jddS(NR[(RRVtfailIfR!(RRX((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestWrongPasswords(RRRZR`Rb(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRUs		tOnDiskDatabaseTestCasecBs;eZd
ddgZdZdZdZd	ZRS(
tuser1tpass1tuser2tpass2tuser3tpass3cCs|j}tj|}t|d}x.|jD]#\}}|jd||fq4W|jxR|jD]G\}}|jt|j	|j
|j|j	|||fqoWdS(Ntws%s:%s
(tmktempRtFilePasswordDBtfiletuserstwritetclosetfailUnlessRaisestKeyErrortgetUsertupperR<(RtdbfiletdbRHtuR5((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestUserLookups
cCs|j}tj|dd}t|d}x.|jD]#\}}|jd||fq:W|jx<|jD]1\}}|j|j|j	||fquWdS(Nt
caseSensitiveiRjs%s:%s
(
RkRRlRmRnRoRpR<RsRt(RRuRvRHRwR5((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestCaseInSensitivitys
c	Cs|j}tj|dd}t|d}x.|jD]#\}}|jd||fq:W|jg|jD]\}}tj||^qu}t	j
g|D]}t	j|j|^q}|j
|jg|jD]\}}|^q|S(NRyiRjs%s:%s
(RkRRlRmRnRoRpRR@Rt
gatherResultst
maybeDeferredtrequestAvatarIdRAR<(	RRuRvRHRwR5tcredsRXtd((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestRequestAvatarIds
.+/c	Cs|j}tj|dd}t|d}x.|jD]#\}}|jd||fq:W|jg|jD]\}}tj||^qu}t	j
g|D]}t	j|j|^q}|j
|jg|jD]\}}|^q|S(NRyiRjs%s:%s
(RkRRlRmRnRoRpRtUsernameHashedPasswordRR{R|R}RAR<(	RRuRvRHRwR5R~RXR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestRequestAvatarId_hasheds
.+/(RdRe(RfRg(RhRi(RRRnRxRzRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRcs				
t$HashedPasswordOnDiskDatabaseTestCasecBskeZdddgZdZdZdZd	Zd
ZdZdZ	e
dkrid
ZnRS(RdReRfRgRhRicCs
t||S(N(R(RRwR5ts((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pythashscCs|j}tj|d|j|_t|d}x;|jD]0\}}|jd|t||d fq@W|j	t
}tj||_
|j
j|jdS(NRRjs%s:%s
i(RkRRlRRvRmRnRoRRpR"RR/tportR3(RRuRHRwR5R4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR7s(
	cCsg|jD]\}}tj||^q
}tjg|D]}|jj|^q;}|j|jg|jD]\}}|^qr|S(N(	RnRR@RR{RvR}RAR<(RRwR5t	goodCredsRXR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestGoodCredentialss../cCsg|jD]\}}tj||^q
}tjg|D]}|jj|dt^q;}|j	d|j	|j
g|jD]\}}|^q|S(NcSs&g|D]\}}}|jj^qS(N(RFR(RPtitaRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQs(RnRR@RR{RRtNoneRRAR<(RRwR5RRXR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestGoodCredentials_logins.	+/cCsg|jD]\}}tj|d^q
}tjg|D]}|jj|dt^q;dt	}|j
|jtj
|S(Nswrong passwordt
consumeErrors(RnRR@RtDeferredListRRRRRRAt_assertFailuresRRO(RRwR5tbadCredsRXR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestBadCredentialss+	1cCsg|jD]+\}}tj|t||d ^q
}tjg|D]}|jj|dt	^qHdt
}|j|jt
j|S(NiR(RnRRRRRRRRRRRARRtUnhandledCredentials(RRwR5thashedCredsRXR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestHashedCredentialss8	1cGs;x4|D],\}}|j|tj|j|qWdS(N(R<RtFAILURERNR(RtfailurestexpectedFailurestflagtfailure((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRsscrypt module not available(suser1spass1(suser2spass2(suser3spass3N(
RRRnRR7RRRRRRRtskip(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRs								t"PluggableAuthenticationModulesTestcBsVeZdZdZdZdZdZdZdZe	sTdZ
nRS(cCstj|_|jt_dS(su
        Replace L{pamauth.callIntoPAM} with a dummy implementation with
        easily-controlled behavior.
        N(R
Rt_oldCallIntoPAM(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR7'scCs|jt_dS(sG
        Restore the original value of L{pamauth.callIntoPAM}.
        N(RR
R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttearDown0scCs|dkr"tjd|n|dkrDtjd|ndddg}||}|dddgkrtjdt|ndS(NtTwistedsbad service: %sttestusersbad username: %sitPasswordisMessage w/ InputisMessage w/o InputR itentrytsbad conversion: %s(iR(isMessage w/ Input(isMessage w/o Input(spasswordi(sentryi(Ri(RROtrepr(Rtservicetusertconvt	questionstreplies((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR7s	csfd}|S(Ncs0tjg|D]\}}|df^q
S(Ni(Rtsucceed(Rtttq(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRKs((RRR((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt	_makeConvJscCshtj}|jidd6dd6dd6}tjd|}|j|}|j|jd|S(NR iRiRiR(Rt%PluggableAuthenticationModulesCheckerRRtPluggableAuthenticationModulesR}RAR<(RRvRR~R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyROs$		cCshtj}|jidd6dd6dd6}tjd|}|j|}|j|tj|S(NRiiiR(	RRRRRR}t
assertFailureRRO(RRvRR~R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRXs$		cCshtj}|jidd6dd6dd6}tjd|}|j|}|j|tj|S(NR iRiRitbaduser(	RRRRRR}RRRO(RRvRR~R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestBadUsernameas$		sCan't run without PyPAM(RRR7RRRRRRR
R(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR%s											t
CheckersMixincBs2eZdZeeZdZeeZRS(ccshxa|jD]S}xJ|jD]<\}}t|j|}|V|j|j|q Wq
WdS(N(tgetCheckerstgetGoodCredentialstwFDR}R<t	getResult(RtchktcredR%R4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestPositivens
ccsbx[|jD]M}xD|jD]6}t|j|}|V|jtj|jq Wq
WdS(N(RtgetBadCredentialsRR}tassertRaisesRROR(RRRR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyttestNegativevs
(RRRtdGR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRms		tHashlessFilePasswordDBMixincBsPeZejZd
ZedZddd
gZ	dZ
dZd	ZRS(cCs|S(N((RP((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQsRdt	password1Rft	password2Rht	password3ccs>x7|jD],\}}|j||j||fVq
WdS(N(t_validCredentialst	credClasstnetworkHash(RRwR5((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRsccs>x7ddd	gD]&\}}|j||j|VqWdS(
NRdRRfRtblooftblarf(suser1R(suser2R(RR(RR(RRwR5((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRsc
#sjpd}jo'fd}xttfD]}j}t|d}x4jD])\}}|jd|||fqbW|jtj	|d|d|Vj}t|d}x4jD])\}}|jd|||fqW|jtj	|dd	d
d|d|Vj}t|d}x:jD]/\}}|jd|j
||fqWW|jtj	|dd
dtd|d|Vq7WdS(NcSs|S(N((RP((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQscs
j|S(N(tdiskHash(RR tstored(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQsRjs%s:%s
tcacheRs%s dingle dongle %s
t iiszip,zap,%s,zup,%s
t,ii(RRRRkRmRRoRpRRlttitle(RRt	hashCheckRtfntfObjRwR5((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRs*!
!
#'
N(suser1s	password1(suser2R(suser3s	password3(
RRRR@RRRtstaticmethodRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR~s				t LocallyHashedFilePasswordDBMixincBseZedZRS(cCs
|jdS(Nthex(tencode(RP((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQs(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRst NetworkHashedFilePasswordDBMixincBs0eZedZdejfdYZRS(cCs
|jdS(NR(R(RP((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRQsRcBseZdZRS(cCs|jjd|kS(NR(thashedtdecode(RR ((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyR!s(RRR!(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRs(RRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRst%HashlessFilePasswordDBCheckerTestCasecBseZRS((RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRst*LocallyHashedFilePasswordDBCheckerTestCasecBseZRS((RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRst*NetworkHashedFilePasswordDBCheckerTestCasecBseZRS((RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyRs(((((2t__doc__R\tzope.interfaceRRt
twisted.trialRttwisted.credRRRRttwisted.pythonRttwisted.internetRttwisted.internet.deferR	RR
RRtImportErrorRttwisted.cred.pamauthRR
RRtAdapterRtregisterAdapterR8RtobjectRR"tTestCaseR+RURcRRRRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_newcred.pyt<module>sF"




J;=H.