Skip to content

Commit

Permalink
transport: Don't pass default service if unset (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored May 7, 2022
1 parent 9d1ceb8 commit 82405e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pkg/v1/remote/transport/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ func (bt *bearerTransport) refreshOauth(ctx context.Context) ([]byte, error) {

v := url.Values{}
v.Set("scope", strings.Join(bt.scopes, " "))
v.Set("service", bt.service)
if bt.service != "" {
v.Set("service", bt.service)
}
v.Set("client_id", defaultUserAgent)
if auth.IdentityToken != "" {
v.Set("grant_type", "refresh_token")
Expand Down
7 changes: 1 addition & 6 deletions pkg/v1/remote/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ func NewWithContext(ctx context.Context, reg name.Registry, auth authn.Authentic
if !ok {
return nil, fmt.Errorf("malformed www-authenticate, missing realm: %v", pr.parameters)
}
service, ok := pr.parameters["service"]
if !ok {
// If the service parameter is not specified, then default it to the registry
// with which we are talking.
service = reg.String()
}
service := pr.parameters["service"]
bt := &bearerTransport{
inner: t,
basic: auth,
Expand Down
7 changes: 4 additions & 3 deletions pkg/v1/remote/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ func TestTransportSelectionBearer(t *testing.T) {
if got, want := r.FormValue("scope"), testReference.Scope(PullScope); got != want {
t.Errorf("FormValue(scope); got %v, want %v", got, want)
}
// Check that we get the default value (we didn't specify it above)
if got, want := r.FormValue("service"), testReference.RegistryStr(); got != want {
t.Errorf("FormValue(service); got %v, want %v", got, want)
// Check that the service isn't set (we didn't specify it above)
// https://github.com/google/go-containerregistry/issues/1359
if got, want := r.FormValue("service"), ""; got != want {
t.Errorf("FormValue(service); got %q, want %q", got, want)
}
w.Write([]byte(`{"token": "dfskdjhfkhsjdhfkjhsdf"}`))
}
Expand Down

0 comments on commit 82405e5

Please sign in to comment.