Reenables keys in e2e and removes monkeypatching

This commit is contained in:
Sergi Delgado Segura
2020-03-17 20:48:33 +01:00
parent d18944e2ba
commit a9e7eeb7f5
3 changed files with 21 additions and 41 deletions

View File

@@ -81,7 +81,8 @@ jobs:
. venv/bin/activate . venv/bin/activate
cp test/teos/e2e/teos-conf.py teos/conf.py cp test/teos/e2e/teos-conf.py teos/conf.py
python3 -m apps.generate_key -d ~/.teos/ python3 -m apps.generate_key -d ~/.teos/
python3 -m apps.generate_key -n cli -d ~/.teos/ python3 -m apps.generate_key -n cli -d ~/.teos_cli/
cp ~/.teos/teos_pk.der ~/.teos_cli/
# Run E2E tests # Run E2E tests

View File

@@ -9,6 +9,6 @@ CLIENT_LOG_FILE = "cli.log"
APPOINTMENTS_FOLDER_NAME = "appointment_receipts" APPOINTMENTS_FOLDER_NAME = "appointment_receipts"
# KEYS # KEYS
TEOS_PUBLIC_KEY = DATA_FOLDER + "teos_pk.der" TEOS_PUBLIC_KEY = "teos_pk.der"
CLI_PRIVATE_KEY = DATA_FOLDER + "cli_sk.der" CLI_PRIVATE_KEY = "cli_sk.der"
CLI_PUBLIC_KEY = DATA_FOLDER + "cli_pk.der" CLI_PUBLIC_KEY = "cli_pk.der"

View File

