MCPcopy Create free account
hub / github.com/prometheus/common / TestModifyTLSCertificates

Function TestModifyTLSCertificates

config/http_config_test.go:2358–2458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2356}
2357
2358func TestModifyTLSCertificates(t *testing.T) {
2359 bs := getCertificateBlobs(t)
2360
2361 tmpDir, err := os.MkdirTemp("", "modifytlscertificates")
2362 require.NoErrorf(t, err, "Failed to create tmp dir")
2363 defer os.RemoveAll(tmpDir)
2364 ca, cert, key := filepath.Join(tmpDir, "ca"), filepath.Join(tmpDir, "cert"), filepath.Join(tmpDir, "key")
2365
2366 handler := func(w http.ResponseWriter, _ *http.Request) {
2367 fmt.Fprint(w, ExpectedMessage)
2368 }
2369 testServer, err := newTestServer(handler)
2370 require.NoError(t, err)
2371 defer testServer.Close()
2372
2373 tests := []struct {
2374 ca string
2375 cert string
2376 key string
2377
2378 errMsg string
2379
2380 modification func()
2381 }{
2382 {
2383 ca: ClientCertificatePath,
2384 cert: ClientCertificatePath,
2385 key: ClientKeyNoPassPath,
2386
2387 errMsg: "certificate signed by unknown authority",
2388
2389 modification: func() { writeCertificate(bs, TLSCAChainPath, ca) },
2390 },
2391 {
2392 ca: TLSCAChainPath,
2393 cert: WrongClientCertPath,
2394 key: ClientKeyNoPassPath,
2395
2396 errMsg: "private key does not match public key",
2397
2398 modification: func() { writeCertificate(bs, ClientCertificatePath, cert) },
2399 },
2400 {
2401 ca: TLSCAChainPath,
2402 cert: ClientCertificatePath,
2403 key: WrongClientCertPath,
2404
2405 errMsg: "found a certificate rather than a key in the PEM for the private key",
2406
2407 modification: func() { writeCertificate(bs, ClientKeyNoPassPath, key) },
2408 },
2409 }
2410
2411 cfg := HTTPClientConfig{
2412 TLSConfig: TLSConfig{
2413 CAFile: ca,
2414 CertFile: cert,
2415 KeyFile: key,

Callers

nothing calls this directly

Calls 5

getCertificateBlobsFunction · 0.85
newTestServerFunction · 0.85
writeCertificateFunction · 0.85
NewClientFromConfigFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…