|
3 | 3 | # the additional special exception to link portions of this program with the OpenSSL library.
|
4 | 4 | # See LICENSE for more details.
|
5 | 5 | #
|
| 6 | +from unittest.mock import patch |
| 7 | + |
6 | 8 | import pytest
|
7 | 9 | import pytest_twisted
|
8 | 10 | from twisted.internet import defer
|
| 11 | +from twisted.internet import error as twisted_error |
9 | 12 |
|
10 | 13 | from deluge import error
|
| 14 | +from deluge._features import DelugeFeatures |
11 | 15 | from deluge.common import AUTH_LEVEL_NORMAL, get_localhost_auth, get_version
|
12 | 16 | from deluge.core.authmanager import AUTH_LEVEL_ADMIN
|
13 | 17 | from deluge.ui.client import Client, DaemonSSLProxy, client
|
@@ -72,6 +76,21 @@ def __on_disconnect(self):
|
72 | 76 | self.disconnect_callback()
|
73 | 77 |
|
74 | 78 |
|
| 79 | +class NoFeatureDaemonSSLProxy(DaemonSSLProxy): |
| 80 | + def call(self, method, *args, **kwargs): |
| 81 | + def on_method_list(methods_list): |
| 82 | + return tuple( |
| 83 | + method_name |
| 84 | + for method_name in methods_list |
| 85 | + if method_name != 'core.get_supported_features' |
| 86 | + ) |
| 87 | + |
| 88 | + d = super().call(method, *args, **kwargs) |
| 89 | + if method == 'daemon.get_method_list': |
| 90 | + d.addCallback(on_method_list) |
| 91 | + return d |
| 92 | + |
| 93 | + |
75 | 94 | @pytest.mark.usefixtures('daemon', 'client')
|
76 | 95 | class TestClient:
|
77 | 96 | def test_connect_no_credentials(self):
|
@@ -134,6 +153,21 @@ def on_failure(failure):
|
134 | 153 | d.addCallbacks(self.fail, on_failure)
|
135 | 154 | return d
|
136 | 155 |
|
| 156 | + def test_connect_invalid_host(self): |
| 157 | + username, password = get_localhost_auth() |
| 158 | + d = client.connect( |
| 159 | + 'somehost', self.listen_port, username=username, password=password |
| 160 | + ) |
| 161 | + |
| 162 | + def on_failure(failure): |
| 163 | + assert ( |
| 164 | + failure.trap(twisted_error.DNSLookupError) |
| 165 | + == twisted_error.DNSLookupError |
| 166 | + ) |
| 167 | + |
| 168 | + d.addCallbacks(self.fail, on_failure) |
| 169 | + return d |
| 170 | + |
137 | 171 | @pytest_twisted.inlineCallbacks
|
138 | 172 | def test_connect_with_password(self):
|
139 | 173 | username, password = get_localhost_auth()
|
@@ -181,12 +215,33 @@ def test_daemon_version(self):
|
181 | 215 | assert client.daemon_version == get_version()
|
182 | 216 |
|
183 | 217 | @pytest_twisted.inlineCallbacks
|
184 |
| - def test_daemon_version_check_min(self): |
| 218 | + def test_is_feature_supported(self): |
185 | 219 | username, password = get_localhost_auth()
|
186 | 220 | yield client.connect(
|
187 | 221 | 'localhost', self.listen_port, username=username, password=password
|
188 | 222 | )
|
189 | 223 |
|
190 |
| - assert client.daemon_version_check_min(get_version()) |
191 |
| - assert not client.daemon_version_check_min(f'{get_version()}1') |
192 |
| - assert client.daemon_version_check_min('0.1.0') |
| 224 | + assert client._daemon_features == DelugeFeatures.ALL |
| 225 | + assert client.is_feature_supported(DelugeFeatures.BASE) |
| 226 | + assert not client.is_feature_supported(-1) |
| 227 | + |
| 228 | + @pytest_twisted.inlineCallbacks |
| 229 | + def test_is_feature_supported_older_daemon(self): |
| 230 | + with patch('deluge.ui.client.DaemonSSLProxy', NoFeatureDaemonSSLProxy): |
| 231 | + username, password = get_localhost_auth() |
| 232 | + yield client.connect( |
| 233 | + 'localhost', self.listen_port, username=username, password=password |
| 234 | + ) |
| 235 | + |
| 236 | + assert client._daemon_features == DelugeFeatures.NONE |
| 237 | + assert not client.is_feature_supported(DelugeFeatures.BASE) |
| 238 | + |
| 239 | + @pytest_twisted.inlineCallbacks |
| 240 | + def test_daemon_features_resets_on_disconnect(self): |
| 241 | + username, password = get_localhost_auth() |
| 242 | + yield client.connect( |
| 243 | + 'localhost', self.listen_port, username=username, password=password |
| 244 | + ) |
| 245 | + assert client._daemon_features == DelugeFeatures.ALL |
| 246 | + yield client.disconnect() |
| 247 | + assert client._daemon_features == DelugeFeatures.NONE |
0 commit comments