Exemplo n.º 1
0
def test_add_appointment_with_invalid_signature():
    # Simulate a request to add_appointment for dummy_appointment, but sign with a different key,
    # make sure that the right endpoint is requested, but the return value is False
    appointment = teos_client.create_appointment(dummy_appointment_data)
    user_signature = Cryptographer.sign(appointment.serialize(), dummy_user_sk)
    appointment_receipt = receipts.create_appointment_receipt(
        user_signature, CURRENT_HEIGHT)

    # Sign with a bad key
    response = {
        "locator": dummy_appointment.locator,
        "signature": Cryptographer.sign(appointment_receipt, another_sk),
        "available_slots": 100,
        "start_block": CURRENT_HEIGHT,
        "subscription_expiry": CURRENT_HEIGHT + 4320,
    }

    responses.add(responses.POST,
                  add_appointment_endpoint,
                  json=response,
                  status=200)

    with pytest.raises(TowerResponseError):
        teos_client.add_appointment(
            Appointment.from_dict(dummy_appointment_data), dummy_user_sk,
            dummy_teos_id, teos_url)

    # should have performed exactly 1 network request
    assert len(responses.calls) == 1
Exemplo n.º 2
0
def test_add_appointment_with_missing_signature():
    # Simulate a request to add_appointment for dummy_appointment, but the response does not have
    # the signature.

    appointment = teos_client.create_appointment(dummy_appointment_data)

    response = {
        "locator": dummy_appointment.locator,
        # no signature
        "available_slots": 100,
        "start_block": CURRENT_HEIGHT,
        "subscription_expiry": CURRENT_HEIGHT + 4320,
    }

    responses.add(responses.POST,
                  add_appointment_endpoint,
                  json=response,
                  status=200)

    with pytest.raises(TowerResponseError,
                       match="does not contain the signature"):
        teos_client.add_appointment(appointment, dummy_user_sk, dummy_teos_id,
                                    teos_url)

    # should have performed exactly 1 network request
    assert len(responses.calls) == 1
Exemplo n.º 3
0
def test_add_appointment():
    # Simulate a request to add_appointment for dummy_appointment, make sure that the right endpoint is requested
    # and the return value is True
    appointment = teos_client.create_appointment(dummy_appointment_data)
    user_signature = Cryptographer.sign(appointment.serialize(), dummy_user_sk)
    appointment_receipt = receipts.create_appointment_receipt(
        user_signature, CURRENT_HEIGHT)

    response = {
        "locator": dummy_appointment.locator,
        "signature": Cryptographer.sign(appointment_receipt, dummy_teos_sk),
        "available_slots": 100,
        "start_block": CURRENT_HEIGHT,
        "subscription_expiry": CURRENT_HEIGHT + 4320,
    }
    responses.add(responses.POST,
                  add_appointment_endpoint,
                  json=response,
                  status=200)

    result = teos_client.add_appointment(
        Appointment.from_dict(dummy_appointment_data), dummy_user_sk,
        dummy_teos_id, teos_url)

    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == add_appointment_endpoint
    assert result
Exemplo n.º 4
0
def add_appointment(teos_id, appointment_data, sk=user_sk):
    return teos_client.add_appointment(appointment_data, sk, teos_id, teos_base_endpoint)