-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f535169
commit 62693cf
Showing
6 changed files
with
65 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**/__pycache__/* | ||
.venv/* | ||
.coverage |
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,13 @@ | ||
coverage==7.5.3 | ||
flake8==7.1.0 | ||
iniconfig==2.0.0 | ||
mccabe==0.7.0 | ||
mypy==1.10.0 | ||
mypy-extensions==1.0.0 | ||
packaging==24.1 | ||
pluggy==1.5.0 | ||
pycodestyle==2.12.0 | ||
pyflakes==3.2.0 | ||
pytest==8.2.2 | ||
pytest-cov==5.0.0 | ||
typing_extensions==4.12.2 |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,71 +5,83 @@ | |
import tempfile | ||
from . import wmap | ||
|
||
def test_parse_algorithm(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert(key.algorithm == wmap.Algorithm.RSA) | ||
|
||
def test_parse_material(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert(key.material == "abc123") | ||
|
||
def test_parse_comment(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert(key.comment == "blah blah blah") | ||
|
||
def test_into_allowed_signer(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
profile = wmap.Profile("example") | ||
signer = key.into_allowed_signer(profile) | ||
assert(signer == "example namespaces=\"[email protected]\" ssh-rsa abc123") | ||
|
||
def test_algorithm_rsa(): | ||
rsa = wmap.Algorithm.parse("ssh-rsa") | ||
assert(rsa == wmap.Algorithm.RSA) | ||
assert rsa == wmap.Algorithm.RSA | ||
|
||
|
||
def test_algorithm_ed25519(): | ||
ed25519 = wmap.Algorithm.parse("ssh-ed25519") | ||
assert(ed25519 == wmap.Algorithm.ED25519) | ||
assert ed25519 == wmap.Algorithm.ED25519 | ||
|
||
|
||
def test_algorithm_bogus(): | ||
with pytest.raises(Exception): | ||
wmap.Algorithm.parse("ssh-junk") | ||
|
||
|
||
def test_authorized_key_parse_algorithm(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert key.algorithm == wmap.Algorithm.RSA | ||
|
||
|
||
def test_authorized_key_parse_material(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert key.material == "abc123" | ||
|
||
|
||
def test_authorized_key_parse_comment(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
assert key.comment == "blah blah blah" | ||
|
||
|
||
def test_authorized_key_into_allowed_signer(): | ||
key = wmap.AuthorizedKey.parse("ssh-rsa abc123 blah blah blah") | ||
profile = wmap.Profile("example") | ||
signer = key.into_allowed_signer(profile) | ||
assert signer == "example namespaces=\"[email protected]\" ssh-rsa abc123" | ||
|
||
|
||
def test_profile_key_url(): | ||
profile_url = "https://github.com/robertdfrench" | ||
authorized_keys_url = "https://github.com/robertdfrench.keys" | ||
profile = wmap.Profile(profile_url) | ||
assert(profile.authorized_keys_url() == authorized_keys_url) | ||
assert profile.authorized_keys_url() == authorized_keys_url | ||
|
||
|
||
def test_profile_fetch_authorized_keys_text(): | ||
profile = wmap.Profile("https://github.com/robertdfrench") | ||
authorized_keys = profile.authorized_keys() | ||
assert(len(authorized_keys) > 0) | ||
assert len(authorized_keys) > 0 | ||
|
||
|
||
def test_profile_allowed_signers(): | ||
profile = wmap.Profile("https://github.com/robertdfrench") | ||
for signer in profile.allowed_signers(): | ||
assert(signer.startswith("https://github.com/robertdfrench")) | ||
assert signer.startswith("https://github.com/robertdfrench") | ||
|
||
|
||
@pytest.fixture | ||
def ssh_private_key_path(): | ||
# Create a temporary directory to store the key pair | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
private_key_path = os.path.join(temp_dir, "id_ed25519") | ||
public_key_path = private_key_path + ".pub" | ||
|
||
# Generate the ed25519 SSH key pair using ssh-keygen | ||
subprocess.run([ | ||
'ssh-keygen', '-t', 'ed25519', '-f', private_key_path, '-N', '' | ||
], check=True) | ||
|
||
# Yield the private key path for use in tests | ||
yield private_key_path | ||
|
||
# Clean up the key files | ||
os.remove(private_key_path) | ||
os.remove(public_key_path) | ||
|
||
|
||
def test_private_key_signing(ssh_private_key_path): | ||
profile = wmap.Profile("https://github.com/robertdfrench") | ||
private_key = wmap.PrivateKey(profile, ssh_private_key_path) | ||
|
@@ -79,13 +91,15 @@ def test_private_key_signing(ssh_private_key_path): | |
signature_file = Path(f.name + ".sig") | ||
assert signature_file.exists() | ||
|
||
|
||
def test_signature_load(): | ||
with tempfile.NamedTemporaryFile(delete=False) as f: | ||
f.write(b"Hello World!") | ||
sig = wmap.Signature.load(f.name) | ||
assert sig.content == "SGVsbG8gV29ybGQh" | ||
os.remove(f.name) | ||
|
||
|
||
def test_signature_dump(): | ||
with tempfile.NamedTemporaryFile(delete=False) as f: | ||
f.write(b"Hello World!") | ||
|
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