@@ -1,8 +1,9 @@
import json import json
import binascii
from time import sleep from time import sleep
from riemann.tx import Tx from riemann.tx import Tx
from teos import config
from teos import HOST, PORT from teos import HOST, PORT
from apps.cli import teos_cli from apps.cli import teos_cli
from common.blob import Blob from common.blob import Blob
@@ -20,6 +21,7 @@ from test.teos.e2e.conftest import (
create_penalty_tx, create_penalty_tx,
run_teosd, run_teosd,
) )
from apps.cli import config as cli_conf
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="") common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
@@ -32,13 +34,6 @@ teos_cli.teos_api_port = PORT
teosd_process = run_teosd() teosd_process = run_teosd()
def get_teos_pk():
teos_sk = Cryptographer.load_private_key_der(Cryptographer.load_key_file(config.get("TEOS_SECRET_KEY")))
teos_pk = teos_sk.public_key
return teos_pk
def broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, addr): def broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, addr):
# Broadcast the commitment transaction and mine a block # Broadcast the commitment transaction and mine a block
bitcoin_cli.sendrawtransaction(commitment_tx) bitcoin_cli.sendrawtransaction(commitment_tx)
@@ -51,9 +46,7 @@ def get_appointment_info(locator):
return teos_cli.get_appointment(locator) return teos_cli.get_appointment(locator)
def test_appointment_life_cycle(monkeypatch, bitcoin_cli, create_txs): def test_appointment_life_cycle(bitcoin_cli, create_txs):
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
commitment_tx, penalty_tx = create_txs commitment_tx, penalty_tx = create_txs
commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid") commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid")
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx) appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
@@ -96,9 +89,7 @@ def test_appointment_life_cycle(monkeypatch, bitcoin_cli, create_txs):
assert appointment_info[0].get("status") == "not_found" assert appointment_info[0].get("status") == "not_found"
def test_appointment_malformed_penalty(monkeypatch, bitcoin_cli, create_txs): def test_appointment_malformed_penalty(bitcoin_cli, create_txs):
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# Lets start by creating two valid transaction # Lets start by creating two valid transaction
commitment_tx, penalty_tx = create_txs commitment_tx, penalty_tx = create_txs
@@ -140,17 +131,13 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
appointment_data["encrypted_blob"] = Cryptographer.encrypt(Blob(penalty_tx), get_random_value_hex(32)) appointment_data["encrypted_blob"] = Cryptographer.encrypt(Blob(penalty_tx), get_random_value_hex(32))
appointment = Appointment.from_dict(appointment_data) appointment = Appointment.from_dict(appointment_data)
# teos_pk, cli_sk, cli_pk_der = teos_cli.load_keys( teos_pk, cli_sk, cli_pk_der = teos_cli.load_keys(
# cli_conf.get("TEOS_PUBLIC_KEY"), cli_conf.get("CLI_PRIVATE_KEY"), cli_conf.get("CLI_PUBLIC_KEY") cli_conf.get("TEOS_PUBLIC_KEY"), cli_conf.get("CLI_PRIVATE_KEY"), cli_conf.get("CLI_PUBLIC_KEY")
# ) )
# hex_pk_der = binascii.hexlify(cli_pk_der) hex_pk_der = binascii.hexlify(cli_pk_der)
#
# signature = Cryptographer.sign(appointment.serialize(), cli_sk) signature = Cryptographer.sign(appointment.serialize(), cli_sk)
# data = {"appointment": appointment.to_dict(), "signature": signature, "public_key": hex_pk_der.decode("utf-8")} data = {"appointment": appointment.to_dict(), "signature": signature, "public_key": hex_pk_der.decode("utf-8")}
# FIXME: Since the pk is now hardcoded for the alpha in the cli we cannot use load_keys here. We need to derive
# the pk from the sk on disk.
teos_pk = get_teos_pk()
data = {"appointment": appointment.to_dict()}
# Send appointment to the server. # Send appointment to the server.
response = teos_cli.post_appointment(data) response = teos_cli.post_appointment(data)
@@ -176,9 +163,7 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
assert appointment_info[0].get("status") == "not_found" assert appointment_info[0].get("status") == "not_found"
def test_two_identical_appointments(monkeypatch, bitcoin_cli, create_txs): def test_two_identical_appointments(bitcoin_cli, create_txs):
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# Tests sending two identical appointments to the tower. # Tests sending two identical appointments to the tower.
# At the moment there are no checks for identical appointments, so both will be accepted, decrypted and kept until # At the moment there are no checks for identical appointments, so both will be accepted, decrypted and kept until
# the end. # the end.
@@ -211,9 +196,7 @@ def test_two_identical_appointments(monkeypatch, bitcoin_cli, create_txs):
assert info.get("penalty_rawtx") == penalty_tx assert info.get("penalty_rawtx") == penalty_tx
def test_two_appointment_same_locator_different_penalty(monkeypatch, bitcoin_cli, create_txs): def test_two_appointment_same_locator_different_penalty(bitcoin_cli, create_txs):
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# This tests sending an appointment with two valid transaction with the same locator. # This tests sending an appointment with two valid transaction with the same locator.
commitment_tx, penalty_tx1 = create_txs commitment_tx, penalty_tx1 = create_txs
commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid") commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid")
@@ -245,11 +228,9 @@ def test_two_appointment_same_locator_different_penalty(monkeypatch, bitcoin_cli
assert appointment_info[0].get("penalty_rawtx") == penalty_tx1 assert appointment_info[0].get("penalty_rawtx") == penalty_tx1
def test_appointment_shutdown_teos_trigger_back_online(monkeypatch, create_txs, bitcoin_cli): def test_appointment_shutdown_teos_trigger_back_online(create_txs, bitcoin_cli):
global teosd_process global teosd_process
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
teos_pid = teosd_process.pid teos_pid = teosd_process.pid
commitment_tx, penalty_tx = create_txs commitment_tx, penalty_tx = create_txs
@@ -285,11 +266,9 @@ def test_appointment_shutdown_teos_trigger_back_online(monkeypatch, create_txs,
assert appointment_info[0].get("status") == "dispute_responded" assert appointment_info[0].get("status") == "dispute_responded"
def test_appointment_shutdown_teos_trigger_while_offline(monkeypatch, create_txs, bitcoin_cli): def test_appointment_shutdown_teos_trigger_while_offline(create_txs, bitcoin_cli):
global teosd_process global teosd_process
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
teos_pid = teosd_process.pid teos_pid = teosd_process.pid
commitment_tx, penalty_tx = create_txs commitment_tx, penalty_tx = create_txs