mirror of
https://github.com/docker/compose.git
synced 2026-11-20 15:09:50 +00:00
test(oci): drop TestNewResolver_SendsPasswordGrant
It covered the resolver credential mapping and containerd grant selection, neither changed by this PR. The token-as-password contract is asserted on the provider output and on the encoded X-Registry-Auth in internal/registry. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
parent
171f9d0767
commit
1a221b21e4
1 changed files with 0 additions and 49 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue