-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtest_window_scp_args.py
More file actions
153 lines (114 loc) · 3.8 KB
/
Copy pathtest_window_scp_args.py
File metadata and controls
153 lines (114 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import sys
import types
from types import SimpleNamespace
if 'cairo' not in sys.modules:
sys.modules['cairo'] = types.ModuleType('cairo')
from sshpilot import window
from sshpilot import scp_window
class _DummyConfig:
def __init__(self, *_, **__):
pass
def get_ssh_config(self):
return {}
class _DummyConnectionManager:
def __init__(self):
self.prepare_calls = []
def get_password(self, *_):
return None
def get_key_passphrase(self, *_):
return None
def prepare_key_for_connection(self, *args):
self.prepare_calls.append(args[0] if args else None)
return True
class _DummyWindow:
"""Stands in for MainWindow as the ScpWindowController's collaborator."""
def __init__(self):
self.connection_manager = _DummyConnectionManager()
self.config = _DummyConfig()
def _make_ctrl(dummy_window):
ctrl = scp_window.ScpWindowController.__new__(scp_window.ScpWindowController)
ctrl.window = dummy_window
ctrl._scp_auth = None
ctrl._scp_strip_askpass = False
ctrl._scp_askpass_helpers = []
return ctrl
def _scp_argv(dummy_window, *args, **kwargs):
return _make_ctrl(dummy_window)._build_scp_argv(*args, **kwargs)
def test_build_scp_argv_skips_key_prep_when_identity_agent_disabled(monkeypatch, tmp_path):
monkeypatch.setattr(window, 'Config', _DummyConfig)
monkeypatch.setattr(scp_window, 'Config', _DummyConfig)
key_path = tmp_path / 'id_test_key'
key_path.write_text('dummy')
connection = SimpleNamespace(
hostname='example.com',
username='alice',
keyfile=str(key_path),
key_select_mode=1,
auth_method=2,
port=22,
identity_agent_disabled=True,
)
dummy_window = _DummyWindow()
_scp_argv(
dummy_window,
connection,
['local.txt'],
'/remote/path',
direction='upload',
)
assert dummy_window.connection_manager.prepare_calls == []
def test_build_scp_argv_prefers_alias_and_proxy(monkeypatch, tmp_path):
monkeypatch.setattr(window, 'Config', _DummyConfig)
monkeypatch.setattr(scp_window, 'Config', _DummyConfig)
config_path = tmp_path / 'ssh_config'
config_path.write_text('Host testbox\n HostName example.com\n')
connection = SimpleNamespace(
host='testbox',
hostname='example.com',
username='alice',
keyfile='',
key_select_mode=0,
auth_method=0,
port=2224,
proxy_jump=['bastion.example.org'],
proxy_command='ssh proxy nc %h %p',
config_root=str(config_path),
)
dummy_window = _DummyWindow()
dummy_window.connection_manager.ssh_config_path = str(config_path)
argv = _scp_argv(
dummy_window,
connection,
['local.txt'],
'/remote/path',
direction='upload',
)
assert '-F' in argv
assert argv[argv.index('-F') + 1] == str(config_path)
assert 'ProxyJump=bastion.example.org' in argv
assert argv[-1] == 'alice@testbox:/remote/path'
def test_build_scp_argv_adds_recursive_for_directories(monkeypatch, tmp_path):
monkeypatch.setattr(window, 'Config', _DummyConfig)
monkeypatch.setattr(scp_window, 'Config', _DummyConfig)
key_path = tmp_path / 'id_test_key'
key_path.write_text('dummy')
source_dir = tmp_path / 'folder'
source_dir.mkdir()
connection = SimpleNamespace(
hostname='example.com',
username='alice',
keyfile=str(key_path),
key_select_mode=1,
auth_method=2,
port=22,
)
dummy_window = _DummyWindow()
argv = _scp_argv(
dummy_window,
connection,
[str(source_dir)],
'/remote/path',
direction='upload',
)
assert '-r' in argv
assert any(arg.endswith('/remote/path') for arg in argv)