Skip to content

Commit

Permalink
robustify the auth test: use the new challenge-handlers argument with…
Browse files Browse the repository at this point in the history
… client commands to specify the handler more stricly, delete temp files as soon as possible, parse session and env options using binary strings

git-svn-id: https://xpra.org/svn/Xpra/trunk@23188 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 17, 2019
1 parent 6b4b1da commit 8ba0ee2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/unittests/unit/process_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ def _temp_file(self, data=None, prefix="xpra-"):
self.temp_files.append(f.name)
return f

def delete_temp_file(self, f):
try:
self.temp_files.remove(f.name)
except ValueError:
pass
try:
os.unlink(f.name)
except OSError as e:
log.error("Error deleting temp file '%s': %s", f.name, e)


@classmethod
def find_X11_display_numbers(cls):
Expand Down
25 changes: 15 additions & 10 deletions src/unittests/unit/server/server_auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import os
import unittest
from xpra.os_util import pollwait, OSX, POSIX

from xpra.os_util import pollwait, strtobytes, OSX, POSIX
from xpra.exit_codes import EXIT_OK, EXIT_FAILURE, EXIT_PASSWORD_REQUIRED, EXIT_NO_AUTHENTICATION
from unit.server_test_util import ServerTestUtil, log

Expand All @@ -25,13 +26,17 @@ def _test_auth(self, auth="fail", uri_prefix="", exit_code=0, password=None):
#try to connect
cmd = ["info", uri_prefix+display]
f = None
if password:
f = self._temp_file(password)
cmd += ["--password-file=%s" % f.name]
client = self.run_xpra(cmd)
r = pollwait(client, 5)
if f:
f.close()
try:
if password:
f = self._temp_file(strtobytes(password))
cmd += ["--password-file=%s" % f.name]
cmd += ["--challenge-handlers=file:filename=%s" % f.name]
client = self.run_xpra(cmd)
r = pollwait(client, 5)
finally:
if f:
f.close()
self.delete_temp_file(f)
if client.poll() is None:
client.terminate()
server.terminate()
Expand All @@ -54,7 +59,7 @@ def test_allow(self):
def test_file(self):
from xpra.os_util import get_hex_uuid
password = get_hex_uuid()
f = self._temp_file(password)
f = self._temp_file(strtobytes(password))
self._test_auth("file", "", EXIT_PASSWORD_REQUIRED)
self._test_auth("file:filename=%s" % f.name, "", EXIT_PASSWORD_REQUIRED)
self._test_auth("file:filename=%s" % f.name, "", EXIT_OK, password)
Expand All @@ -68,7 +73,7 @@ def test_multifile(self):
password = get_hex_uuid()
displays = ""
data = "%s|%s|%i|%i|%s||" % (username, password, os.getuid(), os.getgid(), displays)
f = self._temp_file(data)
f = self._temp_file(strtobytes(data))
self._test_auth("multifile", "", EXIT_PASSWORD_REQUIRED)
self._test_auth("multifile:filename=%s" % f.name, "", EXIT_PASSWORD_REQUIRED)
self._test_auth("multifile:filename=%s" % f.name, "", EXIT_OK, password)
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/server/auth/multifile_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from xpra.server.auth.sys_auth_base import parse_uid, parse_gid
from xpra.server.auth.file_auth_base import log, FileAuthenticatorBase, init
from xpra.os_util import strtobytes, hexstr
from xpra.os_util import strtobytes, bytestostr, hexstr
from xpra.util import parse_simple_dict
from xpra.net.digest import verify_digest
assert init and log #tests will disable logging from here
Expand All @@ -33,9 +33,9 @@ def parse_auth_line(line):
env_options = {}
session_options = {}
if len(ldata)>=6:
env_options = parse_simple_dict(ldata[5], ";")
env_options = parse_simple_dict(ldata[5], b";")
if len(ldata)>=7:
session_options = parse_simple_dict(ldata[6], ";")
session_options = parse_simple_dict(ldata[6], b";")
return username, password, uid, gid, displays, env_options, session_options


Expand Down Expand Up @@ -66,7 +66,7 @@ def parse_filedata(self, data):
except Exception as e:
log("parsing error", exc_info=True)
log.error("Error parsing password file '%s' at line %i:", self.password_filename, i)
log.error(" '%s'", line)
log.error(" '%s'", bytestostr(line))
log.error(" %s", e)
continue
log("parsed auth data from file %s: %s", self.password_filename, auth_data)
Expand Down

0 comments on commit 8ba0ee2

Please sign in to comment.