Skip to content

Commit

Permalink
Fix client shadowing and e2e request ID test case
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Feb 28, 2024
1 parent 5c2572c commit 2255857
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 10 additions & 10 deletions ca/client.go
Expand Up @@ -397,8 +397,8 @@ func getTransportFromSHA256(endpoint, sum string) (http.RoundTripper, error) {
if err != nil {
return nil, err
}
client := &Client{endpoint: u}
root, err := client.Root(sum)
caClient := &Client{endpoint: u}
root, err := caClient.Root(sum)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -759,14 +759,14 @@ func (c *Client) Renew(tr http.RoundTripper) (*api.SignResponse, error) {
func (c *Client) RenewWithContext(ctx context.Context, tr http.RoundTripper) (*api.SignResponse, error) {
var retried bool
u := c.endpoint.ResolveReference(&url.URL{Path: "/renew"})
client := &http.Client{Transport: tr}
caClient := &http.Client{Transport: tr}
retry:
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
resp, err := caClient.Do(req)
if err != nil {
return nil, clientError(err)
}
Expand Down Expand Up @@ -836,14 +836,14 @@ func (c *Client) RekeyWithContext(ctx context.Context, req *api.RekeyRequest, tr
return nil, errors.Wrap(err, "error marshaling request")
}
u := c.endpoint.ResolveReference(&url.URL{Path: "/rekey"})
client := &http.Client{Transport: tr}
caClient := &http.Client{Transport: tr}
retry:
httpReq, err := http.NewRequestWithContext(ctx, "POST", u.String(), bytes.NewReader(body))
if err != nil {
return nil, err
}
httpReq.Header.Set("Content-Type", "application/json")
resp, err := client.Do(httpReq)
resp, err := caClient.Do(httpReq)
if err != nil {
return nil, clientError(err)
}
Expand Down Expand Up @@ -875,16 +875,16 @@ func (c *Client) RevokeWithContext(ctx context.Context, req *api.RevokeRequest,
if err != nil {
return nil, errors.Wrap(err, "error marshaling request")
}
var client *uaClient
var uaClient *uaClient
retry:
if tr != nil {
client = newClient(tr)
uaClient = newClient(tr)
} else {
client = c.client
uaClient = c.client
}

u := c.endpoint.ResolveReference(&url.URL{Path: "/revoke"})
resp, err := client.PostWithContext(ctx, u.String(), "application/json", bytes.NewReader(body))
resp, err := uaClient.PostWithContext(ctx, u.String(), "application/json", bytes.NewReader(body))
if err != nil {
return nil, clientError(err)
}
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/requestid_test.go
Expand Up @@ -19,7 +19,7 @@ import (
"go.step.sm/crypto/pemutil"
)

func TestXxx(t *testing.T) {
func Test_reflectRequestID(t *testing.T) {
dir := t.TempDir()
m, err := minica.New(minica.WithName("Step E2E"))
require.NoError(t, err)
Expand All @@ -37,9 +37,11 @@ func TestXxx(t *testing.T) {
require.NoError(t, err)

// get a random address to listen on and connect to; currently no nicer way to get one before starting the server
l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := net.Listen("tcp4", ":0")
require.NoError(t, err)
randomAddress := l.Addr().String()
_, port, err := net.SplitHostPort(l.Addr().String())
require.NoError(t, err)
err = l.Close()
require.NoError(t, err)

Expand All @@ -48,7 +50,7 @@ func TestXxx(t *testing.T) {
IntermediateCert: intermediateCertFilepath,
IntermediateKey: intermediateKeyFilepath,
Address: randomAddress, // reuse the address that was just "reserved"
DNSNames: []string{"127.0.0.1", "stepca.localhost"},
DNSNames: []string{"127.0.0.1", "[::1]", "localhost"},
AuthorityConfig: &config.AuthConfig{
AuthorityID: "stepca-test",
DeploymentType: "standalone-test",
Expand All @@ -60,7 +62,7 @@ func TestXxx(t *testing.T) {

// instantiate a client for the CA running at the random address
caClient, err := ca.NewClient(
fmt.Sprintf("https://%s", randomAddress),
fmt.Sprintf("https://localhost:%s", port),
ca.WithRootFile(rootFilepath),
)
require.NoError(t, err)
Expand Down

0 comments on commit 2255857

Please sign in to comment.