def test_validate_that_golem_messages_are_signed_with_key_should_not_raise_error_if_correct_message_and_key_is_used( self): task_to_compute = tasks.TaskToComputeFactory() dumped_task_to_compute = dump(task_to_compute, CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY) task_to_compute = load(dumped_task_to_compute, CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY) assert task_to_compute.sig is not None assert task_to_compute.SIGN is not False try: validate_that_golem_messages_are_signed_with_key( CONCENT_PUBLIC_KEY, task_to_compute, ) except Http400: self.fail()
def setUp(self): with freeze_time("2017-11-17 10:00:00"): super().setUp() self.compute_task_def = tasks.ComputeTaskDefFactory() self.compute_task_def['deadline'] = get_current_utc_timestamp() + ( 60 * 37) self.want_to_compute_task = tasks.WantToComputeTaskFactory( sign__privkey=self.PROVIDER_PRIVATE_KEY, ) self.task_to_compute = tasks.TaskToComputeFactory( compute_task_def=self.compute_task_def, want_to_compute_task=self.want_to_compute_task, provider_public_key=self._get_provider_hex_public_key(), requestor_public_key=self._get_requestor_hex_public_key(), sign__privkey=self.REQUESTOR_PRIVATE_KEY, ) self.size = 58 self.report_computed_task = tasks.ReportComputedTaskFactory( task_to_compute=self.task_to_compute, size=self.size, sign__privkey=self.PROVIDER_PRIVATE_KEY, ) self.force_golem_data = message.concents.ForceReportComputedTask( report_computed_task=self.report_computed_task, )
def test_send_should_return_http_400_if_task_to_compute_deadline_exceeded( self): compute_task_def = message.ComputeTaskDef() compute_task_def['task_id'] = '8' compute_task_def['deadline'] = self.message_timestamp - 9000 with freeze_time( datetime.datetime.fromtimestamp(self.message_timestamp - 10000)): task_to_compute = tasks.TaskToComputeFactory( compute_task_def=self.compute_task_def, provider_public_key=PROVIDER_PUBLIC_KEY, requestor_public_key=REQUESTOR_PUBLIC_KEY, price=0, ) serialized_task_to_compute = dump(task_to_compute, REQUESTOR_PRIVATE_KEY, PROVIDER_PUBLIC_KEY) deserialized_task_to_compute = load(serialized_task_to_compute, PROVIDER_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, check_time=False) ack_report_computed_task = message.AckReportComputedTask() ack_report_computed_task.report_computed_task = message.ReportComputedTask( task_to_compute=deserialized_task_to_compute) response_400 = self.client.post( reverse('core:send'), data=dump(ack_report_computed_task, PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY), content_type='application/octet-stream', ) self._test_400_response( response_400, error_code=ErrorCode.QUEUE_COMMUNICATION_NOT_STARTED)
def setUp(self): self.request_factory = RequestFactory() self.want_to_compute = WantToComputeTaskFactory() self.message_to_view = { "task_id": self.want_to_compute.task_id, # pylint: disable=no-member "perf_index": self.want_to_compute.perf_index, # pylint: disable=no-member "price": self.want_to_compute.price, # pylint: disable=no-member "max_resource_size": self.want_to_compute.max_resource_size, # pylint: disable=no-member "max_memory_size": self.want_to_compute.max_memory_size, # pylint: disable=no-member } deadline_offset = 10 message_timestamp = get_current_utc_timestamp() + deadline_offset compute_task_def = tasks.ComputeTaskDefFactory( deadline=message_timestamp, ) task_to_compute = tasks.TaskToComputeFactory( compute_task_def=compute_task_def, requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY), provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), price=0, ) task_to_compute = load( dump( task_to_compute, REQUESTOR_PRIVATE_KEY, settings.CONCENT_PUBLIC_KEY, ), settings.CONCENT_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, check_time=False, ) self.force_report_computed_task = message.concents.ForceReportComputedTask( ) self.force_report_computed_task.report_computed_task = message.tasks.ReportComputedTask( ) self.force_report_computed_task.report_computed_task.task_to_compute = task_to_compute
def test_load_without_public_key_should_load_message(self): """ Test that message loaded with load_without_public_key function will be the same as load with golem_messages load function. """ # Create and fill some data into ComputeTaskDef compute_task_def = tasks.ComputeTaskDefFactory( task_id=generate_uuid_for_tests(), subtask_id=generate_uuid_for_tests(), deadline=1510912800, ) # Create TaskToCompute task_to_compute = tasks.TaskToComputeFactory( compute_task_def=compute_task_def, price=0, ) # Dump TaskToCompute to make it signed dumped_task_to_compute = dump(task_to_compute, REQUESTOR_PRIVATE_KEY, CONCENT_PUBLIC_KEY) loaded_task_to_compute_with_utility_function = load_without_public_key( dumped_task_to_compute, REQUESTOR_PUBLIC_KEY, ) loaded_task_to_compute_with_golem_messages_load = load( dumped_task_to_compute, CONCENT_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, ) self.assertEqual(loaded_task_to_compute_with_utility_function, loaded_task_to_compute_with_golem_messages_load)
def test_that_incorrect_version_of_golem_messages_in_stored_message_should_raise_validation_error(self): with override_settings(GOLEM_MESSAGES_VERSION=self.second_communication_protocol_version): task_to_compute = tasks.TaskToComputeFactory() report_computed_task=tasks.ReportComputedTaskFactory(task_to_compute=task_to_compute) with self.assertRaises(ValidationError) as error: with mock.patch('core.message_handlers.store_message', side_effect=self.store_message_with_custom_protocol_version): store_subtask( task_id=task_to_compute.task_id, subtask_id=task_to_compute.subtask_id, task_to_compute=task_to_compute, provider_public_key=hex_to_bytes_convert(task_to_compute.provider_public_key), requestor_public_key=hex_to_bytes_convert(task_to_compute.requestor_public_key), report_computed_task=report_computed_task, state=Subtask.SubtaskState.REPORTED, next_deadline=None, ) self.assertIn( f"Unsupported Golem Message version. Version in: `task_to_compute` is {self.first_communication_protocol_version}, " f"Version in Concent is {self.second_communication_protocol_version}", str(error.exception) )
def setUp(self): super().setUp() self.compute_task_def = ComputeTaskDefFactory() self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60 self.want_to_compute_task = WantToComputeTaskFactory( node_name=1, task_id=self._get_uuid(), perf_index=3, price=4, max_resource_size=5, max_memory_size=6, num_cores=7, ) self.task_to_compute = tasks.TaskToComputeFactory( compute_task_def=self.compute_task_def, want_to_compute_task=self.want_to_compute_task, provider_public_key=self._get_provider_hex_public_key(), requestor_public_key=self._get_requestor_hex_public_key(), ) self.size = 58 with freeze_time("2017-11-17 10:00:00"): self.report_computed_task = message.tasks.ReportComputedTask( task_to_compute=self.task_to_compute, size=self.size ) self.force_golem_data = message.concents.ForceReportComputedTask( report_computed_task=self.report_computed_task ) message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp()) new_message = StoredMessage( type=self.force_golem_data.report_computed_task.header.type_, timestamp=message_timestamp, data=self.force_golem_data.report_computed_task.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member protocol_version=settings.GOLEM_MESSAGES_VERSION, ) new_message.full_clean() new_message.save() want_to_compute_message = StoredMessage( type=self.want_to_compute_task.header.type_, timestamp=message_timestamp, data=self.want_to_compute_task.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member protocol_version=settings.GOLEM_MESSAGES_VERSION, ) want_to_compute_message.full_clean() want_to_compute_message.save() task_to_compute_message = StoredMessage( type=self.task_to_compute.header.type_, timestamp=message_timestamp, data=self.task_to_compute.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member protocol_version=settings.GOLEM_MESSAGES_VERSION, ) task_to_compute_message.full_clean() task_to_compute_message.save() ack_report_computed_task = message.tasks.AckReportComputedTask( report_computed_task=self.report_computed_task ) stored_ack_report_computed_task = StoredMessage( type=ack_report_computed_task.header.type_, timestamp=message_timestamp, data=ack_report_computed_task.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member protocol_version=settings.GOLEM_MESSAGES_VERSION, ) stored_ack_report_computed_task.full_clean() stored_ack_report_computed_task.save() client_provider = Client( public_key_bytes=self.PROVIDER_PUBLIC_KEY ) client_provider.full_clean() client_provider.save() client_requestor = Client( public_key_bytes=self.REQUESTOR_PUBLIC_KEY ) client_requestor.full_clean() client_requestor.save() subtask = Subtask( task_id = self.compute_task_def['task_id'], subtask_id = self.compute_task_def['subtask_id'], report_computed_task = new_message, task_to_compute = task_to_compute_message, want_to_compute_task=want_to_compute_message, ack_report_computed_task = stored_ack_report_computed_task, state = Subtask.SubtaskState.REPORTED.name, # pylint: disable=no-member provider = client_provider, requestor = client_requestor, result_package_size=self.size, computation_deadline=parse_timestamp_to_utc_datetime(self.compute_task_def['deadline']) ) subtask.full_clean() subtask.save() new_message_inbox = PendingResponse( response_type=PendingResponse.ResponseType.ForceReportComputedTask.name, # pylint: disable=no-member client=client_requestor, queue=PendingResponse.Queue.ReceiveOutOfBand.name, # pylint: disable=no-member subtask=subtask, ) new_message_inbox.full_clean() new_message_inbox.save()
def setUp(self): super().setUp() self.compute_task_def = message.ComputeTaskDef() self.compute_task_def['task_id'] = '1' self.compute_task_def['subtask_id'] = '1' self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60 self.task_to_compute = tasks.TaskToComputeFactory( compute_task_def=self.compute_task_def, provider_public_key=PROVIDER_PUBLIC_KEY, requestor_public_key=REQUESTOR_PUBLIC_KEY, price=0, ) self.size = 58 with freeze_time("2017-11-17 10:00:00"): self.force_golem_data = message.ForceReportComputedTask( report_computed_task=message.tasks.ReportComputedTask( task_to_compute=self.task_to_compute, size=self.size)) message_timestamp = datetime.datetime.now(timezone.utc) new_message = StoredMessage( type=self.force_golem_data.report_computed_task.TYPE, timestamp=message_timestamp, data=self.force_golem_data.report_computed_task.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member ) new_message.full_clean() new_message.save() task_to_compute_message = StoredMessage( type=self.task_to_compute.TYPE, timestamp=message_timestamp, data=self.task_to_compute.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member ) task_to_compute_message.full_clean() task_to_compute_message.save() ack_report_computed_task = message.AckReportComputedTask( report_computed_task=message.tasks.ReportComputedTask( task_to_compute=self.task_to_compute, )) stored_ack_report_computed_task = StoredMessage( type=ack_report_computed_task.TYPE, timestamp=message_timestamp, data=ack_report_computed_task.serialize(), task_id=self.compute_task_def['task_id'], # pylint: disable=no-member subtask_id=self.compute_task_def['subtask_id'], # pylint: disable=no-member ) stored_ack_report_computed_task.full_clean() stored_ack_report_computed_task.save() client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY) client_provider.full_clean() client_provider.save() client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY) client_requestor.full_clean() client_requestor.save() subtask = Subtask( task_id=self.compute_task_def['task_id'], subtask_id=self.compute_task_def['subtask_id'], report_computed_task=new_message, task_to_compute=task_to_compute_message, ack_report_computed_task=stored_ack_report_computed_task, state=Subtask.SubtaskState.REPORTED.name, # pylint: disable=no-member provider=client_provider, requestor=client_requestor, result_package_size=self.size, computation_deadline=parse_timestamp_to_utc_datetime( self.compute_task_def['deadline'])) subtask.full_clean() subtask.save() new_message_inbox = PendingResponse( response_type=PendingResponse.ResponseType.ForceReportComputedTask. name, # pylint: disable=no-member client=client_requestor, queue=PendingResponse.Queue.ReceiveOutOfBand.name, # pylint: disable=no-member subtask=subtask, ) new_message_inbox.full_clean() new_message_inbox.save()