def test_ensure_default(self):
     conf = Config()
     ensure(request('GET', '/'), conf)
     with self.assertLogs() as log:
         with self.assertRaises(HTTPForbidden):
             ensure(request('GET', '/', headers={'Origin': 'localhost'}),
                    conf)
         self.assertIn("'localhost' are not allowed", log.output[0])
 def test_ensure_specific(self):
     conf = Config(allowed_origin='localhost')
     ensure(request('GET', '/', headers={'Origin': 'localhost'}), conf)
     with self.assertLogs() as log:
         with self.assertRaises(HTTPForbidden):
             ensure(request('GET', '/', headers={'Origin': 'hackers.com'}),
                    conf)
         self.assertIn("'hackers.com' are not allowed", log.output[0])
         self.assertIn("'allowed_origin' limits requests to: 'localhost'",
                       log.output[0])