This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validation for selecting the SSH public key (#52)
Signed-off-by: Arjun Naik <[email protected]>
- Loading branch information
Showing
9 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
clickclick>=0.10 | ||
PyYAML | ||
requests | ||
pyperclip | ||
stups-zign>=1.1.26 | ||
boto3>=1.12.0 | ||
botocore>=1.4.10 | ||
click>=1.2.2 | ||
clickclick>=0.10 | ||
pyperclip | ||
requests | ||
sshpubkeys>=3.1.0 | ||
stups-zign>=1.1.26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDR5i0JujjiY5A1fuThjjxvrNDMv/WrvEFN+dTrq0fHsa2I4p51eUdYMnRrkZaQ2rvr6jTuYSt75rtZguNB7DnFFOklG4YDgsIxb+XlizDImnbs5hXawPw869X6uDtaXYxP/ddK1zcVEeW1J0NWBWbJ6t3o2lr0+YkotZ5L/iRC/PR7btNH92oKyqxz11uuL/QtomSScQJoL9nNVAB3MtAO0t5GNRsGk4M7ln9l+R9Xbqcb6abLm6qiIffcfEcDZmLMOYrfI52O0YaLRk7/ifPz4BDLaU8feP/rsc9wAzCwH3nHW+/ymM3JhG7FAEXePswHQ5CdeUmltqXRl3THG4JYUkevD1xIzIl6/DHe6qvoFmIHGsK2P8EEt6ZX4pt1lBsh+g5WMH8PxR9hCuFIoAj5IpHh1lS9suNhN3vck1U7VRQwDtL/WzesKOJbSopoA0TYsahVVrq4KZOTbInTrbe9wu3bKj4xv9BeWAB+tIVN3WSzsFZ5btZRuqtVzzIfI3s= test@blash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id_rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id_rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-mal malformed test@blash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id_rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from os import path | ||
from unittest.mock import MagicMock | ||
|
||
from piu.cli import validate_ssh_key, check_ssh_key | ||
|
||
|
||
def test_validate_ssh_fallback(monkeypatch): | ||
mock_exit = MagicMock() | ||
monkeypatch.setattr("sys.exit", mock_exit) | ||
fallback_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_fallback.pub") | ||
final_path = validate_ssh_key("", "", fallback_path, False) | ||
assert final_path == fallback_path | ||
mock_exit.assert_not_called() | ||
|
||
|
||
def test_validate_ssh_valid_input(monkeypatch): | ||
mock_exit = MagicMock() | ||
monkeypatch.setattr("sys.exit", mock_exit) | ||
option_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_option.pub") | ||
config_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_config.pub") | ||
fallback_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_fallback.pub") | ||
final_path = validate_ssh_key(option_path, config_path, fallback_path, False) | ||
assert final_path == option_path | ||
mock_exit.assert_not_called() | ||
|
||
|
||
def test_validate_ssh_valid_config(monkeypatch): | ||
mock_exit = MagicMock() | ||
monkeypatch.setattr("sys.exit", mock_exit) | ||
config_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_config.pub") | ||
fallback_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_fallback.pub") | ||
final_path = validate_ssh_key("", config_path, fallback_path, False) | ||
assert final_path == config_path | ||
mock_exit.assert_not_called() | ||
|
||
|
||
def test_validate_ssh_valid_error(monkeypatch): | ||
mock_exit = MagicMock() | ||
monkeypatch.setattr("sys.exit", mock_exit) | ||
final_path = validate_ssh_key("", "", "", False) | ||
assert final_path == "" | ||
mock_exit.assert_called_with(1) | ||
|
||
|
||
def test_validate_ssh_valid_no_error_interactive(monkeypatch): | ||
mock_exit = MagicMock() | ||
monkeypatch.setattr("sys.exit", mock_exit) | ||
final_path = validate_ssh_key("", "", "", True) | ||
assert final_path == "" | ||
mock_exit.assert_not_called() | ||
|
||
|
||
def test_malformed_ssh_key(monkeypatch): | ||
malformed_path = path.join(path.abspath(path.dirname(__file__)), "resources/id_rsa_malformed.pub") | ||
assert not check_ssh_key(malformed_path) |