diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-11-25 15:19:31 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-11-25 15:19:31 +0100 |
commit | 7217e52463adb022eeb2c56293af1bfee09c387d (patch) | |
tree | fe03b7952de3871d35dba45d45355ce0c3f1baea /client | |
parent | dfcf411bacc993d20ff293c9e4c2ae101f357a6f (diff) |
Allow external URIs (with default no auth) in vespa test command
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/command_tester.go | 2 | ||||
-rw-r--r-- | client/go/cmd/test.go | 24 | ||||
-rw-r--r-- | client/go/cmd/test_test.go | 9 | ||||
-rw-r--r-- | client/go/util/http.go | 6 | ||||
-rw-r--r-- | client/go/util/http_test.go | 2 | ||||
-rw-r--r-- | client/go/vespa/target.go | 4 |
6 files changed, 35 insertions, 12 deletions
diff --git a/client/go/cmd/command_tester.go b/client/go/cmd/command_tester.go index 2d2de6a201c..eb55021b536 100644 --- a/client/go/cmd/command_tester.go +++ b/client/go/cmd/command_tester.go @@ -127,4 +127,4 @@ func (c *mockHttpClient) Do(request *http.Request, timeout time.Duration) (*http nil } -func (c *mockHttpClient) UseCertificate(certificate tls.Certificate) {} +func (c *mockHttpClient) UseCertificate(certificates []tls.Certificate) {} diff --git a/client/go/cmd/test.go b/client/go/cmd/test.go index 5e91a7ed634..53cf2f6b6af 100644 --- a/client/go/cmd/test.go +++ b/client/go/cmd/test.go @@ -6,6 +6,7 @@ package cmd import ( "bytes" + "crypto/tls" "encoding/json" "fmt" "github.com/spf13/cobra" @@ -176,14 +177,21 @@ func verify(step step, testsPath string, defaultCluster string, defaultParameter method = "GET" } - pathAndQuery := step.Request.URI - if pathAndQuery == "" { - pathAndQuery = "/search/" + requestUri := step.Request.URI + if requestUri == "" { + requestUri = "/search/" } - requestUrl, err := url.ParseRequestURI(service.BaseURL + pathAndQuery) + requestUrl, err := url.ParseRequestURI(requestUri) if err != nil { return "", "", err } + externalEndpoint := requestUrl.IsAbs() + if !externalEndpoint { + requestUrl, err = url.ParseRequestURI(service.BaseURL + requestUri) + if err != nil { + return "", "", err + } + } query := requestUrl.Query() for name, value := range parameters { query.Add(name, value) @@ -201,7 +209,13 @@ func verify(step step, testsPath string, defaultCluster string, defaultParameter } defer request.Body.Close() - response, err := service.Do(request, 600*time.Second) // Vespa should provide a response within the given request timeout + var response *http.Response + if externalEndpoint { + util.ActiveHttpClient.UseCertificate([]tls.Certificate{}) + response, err = util.ActiveHttpClient.Do(request, 60*time.Second) + } else { + response, err = service.Do(request, 600*time.Second) // Vespa should provide a response within the given request timeout + } if err != nil { return "", "", err } diff --git a/client/go/cmd/test_test.go b/client/go/cmd/test_test.go index 8db10282d51..598f550359e 100644 --- a/client/go/cmd/test_test.go +++ b/client/go/cmd/test_test.go @@ -41,6 +41,15 @@ func TestSuite(t *testing.T) { assertRequests(requests, client, t) } +func TestProductionTest(t *testing.T) { + client := &mockHttpClient{} + client.NextStatus(200) + outBytes, errBytes := execute(command{args: []string{"test", "testdata/tests/production-test/external.json"}}, t, client) + assert.Equal(t, "Running testdata/tests/production-test/external.json: . OK\n\n1 tests completed successfully\n", outBytes) + assert.Equal(t, "", errBytes) + assertRequests([]*http.Request{createRequest("GET", "https://my.service:123/path?query=wohoo", "")}, client, t) +} + func TestTestWithoutAssertions(t *testing.T) { client := &mockHttpClient{} _, errBytes := execute(command{args: []string{"test", "testdata/tests/system-test/foo/query.json"}}, t, client) diff --git a/client/go/util/http.go b/client/go/util/http.go index acd9bb4f7ec..d5b8e3128ff 100644 --- a/client/go/util/http.go +++ b/client/go/util/http.go @@ -19,7 +19,7 @@ var ActiveHttpClient = CreateClient(time.Second * 10) type HttpClient interface { Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) - UseCertificate(certificate tls.Certificate) + UseCertificate(certificate []tls.Certificate) } type defaultHttpClient struct { @@ -33,9 +33,9 @@ func (c *defaultHttpClient) Do(request *http.Request, timeout time.Duration) (re return c.client.Do(request) } -func (c *defaultHttpClient) UseCertificate(certificate tls.Certificate) { +func (c *defaultHttpClient) UseCertificate(certificates []tls.Certificate) { c.client.Transport = &http.Transport{TLSClientConfig: &tls.Config{ - Certificates: []tls.Certificate{certificate}, + Certificates: certificates, }} } diff --git a/client/go/util/http_test.go b/client/go/util/http_test.go index 0a0de1fdd4c..e87a1e5ada4 100644 --- a/client/go/util/http_test.go +++ b/client/go/util/http_test.go @@ -36,7 +36,7 @@ func (c mockHttpClient) Do(request *http.Request, timeout time.Duration) (respon nil } -func (c mockHttpClient) UseCertificate(certificate tls.Certificate) {} +func (c mockHttpClient) UseCertificate(certificates []tls.Certificate) {} func TestHttpRequest(t *testing.T) { ActiveHttpClient = mockHttpClient{} diff --git a/client/go/vespa/target.go b/client/go/vespa/target.go index 0b3223c0d2e..204dda6538f 100644 --- a/client/go/vespa/target.go +++ b/client/go/vespa/target.go @@ -90,7 +90,7 @@ func (t *customTarget) PrepareApiRequest(req *http.Request, sigKeyId string) err // Do sends request to this service. Any required authentication happens automatically. func (s *Service) Do(request *http.Request, timeout time.Duration) (*http.Response, error) { if s.TLSOptions.KeyPair.Certificate != nil { - util.ActiveHttpClient.UseCertificate(s.TLSOptions.KeyPair) + util.ActiveHttpClient.UseCertificate([]tls.Certificate{s.TLSOptions.KeyPair}) } return util.HttpDo(request, timeout, s.Description()) } @@ -536,7 +536,7 @@ type requestFunc func() *http.Request func wait(fn responseFunc, reqFn requestFunc, certificate *tls.Certificate, timeout time.Duration) (int, error) { if certificate != nil { - util.ActiveHttpClient.UseCertificate(*certificate) + util.ActiveHttpClient.UseCertificate([]tls.Certificate{*certificate}) } var ( httpErr error |