def test_create_ip_check(self):
     checker = last_ip_check.filter_factory(self.global_conf)(self.app)
     self.assertTrue(checker is not None)
     self.assertTrue(isinstance(checker, last_ip_check.LastIpCheck))
     call_fx = getattr(checker, "__call__", None)
     self.assertIsNotNone(call_fx)
     self.assertTrue(callable(call_fx))
     self.assertTrue(callable(checker))
 def test_create_ip_check(self):
     checker = last_ip_check.filter_factory(self.global_conf)(self.app)
     self.assertTrue(checker is not None)
     self.assertTrue(isinstance(checker, last_ip_check.LastIpCheck))
     call_fx = getattr(checker, "__call__", None)
     self.assertIsNotNone(call_fx)
     self.assertTrue(callable(call_fx))
     self.assertTrue(callable(checker))
 def test_runtime_override(self):
     self.set_reconfigure()
     result = last_ip_check.filter_factory(self.global_conf)(self.app)
     resp = result.__call__.request('/ports/1234', method='PUT',
                                    body=self.empty_fixed_ips)
     self.assertEqual(403, resp.status_code)
     headers = {'X_WAFFLEHAUS_LASTIPCHECK_ENABLED': False}
     resp = result.__call__.request('/ports/1234', method='PUT',
                                    headers=headers,
                                    body=self.empty_fixed_ips)
     self.assertEqual(self.app, resp)
 def test_runtime_override(self):
     self.set_reconfigure()
     result = last_ip_check.filter_factory(self.global_conf)(self.app)
     resp = result.__call__.request('/ports/1234',
                                    method='PUT',
                                    body=self.empty_fixed_ips)
     self.assertEqual(403, resp.status_code)
     headers = {'X_WAFFLEHAUS_LASTIPCHECK_ENABLED': False}
     resp = result.__call__.request('/ports/1234',
                                    method='PUT',
                                    headers=headers,
                                    body=self.empty_fixed_ips)
     self.assertEqual(self.app, resp)
    def setUp(self):
        super(TestLastIpCheck, self).setUp()
        self.app = self._fake_app
        self.global_conf = {'enabled': 'true'}
        self.checker = last_ip_check.filter_factory(self.global_conf)(self.app)

        self.good_only_v4 = self._create_body([self._v4()])
        self.good_only_v6 = self._create_body([self._v6()])
        self.good_add_v4 = self._create_body([self._add_v4()])
        self.good_add_v6 = self._create_body([self._add_v6()])
        self.good_add_v6_w4 = self._create_body([self._v4(), self._add_v6()])
        self.good_add_v4_w4 = self._create_body([self._v4(), self._add_v4()])
        self.good_add_v4_w6 = self._create_body([self._v6(), self._add_v4()])
        self.good_add_v6_w6 = self._create_body([self._v6(), self._add_v6()])

        self.bad_resource = '{"derp": {"fixed_ips":[{"derp": "derp"}]}}'
        self.bad_no_fixed = '{"port": {"derply":[{"derp": "derp"}]}}'
        self.empty_fixed_ips = '{"port": {"fixed_ips":[]}}'
    def setUp(self):
        super(TestLastIpCheck, self).setUp()
        self.app = self._fake_app
        self.global_conf = {'enabled': 'true'}
        self.checker = last_ip_check.filter_factory(self.global_conf)(self.app)

        self.good_only_v4 = self._create_body([self._v4()])
        self.good_only_v6 = self._create_body([self._v6()])
        self.good_add_v4 = self._create_body([self._add_v4()])
        self.good_add_v6 = self._create_body([self._add_v6()])
        self.good_add_v6_w4 = self._create_body([self._v4(), self._add_v6()])
        self.good_add_v4_w4 = self._create_body([self._v4(), self._add_v4()])
        self.good_add_v4_w6 = self._create_body([self._v6(), self._add_v4()])
        self.good_add_v6_w6 = self._create_body([self._v6(), self._add_v6()])

        self.bad_resource = '{"derp": {"fixed_ips":[{"derp": "derp"}]}}'
        self.bad_no_fixed = '{"port": {"derply":[{"derp": "derp"}]}}'
        self.empty_fixed_ips = '{"port": {"fixed_ips":[]}}'
        self.true_body = 'true'