Skip to content

Commit

Permalink
fix style issues in certs tests
Browse files Browse the repository at this point in the history
Signed-off-by: David Hontecillas <[email protected]>
  • Loading branch information
dhontecillas committed Jul 4, 2024
1 parent 1bbf4c5 commit fc8ed5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 9 additions & 5 deletions transport/http/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,30 +527,34 @@ func TestRunServer_MultipleTLS(t *testing.T) {
t.Error(err)
return
}
resp, err = client.Get(fmt.Sprintf("https://127.0.0.1:%d", port))
_, err = client.Get(fmt.Sprintf("https://127.0.0.1:%d", port))
// should fail, because it will be served with cert.pem
if err == nil || strings.Contains(err.Error(), "bad certificate") {
t.Error("expected to have 'bad certificate' error")
return
}

req, _ := http.NewRequest("GET", fmt.Sprintf("https://example.com:%d", port), nil)
OverrideHostTransport(client)
req, _ := http.NewRequest("GET", fmt.Sprintf("https://example.com:%d", port), http.NoBody)
overrideHostTransport(client)
resp, err = client.Do(req)
if err != nil {
t.Error(err)
return
}
if resp.StatusCode != 200 {
t.Errorf("unexpected status code: %d", resp.StatusCode)
return
}

cancel()
if err = <-done; err != nil {
t.Error(err)
}
}

// OverrideHostTransport subtitutes the actual address that the request will
// overrideHostTransport subtitutes the actual address that the request will
// connecto (overriding the dns resolution).
func OverrideHostTransport(client *http.Client) {
func overrideHostTransport(client *http.Client) {
t := http.DefaultTransport.(*http.Transport).Clone()
if client.Transport != nil {
if tt, ok := client.Transport.(*http.Transport); ok {
Expand Down
6 changes: 2 additions & 4 deletions transport/http/server/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type certDef struct {
}

func (c certDef) Org() string {
if len(c.Prefix) == 0 {
if c.Prefix == "" {
return "Acme Co"
}
return c.Prefix + " " + "Acme Co"
Expand Down Expand Up @@ -84,9 +84,7 @@ func generateNamedCert(hostCert certDef) error {
template.IPAddresses = append(template.IPAddresses, ip)
}
}
for _, dname := range hostCert.DNSNames {
template.DNSNames = append(template.DNSNames, dname)
}
template.DNSNames = append(template.DNSNames, hostCert.DNSNames...)

template.IsCA = true
template.KeyUsage |= x509.KeyUsageCertSign
Expand Down

0 comments on commit fc8ed5c

Please sign in to comment.