def test_bad_path(self): path = '/a/b/c' params = dict(d=5, e=6) signed_params = security.sign_request(path, params, self.client['_id'], self.key_str) req = testing.DummyRequest(path=path + 'd/', params=signed_params, remote_addr='1.2.3.5') with self.assertRaises(exc.HTTPForbidden): security.validate_request(req)
def test_no_client_id(self): path = '/a/b/c' params = dict(d=5, e=6) signed_params = security.sign_request(path, params, self.client['_id'], self.key_str) signed_params = dict(signed_params) signed_params.pop('client_id') req = testing.DummyRequest(path=path + 'd/', params=signed_params, remote_addr='1.2.3.5') with self.assertRaises(exc.HTTPBadRequest): security.validate_request(req)
def test_bad_client(self): path = '/a/b/c' params = dict(d=5, e=6) signed_params = security.sign_request(path, params, self.client['_id'], self.key_str) signed_params = dict(signed_params) signed_params['client_id'] = bson.ObjectId() req = testing.DummyRequest(path=path + 'd/', params=signed_params, remote_addr='1.2.3.5') with self.assertRaises(exc.HTTPNotFound): security.validate_request(req)
def test_valid(self): path = '/a/b/c' params = dict(d=5, e=6) signed_params = security.sign_request(path, params, self.client['_id'], self.key_str) req = testing.DummyRequest(path=path, params=signed_params, remote_addr='1.2.3.4') client_doc = security.validate_request(req) self.assertEqual(client_doc['_id'], self.client['_id'])