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

Function TestTLSRoundTripper

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

Source from the content-addressed store, hash-verified

1041}
1042
1043func TestTLSRoundTripper(t *testing.T) {
1044 bs := getCertificateBlobs(t)
1045
1046 tmpDir, err := os.MkdirTemp("", "tlsroundtripper")
1047 require.NoErrorf(t, err, "Failed to create tmp dir")
1048 defer os.RemoveAll(tmpDir)
1049
1050 ca, cert, key := filepath.Join(tmpDir, "ca"), filepath.Join(tmpDir, "cert"), filepath.Join(tmpDir, "key")
1051
1052 handler := func(w http.ResponseWriter, _ *http.Request) {
1053 fmt.Fprint(w, ExpectedMessage)
1054 }
1055 testServer, err := newTestServer(handler)
1056 require.NoError(t, err)
1057 defer testServer.Close()
1058
1059 testCases := []struct {
1060 ca string
1061 cert string
1062 key string
1063
1064 errMsg string
1065 }{
1066 {
1067 // Valid certs.
1068 ca: TLSCAChainPath,
1069 cert: ClientCertificatePath,
1070 key: ClientKeyNoPassPath,
1071 },
1072 {
1073 // CA not matching.
1074 ca: ClientCertificatePath,
1075 cert: ClientCertificatePath,
1076 key: ClientKeyNoPassPath,
1077
1078 errMsg: "certificate signed by unknown authority",
1079 },
1080 {
1081 // Invalid client cert+key.
1082 ca: TLSCAChainPath,
1083 cert: WrongClientCertPath,
1084 key: WrongClientKeyPath,
1085
1086 errMsg: "remote error: tls",
1087 },
1088 {
1089 // CA file empty
1090 ca: EmptyFile,
1091 cert: ClientCertificatePath,
1092 key: ClientKeyNoPassPath,
1093
1094 errMsg: "unable to use specified CA cert",
1095 },
1096 {
1097 // cert file empty
1098 ca: TLSCAChainPath,
1099 cert: EmptyFile,
1100 key: ClientKeyNoPassPath,

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…