Ejemplo n.º 1
0
    def test_golem_messages_version_middleware_should_attach_http_header_to_response(
            self):
        """
        Tests that response from Concent:

        * Contains HTTP header 'Concent-Golem-Messages-Version'.
        * Header contains latest version of golem_messages package.
        """
        ping_message = message.Ping()
        serialized_ping_message = dump(ping_message, PROVIDER_PRIVATE_KEY,
                                       CONCENT_PUBLIC_KEY)

        response = self.client.post(
            reverse('core:send'),
            data=serialized_ping_message,
            content_type='application/octet-stream',
        )

        self.assertFalse(500 <= response.status_code < 600)
        self.assertIn('concent-golem-messages-version', response._headers)
        self.assertEqual(
            response._headers['concent-golem-messages-version'][0],
            'Concent-Golem-Messages-Version')
        self.assertEqual(
            response._headers['concent-golem-messages-version'][1],
            __version__)
Ejemplo n.º 2
0
 def test_dump_load(self):
     msg = message.Ping()
     payload = golem_messages.dump(msg, self.ecc.raw_privkey,
                                   self.ecc.raw_pubkey)
     msg2 = golem_messages.load(payload, self.ecc.raw_privkey,
                                self.ecc.raw_pubkey)
     self.assertEqual(msg, msg2)
Ejemplo n.º 3
0
    def test_golem_messages_version_middleware_should_attach_http_header_to_response(
            self):
        """
        Tests that response from Concent:

        * Contains HTTP header 'Concent-Version'.
        * Header contains version of Concent taken from settings.
        """
        ping_message = message.Ping()
        serialized_ping_message = dump(ping_message, PROVIDER_PRIVATE_KEY,
                                       CONCENT_PUBLIC_KEY)

        with mock.patch(
                'concent_api.middleware.ConcentVersionMiddleware._concent_version',
                '1.0'):
            response = self.client.post(
                reverse('core:send'),
                data=serialized_ping_message,
                content_type='application/octet-stream',
                HTTP_X_Golem_Messages=settings.GOLEM_MESSAGES_VERSION,
            )

        self.assertFalse(500 <= response.status_code < 600)
        self.assertIn('concent-golem-messages-version', response._headers)
        self.assertEqual(response._headers['concent-version'][0],
                         'Concent-Version')
        self.assertEqual(response._headers['concent-version'][1], '1.0')
Ejemplo n.º 4
0
 def test_deserialization_with_time_verification(self, vft_mock):
     msg = message.Ping()
     payload = golem_messages.dump(msg, self.ecc.raw_privkey,
                                   self.ecc.raw_pubkey)
     self.assertEqual(vft_mock.call_count, 0)
     golem_messages.load(payload, self.ecc.raw_privkey, self.ecc.raw_pubkey)
     self.assertEqual(vft_mock.call_count, 1)
Ejemplo n.º 5
0
    def test_add_signature_with_correct_keys_pair(self):
        ping_message = message.Ping()
        self.assertEqual(ping_message.sig, None)

        ping_message = sign_message(ping_message, CONCENT_PRIVATE_KEY)

        self.assertIsNot(ping_message.sig, None)
        self.assertIsInstance(ping_message.sig, bytes)
    def test_that_validate_all_messages_identical_should_raise_error_when_not_all_list_items_are_instances_of_task_to_compute(
            self):

        with self.assertRaises(AssertionError):
            validate_all_messages_identical([
                message.TaskToCompute(),
                message.TaskToCompute(),
                message.Ping(),
            ])
Ejemplo n.º 7
0
 def test_deserialize_verify(self):
     """Basic verificating deserializer"""
     ping = message.Ping()
     result = message.base.deserialize_verify(
         key='ping',
         verify_key='ping',
         value=ping,
         verify_class=message.Ping,
     )
     self.assertEqual(result, ping)
