remove ssh.id_ed25519 from facts test

we have moved this to vars now.
This commit is contained in:
Jörg Thalheim
2024-11-13 13:54:52 +01:00
committed by kenji
parent 4f0c44f3dd
commit b3b72e54cd
3 changed files with 1 additions and 37 deletions

View File

@@ -1,5 +1,4 @@
import subprocess import subprocess
import tempfile
class Error(Exception): class Error(Exception):
@@ -20,25 +19,3 @@ def is_valid_age_key(secret_key: str) -> bool:
return True return True
msg = f"Invalid age key: {secret_key}" msg = f"Invalid age key: {secret_key}"
raise Error(msg) raise Error(msg)
def is_valid_ssh_key(secret_key: str, ssh_pub: str) -> bool:
# create tempfile and write secret_key to it
with tempfile.NamedTemporaryFile() as temp:
temp.write(secret_key.encode("utf-8"))
temp.flush()
# Run the ssh-keygen command with the -y flag to check the key format
result = subprocess.run(
["ssh-keygen", "-y", "-f", temp.name],
capture_output=True,
text=True,
check=False,
)
if result.returncode == 0:
if result.stdout != ssh_pub:
msg = f"Expected '{ssh_pub}' got '{result.stdout}' for ssh key: {secret_key}"
raise Error(msg)
return True
msg = f"Invalid ssh key: {secret_key}"
raise Error(msg)

View File

@@ -9,7 +9,7 @@ from clan_cli.machines.machines import Machine
from clan_cli.secrets.folders import sops_secrets_folder from clan_cli.secrets.folders import sops_secrets_folder
from fixtures_flakes import FlakeForTest from fixtures_flakes import FlakeForTest
from helpers import cli from helpers import cli
from helpers.validator import is_valid_age_key, is_valid_ssh_key from helpers.validator import is_valid_age_key
if TYPE_CHECKING: if TYPE_CHECKING:
from age_keys import KeyPair from age_keys import KeyPair
@@ -85,7 +85,6 @@ def test_generate_secret(
assert store2.exists("", "password-hash") assert store2.exists("", "password-hash")
assert store2.exists("", "user-password") assert store2.exists("", "user-password")
assert store2.exists("", "user-password-hash") assert store2.exists("", "user-password-hash")
assert store2.exists("", "ssh.id_ed25519")
assert store2.exists("", "age.key") assert store2.exists("", "age.key")
assert store2.exists("", "zerotier-identity-secret") assert store2.exists("", "zerotier-identity-secret")
@@ -97,11 +96,6 @@ def test_generate_secret(
assert age_secret.isprintable() assert age_secret.isprintable()
assert is_valid_age_key(age_secret) assert is_valid_age_key(age_secret)
# Assert that the ssh key is valid
ssh_secret = store2.get("", "ssh.id_ed25519").decode()
ssh_pub = machine_get_fact(test_flake_with_core.path, "vm2", "ssh.id_ed25519.pub")
assert is_valid_ssh_key(ssh_secret, ssh_pub)
# Assert that root-password is valid # Assert that root-password is valid
pwd_secret = store2.get("", "password").decode() pwd_secret = store2.get("", "password").decode()
assert pwd_secret.isprintable() assert pwd_secret.isprintable()

View File

@@ -10,7 +10,6 @@ from clan_cli.nix import nix_shell
from clan_cli.ssh import HostGroup from clan_cli.ssh import HostGroup
from fixtures_flakes import ClanFlake from fixtures_flakes import ClanFlake
from helpers import cli from helpers import cli
from helpers.validator import is_valid_ssh_key
@pytest.mark.impure @pytest.mark.impure
@@ -90,14 +89,8 @@ def test_upload_secret(
assert store.exists("", "password-hash") assert store.exists("", "password-hash")
assert store.exists("", "user-password") assert store.exists("", "user-password")
assert store.exists("", "user-password-hash") assert store.exists("", "user-password-hash")
assert store.exists("", "ssh.id_ed25519")
assert store.exists("", "zerotier-identity-secret") assert store.exists("", "zerotier-identity-secret")
# Assert that the ssh key is valid
ssh_secret = store.get("", "ssh.id_ed25519").decode()
ssh_pub = machine_get_fact(flake.path, "vm1", "ssh.id_ed25519.pub")
assert is_valid_ssh_key(ssh_secret, ssh_pub)
# Assert that root-password is valid # Assert that root-password is valid
pwd_secret = store.get("", "password").decode() pwd_secret = store.get("", "password").decode()
assert pwd_secret.isprintable() assert pwd_secret.isprintable()