[UI] Fix non-unique hostlist host_id

Use a sha1 of time.time() can result in identical host_id. This was
evident with Travis tests randomly failing due to host_id collision
returning the wrong host details.

Using uuid4 to generate a random UUID in hex form should fix this issue.
This commit is contained in:
Calum Lind 2018-05-20 22:35:43 +01:00
parent 8439698336
commit d4addeedd6
2 changed files with 4 additions and 4 deletions

View File

@ -8,6 +8,7 @@
there to allow acting upon them. there to allow acting upon them.
* Enforced the use of the "deluge.plugins" namespace to reduce package * Enforced the use of the "deluge.plugins" namespace to reduce package
names clashing beetween regular packages and deluge plugins. names clashing beetween regular packages and deluge plugins.
* Fix potential for host_id collision when creating hostlist entries.
==== Core ==== ==== Core ====
* Make the distinction between adding to the session new unmanaged torrents * Make the distinction between adding to the session new unmanaged torrents

View File

@ -11,8 +11,7 @@ from __future__ import unicode_literals
import logging import logging
import os import os
import time import uuid
from hashlib import sha1
from socket import gaierror, gethostbyname from socket import gaierror, gethostbyname
from twisted.internet import defer from twisted.internet import defer
@ -31,7 +30,7 @@ LOCALHOST = ('127.0.0.1', 'localhost')
def default_hostlist(): def default_hostlist():
"""Create a new hosts key for hostlist with a localhost entry""" """Create a new hosts key for hostlist with a localhost entry"""
host_id = sha1(str(time.time()).encode('utf8')).hexdigest() host_id = uuid.uuid4().hex
username, password = get_localhost_auth() username, password = get_localhost_auth()
return {'hosts': [(host_id, DEFAULT_HOST, DEFAULT_PORT, username, password)]} return {'hosts': [(host_id, DEFAULT_HOST, DEFAULT_PORT, username, password)]}
@ -132,7 +131,7 @@ class HostList(object):
validate_host_info(hostname, port) validate_host_info(hostname, port)
self.check_info_exists(hostname, port, username) self.check_info_exists(hostname, port, username)
host_id = sha1(str(time.time())).hexdigest() host_id = uuid.uuid4().hex
self.config['hosts'].append((host_id, hostname, port, username, password)) self.config['hosts'].append((host_id, hostname, port, username, password))
self.config.save() self.config.save()
return host_id return host_id