예제 #1
0
from golem_messages.message.concents import ClientAuthorization
from golem_messages.shortcuts import dump
from golem_messages.shortcuts import load
from golem_messages.utils import encode_hex

import datetime
import json
import requests
import http.client

from protocol_constants import get_protocol_constants
from protocol_constants import print_protocol_constants
from utils.helpers import sign_message
from utils.testing_helpers import generate_ecc_key_pair

(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY) = generate_ecc_key_pair()
(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY) = generate_ecc_key_pair()

REQUESTOR_ETHEREUM_PUBLIC_KEY = '46de69a1c010c84dceafc0700d8e8fb160208df73da6b6ba7a4cbb59d63ad5068d50e723b9bbf854c733eb487f32ca76b1d877dedb89f0dd44a5bf0330f3963b'
PROVIDER_ETHEREUM_PUBLIC_KEY = '05a777c69b893cf8527aefc441774e7da00e7b70c8a74146fcd236c129db67708b5d39fdaa5dd548403f4614db558b938df1fc2f7b73338cc7802d2c9d1934758d'


class TestAssertionException(Exception):
    pass


class count_fails(object):
    """
    Decorator that wraps a test functions for intercepting assertions and counting them.
    """
    instances = []  # type: ignore
    return mocked_object


def mock_send_incorrect_request_to_cluster_incorrect_response(_headers, _request_http):
    mocked_object = mock.Mock()
    mocked_object.status_code = 404
    return mocked_object


def mock_send_incorrect_request_to_cluster_unexpected_response(_headers, _request_http):
    mocked_object = mock.Mock()
    mocked_object.status_code = 500
    return mocked_object


(CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY)       = generate_ecc_key_pair()


@override_settings(
    CONCENT_PRIVATE_KEY       = CONCENT_PRIVATE_KEY,
    CONCENT_PUBLIC_KEY        = CONCENT_PUBLIC_KEY,
)
class RequestUploadStatusTest(ConcentIntegrationTestCase):
    def test_properly_work_of_request_upload_status_function(self):

        report_computed_task=self._get_deserialized_report_computed_task(
            subtask_id='1',
            task_to_compute=self._get_deserialized_task_to_compute(
                task_id='1/1',
                subtask_id='1',
            )
예제 #3
0
 def setUp(self):
     self.message = "Missing 'Authorization' header."
     self.path = 'blender/benchmark/test_task/scene-Helicopter-27-cycles.blend'
     self.client_key = b64encode(generate_ecc_key_pair()[1]).decode("ascii")
예제 #4
0
from golem_messages                 import settings
from golem_messages.factories       import tasks
from golem_messages.shortcuts       import dump
from golem_messages.shortcuts       import load

from core.models                    import Client
from core.models                    import StoredMessage
from core.models                    import PendingResponse
from core.tests.utils               import ConcentIntegrationTestCase
from core.models                    import Subtask
from utils.constants                import ErrorCode
from utils.helpers                  import get_current_utc_timestamp
from utils.testing_helpers          import generate_ecc_key_pair


(CONCENT_PRIVATE_KEY,   CONCENT_PUBLIC_KEY)   = generate_ecc_key_pair()
(PROVIDER_PRIVATE_KEY,  PROVIDER_PUBLIC_KEY)  = generate_ecc_key_pair()
(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY) = generate_ecc_key_pair()
(DIFFERENT_PRIVATE_KEY, DIFFERENT_PUBLIC_KEY) = generate_ecc_key_pair()


@override_settings(
    CONCENT_PRIVATE_KEY    = CONCENT_PRIVATE_KEY,
    CONCENT_PUBLIC_KEY     = CONCENT_PUBLIC_KEY,
    CONCENT_MESSAGING_TIME = 3600,
)
class CoreViewSendTest(ConcentIntegrationTestCase):

    @freeze_time("2017-11-17 10:00:00")
    def setUp(self):
        super().setUp()
예제 #5
0
from django.test                    import TestCase

from golem_messages                 import message
from golem_messages.factories       import tasks
from golem_messages.shortcuts       import dump
from golem_messages.shortcuts       import load

from core.exceptions                import Http400
from core.validation                import validate_all_messages_identical
from core.validation                import validate_golem_message_client_authorization
from core.validation                import validate_golem_message_signed_with_key
from utils.shortcuts                import load_without_public_key
from utils.testing_helpers          import generate_ecc_key_pair


(CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY)       = generate_ecc_key_pair()
(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY)   = generate_ecc_key_pair()


@override_settings(
    CONCENT_PRIVATE_KEY       = CONCENT_PRIVATE_KEY,
    CONCENT_PUBLIC_KEY        = CONCENT_PUBLIC_KEY,
)
class LoadWithoutPublicKeyUnitTest(TestCase):

    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.
        """
예제 #6
0
 def _get_or_generate_keys(party):
     if are_keys_predifined(party):
         return _get_predefined_keys(party)
     return generate_ecc_key_pair()
예제 #7
0
파일: utils.py 프로젝트: etsangsplk/concent
    def setUp(self):
        super().setUp()

        # Keys
        (self.PROVIDER_PRIVATE_KEY,                 self.PROVIDER_PUBLIC_KEY)               = generate_ecc_key_pair()
        (self.REQUESTOR_PRIVATE_KEY,                self.REQUESTOR_PUBLIC_KEY)              = generate_ecc_key_pair()
        (self.DIFFERENT_PROVIDER_PRIVATE_KEY,       self.DIFFERENT_PROVIDER_PUBLIC_KEY)     = generate_ecc_key_pair()
        (self.DIFFERENT_REQUESTOR_PRIVATE_KEY,      self.DIFFERENT_REQUESTOR_PUBLIC_KEY)    = generate_ecc_key_pair()
        (self.PROVIDER_PRIV_ETH_KEY,                self.PROVIDER_PUB_ETH_KEY)              = generate_priv_and_pub_eth_account_key()
        (self.REQUESTOR_PRIV_ETH_KEY,               self.REQUESTOR_PUB_ETH_KEY)             = generate_priv_and_pub_eth_account_key()
        (self.DIFFERENT_PROVIDER_PRIV_ETH_KEY,      self.DIFFERENT_PROVIDER_PUB_ETH_KEY)    = generate_priv_and_pub_eth_account_key()
        (self.DIFFERENT_REQUESTOR_PRIV_ETH_KEY,     self.DIFFERENT_REQUESTOR_PUB_ETH_KEY)   = generate_priv_and_pub_eth_account_key()

        # StoredMessage
        self.stored_message_counter = 0

        # Auth
        self.auth_message_counter = 0