navid/veinsforge / f19b5da8080ed8686dfea72c79bec23d4628b62386bdf7c391249f8a5ff2e44a / internal/auth/keys_test.go
keys_test.go
← internal/auth · 758 bytes · raw · download
package auth
import "testing"
func TestParsePublicKeyAndFingerprint(t *testing.T) {
const key = "ed25519:vl99ipKRQSi1hHY_c2-3ewa3WY6rGLWgnzvQPd29hpw"
canonical, raw, fingerprint, err := ParsePublicKey(key)
if err != nil {
t.Fatal(err)
}
if canonical != key {
t.Fatalf("canonical key = %q, want %q", canonical, key)
}
if len(raw) != 32 {
t.Fatalf("raw key length = %d", len(raw))
}
if fingerprint != "GCQWILDZKFUIUVJWQKUPYV2K3Y" {
t.Fatalf("fingerprint = %q", fingerprint)
}
}
func TestParsePublicKeyRejectsInvalid(t *testing.T) {
for _, input := range []string{"", "ssh-ed25519 foo", "ed25519:not-base64", "ed25519:AAAA"} {
if _, _, _, err := ParsePublicKey(input); err == nil {
t.Fatalf("accepted invalid key %q", input)
}
}
}