def testRenderHTTPAllowDefault(self): streamer = FakeStreamer(mediumClass=FakeAuthFailingMedium) httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) httpauth.setBouncerName('fakebouncer') streamer.caps = True self.failUnless(resource.isReady()) d = defer.Deferred() def wrongToken(_): request = FakeRequest(user='******') return self.deferAssertUnauthorized(httpauth, request) def errorDisallowDefault(_, error): streamer.medium.failure = error request = FakeRequest(user='******') return self.deferAssertInternalServerError(httpauth, request) def errorAllowDefault(_, error): streamer.medium.failure = error httpauth.setAllowDefault(True) request = FakeRequest(user='******') return self.deferAssertAuthorized(httpauth, request) d.addCallback(wrongToken) d.addCallback(errorDisallowDefault, errors.NotConnectedError()) d.addCallback(errorDisallowDefault, errors.UnknownComponentError()) d.addCallback(errorAllowDefault, errors.NotConnectedError()) d.addCallback(errorAllowDefault, errors.UnknownComponentError()) d.callback(None) return d
def testRenderTopStreamer(self): # a streamer that is at /a root = resources.HTTPRoot() site = server.Site(resource=root) streamer = FakeStreamer() httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) root.putChild('a', resource) # a request for / should give 404 log.debug('unittest', 'requesting /, should 404') request = FakeRequest(ip='') r = site.getResourceFor(request) output = r.render(request) self.assertEquals(request.response, http.NOT_FOUND) # a request for /a should work log.debug('unittest', 'requesting /a, should work') request = FakeRequest(ip='', postpath=['a']) r = site.getResourceFor(request) self.assertEquals(r, resource) output = r.render(request) self.assertEquals(output, server.NOT_DONE_YET) # a request for /a/b should give 404 log.debug('unittest', 'requesting /a/b, should 404') request = FakeRequest(ip='', postpath=['a', 'b']) r = site.getResourceFor(request) output = r.render(request) self.assertEquals(request.response, http.NOT_FOUND)
def testRenderHTTPTokenAuthorized(self): streamer = FakeStreamer(mediumClass=FakeTokenMedium) httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) # override issuer httpauth.setBouncerName('fakebouncer') httpauth.setDomain('FakeDomain') streamer.caps = True self.failUnless(resource.isReady()) d = defer.Deferred() def rightToken(_): request = FakeRequest(ip='127.0.0.1', args={'token': 'LETMEIN'}) return self.deferAssertAuthorized(httpauth, request) def rightTokenTwice(_): request = FakeRequest(ip='127.0.0.1', args={'token': ['LETMEIN', 'LETMEIN']}) return self.deferAssertAuthorized(httpauth, request) d.addCallback(rightToken) d.addCallback(rightTokenTwice) d.callback(None) return d
def testRenderReachedMaxClients(self): streamer = FakeStreamer() httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) self.failIf(resource.isReady()) streamer.caps = True self.failUnless(resource.isReady()) #assert resource.maxAllowedClients() == 974 resource._requests = ' ' * (resource.maxclients + 1) self.failUnless(resource.reachedServerLimits()) request = FakeRequest(ip='127.0.0.1') data = resource.render(request) error_code = http.SERVICE_UNAVAILABLE self.assertEquals(request.headers.get('content-type', ''), 'text/html') self.assertEquals(request.headers.get('server', ''), resources.HTTP_VERSION) self.assertEquals(request.response, error_code) expected = resources.ERROR_TEMPLATE % { 'code': error_code, 'error': http.RESPONSES[error_code]} self.assertEquals(data, expected)
def testRenderNotReady(self): streamer = FakeStreamer() httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) self.failIf(resource.isReady()) status = resource.render(FakeRequest(ip='')) self.assertEquals(status, server.NOT_DONE_YET)
def testRenderNew(self): streamer = FakeStreamer() httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) streamer.caps = True streamer.mime = 'application/x-ogg' request = FakeRequest(ip='127.0.0.1') data = resource.render(request) self.failUnless(server.NOT_DONE_YET)
def testRenderHTTPAuthUnauthorized(self): streamer = FakeStreamer() httpauth = HTTPAuthentication(streamer) resource = resources.HTTPStreamingResource(streamer, httpauth) httpauth.setBouncerName('fakebouncer') httpauth.setDomain('FakeDomain') streamer.caps = True self.failUnless(resource.isReady()) request = FakeRequest(ip='127.0.0.1', user='******') return self.deferAssertUnauthorized(httpauth, request)