class TestCorrectMessageToForcePaymentHandler:
    @pytest.mark.parametrize('subtask_results_accepted_list',
                             (None, [], [message.Ping()], ()))
    def test_that_force_payment_with_malformed_subtask_results_accepted_list_raises_assertion(
            self, subtask_results_accepted_list):  # pylint: disable=no-self-use
        force_payment = message.concents.ForcePayment(
            subtask_results_accepted_list=subtask_results_accepted_list)

        with pytest.raises(AssertionError):
            handle_send_force_payment(force_payment)
Ejemplo n.º 9
0
 def test_that_middleware_does_not_intercept_bad_requests(self):
     ping_message = message.Ping()
     serialized_ping_message = dump(ping_message, PROVIDER_PRIVATE_KEY,
                                    CONCENT_PUBLIC_KEY)
     response = self.client.post(
         reverse('core:receive'),
         data=serialized_ping_message,
         content_type='application/octet-stream',
     )
     self.assertEqual(response.status_code, 400)
Ejemplo n.º 10
0
    def test_send_should_reject_message_when_timestamp_too_old(self):
        with freeze_time("2017-11-17 09:40:00"):
            ping = message.Ping()

        with freeze_time("2017-11-17 10:00:00"):
            timestamp = dateutil.parser.parse("2017-11-17 09:40:00")
            assert datetime.datetime.now() - timestamp > settings.MSG_TTL
            response = self.client.post(
                reverse('core:send'),
                data=dump(ping, PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY),
                content_type='application/octet-stream',
            )

        self._test_400_response(response)
Ejemplo n.º 11
0
    def test_send_should_reject_message_when_timestamp_too_old(self):
        with freeze_time("2017-11-17 09:40:00"):
            ping = message.Ping()

        with freeze_time("2017-11-17 10:00:00"):
            timestamp = self._create_datetime_from_string(
                "2017-11-17 09:40:00")
            assert parse_timestamp_to_utc_datetime(get_current_utc_timestamp(
            )) - timestamp > golem_settings.MSG_TTL
            response = self.send_request(
                url='core:send',
                data=dump(ping, self.PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY),
            )

        self._test_400_response(response)
Ejemplo n.º 12
0
    def test_send_should_reject_message_when_timestamp_too_far_in_future(self):
        with freeze_time("2017-11-17 10:10:00"):
            ping = message.Ping()

        with freeze_time("2017-11-17 10:00:00"):
            timestamp = self._create_datetime_from_string(
                "2017-11-17 10:10:00")
            assert timestamp - parse_timestamp_to_utc_datetime(
                get_current_utc_timestamp(
                )) > golem_settings.FUTURE_TIME_TOLERANCE
            response = self.send_request(
                url='core:send',
                data=dump(ping, self.PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY),
            )

        self._test_400_response(response)
 def setUp(self):
     self.dummy_message_to_concent = message.Ping()
     self.serialized_dummy_message_to_concent = dump(
         self.dummy_message_to_concent, PROVIDER_PRIVATE_KEY,
         CONCENT_PUBLIC_KEY)
Ejemplo n.º 14
0
 def test_message_dict(self):
     d = {'m': message.Ping()}
     self.equal_after_processing(d)
Ejemplo n.º 15
0
 def test_message_list(self):
     aList = [message.Ping()]
     self.equal_after_processing(aList)
Ejemplo n.º 16
0
 def _create_test_ping_message(self):  # pylint: disable=no-self-use
     ping_message = message.Ping()
     return ping_message
Ejemplo n.º 17
0
    def test_validate_golem_message_client_authorization_should_raise_400_error_when_wrong_message_is_used(self):
        ping = message.Ping()

        with self.assertRaises(Http400):
            validate_golem_message_client_authorization(ping)
Ejemplo n.º 18
0
 def test_year_is_out_of_range(self, timestamp_mock):
     for err in (TypeError, OSError, OverflowError, ValueError):
         timestamp_mock.side_effect = err
         with self.assertRaises(exceptions.TimestampError):
             msg = message.Ping()
             message.base.verify_time(msg.timestamp)
Ejemplo n.º 19
0
 def test_message(self):
     m = message.Ping()
     self.equal_after_processing(m)