generateTestCACert generates a self-signed CA certificate for testing
(t *testing.T)
| 253 | |
| 254 | // generateTestCACert generates a self-signed CA certificate for testing |
| 255 | func generateTestCACert(t *testing.T) []byte { |
| 256 | t.Helper() |
| 257 | |
| 258 | // Generate a new ECDSA private key |
| 259 | privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| 260 | require.NoError(t, err) |
| 261 | |
| 262 | // Create a CA certificate template |
| 263 | template := x509.Certificate{ |
| 264 | SerialNumber: big.NewInt(1), |
| 265 | Subject: pkix.Name{ |
| 266 | Organization: []string{"Test CA"}, |
| 267 | }, |
| 268 | NotBefore: time.Now(), |
| 269 | NotAfter: time.Now().Add(time.Hour), |
| 270 | KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, |
| 271 | IsCA: true, |
| 272 | BasicConstraintsValid: true, |
| 273 | } |
| 274 | |
| 275 | // Create the certificate |
| 276 | certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &privateKey.PublicKey, privateKey) |
| 277 | require.NoError(t, err) |
| 278 | |
| 279 | // Encode certificate to PEM |
| 280 | return pem.EncodeToMemory(&pem.Block{ |
| 281 | Type: "CERTIFICATE", |
| 282 | Bytes: certDER, |
| 283 | }) |
| 284 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…