def test_successful(self): signature = sign_message_with_static_key('') public_address = generate_static_public_address() headers = { "Authorization": "Signature {}".format(base64.b64encode(signature)) } recovered_public_address = decode_authorization_header(headers) self.assertEqual(public_address.lower(), recovered_public_address)
def test_node_reg_successful(self): public_address = generate_static_public_address() payload = { "service_proposal": { "id": 1, "format": "service-proposal/v1", "provider_id": public_address, } } auth = generate_test_authorization(json.dumps(payload)) re = self._post('/v1/node_register', payload, headers=auth['headers']) self.assertEqual(200, re.status_code) re.json
def test_unregister_proposal_successful(self): public_address = generate_static_public_address() node = self._create_node(public_address) node.mark_activity() self.assertTrue(node.is_active()) # unregister payload = {"provider_id": public_address} auth = generate_test_authorization(json.dumps(payload)) re = self._post('/v1/unregister_proposal', payload, headers=auth['headers']) self.assertEqual(200, re.status_code) self.assertIsNotNone(re.json) self.assertFalse(node.is_active())
def test_register_proposal_successful(self): public_address = generate_static_public_address() payload = { "service_proposal": { "id": 1, "format": "service-proposal/v1", "provider_id": public_address, } } auth = generate_test_authorization(json.dumps(payload)) re = self._post('/v1/register_proposal', payload, headers=auth['headers']) self.assertEqual(200, re.status_code) self.assertIsNotNone(re.json) node = Node.query.get(public_address) self.assertEqual(self.REMOTE_ADDR, node.ip)
def test_register_proposal_with_unknown_ip(self): public_address = generate_static_public_address() payload = { "service_proposal": { "id": 1, "format": "service-proposal/v1", "provider_id": public_address, } } auth = generate_test_authorization(json.dumps(payload)) re = self._post('/v1/register_proposal', payload, headers=auth['headers'], remote_addr='127.0.0.1') self.assertEqual(200, re.status_code) self.assertIsNotNone(re.json) node = Node.query.get(public_address) self.assertEqual('127.0.0.1', node.ip)