Skip to content

Commit

Permalink
Merge pull request #200 from zeitlinger/opentracing_auth_info
Browse files Browse the repository at this point in the history
fix nil pointer when auth info is nil
  • Loading branch information
casualjim authored Apr 26, 2021
2 parents 2ad8938 + 5e01e8c commit 539cabc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/opentracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (t *tracingTransport) Submit(op *runtime.ClientOperation) (interface{}, err

op.AuthInfo = runtime.ClientAuthInfoWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
span = createClientSpan(op, req.GetHeaderParams(), t.host, t.opts)
if authInfo == nil {
return nil
}
return authInfo.AuthenticateRequest(req, reg)
})

Expand Down
15 changes: 14 additions & 1 deletion client/opentracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func Test_TracingRuntime_submit(t *testing.T) {
t.Parallel()
tracer := mocktracer.New()
_, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
testSubmit(t, testOperation(ctx), tracer)
}

func Test_TracingRuntime_submit_nullAuthInfo(t *testing.T) {
t.Parallel()
tracer := mocktracer.New()
_, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
operation := testOperation(ctx)
operation.AuthInfo = nil
testSubmit(t, operation, tracer)
}

func testSubmit(t *testing.T, operation *runtime.ClientOperation, tracer *mocktracer.MockTracer) {

header := map[string][]string{}
r := newOpenTracingTransport(&mockRuntime{runtime.TestClientRequest{Headers: header}},
Expand All @@ -71,7 +84,7 @@ func Test_TracingRuntime_submit(t *testing.T) {
Value: "service",
}})

_, err := r.Submit(testOperation(ctx))
_, err := r.Submit(operation)
require.NoError(t, err)

if assert.Len(t, tracer.FinishedSpans(), 1) {
Expand Down

0 comments on commit 539cabc

Please sign in to comment.