diff --git a/internal/oci/resolver_test.go b/internal/oci/resolver_test.go index de53535e8..2a1789116 100644 --- a/internal/oci/resolver_test.go +++ b/internal/oci/resolver_test.go @@ -25,12 +25,9 @@ import ( "github.com/distribution/reference" "github.com/docker/cli/cli/config/configfile" - clitypes "github.com/docker/cli/cli/config/types" "github.com/opencontainers/go-digest" spec "github.com/opencontainers/image-spec/specs-go/v1" "gotest.tools/v3/assert" - - "github.com/docker/compose/v5/internal/registry" ) // recordingRoundTripper counts RoundTrip invocations on a delegate so tests @@ -108,52 +105,6 @@ func TestNewResolver_AuthorizerUsesProvidedTransport(t *testing.T) { "authorizer token fetch did not go through the supplied transport (bypassed via http.DefaultClient)") } -func TestNewResolver_SendsPasswordGrant(t *testing.T) { - type tokenRequest struct { - GrantType, Username, Password string - } - requests := make(chan tokenRequest, 1) - - var server *httptest.Server - server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if strings.HasSuffix(r.URL.Path, "/token") { - if r.Method == http.MethodPost && r.ParseForm() == nil { - select { - case requests <- tokenRequest{ - GrantType: r.PostForm.Get("grant_type"), - Username: r.PostForm.Get("username"), - Password: r.PostForm.Get("password"), - }: - default: - } - } - _, _ = w.Write([]byte(`{"token":"fake","access_token":"fake","expires_in":300}`)) - return - } - if r.Header.Get("Authorization") == "" { - w.Header().Set("Www-Authenticate", `Bearer realm="`+server.URL+`/token",service="test"`) - w.WriteHeader(http.StatusUnauthorized) - return - } - w.WriteHeader(http.StatusNotFound) - })) - t.Cleanup(server.Close) - - host := server.Listener.Addr().String() - credentials := registry.AuthProviderFunc(func(string) (clitypes.AuthConfig, error) { - return clitypes.AuthConfig{Username: "hubuser", Password: "desktop-oauth-token"}, nil - }) - resolver := NewResolver(credentials, &http.Transport{}, host) - _, _, _ = resolver.Resolve(t.Context(), host+"/test/image:latest") - - select { - case got := <-requests: - assert.DeepEqual(t, got, tokenRequest{GrantType: "password", Username: "hubuser", Password: "desktop-oauth-token"}) - default: - t.Fatal("the resolver never requested a token with the provided credentials") - } -} - func TestNewResolver_NilTransportIsValid(t *testing.T) { resolver := NewResolver(&configfile.ConfigFile{}, nil) assert.Assert(t, resolver != nil, "NewResolver must return a non-nil resolver when transport is nil")