mirror of https://github.com/knative/func.git
fix: auth check (#773)
* fix: auth check Signed-off-by: Matej Vasek <mvasek@redhat.com> * fix: auth check Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
e918f74b9e
commit
153e486bc6
|
@ -41,7 +41,7 @@ func CheckAuth(ctx context.Context, registry string, credentials docker.Credenti
|
|||
serverAddress = "https://" + serverAddress
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/v2", serverAddress)
|
||||
url := fmt.Sprintf("%s/v2/", serverAddress)
|
||||
|
||||
authenticator := &authn.Basic{
|
||||
Username: credentials.Username,
|
||||
|
@ -55,6 +55,10 @@ func CheckAuth(ctx context.Context, registry string, credentials docker.Credenti
|
|||
|
||||
tr, err := transport.NewWithContext(ctx, reg, authenticator, trans, nil)
|
||||
if err != nil {
|
||||
var transportErr *transport.Error
|
||||
if errors.As(err, &transportErr); transportErr.StatusCode == 401 {
|
||||
return ErrUnauthorized
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -170,6 +170,7 @@ func startServer(t *testing.T) (addr, addrTLS string, stopServer func()) {
|
|||
addrTLS = listenerTLS.Addr().String()
|
||||
|
||||
handler := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
// TODO add also test for token based auth
|
||||
resp.Header().Add("WWW-Authenticate", "basic")
|
||||
if user, pwd, ok := req.BasicAuth(); ok {
|
||||
if user == "testuser" && pwd == "testpwd" {
|
||||
|
|
Loading…
Reference in New Issue