mirror of
https://github.com/pgsty/minio.git
synced 2026-08-09 07:43:29 +03:00
Improve coverage of web-handlers.go (#3157)
This patch additionally relaxes the requirement for accesskeys to be in a regexy set of values. Fixes #3063
This commit is contained in:
+14
-13
@@ -44,28 +44,30 @@ const (
|
||||
// newJWT - returns new JWT object.
|
||||
func newJWT(expiry time.Duration) (*JWT, error) {
|
||||
if serverConfig == nil {
|
||||
return nil, errors.New("Server not initialized")
|
||||
return nil, errServerNotInitialized
|
||||
}
|
||||
|
||||
// Save access, secret keys.
|
||||
cred := serverConfig.GetCredential()
|
||||
if !isValidAccessKey.MatchString(cred.AccessKeyID) {
|
||||
return nil, errors.New("Invalid access key")
|
||||
if !isValidAccessKey(cred.AccessKeyID) {
|
||||
return nil, errInvalidAccessKeyLength
|
||||
}
|
||||
if !isValidSecretKey.MatchString(cred.SecretAccessKey) {
|
||||
return nil, errors.New("Invalid secret key")
|
||||
if !isValidSecretKey(cred.SecretAccessKey) {
|
||||
return nil, errInvalidSecretKeyLength
|
||||
}
|
||||
|
||||
return &JWT{cred, expiry}, nil
|
||||
}
|
||||
|
||||
var errInvalidAccessKeyLength = errors.New("Invalid access key, access key should be 5 to 20 characters in length.")
|
||||
var errInvalidSecretKeyLength = errors.New("Invalid secret key, secret key should be 8 to 40 characters in length.")
|
||||
|
||||
// GenerateToken - generates a new Json Web Token based on the incoming access key.
|
||||
func (jwt *JWT) GenerateToken(accessKey string) (string, error) {
|
||||
// Trim spaces.
|
||||
accessKey = strings.TrimSpace(accessKey)
|
||||
|
||||
if !isValidAccessKey.MatchString(accessKey) {
|
||||
return "", errors.New("Invalid access key")
|
||||
if !isValidAccessKey(accessKey) {
|
||||
return "", errInvalidAccessKeyLength
|
||||
}
|
||||
|
||||
tUTCNow := time.Now().UTC()
|
||||
@@ -79,7 +81,6 @@ func (jwt *JWT) GenerateToken(accessKey string) (string, error) {
|
||||
}
|
||||
|
||||
var errInvalidAccessKeyID = errors.New("The access key ID you provided does not exist in our records.")
|
||||
|
||||
var errAuthentication = errors.New("Authentication failed, check your access credentials.")
|
||||
|
||||
// Authenticate - authenticates incoming access key and secret key.
|
||||
@@ -87,11 +88,11 @@ func (jwt *JWT) Authenticate(accessKey, secretKey string) error {
|
||||
// Trim spaces.
|
||||
accessKey = strings.TrimSpace(accessKey)
|
||||
|
||||
if !isValidAccessKey.MatchString(accessKey) {
|
||||
return errors.New("Invalid access key")
|
||||
if !isValidAccessKey(accessKey) {
|
||||
return errInvalidAccessKeyLength
|
||||
}
|
||||
if !isValidSecretKey.MatchString(secretKey) {
|
||||
return errors.New("Invalid secret key")
|
||||
if !isValidSecretKey(secretKey) {
|
||||
return errInvalidSecretKeyLength
|
||||
}
|
||||
|
||||
if accessKey != jwt.AccessKeyID {
|
||||
|
||||
Reference in New Issue
Block a user