Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http/httptest: does not support standard TLS client requests #37527

Closed
lmtyler opened this issue Feb 27, 2020 · 2 comments
Closed

net/http/httptest: does not support standard TLS client requests #37527

lmtyler opened this issue Feb 27, 2020 · 2 comments

Comments

@lmtyler
Copy link

lmtyler commented Feb 27, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.8 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

attempting to use httptest to mock a http response with a client request

What did you expect to see?

Successful client response

What did you see instead?

Get https://127.0.0.1:65088: x509: certificate signed by unknown authority

This TLS Fails
This TLS Works

You must set InsecureSkipVerify: true for it to work, which I am not able to do
this TLS works but not ok

NON TLS Succeeded

@cagedmantis cagedmantis changed the title httptest does not support standard TLS client requests net/http/httptest: does not support standard TLS client requests Feb 28, 2020
@cagedmantis
Copy link
Contributor

@lmtyler Have you considered using NewTLSServer instead? This is working as intended. I'm going to close this issue. If you think I closed it in error, please comment below.

@lmtyler
Copy link
Author

lmtyler commented Feb 28, 2020

That produces the same results

I was able to figure out how to get around it

	cert, err := x509.ParseCertificate(ts.TLS.Certificates[0].Certificate[0])
	if err != nil {
		t.Fatal(err)
	}

	var buf bytes.Buffer
	if err := pem.Encode(&buf, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}); err != nil {
		t.Fatalf("Yikes!  %v", err)
	}

I believe this should be added to documentation or better yet a method added to get the certificate as a PEM

@golang golang locked and limited conversation to collaborators Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants