mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-20 16:51:03 -04:00
Add more useful error for bad credentials. (#51)
* Add more useful error for bad credentials. The www-authenticate: basic response currently gets caught by the token transport, which fails to parse it and spits out a rather oblique "malformed auth challenge header" error. Make the token transport ignore basic auth types, and make the error transport handle a 401 response. * Format authchallenge.go correctly.
This commit is contained in:
parent
3bc47ed926
commit
0ff43808ca
2 changed files with 6 additions and 1 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
var (
|
||||
authChallengeRegex = regexp.MustCompile(
|
||||
`^\s*Bearer\s+realm="([^"]+)",service="([^"]+)"\s*$`)
|
||||
basicRegex = regexp.MustCompile(`^\s*Basic\s+.*$`)
|
||||
challengeRegex = regexp.MustCompile(
|
||||
`^\s*Bearer\s+realm="([^"]+)",service="([^"]+)",scope="([^"]+)"\s*$`)
|
||||
|
||||
|
@ -26,6 +27,10 @@ func parseAuthHeader(header http.Header) (*authService, error) {
|
|||
}
|
||||
|
||||
func parseChallenge(challengeHeader string) (*authService, error) {
|
||||
if basicRegex.MatchString(challengeHeader) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
match := challengeRegex.FindAllStringSubmatch(challengeHeader, -1)
|
||||
|
||||
if len(match) != 1 {
|
||||
|
|
|
@ -29,7 +29,7 @@ func (t *ErrorTransport) RoundTrip(request *http.Request) (*http.Response, error
|
|||
return resp, err
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 500 {
|
||||
if resp.StatusCode >= 500 || resp.StatusCode == http.StatusUnauthorized {
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue