Merge pull request #965 from harshavardhana/handle-spaces

signature: Handle all corner cases with spaces.
This commit is contained in:
Harshavardhana 2015-11-10 18:17:44 -08:00
commit ae52fc682d
1 changed files with 10 additions and 8 deletions

View File

@ -40,18 +40,20 @@ func getCredentialsFromAuth(authValue string) ([]string, *probe.Error) {
if authValue == "" { if authValue == "" {
return nil, probe.NewError(errMissingAuthHeaderValue) return nil, probe.NewError(errMissingAuthHeaderValue)
} }
// replace all spaced strings
authValue = strings.Replace(authValue, " ", "", -1)
if !strings.HasPrefix(authValue, authHeaderPrefix) {
return nil, probe.NewError(errMissingFieldsAuthHeader)
}
if !strings.HasPrefix(strings.TrimPrefix(authValue, authHeaderPrefix), "Credential") {
return nil, probe.NewError(errInvalidAuthHeaderPrefix)
}
authValue = strings.TrimPrefix(authValue, authHeaderPrefix)
authFields := strings.Split(strings.TrimSpace(authValue), ",") authFields := strings.Split(strings.TrimSpace(authValue), ",")
if len(authFields) != 3 { if len(authFields) != 3 {
return nil, probe.NewError(errInvalidAuthHeaderValue) return nil, probe.NewError(errInvalidAuthHeaderValue)
} }
authPrefixFields := strings.Fields(authFields[0]) credentials := strings.Split(strings.TrimSpace(authFields[0]), "=")
if len(authPrefixFields) != 2 {
return nil, probe.NewError(errMissingFieldsAuthHeader)
}
if authPrefixFields[0] != authHeaderPrefix {
return nil, probe.NewError(errInvalidAuthHeaderPrefix)
}
credentials := strings.Split(strings.TrimSpace(authPrefixFields[1]), "=")
if len(credentials) != 2 { if len(credentials) != 2 {
return nil, probe.NewError(errMissingFieldsCredentialTag) return nil, probe.NewError(errMissingFieldsCredentialTag)
} }