Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httputil: work around NPE in signer.Add() #1999

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/httputil/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (s *Signer) Add(ctx context.Context, uri string) error {
if err != nil {
return err
}
if s.use == nil {
return errors.New("authority map not initialized, perhaps missing auth section in config")
}
a := u.Host
s.use[a] = struct{}{}
return nil
Expand Down
25 changes: 25 additions & 0 deletions internal/httputil/signer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package httputil

import (
"context"
"github.com/quay/clair/config"
"github.com/quay/zlog"
"gopkg.in/square/go-jose.v2/jwt"
"testing"
)

func TestNewSigner(t *testing.T) {
ctx := zlog.Test(context.Background(), t)
cfg := config.Config{}
signer, err := NewSigner(ctx, &cfg, jwt.Claims{})
if err != nil {
t.Error("signer initialization with empty config should succeed")
}
if signer.use != nil {
t.Error("signed request authority map should be non-initialized")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Error("signed request authority map should be non-initialized")
t.Error("signed request authority map should be initialized")

}
err = signer.Add(ctx, "http://test-url")
if err == nil {
t.Error("Adding host to non-initialized signed request authority map should fail")
}
}