(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func TestGenerateSignVerify(t *testing.T) { |
| 155 | // This test verifies whether a freshly generated key can be used for |
| 156 | // signing and verification. |
| 157 | // |
| 158 | // It is a kind of "integration" test for DKIM modifier, as it tests |
| 159 | // whether everything works correctly together. |
| 160 | // |
| 161 | // Additionally it also tests whether key selection works correctly. |
| 162 | |
| 163 | test := func(domains []string, envelopeFrom string, expectDomain []string, keyAlgo string, headerCanon, bodyCanon dkim.Canonicalization, reload bool) { |
| 164 | t.Helper() |
| 165 | |
| 166 | dir := t.TempDir() |
| 167 | |
| 168 | m := newTestModifier(t, dir, keyAlgo, domains) |
| 169 | m.bodyCanon = bodyCanon |
| 170 | m.headerCanon = headerCanon |
| 171 | if reload { |
| 172 | m = newTestModifier(t, dir, keyAlgo, domains) |
| 173 | } |
| 174 | |
| 175 | testHdr, body := signTestMsg(t, m, envelopeFrom) |
| 176 | verifyTestMsg(t, dir, expectDomain, testHdr, body) |
| 177 | } |
| 178 | |
| 179 | for _, algo := range [2]string{"rsa2048", "ed25519"} { |
| 180 | for _, hdrCanon := range [2]dkim.Canonicalization{dkim.CanonicalizationSimple, dkim.CanonicalizationRelaxed} { |
| 181 | for _, bodyCanon := range [2]dkim.Canonicalization{dkim.CanonicalizationSimple, dkim.CanonicalizationRelaxed} { |
| 182 | test([]string{"maddy.test"}, "test@maddy.test", []string{"maddy.test"}, algo, hdrCanon, bodyCanon, false) |
| 183 | test([]string{"maddy.test"}, "test@maddy.test", []string{"maddy.test"}, algo, hdrCanon, bodyCanon, true) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // Key selection tests |
| 189 | test( |
| 190 | []string{"maddy.test"}, // Generated keys. |
| 191 | "test@maddy.test", // Envelope sender. |
| 192 | []string{"maddy.test"}, // Expected signature domains. |
| 193 | "ed25519", dkim.CanonicalizationRelaxed, dkim.CanonicalizationRelaxed, false) |
| 194 | test( |
| 195 | []string{"maddy.test"}, |
| 196 | "test@unrelated.maddy.test", |
| 197 | []string{}, |
| 198 | "ed25519", dkim.CanonicalizationRelaxed, dkim.CanonicalizationRelaxed, false) |
| 199 | test( |
| 200 | []string{"maddy.test", "related.maddy.test"}, |
| 201 | "test@related.maddy.test", |
| 202 | []string{"related.maddy.test"}, |
| 203 | "ed25519", dkim.CanonicalizationRelaxed, dkim.CanonicalizationRelaxed, false) |
| 204 | test( |
| 205 | []string{"fallback.maddy.test", "maddy.test"}, |
| 206 | "postmaster", |
| 207 | []string{"fallback.maddy.test"}, |
| 208 | "ed25519", dkim.CanonicalizationRelaxed, dkim.CanonicalizationRelaxed, false) |
| 209 | test( |
| 210 | []string{"fallback.maddy.test", "maddy.test"}, |
| 211 | "", |
nothing calls this directly
no test coverage detected