def make_http_pool_and_agent(params): cp_size = params.get('cp_size', 5) c_timeout = params.get('c_timeout', 30.0) # XXX: more extensibility auth = params.get('auth', 'authhmac') assert not auth or auth.lower() in ['none', 'authhmac', 'basic', 'digest'] http_pool = client.HTTPConnectionPool(reactor) http_pool._factory = _NoiselessHTTP11ClientFactory http_pool.retryAutomatically = False http_pool.maxPersistentPerHost = cp_size agent = client.Agent(reactor, pool=http_pool, connectTimeout=c_timeout) if not auth or auth.lower() == 'none': pass elif auth.lower() == 'authhmac': access_key = params['access_key'] secret_key = params.get('secret_key') agent = authhmac.AuthHMACAgent(agent, access_key, secret_key) elif auth.lower() == 'basic': username = params['username'] password = params.get('password') agent = httprpc.BasicAuthAgent(agent, username, password) else: raise AssertionError("unknown %r auth" % auth) return http_pool, agent
def test_too_old_request(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") headers = Headers({'date': [datetimeToString(time.time() - 1500)]}) bodyp = web.StringBodyProducer("some content") resp = yield agent.request('POST', self.request_url(""), headers, bodyp) yield self.check_fail(resp)
def test_wrong_md5(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") headers = Headers({'content-md5': ["xxx"]}) bodyp = web.StringBodyProducer("some content") resp = yield agent.request('POST', self.request_url(""), headers, bodyp) yield self.check_fail(resp)
def test_ok_post_with_ct(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") bodyp = web.StringBodyProducer("some content") headers = Headers({'content-type': ['unknown-content-type']}) resp = yield agent.request('POST', self.request_url(""), headers, bodyp) yield self.check_ok(resp)
def test_ok_get(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") for p in [ "//path/path//", "?a=1&b=2", "?", "#", "#test test test", "?a=1&b=2#", "$..$Ssrt?rsat=sart325ea..rst2%%sta#srat=/../#xxxyyy", ]: resp = yield agent.request('GET', self.request_url(p), None, None) yield self.check_ok(resp)
def test_ok_post(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") bodyp = web.StringBodyProducer("some content") resp = yield agent.request('POST', self.request_url(""), None, bodyp) yield self.check_ok(resp)
def test_wrong_secret(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "bad-secret") resp = yield agent.request('GET', self.request_url(""), None, None) yield self.check_fail(resp)
def test_ok_get_simple(self): agent = authhmac.AuthHMACAgent(self.agent, "key", "secret") resp = yield agent.request('GET', self.request_url(""), None, None) yield self.check_ok(resp)