Open mitar opened 10 months ago
The source of the issue is here: https://github.com/golang/go/blob/883f062fc0a097bf561030ad453fd3e300896975/src/net/http/httptest/server.go#L167-L169
I guess it could also check if s.TLS.GetCertificate == nil
. But then I don't know what the Certificate
method is supposed to return in that case.
I'll also note that this behavior of httptest.Server
seems to be completely undocumented.
I thnk GetCertificate
should be called with 127.0.0.1
(or more precisely s.Listener.Addr()
) as a parameter. That is what it gets set in s.URL
. That can then be stored in s.certificate
.
GetCertificate
takes an entire ClientHelloInfo
, not just a hostname.
@rittneje, yes, I know. What I mean that it should be a dummy ClientHelloInfo
with s.Listener.Addr()
.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to test a
http.Server
instance with httptest'sServer
:I want to check that server's TLS configuration works. Server's TLS configuration uses
GetCertificate
What did you expect to see?
That once I call
StartTLS
is called,GetCertificate
is called to obtain the certificate to configure the testing server and testing client.What did you see instead?
StartTLS
ignores and never callsGetCertificate
but instead configures testing server and testing client to use testing certificate.Discussion
I can call something like:
before calling
StartTLS
. But ideally that should be called byStartTLS
. This is documented intls.Config
:Currently only
Certificates
is checked, butGetCertificate
orGetConfigForClient
are ignored.My motivation is to do a test with
golang.org/x/crypto/acme/autocert
serving as manager against Pebble to test thathttp.Server
's configuration and everything works correctly.