Skip to content

Commit

Permalink
Fix test for create_ssh_keypair on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice <[email protected]>
  • Loading branch information
lebrice committed Jan 16, 2024
1 parent e06c254 commit 0dced13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 3 additions & 7 deletions milatools/cli/init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,9 @@ def get_windows_home_path_in_wsl() -> Path:

def create_ssh_keypair(ssh_private_key_path: Path, local: Local) -> None:
local.run(
"ssh-keygen",
"-f",
shlex.quote(str(ssh_private_key_path)),
"-t",
"rsa",
"-N",
'""',
*shlex.split(
f'ssh-keygen -f {shlex.quote(str(ssh_private_key_path))} -t rsa -N=""'
),
)


Expand Down
13 changes: 8 additions & 5 deletions tests/cli/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from milatools.cli.local import Local
from milatools.cli.utils import SSHConfig, running_inside_WSL
from tests.cli.common import xfails_on_windows
from tests.cli.common import on_windows, xfails_on_windows


def raises_NoConsoleScreenBufferError_on_windows_ci_action():
Expand Down Expand Up @@ -614,7 +614,6 @@ def test_fixes_dir_permission_issues(
assert file.stat().st_mode & 0o777 == 0o600


@permission_bits_check_doesnt_work_on_windows()
def test_create_ssh_keypair(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
here = Local()
mock_run = Mock(
Expand All @@ -624,20 +623,24 @@ def test_create_ssh_keypair(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
fake_ssh_folder = tmp_path / "fake_ssh"
fake_ssh_folder.mkdir(mode=0o700)
ssh_private_key_path = fake_ssh_folder / "bob"

create_ssh_keypair(ssh_private_key_path=ssh_private_key_path, local=here)

mock_run.assert_called_once_with(
("ssh-keygen", "-f", str(ssh_private_key_path), "-t", "rsa", "-N", '""'),
("ssh-keygen", "-f", f"{ssh_private_key_path}", "-t", "rsa", "-N="),
universal_newlines=True,
capture_output=False,
stderr=None,
stdout=None,
timeout=None,
)
assert ssh_private_key_path.exists()
assert ssh_private_key_path.stat().st_mode & 0o777 == 0o600
if not on_windows:
assert ssh_private_key_path.stat().st_mode & 0o777 == 0o600
ssh_public_key_path = ssh_private_key_path.with_suffix(".pub")
assert ssh_public_key_path.exists()
assert ssh_public_key_path.stat().st_mode & 0o777 == 0o644
if not on_windows:
assert ssh_public_key_path.stat().st_mode & 0o777 == 0o644


@pytest.fixture
Expand Down

0 comments on commit 0dced13

Please sign in to comment.