(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func TestBasicResolver(t *testing.T) { |
| 87 | basicAuth := func(h http.Handler) (string, ResolverOptions, func()) { |
| 88 | // Wrap with basic auth |
| 89 | wrapped := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 90 | username, password, ok := r.BasicAuth() |
| 91 | if !ok || username != "user1" || password != "password1" { |
| 92 | rw.Header().Set("WWW-Authenticate", "Basic realm=localhost") |
| 93 | rw.WriteHeader(http.StatusUnauthorized) |
| 94 | return |
| 95 | } |
| 96 | h.ServeHTTP(rw, r) |
| 97 | }) |
| 98 | |
| 99 | base, options, close := tlsServer(wrapped) |
| 100 | authorizer := NewDockerAuthorizer( |
| 101 | WithAuthClient(options.Client), |
| 102 | WithAuthCreds(func(host string) (string, string, error) { |
| 103 | return "user1", "password1", nil |
| 104 | }), |
| 105 | ) |
| 106 | options.Hosts = ConfigureDefaultRegistries( |
| 107 | WithClient(options.Client), |
| 108 | WithAuthorizer(authorizer), |
| 109 | ) |
| 110 | return base, options, close |
| 111 | } |
| 112 | runBasicTest(t, "testname", basicAuth) |
| 113 | } |
| 114 | |
| 115 | func TestAnonymousTokenResolver(t *testing.T) { |
| 116 | th := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…