aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/tests/test_cli_actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-cli/tests/test_cli_actions.py')
-rw-r--r--packages/meshbay-cli/tests/test_cli_actions.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/packages/meshbay-cli/tests/test_cli_actions.py b/packages/meshbay-cli/tests/test_cli_actions.py
index 006c183..ad914fd 100644
--- a/packages/meshbay-cli/tests/test_cli_actions.py
+++ b/packages/meshbay-cli/tests/test_cli_actions.py
@@ -83,6 +83,17 @@ def test_no_passphrase_and_no_terminal_exits_2(hub, monkeypatch, capsys):
assert "MESHBAY_PASSWORD" in capsys.readouterr().err
+def test_the_null_device_is_no_terminal(hub, monkeypatch, capsys):
+ """`< NUL` on Windows: a character device, which isatty() calls a terminal.
+ A script run so was asked for a passphrase it could not type."""
+ from meshbay_cli.output import terminal
+ with open(os.devnull) as null:
+ assert not terminal(null)
+ monkeypatch.setattr("sys.stdin", null)
+ assert main("--hub", hub.url, "-u", USERNAME, "login") == 2
+ assert "MESHBAY_PASSWORD" in capsys.readouterr().err
+
+
async def _session():
return FakeSession()
@@ -177,6 +188,58 @@ def test_put_into_a_read_only_folder_sends_nothing(node, tmp_path, capsys):
assert "read-only" in capsys.readouterr().err
+def _max_path_in_force() -> bool:
+ if sys.platform != "win32":
+ return False
+ import winreg
+ try:
+ with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
+ r"SYSTEM\CurrentControlSet\Control\FileSystem") as key:
+ return winreg.QueryValueEx(key, "LongPathsEnabled")[0] == 0
+ except OSError:
+ return True
+
+
+@pytest.mark.skipif(not _max_path_in_force(), reason="Windows with MAX_PATH in force")
+def test_get_and_put_past_max_path(node, tmp_path, capsys):
+ """Windows refuses a plain path of 260 characters or more. The node uses the
+ long form at each disk call, and the client has to as well: `get -R` into a
+ deep folder died with a traceback creating its first folder."""
+ import shutil
+
+ from meshbay_common.paths import long_path
+ segment = "A folder name as long as the ones a real library has"
+ deep = tmp_path / "deep"
+ while len(str(deep)) < 240:
+ deep = deep / segment
+ try:
+ node.add("share/2024", "a.jpg", b"A" * 3000)
+ assert main("get", "-R", "Family/share/2024", "-o", f"{deep}{os.sep}") == 0, \
+ capsys.readouterr().err
+ got = deep / "2024" / "a.jpg"
+ assert len(str(got)) >= 260
+ with open(long_path(got), "rb") as f:
+ assert f.read() == b"A" * 3000
+
+ # A part left from an interrupted run, resumed past the limit too.
+ node.add("share/2024", "b.bin", b"B" * 10)
+ with open(long_path(deep / "2024" / "b.bin.meshbay-part"), "wb") as f:
+ f.write(b"B")
+ assert main("get", "-R", "Family/share/2024", "-o", f"{deep}{os.sep}", "-n") == 0
+ with open(long_path(deep / "2024" / "b.bin"), "rb") as f:
+ assert f.read() == b"B" * 10
+
+ # And a tree past the limit, sent.
+ src = deep / "Scans"
+ os.makedirs(long_path(src / segment))
+ with open(long_path(src / segment / "page.pdf"), "wb") as f:
+ f.write(b"%PDF")
+ assert main("put", "-R", str(src), "Family/share") == 0, capsys.readouterr().err
+ assert node.stored(f"share/Scans/{segment}/page.pdf") == b"%PDF"
+ finally:
+ shutil.rmtree("\\\\?\\" + str(tmp_path / "deep"), ignore_errors=True)
+
+
def test_trust_lists_and_forgets_pins(hub, capsys):
assert main("trust", "list") == 0 # nothing stored: nothing pinned
assert main("--hub", hub.url, "-u", USERNAME, "--password", PASSPHRASE,