Skip to content

Commit 61de825

Browse files
mahepererarayokota
andauthored
fix: prevent panic when schemaregistry is configured without an auth provider (#1424)
* Add TestNoAuthProviderSetAuthenticationHeaders to demonstrate panic when no auth provider is set in schemaregistry client config * Add early return to SetAuthenticationHeaders when provider is nil --------- Co-authored-by: Robert Yokota <[email protected]>
1 parent a824817 commit 61de825

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

schemaregistry/internal/rest_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ func (rs *RestService) HandleRequest(request *API, response interface{}) error {
456456

457457
// SetAuthenticationHeaders sets the authentication headers on the request
458458
func SetAuthenticationHeaders(provider AuthenticationHeaderProvider, headers *http.Header) error {
459+
if provider == nil {
460+
return nil
461+
}
459462
authHeader, err := provider.GetAuthenticationHeader()
460463
if err != nil {
461464
return err

schemaregistry/internal/rest_service_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,19 @@ func TestSetAuthenticationHandlers(t *testing.T) {
315315
t.Errorf("should have Confluent-Identity-Pool-Id header with value pool_id")
316316
}
317317
}
318+
319+
func TestNoAuthProviderSetAuthenticationHeaders(t *testing.T) {
320+
config := &ClientConfig{}
321+
322+
rs, err := NewRestService(config)
323+
324+
if err != nil {
325+
t.Errorf("should work with no auth provider")
326+
}
327+
328+
err = SetAuthenticationHeaders(config.AuthenticationHeaderProvider, &rs.headers)
329+
330+
if err != nil {
331+
t.Errorf("should work with no auth provider, got err %s", err)
332+
}
333+
}

0 commit comments

Comments
 (0)