ϪfdZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZmZmZGd d eZGd deZGddeZy)z! Tests for L{twisted.web.vhost}. ) gatherResults)TestCase) NOT_FOUND) NoResource)Site)Data)_render) DummyRequest)NameVirtualHostVHostMonsterResource _HostResourceceZdZdZdZy)HostResourceTestsz% Tests for L{_HostResource}. c&tdd}tdd}tdd}|jd||jd|t}t}tdd|_|j d|t ddg}gd |_t||_ d |_ d |_ |jd|}|j|tt ddg}|jd|}|j|ty ) z L{_HostResource.getChild} returns the proper I{Resource} for the vhost embedded in the URL. Verify that returning the proper I{Resource} required changing the I{Host} in the header. s root datasuri datas test datastestsuris default databaz.com)sbarhttprcy)NFr=/usr/lib/python3/dist-packages/twisted/web/test/test_vhost.pyz1HostResourceTests.test_getChild..-srrN)rputChildr r defaultaddHostr prepathrsiteisSecurehostgetChildassertIsInstancer)selfbazrootbazuribaztesthrrootrequeststeps r test_getChildzHostResourceTests.test_getChilds |R(k2&|R()( _ OR0  Z)017Dz ( {{:w/ dD)01}}VW- dJ/rN__name__ __module__ __qualname____doc__r*rrrrrs 0rrc:eZdZdZdZdZdZdZdZdZ dZ y ) NameVirtualHostTestsz' Tests for L{NameVirtualHost}. ct}tdd|_tdg}|j |j |dy)z L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no I{Host} header in the request. scorrect resultrrN)r rrr assertEqualrenderr"virtualHostResourcer(s rtest_renderWithoutHostz+NameVirtualHostTests.test_renderWithoutHost=sG ./&*+OPrc|t}tdgt|}fd}|j||S)z L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no I{Host} header in the request. rcFjjtyNr3 responseCoderignoredr(r"s r cbRenderedzHNameVirtualHostTests.test_renderWithoutHostNoDefault..cbRenderedR   W119 =r)r r r addCallbackr"r6dr?r(s` @rtest_renderWithoutHostNoDefaultz4NameVirtualHostTests.test_renderWithoutHostNoDefaultHs? ./u% ' 1 > j!rct}|jdtddtdg}|jj ddt ||}fd}|j||tdg}|jj ddt ||}fd}|j||t||gS) z L{NameVirtualHost.render} returns the result of rendering the resource which is the value in the instance's C{host} dictionary corresponding to the key indicated by the value of the I{Host} header in the request. s example.orgwinnerrrhostc\jdj|jdyNrrFr3joinwrittenr=s rr?z.cbRenderedes   SXXgoo6 Brsexample.org:8000c\jdj|jdyrIrJ)r>requestWithPortr"s rr?z.cbRenderedos"   SXXo&=&=> Jr) r rrr requestHeaders addRawHeaderr rAr)r"r6r(rCr?rN dWithPorts` rtest_renderWithHostz(NameVirtualHostTests.test_renderWithHostXs ./##NDB4GHu%++G^D ' 1 C j'*'u-&&33G=PQ/A  K j/:a^,,rct}tdd|_tdgjj ddt |}fd}|j||S)z L{NameVirtualHost.render} returns the result of rendering the instance's C{default} if it is not L{None} and there is no host matching the value of the I{Host} header in the request. correct datarrrG example.comc\jdjjdy)NrrTrJr=s rr?zCNameVirtualHostTests.test_renderWithUnknownHost..cbRendereds   SXXgoo6 Hr)r rrr rOrPr rArBs` @rtest_renderWithUnknownHostz/NameVirtualHostTests.test_renderWithUnknownHostvsf ./&*?B&?#u%++G^D ' 1 I j!rct}tdgjjddt |}fd}|j ||S)z L{NameVirtualHost.render} returns a response with a status of I{NOT FOUND} if the instance's C{default} is L{None} and there is no host matching the value of the I{Host} header in the request. rrGrUcFjjtyr:r;r=s rr?zLNameVirtualHostTests.test_renderWithUnknownHostNoDefault..cbRenderedr@r)r r rOrPr rArBs` @r#test_renderWithUnknownHostNoDefaultz8NameVirtualHostTests.test_renderWithUnknownHostNoDefaultsU ./u%++G^D ' 1 > j!rcKt}tdg}|jjddt ||d{|j ddj |jy70w)zs L{NameVirtualHost.render} doesn't echo unescaped HTML when present in the I{Host} header. rrGsexample.comNs)r r rOrPr assertNotInrKrLr5s rtest_renderWithHTMLHostz,NameVirtualHostTests.test_renderWithHTMLHostsg ./u%++G5JK)7333 '//!:; 4sAA7A51A7ct}tdd}d|_tdd}|jd||jd|t g}|j j dddg|_|j|jd|t|j|jdg|j|jgt g}|j j dddg|_|j|jd|t|j|jg|j|jdgy ) z L{NameVirtualHost.getChild} returns correct I{Resource} based off the header and modifies I{Request} to ensure proper prepath and postpath are set. s leaf datarTs norm datasleaf.example.orgsnorm.example.orgrGrN) r risLeafrr rOrPrr!r rr3postpath)r"r6 leafResource normResourcer(s rr*z"NameVirtualHostTests.test_getChilds7 ./L"- " L"- ##$7F##$7Fr"++G5HI% 1::3H*U 3%0 ))2.r"++G5HI% 1::3H$O "- ))C51rN) r,r-r.r/r7rDrRrWrZr]r*rrrr1r18s+ Q -<$" <2rr1ceZdZdZdZy)VHostMonsterResourceTestsz, Tests for L{VHostMonsterResource}. cXt}tg}|j|jd|t|j |j tg}|j|jd|t|j|j y)z L{VHostMonsterResource.getChild} returns I{_HostResource} and modifies I{Request} with correct L{Request.isSecure}. rshttpsN)r r r!r r assertFalser assertTrue)r"vhmr(s rr*z'VHostMonsterResourceTests.test_getChilds #$r" cll7GrrsR 1+&+##*2RR!0!0HI28I2X,,r