Ñò ˆ_‚Jc@s_dZddklZddklZddklZddkZddkl Z ddk l Z ddk l Z lZdd klZdd klZlZdd klZlZlZlZdd klZlZlZddkZdd klZddkl Z ddk!l"Z"l#Z#ddk$l%Z%l&Z&ddk'l(Z(ddk)l*Z*ddk+l,Z,l-Z-l.Z.dZ/ei0i1ei0i2e3ƒƒZ4ei0i5e4dƒZ6ee6de7ƒhd„Z8d„Z9defd„ƒYZ:defd„ƒYZ;defd„ƒYZ<ee.ƒƒe<ƒZ<defd „ƒYZ=d!efd"„ƒYZ>d#efd$„ƒYZ?ee-d%ƒƒe?ƒZ?d&efd'„ƒYZ@d(e@fd)„ƒYZAd*e@fd+„ƒYZBd,e@fd-„ƒYZCd.e@fd/„ƒYZDd0e@fd1„ƒYZEd2e@fd3„ƒYZFd4e@fd5„ƒYZGd6e@fd7„ƒYZHd8e@fd9„ƒYZIdS(:s0 repoze.what & repoze.what-pylons **integration** tests. Note that it is not necessary to have integration tests for the other auth* software in this package. They must be in tg.devtools, specifically in the test suite of the quickstarted applications (and there's where they are, as of this writing). iÿÿÿÿ(tTestCase(trmtree(tunquoteN(thttpexceptions(tRegistryManager(tResponsetRequest(tTestApp(tCacheMiddlewaretSessionMiddleware(tresponsetexposetrequiret allow_only(t TGControllertWSGIAppControllertRestController(t tmpl_context(tabort(t ContextObjt PylonsContext(tControllerWraptSetupCacheGlobal(tAuthTktCookiePlugin(t setup_auth(tNottis_usert not_anonymouss-The current user must have been authenticatedtsessiont ignore_errorsc CsÙt|ƒ}t||dtdtƒ}t|ƒ}t|hdtƒ}t|hdtii t dƒƒ}d }d }t ddƒ}d|fg}t |||d|d gd gd tƒ}ti|ƒ}t|ƒS( sCreates a ``TestApp`` instance.t setup_cachet setup_sessiontdata_dirtcachetsecrettauthtkttcookiet identifierstauthenticatorst challengerstskip_authenticationN(RRtTrueRR t session_dirRtostpathtjoinR tNoneRRRtmake_middlewareR(tcontroller_klasstenvirontapptgroups_adapterstpermissions_adaptersR$R%((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytmake_app.s  $ cCs3t|ƒ}td|i|iƒ}|||ƒS(sMock WSGI applications Hello from %s(RRt script_namet path_info(R1tstart_responsetreqtresp((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytwsgi_appJs tDaRestControllercBs,eZdZedƒZeƒd„ƒZRS(sMock REST controllertgustavocCsdS(Nsnew here((tself((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytnewVs(t__name__t __module__t__doc__RR R R?(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR<Qs tHRManagementControllercBs>eZdZedƒZeƒd„ƒZeƒd„ƒZRS(s=Mock TG2 protected controller using the .allow_only attributeshiring-managercCsdS(Nsyou can manage Human Resources((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytindex`scCsd|S(Ns%s was just hired((R>t person_name((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pythireds(R@RARBRR R RDRF(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRC[s t ControlPanelcBsMeZdZeƒZeƒd„ƒZeƒeedƒƒd„ƒƒZ RS(s9Mock TG2 protected controller using @allow_only directly.cCsdS(Nsyou are in the panel((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRDnstadmincCsd|S(Ns%s was just registered((R>t user_name((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytadd_userrs( R@RARBRCthrR RDR RRJ(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRGis  tRootControllercBsheZeƒZeƒZeededƒƒZ e ƒd„ƒZ e ƒe edƒƒd„ƒƒZ RS(R R=cCsdS(Nsyou're in the main page((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRD‚st developercCsdS(Nsyou can commit((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytcommit†s(R@RARGtcpR<trestRR;Rt mounted_appR RDR RN(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRLzs   t5ControllerWithAllowOnlyAttributeAndAuthzDenialHandlercBs;eZdZedƒZeƒd„ƒZed„ƒZRS(s=Mock TG2 protected controller using the .allow_only attributetfoobarcCsdS(NsWelcome back, foobar!((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRD‘scCstdƒdS(Ni’(R(R>treason((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt_failed_authorization•s( R@RARBRR R RDt classmethodRU(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRRŒs t5ControllerWithAllowOnlyDecoratorAndAuthzDenialHandlercBs/eZdZeƒd„ƒZed„ƒZRS(su Mock TG2 protected controller using the @allow_only decorator, but also using ._failed_authorization() cCsdS(NsWelcome back, foobar!((R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRD¢scCstdƒdS(Ni’(R(R>RT((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRU¦s(R@RARBR RDRVRU(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRW›sRStBaseIntegrationTestscBs/eZdZeZd„Zd„Zd„ZRS(s(Base test case for the integration testscCs•tiitƒptitƒntƒ}tƒ}||_d|_ |_ ht ddƒd6|d6}t ii |ƒt|i|ƒ|_dS(NtactionRDspylons.routes_dicts pylons.pylons(R+R,texistsR*tmakedirsRRtcR.trequestR tdicttpylonst _push_objectR5t controllerR2(R>R\tpy_objR1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pytsetUp·s    cCstiƒttdtƒdS(NR(Rt _pop_objectRR*R)(R>((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyttearDownÆs cGs2t|idƒ}x|D]}d|}qWdS(sW Check that ``expected_messages`` are defined in the WebFlash cookie. twebflashs"%s"N(Rt cookies_set(R>R texpected_messagestflashtmsg((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt _check_flashËs  (R@RARBRLRaRcReRk(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRX²s   t TestRequirecBs2eZdZd„Zd„Zd„Zd„ZRS(s$Test case for the @require decoratorcCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRMt REMOTE_USERs/committ extra_environtstatusiÈsyou can commit(R2tgett assertEqualtbody(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt%test_authz_granted_in_root_controllerÚs cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns/commitRoi‘s&The current user must be \"developer\"RSRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt$test_authz_denied_in_root_controllerßs  cCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRHRms/cp/add_user/fooRnRoiÈsfoo was just registered(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt$test_authz_granted_in_sub_controllerês  cCsg|iidddƒ}|i|tƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns/cp/add_user/fooRoi‘RSRmRni“s"The current user must be \"admin\"(R2RpRktNOT_AUTHENTICATED(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt#test_authz_denied_in_sub_controllerðs   (R@RARBRsRtRuRw(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRl×s   t%TestAllowOnlyDecoratorInSubControllercBs2eZdZd„Zd„Zd„Zd„ZRS(s;Test case for the @allow_only decorator in a sub-controllercCsBhdd6}|iidd|ddƒ}|id|iƒdS(NtsomeoneRms/cp/RnRoiÈsyou are in the panel(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt"test_authz_granted_without_requires cCs,|iidddƒ}|i|tƒdS(Ns/cp/Roi‘(R2RpRkRv(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt!test_authz_denied_without_requirescCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRHRms/cp/add_user/fooRnRoiÈsfoo was just registered(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyttest_authz_granted_with_require s  cCs,|iidddƒ}|i|tƒdS(Ns/cp/add_user/fooRoi‘(R2RpRkRv(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyttest_authz_denied_with_requires(R@RARBRzR{R|R}(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRxýs    t2TestAllowOnlyDecoratorAndDefaultAuthzDenialHandlercBs&eZdZeZd„Zd„ZRS(s{ Test case for the @allow_only decorator in a controller using _failed_authorization() as its denial handler. cCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRSRmt/RnRoiÈsWelcome back, foobar!(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyttest_authz_granteds cCs|iidddƒ}dS(NRRoi’(R2Rp(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyttest_authz_denied$s(R@RARBRWRaR€R(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR~s t%TestAllowOnlyAttributeInSubControllercBs8eZdZeZd„Zd„Zd„Zd„ZRS(s;Test case for the .allow_only attribute in a sub-controllercCsBhdd6}|iidd|ddƒ}|id|iƒdS(Nshiring-managerRms/hr/RnRoiÈsyou can manage Human Resources(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRz.s cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns/hr/Roi‘s+The current user must be \"hiring-manager\"RyRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR{3s  cCsBhdd6}|iidd|ddƒ}|id|iƒdS(Nshiring-managerRms/hr/hire/gustavoRnRoiÈsgustavo was just hired(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR|>s  cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns/hr/hire/gustavoRoi‘s+The current user must be \"hiring-manager\"RyRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR}Ds  ( R@RARBRGRaRzR{R|R}(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR‚)s   t2TestAllowOnlyAttributeAndDefaultAuthzDenialHandlercBs&eZdZeZd„Zd„ZRS(s{ Test case for the .allow_only attribute in a controller using _failed_authorization() as its denial handler. cCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRSRmRRnRoiÈsWelcome back, foobar!(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR€Ys cCs|iidddƒ}dS(NRRoi’(R2Rp(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR^s(R@RARBRRRaR€R(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRƒPs t&TestAppWideAuthzWithAllowOnlyDecoratorcBs8eZdZeZd„Zd„Zd„Zd„ZRS(sCTest case for application-wide authz with the @allow_only decoratorcCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRyRmRRnRoiÈsyou are in the panel(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRzhs cCs,|iidddƒ}|i|tƒdS(NRRoi‘(R2RpRkRv(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR{mscCsBhdd6}|iidd|ddƒ}|id|iƒdS(NRHRms /add_user/fooRnRoiÈsfoo was just registered(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR|rs  cCs,|iidddƒ}|i|tƒdS(Ns /add_user/fooRoi‘(R2RpRkRv(R>R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR}xs( R@RARBRGRaRzR{R|R}(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR„cs    t&TestAppWideAuthzWithAllowOnlyAttributecBs8eZdZeZd„Zd„Zd„Zd„ZRS(sCTest case for application-wide authz with the .allow_only attributecCsGhdd6}|iidd|ddƒ}|GH|id|iƒdS(Nshiring-managerRmRRnRoiÈsyou can manage Human Resources(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRzƒs cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( NRRoi‘s+The current user must be \"hiring-manager\"RyRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR{‰s  cCsBhdd6}|iidd|ddƒ}|id|iƒdS(Nshiring-managerRms /hire/gustavoRnRoiÈsgustavo was just hired(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR|”s  cCso|iidddƒ}|iGH|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns /hire/gustavoRoi‘s+The current user must be \"hiring-manager\"RyRmRni“(R2RpRrRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR}šs  ( R@RARBRCRaRzR{R|R}(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR…~s   tTestProtectedRESTContollercBs eZdZd„Zd„ZRS(s(Test case for protected REST controllerscCsBhdd6}|iidd|ddƒ}|id|iƒdS(NR=Rms /rest/newRnRoiÈsnew here(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR€ªs  cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns /rest/newRoi‘s$The current user must be \"gustavo\"s non-gustavoRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR°s  (R@RARBR€R(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR†§s tTestProtectedWSGIApplicationcBs eZdZd„Zd„ZRS(sCTest case for protected WSGI applications mounted on the controllercCsBhdd6}|iidd|ddƒ}|id|iƒdS(NR=Rms/mounted_app/da-pathRnRoiÈsHello from /mounted_app/da-path(R2RpRqRr(R>R1R:((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR€¿s  cCsg|iidddƒ}|i|dƒhdd6}|iidd|ddƒ}|i|dƒdS( Ns/mounted_app/da-pathRoi‘s$The current user must be \"gustavo\"s non-gustavoRmRni“(R2RpRk(R>R:R1((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyRÅs   (R@RARBR€R(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyR‡¼s (JRBtunittestRtshutilRturllibRR+tpasteRtpaste.registryRtwebobRRtwebtestRtbeaker.middlewareRR ttgR R R R ttg.controllersRRRR_Rtpylons.controllers.utilRt pylons.utilRRtpylons.testutilRRtrepoze.who.plugins.auth_tktRtrepoze.what.middlewareRtrepoze.what.predicatesRRRRvR,tdirnametabspatht__file__R R-R*R)R5R;R<RCRGRLRRRWRXRlRxR~R‚RƒR„R…R†R‡(((s</usr/lib/python2.6/site-packages/tg/test_stack/test_authz.pyt sX "    %&')