@@ -2064,11 +2064,13 @@ func TestModifyTLSCertificates(t *testing.T) {
20642064 }
20652065}
20662066
2067+ // TestTLSRoundTripper_NoCAConfigured verifies that client cert rotation works
2068+ // when no ca_file is configured. Regression test for prometheus/prometheus#16622.
20672069func TestTLSRoundTripper_NoCAConfigured (t * testing.T ) {
20682070 bs := getCertificateBlobs (t )
20692071
2070- tmpDir , err := os .MkdirTemp ("" , "tlspanic " )
2071- require .NoErrorf (t , err , "Failed to create tmp dir" )
2072+ tmpDir , err := os .MkdirTemp ("" , "tlsnocacert " )
2073+ require .NoError (t , err )
20722074 defer os .RemoveAll (tmpDir )
20732075 cert , key := filepath .Join (tmpDir , "cert" ), filepath .Join (tmpDir , "key" )
20742076
@@ -2090,20 +2092,24 @@ func TestTLSRoundTripper_NoCAConfigured(t *testing.T) {
20902092 writeCertificate (bs , ClientCertificatePath , cert )
20912093 writeCertificate (bs , ClientKeyNoPassPath , key )
20922094 c , err := NewClientFromConfig (cfg , "test" )
2093- require .NoErrorf ( t , err , "Error creating HTTP Client: %v" , err )
2095+ require .NoError ( t , err )
20942096
20952097 req , err := http .NewRequest (http .MethodGet , testServer .URL , nil )
2096- require .NoErrorf ( t , err , "Error creating HTTP request: %v" , err )
2098+ require .NoError ( t , err )
20972099
20982100 r , err := c .Do (req )
2099- require .NoErrorf (t , err , "Can't connect to the test server " )
2101+ require .NoErrorf (t , err , "request should succeed before cert rotation " )
21002102 r .Body .Close ()
21012103
2102- err = os .WriteFile (cert , []byte ("-----BEGIN GARBAGE-----\n abc\n -----END GARBAGE-----\n " ), 0o664 )
2103- require .NoError (t , err )
2104+ // Rotate the cert/key files to different (but still valid) certs.
2105+ // Tthe next RoundTrip should rebuild the transport.
2106+ writeCertificate (bs , ServerCertificatePath , cert )
2107+ writeCertificate (bs , ServerKeyPath , key )
21042108
2105- _ , err = c .Do (req )
2106- require .ErrorContainsf (t , err , "unable to use specified CA cert: none configured" , "Expected error to mention missing CA cert" )
2109+ // The request still succeeds after cert rotation.
2110+ r , err = c .Do (req )
2111+ require .NoErrorf (t , err , "request should succeed after cert rotation without ca_file" )
2112+ r .Body .Close ()
21072113}
21082114
21092115// loadHTTPConfigJSON parses the JSON input s into a HTTPClientConfig.
0 commit comments