81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
from scripts.bezalel_tailscale_bootstrap import (
|
|
DEFAULT_PEERS,
|
|
build_remote_script,
|
|
build_ssh_command,
|
|
parse_peer_args,
|
|
parse_tailscale_status,
|
|
)
|
|
|
|
|
|
def test_build_remote_script_contains_install_up_and_key_append():
|
|
script = build_remote_script(
|
|
auth_key="tskey-auth-123",
|
|
ssh_public_key="ssh-ed25519 AAAATEST timmy@mac",
|
|
peers=DEFAULT_PEERS,
|
|
hostname="bezalel",
|
|
)
|
|
|
|
assert "curl -fsSL https://tailscale.com/install.sh | sh" in script
|
|
assert "tailscale up --authkey tskey-auth-123 --ssh --hostname bezalel" in script
|
|
assert "install -d -m 700 ~/.ssh" in script
|
|
assert "authorized_keys" in script
|
|
assert "grep -qxF 'ssh-ed25519 AAAATEST timmy@mac' ~/.ssh/authorized_keys" in script
|
|
|
|
|
|
def test_build_remote_script_pings_expected_peer_targets():
|
|
script = build_remote_script(
|
|
auth_key="tskey-auth-123",
|
|
ssh_public_key="ssh-ed25519 AAAATEST timmy@mac",
|
|
peers={"mac": "100.124.176.28", "ezra": "100.126.61.75"},
|
|
hostname="bezalel",
|
|
)
|
|
|
|
assert "PING_OK:mac:100.124.176.28" in script
|
|
assert "PING_OK:ezra:100.126.61.75" in script
|
|
|
|
|
|
def test_parse_tailscale_status_extracts_self_and_peer_ips():
|
|
payload = {
|
|
"Self": {
|
|
"HostName": "bezalel",
|
|
"DNSName": "bezalel.tailnet.ts.net",
|
|
"TailscaleIPs": ["100.90.0.10"],
|
|
},
|
|
"Peer": {
|
|
"node-1": {"HostName": "ezra", "TailscaleIPs": ["100.126.61.75"]},
|
|
"node-2": {"HostName": "mac", "TailscaleIPs": ["100.124.176.28"]},
|
|
},
|
|
}
|
|
|
|
result = parse_tailscale_status(payload)
|
|
|
|
assert result == {
|
|
"self": {
|
|
"hostname": "bezalel",
|
|
"dns_name": "bezalel.tailnet.ts.net",
|
|
"tailscale_ips": ["100.90.0.10"],
|
|
},
|
|
"peers": {
|
|
"ezra": ["100.126.61.75"],
|
|
"mac": ["100.124.176.28"],
|
|
},
|
|
}
|
|
|
|
|
|
def test_build_ssh_command_targets_remote_script_path():
|
|
assert build_ssh_command("159.203.146.185", "/tmp/bootstrap.sh") == [
|
|
"ssh",
|
|
"159.203.146.185",
|
|
"bash /tmp/bootstrap.sh",
|
|
]
|
|
|
|
|
|
def test_parse_peer_args_merges_overrides_into_defaults():
|
|
peers = parse_peer_args(["forge=100.70.0.9", "ezra=100.126.61.76"])
|
|
|
|
assert peers == {
|
|
"mac": "100.124.176.28",
|
|
"ezra": "100.126.61.76",
|
|
"forge": "100.70.0.9",
|
|
}
|