navid/veinsforge / 44e1bef61403607f5c01071f52e3799aefb46008923082f2ba10b6fd2ac690c3 / 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)
		}
	}
}