From 5e01e8c3f58f057e875400e4b326fe3ad94fe306 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 26 Apr 2021 12:01:11 +0200 Subject: [PATCH] fix nil pointer when auth info is nil Signed-off-by: Gregor Zeitlinger --- client/opentracing.go | 3 +++ client/opentracing_test.go | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/opentracing.go b/client/opentracing.go index 87e0753a..1b64da0a 100644 --- a/client/opentracing.go +++ b/client/opentracing.go @@ -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) }) diff --git a/client/opentracing_test.go b/client/opentracing_test.go index db1922a1..f6e8667c 100644 --- a/client/opentracing_test.go +++ b/client/opentracing_test.go @@ -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}}, @@ -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) {