qa: Prevent concurrency issues reading .cookie file

This commit is contained in:
João Barbosa 2019-04-08 19:33:25 +01:00
parent a238fccce8
commit 90bce24576

View file

@ -323,12 +323,14 @@ def get_auth_cookie(datadir):
if line.startswith("rpcpassword="): if line.startswith("rpcpassword="):
assert password is None # Ensure that there is only one rpcpassword line assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n") password = line.split("=")[1].strip("\n")
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")) and os.access(os.path.join(datadir, "regtest", ".cookie"), os.R_OK): try:
with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f: with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f:
userpass = f.read() userpass = f.read()
split_userpass = userpass.split(':') split_userpass = userpass.split(':')
user = split_userpass[0] user = split_userpass[0]
password = split_userpass[1] password = split_userpass[1]
except OSError:
pass
if user is None or password is None: if user is None or password is None:
raise ValueError("No RPC credentials") raise ValueError("No RPC credentials")
return user, password return user, password