summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Packman <gzlist@googlemail.com>2017-06-06 21:25:15 +0100
committerJeff Forcier <jeff@bitprophet.org>2021-11-28 20:24:18 -0500
commitba8c57f54d359de89920c1dbb7355ec2cbd5ed3a (patch)
treefab205a00d9aa8aaf047ccbc68f8c479d0f93f74 /tests
parent54cbd9b27c30db5ac08c18ad8aadd2075a078a22 (diff)
downloadparamiko-ba8c57f54d359de89920c1dbb7355ec2cbd5ed3a.tar.gz
Fix failure in listdir when server uses a locale
Fixes #985 SFTPAttributes uses the locale-aware %b directive for the abbreviated month name with time.strftime, but was not decoding the result on Python 2.7. Add a strftime alias in py3compat that will always return unicode, and resolve the mixing of bytes and text in SFTPAttributes methods. Add a test at the listdir level, and a more specific test for the SFTPAttributes asbytes method.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_sftp.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index a98a46c6..84c5252b 100644
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -34,6 +34,11 @@ import pytest
from paramiko.py3compat import PY2, b, u, StringIO
from paramiko.common import o777, o600, o666, o644
+from tests import requireNonAsciiLocale, skipUnlessBuiltin
+from tests.stub_sftp import StubServer, StubSFTPServer
+from tests.loop import LoopSocket
+from tests.util import test_path
+import paramiko.util
from paramiko.sftp_attr import SFTPAttributes
from .util import needs_builtin
@@ -270,6 +275,16 @@ class TestSFTP(object):
sftp.remove(sftp.FOLDER + "/fish.txt")
sftp.remove(sftp.FOLDER + "/tertiary.py")
+ @requireNonAsciiLocale()
+ def test_listdir_in_locale(self):
+ """Test listdir under a locale that uses non-ascii text."""
+ sftp.open(FOLDER + '/canard.txt', 'w').close()
+ try:
+ folder_contents = sftp.listdir(FOLDER)
+ self.assertEqual(['canard.txt'], folder_contents)
+ finally:
+ sftp.remove(FOLDER + '/canard.txt')
+
def test_setstat(self, sftp):
"""
verify that the setstat functions (chown, chmod, utime, truncate) work.
@@ -781,6 +796,13 @@ class TestSFTP(object):
finally:
sftp.remove("%s/nonutf8data" % sftp.FOLDER)
+ @requireNonAsciiLocale('LC_TIME')
+ def test_sftp_attributes_locale_time(self):
+ """Test SFTPAttributes under a locale with non-ascii time strings."""
+ some_stat = os.stat(sftp.FOLDER)
+ sftp_attributes = SFTPAttributes.from_stat(some_stat, u('a_directory'))
+ self.assertTrue(b'a_directory' in sftp_attributes.asbytes())
+
def test_sftp_attributes_empty_str(self, sftp):
sftp_attributes = SFTPAttributes()
assert (