mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Merge pull request #1058 from tahoe-lafs/3707-more-integration-python-3
Port more integration tests to Python 3 Fixes ticket:3707
This commit is contained in:
commit
e01baaeb95
@ -5,6 +5,15 @@
|
||||
# You can safely skip any of these tests, it'll just appear to "take
|
||||
# longer" to start the first test as the fixtures get built
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
|
||||
def test_create_flogger(flog_gatherer):
|
||||
print("Created flog_gatherer")
|
||||
|
@ -1,3 +1,6 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import (
|
||||
print_function,
|
||||
unicode_literals,
|
||||
@ -5,12 +8,18 @@ from __future__ import (
|
||||
division,
|
||||
)
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from six import ensure_text
|
||||
|
||||
import json
|
||||
|
||||
from os.path import (
|
||||
join,
|
||||
)
|
||||
from urlparse import (
|
||||
from urllib.parse import (
|
||||
urlsplit,
|
||||
)
|
||||
|
||||
@ -68,7 +77,7 @@ def _connect_client(reactor, api_auth_token, ws_url):
|
||||
factory = WebSocketClientFactory(
|
||||
url=ws_url,
|
||||
headers={
|
||||
"Authorization": "{} {}".format(SCHEME, api_auth_token),
|
||||
"Authorization": "{} {}".format(str(SCHEME, "ascii"), api_auth_token),
|
||||
}
|
||||
)
|
||||
factory.protocol = _StreamingLogClientProtocol
|
||||
@ -127,7 +136,7 @@ def _test_streaming_logs(reactor, temp_dir, alice):
|
||||
node_url = cfg.get_config_from_file("node.url")
|
||||
api_auth_token = cfg.get_private_config("api_auth_token")
|
||||
|
||||
ws_url = node_url.replace("http://", "ws://")
|
||||
ws_url = ensure_text(node_url).replace("http://", "ws://")
|
||||
log_url = ws_url + "private/logs/v1"
|
||||
|
||||
print("Connecting to {}".format(log_url))
|
||||
|
@ -532,7 +532,8 @@ def generate_ssh_key(path):
|
||||
key = RSAKey.generate(2048)
|
||||
key.write_private_key_file(path)
|
||||
with open(path + ".pub", "wb") as f:
|
||||
f.write(b"%s %s" % (key.get_name(), key.get_base64()))
|
||||
s = "%s %s" % (key.get_name(), key.get_base64())
|
||||
f.write(s.encode("ascii"))
|
||||
|
||||
|
||||
def run_in_thread(f):
|
||||
|
0
newsfragments/3707.minor
Normal file
0
newsfragments/3707.minor
Normal file
@ -928,7 +928,8 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
random data in "api_auth_token" which must be echoed to API
|
||||
calls.
|
||||
"""
|
||||
return self.config.get_private_config('api_auth_token')
|
||||
return self.config.get_private_config(
|
||||
'api_auth_token').encode("ascii")
|
||||
|
||||
def _create_auth_token(self):
|
||||
"""
|
||||
|
@ -80,5 +80,5 @@ class AccountFileChecker(object):
|
||||
return defer.fail(error.UnauthorizedLogin())
|
||||
|
||||
d = defer.maybeDeferred(creds.checkPassword, correct)
|
||||
d.addCallback(self._cbPasswordMatch, str(creds.username))
|
||||
d.addCallback(self._cbPasswordMatch, creds.username)
|
||||
return d
|
||||
|
@ -1011,8 +1011,8 @@ class SFTPUserHandler(ConchUser, PrefixingLogMixin):
|
||||
PrefixingLogMixin.__init__(self, facility="tahoe.sftp", prefix=username)
|
||||
if noisy: self.log(".__init__(%r, %r, %r)" % (client, rootnode, username), level=NOISY)
|
||||
|
||||
self.channelLookup["session"] = session.SSHSession
|
||||
self.subsystemLookup["sftp"] = FileTransferServer
|
||||
self.channelLookup[b"session"] = session.SSHSession
|
||||
self.subsystemLookup[b"sftp"] = FileTransferServer
|
||||
|
||||
self._client = client
|
||||
self._root = rootnode
|
||||
|
@ -65,7 +65,7 @@ class AccountFileCheckerKeyTests(unittest.TestCase):
|
||||
avatarId = self.checker.requestAvatarId(key_credentials)
|
||||
return self.assertFailure(avatarId, error.UnauthorizedLogin)
|
||||
|
||||
def test_password_auth_user(self):
|
||||
def test_password_auth_user_with_ssh_key(self):
|
||||
"""
|
||||
AccountFileChecker.requestAvatarId returns a Deferred that fires with
|
||||
UnauthorizedLogin if called with an SSHPrivateKey object for a username
|
||||
@ -76,6 +76,29 @@ class AccountFileCheckerKeyTests(unittest.TestCase):
|
||||
avatarId = self.checker.requestAvatarId(key_credentials)
|
||||
return self.assertFailure(avatarId, error.UnauthorizedLogin)
|
||||
|
||||
def test_password_auth_user_with_correct_password(self):
|
||||
"""
|
||||
AccountFileChecker.requestAvatarId returns a Deferred that fires with
|
||||
the user if the correct password is given.
|
||||
"""
|
||||
key_credentials = credentials.UsernamePassword(b"alice", b"password")
|
||||
d = self.checker.requestAvatarId(key_credentials)
|
||||
def authenticated(avatarId):
|
||||
self.assertEqual(
|
||||
(b"alice",
|
||||
b"URI:DIR2:aaaaaaaaaaaaaaaaaaaaaaaaaa:1111111111111111111111111111111111111111111111111111"),
|
||||
(avatarId.username, avatarId.rootcap))
|
||||
return d
|
||||
|
||||
def test_password_auth_user_with_wrong_password(self):
|
||||
"""
|
||||
AccountFileChecker.requestAvatarId returns a Deferred that fires with
|
||||
UnauthorizedLogin if the wrong password is given.
|
||||
"""
|
||||
key_credentials = credentials.UsernamePassword(b"alice", b"WRONG")
|
||||
avatarId = self.checker.requestAvatarId(key_credentials)
|
||||
return self.assertFailure(avatarId, error.UnauthorizedLogin)
|
||||
|
||||
def test_unrecognized_key(self):
|
||||
"""
|
||||
AccountFileChecker.requestAvatarId returns a Deferred that fires with
|
||||
|
@ -415,7 +415,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
f.write("deadbeef")
|
||||
|
||||
token = c.get_auth_token()
|
||||
self.assertEqual("deadbeef", token)
|
||||
self.assertEqual(b"deadbeef", token)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_web_staticdir(self):
|
||||
|
@ -18,10 +18,13 @@ if PY2:
|
||||
|
||||
|
||||
# Every time a module is added here, also add it to tox.ini environment
|
||||
# integrations3. Bit of duplication, but it's only a handful of files so quite
|
||||
# temporary.
|
||||
# integrations3. Bit of duplication, but it's only a handful of files and quite
|
||||
# temporary, just until we've ported them all.
|
||||
PORTED_INTEGRATION_TESTS = [
|
||||
"integration.test_aaa_aardvark",
|
||||
"integration.test_servers_of_happiness",
|
||||
"integration.test_sftp",
|
||||
"integration.test_streaming_logs",
|
||||
]
|
||||
|
||||
|
||||
|
2
tox.ini
2
tox.ini
@ -104,7 +104,7 @@ setenv =
|
||||
commands =
|
||||
python --version
|
||||
# NOTE: 'run with "py.test --keep-tempdir -s -v integration/" to debug failures'
|
||||
py.test --timeout=1800 --coverage -v {posargs:integration/test_servers_of_happiness.py}
|
||||
python3 -b -m pytest --timeout=1800 --coverage -v {posargs:integration/test_aaa_aardvark.py integration/test_servers_of_happiness.py integration/test_sftp.py integration/test_streaming_logs.py}
|
||||
coverage combine
|
||||
coverage report
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user