Fixes some bugs based on E2E testing

This commit is contained in:
Sergi Delgado Segura
2020-01-16 17:08:44 +01:00
parent d3846c1fe6
commit 90e1245a84
3 changed files with 23 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ from apps.cli import (
from common.logger import Logger
from common.appointment import Appointment
from common.cryptographer import Cryptographer
from common.tools import check_sha256_hex_format, compute_locator
from common.tools import check_sha256_hex_format, check_locator_format, compute_locator
HTTP_OK = 200
@@ -256,7 +256,7 @@ def check_signature(signature, appointment):
def get_appointment(args):
if not args:
logger.error("No arguments were given")
return False
return None
arg_opt = args.pop(0)
@@ -264,27 +264,27 @@ def get_appointment(args):
sys.exit(help_get_appointment())
else:
locator = arg_opt
valid_locator = check_sha256_hex_format(locator)
valid_locator = check_locator_format(locator)
if not valid_locator:
logger.error("The provided locator is not valid", locator=locator)
return False
return None
get_appointment_endpoint = "http://{}:{}/get_appointment".format(pisa_api_server, pisa_api_port)
parameters = "?locator={}".format(locator)
try:
r = requests.get(url=get_appointment_endpoint + parameters, timeout=5)
logger.info("Appointment response returned from server: " + str(r))
return True
logger.info("Appointment response returned from server: {}".format(r.json()))
return r.json()
except ConnectTimeout:
logger.error("Can't connect to pisa API. Connection timeout")
return False
return None
except ConnectionError:
logger.error("Can't connect to pisa API. Server cannot be reached")
return False
return None
def get_appointment_signature(appointment):

View File

@@ -15,6 +15,19 @@ def check_sha256_hex_format(value):
return isinstance(value, str) and re.match(r"^[0-9A-Fa-f]{64}$", value) is not None
def check_locator_format(value):
"""
Checks if a given value is a 16-byte hex encoded string.
Args:
value(:mod:`str`): the value to be checked.
Returns:
:mod:`bool`: Whether or not the value matches the format.
"""
return isinstance(value, str) and re.match(r"^[0-9A-Fa-f]{32}$", value) is not None
def compute_locator(tx_id):
"""
Computes an appointment locator given a transaction id.

View File

@@ -1,4 +1,5 @@
from http.client import HTTPException
from socket import timeout
import pisa.conf as conf
from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException
@@ -36,7 +37,7 @@ def can_connect_to_bitcoind():
try:
bitcoin_cli().help()
except (ConnectionRefusedError, JSONRPCException, HTTPException):
except (timeout, ConnectionRefusedError, JSONRPCException, HTTPException):
can_connect = False
return can_connect