MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestKeyLoad_new

Function TestKeyLoad_new

internal/modify/dkim/keys_test.go:33–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestKeyLoad_new(t *testing.T) {
34 m := Modifier{}
35 m.log = testutils.Logger(t, m.Name())
36
37 dir := t.TempDir()
38
39 signer, newKey, err := m.loadOrGenerateKey(filepath.Join(dir, "testkey.key"), "ed25519")
40 if err != nil {
41 t.Fatal(err)
42 }
43 if !newKey {
44 t.Fatal("newKey=false")
45 }
46
47 recordBlob, err := os.ReadFile(filepath.Join(dir, "testkey.dns"))
48 if err != nil {
49 t.Fatal(err)
50 }
51 var keyBlob []byte
52 for _, part := range strings.Split(string(recordBlob), ";") {
53 part = strings.TrimSpace(part)
54 if strings.HasPrefix(part, "k=") {
55 if part != "k=ed25519" {
56 t.Fatalf("Wrong type of generated key, want ed25519, got %s", part)
57 }
58 }
59 if strings.HasPrefix(part, "p=") {
60 keyBlob, err = base64.StdEncoding.DecodeString(part[2:])
61 if err != nil {
62 t.Fatal(err)
63 }
64 }
65 }
66
67 blob := signer.Public().(ed25519.PublicKey)
68 if string(blob) != string(keyBlob) {
69 t.Fatal("wrong public key placed into record file")
70 }
71}
72
73const pkeyEd25519 = `-----BEGIN PRIVATE KEY-----
74MC4CAQAwBQYDK2VwBCIEIJG9zs4vi2MYNkL9gUQwlmBLCzDODIJ5/1CwTAZFDm5U

Callers

nothing calls this directly

Calls 3

NameMethod · 0.95
loadOrGenerateKeyMethod · 0.95
LoggerFunction · 0.92

Tested by

no test coverage detected