Skip to content

Commit 09840a6

Browse files
committed
fix first connection handler: clear widgets after SSH auth is completed
1 parent b4e92d9 commit 09840a6

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

pythonhere/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def on_stop(self):
103103
Logger.info("PythonHere: app stopped")
104104

105105
def on_ssh_connection_made(self):
106-
"""New SSH client connected handler."""
106+
"""New authenticated SSH client connected handler."""
107107
Logger.info("PythonHere: new SSH client connected")
108108
if not self.ssh_server_connected.is_set():
109109
self.ssh_server_connected.set()

pythonhere/server_here.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
class PythonHereServer(SSHServerHere):
1313
"""SSH server protocol handler."""
1414

15-
def connection_made(self, *args, **kwargs):
16-
"""Called when a channel is opened successfully."""
17-
super().connection_made(*args, **kwargs)
15+
def auth_completed(self):
16+
"""Authentication was completed successfully."""
17+
super().auth_completed()
1818
App.get_running_app().on_ssh_connection_made()
1919

2020

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from pathlib import Path
55

6+
from asyncssh import PermissionDenied
67
import nest_asyncio
78
import pytest
89
from kivy.config import Config
@@ -56,6 +57,16 @@ async def there(app_instance, connection_config):
5657
yield client
5758

5859

60+
@pytest.fixture
61+
async def there_with_wrong_password(app_instance, connection_config):
62+
client = Client()
63+
connection_config.password = "nowhere"
64+
await asyncio.wait_for(app_instance.ssh_server_started.wait(), 5)
65+
with pytest.raises(PermissionDenied):
66+
await client.connect(connection_config)
67+
yield client
68+
69+
5970
@pytest.fixture
6071
def nested_event_loop(event_loop):
6172
nest_asyncio.apply()

tests/test_main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22

3+
from asyncssh import PermissionDenied
34
import pytest
45

56
from main import PythonHereApp
@@ -24,6 +25,15 @@ async def test_code_line_executed(capfd, app_instance, there):
2425
assert capfd.readouterr().out == "hello there\n"
2526

2627

28+
@pytest.mark.asyncio
29+
async def test_connect_with_wrong_password(capfd, app_instance,
30+
there_with_wrong_password):
31+
with pytest.raises(PermissionDenied):
32+
await there_with_wrong_password.runcode("print('hello there')")
33+
app_instance.on_ssh_connection_made.assert_not_called()
34+
assert not capfd.readouterr().out
35+
36+
2737
@pytest.mark.asyncio
2838
async def test_button_created(capfd, app_instance, there):
2939
await there.runcode(

0 commit comments

Comments
 (0)