Lightweight and easily self-hostable Git forge. git.poy.ooo
git-forge selfhosting homebrew
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839package lib
import ( "strings" "testing")
// just a random key.const testPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIORiMzyBuNhagHOFNMsKeElwwE8Z9kWqg9M49Bn9KOyd test@example.com"
func TestParseKey(t *testing.T) { key, err := ParseKey(testPublicKey) if err != nil { t.Fatalf("ParseKey: %v", err) }
if key.Algorithm != "ssh-ed25519" { t.Errorf("Algorithm = %q, want ssh-ed25519", key.Algorithm) } if key.Fingerprint != "SHA256:Uekr4Xx0xPzdGYQq5KMgaVDmzkNePAo4oNZOt3kMaos" { t.Errorf("Fingerprint = %q, want SHA256:Uekr4Xx0xPzdGYQq5KMgaVDmzkNePAo4oNZOt3kMaos", key.Fingerprint) } if !strings.HasPrefix(key.Key, "ssh-ed25519 ") { t.Errorf("Key = %q, want it to start with \"ssh-ed25519 \"", key.Key) } if strings.Contains(key.Key, "test@example.com") { t.Errorf("Key = %q, want the comment stripped", key.Key) }}
func TestParseKeyInvalid(t *testing.T) { if _, err := ParseKey("not a key"); err == nil { t.Error("ParseKey(garbage) = nil error, want error") } if _, err := ParseKey(""); err == nil { t.Error("ParseKey(empty) = nil error, want error") }}