vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
| 1 | package main |
| 2 | |
| 3 | // `vole ssh-config` is the one command an operator runs to produce the front-door |
| 4 | // drop-in with the real paths. The renderer itself is tested in |
| 5 | // internal/sshdconfig; these tests cover the command's flag handling: the |
| 6 | // platform selects the commands, and each explicit flag overrides its default |
| 7 | // rather than being ignored. |
| 8 | |
| 9 | import ( |
| 10 | "runtime" |
| 11 | "strings" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | func TestSSHConfigChoosesThePlatform(t *testing.T) { |
| 16 | got := captureStdout(t, func() error { return cmdSSHConfig([]string{"--platform", "darwin"}) }) |
| 17 | for _, want := range []string{ |
| 18 | "sudo sshd -t && sudo launchctl kickstart -k system/com.openssh.sshd", |
| 19 | "systemsetup -setremotelogin on", |
| 20 | "brew services restart vole", |
| 21 | } { |
| 22 | if !strings.Contains(got, want) { |
| 23 | t.Errorf("darwin render is missing %q:\n%s", want, got) |
| 24 | } |
| 25 | } |
| 26 | if strings.Contains(got, "systemctl") || strings.Contains(got, "useradd") { |
| 27 | t.Errorf("darwin render names a Linux command:\n%s", got) |
| 28 | } |
| 29 | |
| 30 | got = captureStdout(t, func() error { return cmdSSHConfig([]string{"--platform", "linux"}) }) |
| 31 | if !strings.Contains(got, "systemctl reload ssh") { |
| 32 | t.Errorf("linux render is missing systemctl reload:\n%s", got) |
| 33 | } |
| 34 | if strings.Contains(got, "launchctl") || strings.Contains(got, "sysadminctl") { |
| 35 | t.Errorf("linux render names a macOS command:\n%s", got) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestSSHConfigDefaultsToThisMachine(t *testing.T) { |
| 40 | got := captureStdout(t, func() error { return cmdSSHConfig(nil) }) |
| 41 | want := "launchctl" // darwin, the host these tests run on |
| 42 | if runtime.GOOS == "linux" { |
| 43 | want = "systemctl" |
| 44 | } |
| 45 | if !strings.Contains(got, want) { |
| 46 | t.Errorf("no --platform did not follow the host (expected %q):\n%s", want, got) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestSSHConfigAppliesOverrides(t *testing.T) { |
| 51 | got := captureStdout(t, func() error { |
| 52 | return cmdSSHConfig([]string{ |
| 53 | "--platform", "darwin", |
| 54 | "--user", "git-clone", |
| 55 | "--service-user", "forge", |
| 56 | "--vole", "/opt/homebrew/bin/vole", |
| 57 | "--config", "/opt/homebrew/etc/vole/vole.toml", |
| 58 | "--socket", "/opt/homebrew/var/vole/ssh.sock", |
| 59 | }) |
| 60 | }) |
| 61 | for _, want := range []string{ |
| 62 | "Match User git-clone", |
| 63 | "AuthorizedKeysCommandUser forge", |
| 64 | "AuthorizedKeysCommand /opt/homebrew/bin/vole ssh-authorized-keys --config /opt/homebrew/etc/vole/vole.toml", |
| 65 | `ssh_socket = "/opt/homebrew/var/vole/ssh.sock"`, |
| 66 | } { |
| 67 | if !strings.Contains(got, want) { |
| 68 | t.Errorf("override render is missing %q:\n%s", want, got) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestSSHConfigRejectsABadPlatform(t *testing.T) { |
| 74 | err := cmdSSHConfig([]string{"--platform", "windows"}) |
| 75 | if err == nil || !strings.Contains(err.Error(), "not linux or darwin") { |
| 76 | t.Errorf("a bad platform was accepted: %v", err) |
| 77 | } |
| 78 | } |
| 79 |