mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 04:13:07 +02:00
Fix usage of taskd.trust=strict on the test suite
* This reverts commit 67cb30fdce
.
* Code also now tests if taskd is listening on IPv4 or IPv6 interfaces.
This commit is contained in:
parent
73b7b21b81
commit
d1698eab2d
3 changed files with 32 additions and 9 deletions
|
@ -99,7 +99,6 @@ class Task(object):
|
||||||
self.config("taskd.certificate", cert)
|
self.config("taskd.certificate", cert)
|
||||||
self.config("taskd.key", key)
|
self.config("taskd.key", key)
|
||||||
self.config("taskd.ca", self.taskd.ca_cert)
|
self.config("taskd.ca", self.taskd.ca_cert)
|
||||||
self.config("taskd.trust", "ignore hostname")
|
|
||||||
|
|
||||||
address = ":".join((self.taskd.address, str(self.taskd.port)))
|
address = ":".join((self.taskd.address, str(self.taskd.port)))
|
||||||
self.config("taskd.server", address)
|
self.config("taskd.server", address)
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Taskd(object):
|
||||||
DEFAULT_TASKD = binary_location("taskd")
|
DEFAULT_TASKD = binary_location("taskd")
|
||||||
|
|
||||||
def __init__(self, taskd=DEFAULT_TASKD, certpath=None,
|
def __init__(self, taskd=DEFAULT_TASKD, certpath=None,
|
||||||
address="127.0.0.1"):
|
address="localhost"):
|
||||||
"""Initialize a Task server that runs in the background and stores data
|
"""Initialize a Task server that runs in the background and stores data
|
||||||
in a temporary folder
|
in a temporary folder
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class Taskd(object):
|
||||||
self.certpath = certpath
|
self.certpath = certpath
|
||||||
|
|
||||||
self.address = address
|
self.address = address
|
||||||
self.port = find_unused_port()
|
self.port = find_unused_port(self.address)
|
||||||
|
|
||||||
# Keep all certificate paths public for access by TaskClients
|
# Keep all certificate paths public for access by TaskClients
|
||||||
self.client_cert = os.path.join(self.certpath, "client.cert.pem")
|
self.client_cert = os.path.join(self.certpath, "client.cert.pem")
|
||||||
|
@ -182,7 +182,7 @@ class Taskd(object):
|
||||||
if self.proc.poll() is not None:
|
if self.proc.poll() is not None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not port_used(port=self.port):
|
if not port_used(addr=self.address, port=self.port):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -164,16 +164,40 @@ def run_cmd_wait_nofail(*args, **kwargs):
|
||||||
return e.code, e.out, e.err
|
return e.code, e.out, e.err
|
||||||
|
|
||||||
|
|
||||||
|
def get_IPs(hostname):
|
||||||
|
output = {}
|
||||||
|
addrs = socket.getaddrinfo(hostname, 0, 0, 0, socket.IPPROTO_TCP)
|
||||||
|
|
||||||
|
for family, socktype, proto, canonname, sockaddr in addrs:
|
||||||
|
addr = sockaddr[0]
|
||||||
|
output[family] = addr
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def port_used(addr="localhost", port=None):
|
def port_used(addr="localhost", port=None):
|
||||||
"Return True if port is in use, False otherwise"
|
"Return True if port is in use, False otherwise"
|
||||||
if port is None:
|
if port is None:
|
||||||
raise TypeError("Argument 'port' may not be None")
|
raise TypeError("Argument 'port' may not be None")
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
# If we got an address name, resolve it both to IPv6 and IPv4.
|
||||||
result = s.connect_ex((addr, port))
|
IPs = get_IPs(addr)
|
||||||
s.close()
|
|
||||||
# result == 0 if connection was successful
|
# Taskd seems to prefer IPv6 so we do it first
|
||||||
return result == 0
|
for family in (socket.AF_INET6, socket.AF_INET):
|
||||||
|
try:
|
||||||
|
addr = IPs[family]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
s = socket.socket(family, socket.SOCK_STREAM)
|
||||||
|
result = s.connect_ex((addr, port))
|
||||||
|
s.close()
|
||||||
|
if result == 0:
|
||||||
|
# connection was successful
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def find_unused_port(addr="localhost", start=53589, track=True):
|
def find_unused_port(addr="localhost", start=53589, track=True):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue