Skip to content

Commit

Permalink
HTTP tenancy test
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Snible <[email protected]>
  • Loading branch information
esnible committed Jul 11, 2022
1 parent 8280c9f commit 6541aa5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/query/app/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@ func TestTenancyContextFlowGRPC(t *testing.T) {

for tenant, expected := range allExpectedResults {
t.Run(tenant, func(t *testing.T) {

// Test context propagation to Unary method.
resGetServices, err := client.GetServices(withOutgoingMetadata(t, context.Background(), tc.Header, tenant), &api_v2.GetServicesRequest{})
require.NoError(t, err, "expecting gRPC to succeed with %q tenancy header", tenant)
Expand Down
43 changes: 43 additions & 0 deletions cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package app

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -933,3 +934,45 @@ func TestSearchTenancyRejectionHTTP(t *testing.T) {
require.Equal(t, http.StatusOK, resp.StatusCode)
// Skip unmarshal of response; it is enough that it succeeded
}

func TestSearchTenancyFlowTenantHTTP(t *testing.T) {
tenancyOptions := tenancy.Options{
Enabled: true,
}
ts := initializeTestServerWithOptions(
*tenancy.NewTenancyConfig(&tenancyOptions),
querysvc.QueryServiceOptions{})
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.MatchedBy(func(v interface{}) bool {
ctx, ok := v.(context.Context)
if !ok || tenancy.GetTenant(ctx) != "acme" {
return false
}
return true
}), mock.AnythingOfType("model.TraceID")).Return(mockTrace, nil).Twice()
ts.spanReader.On("GetTrace", mock.MatchedBy(func(v interface{}) bool {
ctx, ok := v.(context.Context)
if !ok || tenancy.GetTenant(ctx) != "megacorp" {
return false
}
return true
}), mock.AnythingOfType("model.TraceID")).Return(nil, errStorage).Once()

var responseAcme structuredResponse
err := getJSONCustomHeaders(
ts.server.URL+`/api/traces?traceID=1&traceID=2`,
map[string]string{"x-tenant": "acme"},
&responseAcme)
assert.NoError(t, err)
assert.Len(t, responseAcme.Errors, 0)
assert.Len(t, responseAcme.Data, 2)

var responseMegacorp structuredResponse
err = getJSONCustomHeaders(
ts.server.URL+`/api/traces?traceID=1&traceID=2`,
map[string]string{"x-tenant": "megacorp"},
&responseMegacorp)
assert.Contains(t, err.Error(), "storage error")
assert.Len(t, responseMegacorp.Errors, 0)
assert.Nil(t, responseMegacorp.Data)
}

0 comments on commit 6541aa5

Please sign in to comment.