Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable scp/sftp by default (and add test) #5

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jupyter_sshd_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def setup_sshd() -> Dict[str, Any]:
# Last login info is from /var/log/lastlog, which is transient in containerized systems
'-o', 'PrintLastLog no',
'-o', f'AuthorizedKeysFile {AUTHORIZED_KEYS_PATH}',
'-o', f'LogLevel {SSHD_LOG_LEVEL}'
'-o', f'LogLevel {SSHD_LOG_LEVEL}',
# Default to enabling sftp
'-o', 'Subsystem sftp internal-sftp'

]

return {
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,25 @@ def test_ssh_interactive(jupyter_server):
proc.wait()
assert proc.exitstatus == 0


# Test for both the sftp protocol (default on newer scp) ("-s"), and the older
# scp protocol ("-O").
@pytest.mark.parametrize("extra_scp_args", [["-s"], ["-O"]])
def test_scp(jupyter_server, extra_scp_args):
with tempfile.NamedTemporaryFile() as f, tempfile.TemporaryDirectory() as d:
file_contents = secrets.token_hex()
f.write(file_contents.encode())
f.flush()

target_path = os.path.join(d, "target")

cmd = [
'scp', '-v',
] + extra_scp_args + [f"-o={o}" for o in get_ssh_client_options(*jupyter_server)] + [
f.name, f'127.0.0.1:{target_path}'
]

proc = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

with open(target_path) as tpf:
assert tpf.read() == file_contents
Loading