def test_post_(self): host = Host.objects.last() url = '/api/host/%s/deployed_config_version' % host.uid auth_headers = basic_auth(host.uid, host.secret) ret = self.client.post(url, {'version': 1}, **auth_headers) self.assertEqual(ret.status_code, 410)
def test_get_config(self, version_str, _comment): # Note: using an existing host and correct auth headers, but this will not matter. host = Host.objects.last() url = '/api/%shost/%s/config' % (version_str, host.uid) auth_headers = basic_auth(host.uid, host.secret) ret = self.client.get(url, **auth_headers) self.assertEqual(ret.status_code, 410)
def _fake_notify_deploy_success(host_id, host_secret): # Mock the client side call to notify success to the coordinator client = TestCase.client_class() deployed_config_version = Host.objects.get(uid=host_id).config_version post_url = reverse('api_post_deployed_version', kwargs={'uid': host_id}) auth_headers = basic_auth(host_id, host_secret) response = client.post(post_url, {'version': deployed_config_version}, **auth_headers) logging.info("Status code" " of posting version %s to API endpoint %s: %s" % (deployed_config_version, post_url, response.status_code)) global deployment_required deployment_required = False
def setUp(self): # Create IXPs self.ixp1 = IXP.objects.create(label="ixp1", ip_network="10.1.1.0/24") self.ixp2 = IXP.objects.create(label="ixp2", ip_network="10.1.2.0/24") # Set user ASes as IXP members self.ases = [ UserAS.objects.get(as_id="ffaa:1:%d" % i) for i in range(1, 6) ] IXPMember.objects.create(ixp=self.ixp1, host=self.ases[0].hosts.first(), public_ip="10.1.1.2") IXPMember.objects.create(ixp=self.ixp1, host=self.ases[1].hosts.first(), public_ip="10.1.1.3") IXPMember.objects.create(ixp=self.ixp1, host=self.ases[2].hosts.first(), public_ip="10.1.1.4") IXPMember.objects.create(ixp=self.ixp1, host=self.ases[3].hosts.first(), public_ip="10.1.1.5") IXPMember.objects.create(ixp=self.ixp1, host=self.ases[4].hosts.first(), public_ip="10.1.1.6") IXPMember.objects.create(ixp=self.ixp2, host=self.ases[0].hosts.first(), public_ip="10.1.2.2") IXPMember.objects.create(ixp=self.ixp2, host=self.ases[1].hosts.first(), public_ip="10.1.2.3") IXPMember.objects.create(ixp=self.ixp2, host=self.ases[2].hosts.first(), public_ip="10.1.2.4") # Avoid duplication, get this info here: self.host = Host.objects.get(AS__as_id="ffaa:1:1") self.url_peers = '/api/peering/host/%s/peers' % self.host.uid self.url_policies = '/api/peering/host/%s/policies' % self.host.uid self.auth_headers = basic_auth(self.host.uid, self.host.secret)
def _get_auth_headers(host): return basic_auth(host.uid, host.secret)
def test_bad_auth(self): auth_headers = basic_auth(self.host.uid, self.host.secret + "_foobar") ret = self.client.get(self.url, **auth_headers) self.assertEqual(ret.status_code, 401)
def setUp(self): # Avoid duplication, get this info here: self.host = Host.objects.last() self.url = '/api/host/%s/config' % self.host.uid self.auth_headers = basic_auth(self.host.uid, self.host.secret)