Skip to content

Commit

Permalink
Test runner needs to add synthetic headers to raw request, too (#758)
Browse files Browse the repository at this point in the history
These are extra headers used by the reference server, to verify that the
client created the request in the expected way. They were previously
only added to the structured request that normal clients use. But they
also need to be included in the raw request, for test cases that use
raw requests with the reference client.

This also makes it so that the test case name header is _always_ added,
even when not running against the reference server. This is useful if
tracing through and debugging an implementation -- you can easily tell
which test case the request is for because it is always in the request
headers.
  • Loading branch information
jhump authored Jan 22, 2024
1 parent 077730a commit 1b134c1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
34 changes: 22 additions & 12 deletions internal/app/connectconformance/server_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,37 @@ func runTestCasesForServer(
req.Port = resp.Port
req.ServerTlsCert = resp.PemCert
req.ClientTlsCreds = clientCreds

// We always include test name in request header.
testCaseHeader := &conformancev1.Header{Name: "x-test-case-name", Value: []string{testCase.Request.TestName}}
req.RequestHeaders = append(req.RequestHeaders, testCaseHeader)
if req.RawRequest != nil {
req.RawRequest.Headers = append(req.RawRequest.Headers, testCaseHeader)
}
if isReferenceServer {
// The reference server wants more metadata in headers, to perform add'l validations.
httpMethod := http.MethodPost
if req.UseGetHttpMethod {
httpMethod = http.MethodGet
}
req.RequestHeaders = append(
req.RequestHeaders,
&conformancev1.Header{Name: "x-test-case-name", Value: []string{testCase.Request.TestName}},
&conformancev1.Header{Name: "x-expect-http-version", Value: []string{strconv.Itoa(int(req.HttpVersion))}},
&conformancev1.Header{Name: "x-expect-http-method", Value: []string{httpMethod}},
&conformancev1.Header{Name: "x-expect-protocol", Value: []string{strconv.Itoa(int(req.Protocol))}},
&conformancev1.Header{Name: "x-expect-codec", Value: []string{strconv.Itoa(int(req.Codec))}},
&conformancev1.Header{Name: "x-expect-compression", Value: []string{strconv.Itoa(int(req.Compression))}},
&conformancev1.Header{Name: "x-expect-tls", Value: []string{strconv.FormatBool(len(resp.PemCert) > 0)}},
)
extraHeaders := []*conformancev1.Header{
{Name: "x-expect-http-version", Value: []string{strconv.Itoa(int(req.HttpVersion))}},
{Name: "x-expect-http-method", Value: []string{httpMethod}},
{Name: "x-expect-protocol", Value: []string{strconv.Itoa(int(req.Protocol))}},
{Name: "x-expect-codec", Value: []string{strconv.Itoa(int(req.Codec))}},
{Name: "x-expect-compression", Value: []string{strconv.Itoa(int(req.Compression))}},
{Name: "x-expect-tls", Value: []string{strconv.FormatBool(len(resp.PemCert) > 0)}},
}
if clientCreds != nil {
req.RequestHeaders = append(
req.RequestHeaders,
extraHeaders = append(
extraHeaders,
&conformancev1.Header{Name: "x-expect-client-cert", Value: []string{internal.ClientCertName}},
)
}
req.RequestHeaders = append(req.RequestHeaders, extraHeaders...)
if req.RawRequest != nil {
req.RawRequest.Headers = append(req.RawRequest.Headers, extraHeaders...)
}
}

wg.Add(1)
Expand Down
25 changes: 15 additions & 10 deletions internal/app/connectconformance/server_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,30 @@ func TestRunTestCasesForServer(t *testing.T) {
client.requestHookCount = testCase.svrKillAfter
expectedRequests = requests[:testCase.svrKillAfter]
}
if testCase.isReferenceServer {
copyOfRequests := make([]*conformancev1.ClientCompatRequest, len(expectedRequests))
// runner adds headers for the reference server
for i, req := range expectedRequests {
req = proto.Clone(req).(*conformancev1.ClientCompatRequest) //nolint:errcheck,forcetypeassert
req.RequestHeaders = append(req.RequestHeaders,
&conformancev1.Header{Name: "x-test-case-name", Value: []string{req.TestName}},
// we didn't set this above, so they're all zero/unspecified
// runner adds headers
copyOfRequests := make([]*conformancev1.ClientCompatRequest, len(expectedRequests))
for i, req := range expectedRequests {
req = proto.Clone(req).(*conformancev1.ClientCompatRequest) //nolint:errcheck,forcetypeassert
req.RequestHeaders = append(
req.RequestHeaders,
&conformancev1.Header{Name: "x-test-case-name", Value: []string{req.TestName}},
)
// more are set for reference server
if testCase.isReferenceServer {
// we didn't set these above in request definition, so they're all zero/unspecified
req.RequestHeaders = append(
req.RequestHeaders,
&conformancev1.Header{Name: "x-expect-http-version", Value: []string{"0"}},
&conformancev1.Header{Name: "x-expect-http-method", Value: []string{"POST"}},
&conformancev1.Header{Name: "x-expect-protocol", Value: []string{"0"}},
&conformancev1.Header{Name: "x-expect-codec", Value: []string{"0"}},
&conformancev1.Header{Name: "x-expect-compression", Value: []string{"0"}},
&conformancev1.Header{Name: "x-expect-tls", Value: []string{"false"}},
)
copyOfRequests[i] = req
}
expectedRequests = copyOfRequests
copyOfRequests[i] = req
}
expectedRequests = copyOfRequests

responsesToSend := responses
if testCase.clientCloseAfter > 0 {
Expand Down

0 comments on commit 1b134c1

Please sign in to comment.