mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 02:04:04 +08:00
Refactor toolshed password validation
This commit is contained in:
@@ -16,8 +16,8 @@ from galaxy import (
|
||||
from galaxy.actions.admin import AdminActions
|
||||
from galaxy.exceptions import ActionInputError, MessageException
|
||||
from galaxy.model import tool_shed_install as install_model
|
||||
from galaxy.tool_shed.util.repository_util import get_ids_of_tool_shed_repositories_being_installed
|
||||
from galaxy.security.validate_user_input import validate_password
|
||||
from galaxy.tool_shed.util.repository_util import get_ids_of_tool_shed_repositories_being_installed
|
||||
from galaxy.util import (
|
||||
nice_size,
|
||||
sanitize_text,
|
||||
|
||||
@@ -4,12 +4,12 @@ import time
|
||||
from sqlalchemy import false, func
|
||||
|
||||
from galaxy import util, web
|
||||
from galaxy.security.validate_user_input import validate_password
|
||||
from galaxy.util import inflector
|
||||
from galaxy.util.hash_util import new_secure_hash
|
||||
from galaxy.web.form_builder import CheckboxField
|
||||
from tool_shed.util.web_util import escape
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
compliance_log = logging.getLogger('COMPLIANCE')
|
||||
|
||||
@@ -685,13 +685,8 @@ class Admin(object):
|
||||
user = get_user(trans, user_id)
|
||||
password = kwd.get('password', None)
|
||||
confirm = kwd.get('confirm', None)
|
||||
if len(password) < 6:
|
||||
message = "Use a password of at least 6 characters."
|
||||
status = 'error'
|
||||
break
|
||||
elif password != confirm:
|
||||
message = "Passwords do not match."
|
||||
status = 'error'
|
||||
message = validate_password(trans, password, confirm)
|
||||
if message:
|
||||
break
|
||||
else:
|
||||
user.set_password_cleartext(password)
|
||||
|
||||
@@ -8,6 +8,7 @@ from datetime import (
|
||||
import tool_shed.repository_types.util as rt_util
|
||||
from galaxy import util
|
||||
from galaxy.model.orm.now import now
|
||||
from galaxy.security.validate_user_input import validate_password_str
|
||||
from galaxy.util import unique_id
|
||||
from galaxy.util.bunch import Bunch
|
||||
from galaxy.util.dictifiable import Dictifiable
|
||||
@@ -63,6 +64,9 @@ class User(Dictifiable):
|
||||
total_disk_usage = property(get_disk_usage, set_disk_usage)
|
||||
|
||||
def set_password_cleartext(self, cleartext):
|
||||
message = validate_password_str(cleartext, cleartext)
|
||||
if message:
|
||||
raise Exception("Invalid password: %s" % message)
|
||||
"""Set 'self.password' to the digest of 'cleartext'."""
|
||||
self.password = new_secure_hash(text_type=cleartext)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import print_function
|
||||
import logging
|
||||
import optparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from six.moves.configparser import ConfigParser
|
||||
@@ -14,16 +13,17 @@ sys.path.insert(1, os.path.join(os.path.dirname(__file__)))
|
||||
|
||||
import tool_shed.webapp.config as tool_shed_config
|
||||
from galaxy.security.idencoding import IdEncodingHelper
|
||||
from galaxy.security.validate_user_input import (
|
||||
validate_email_str,
|
||||
validate_password_str,
|
||||
validate_publicname_str
|
||||
)
|
||||
from tool_shed.webapp.model import mapping
|
||||
from bootstrap_util import admin_user_info # noqa: I100,I201
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
VALID_PUBLICNAME_RE = re.compile(r"^[a-z0-9\-]+$")
|
||||
VALID_EMAIL_RE = re.compile(r"[^@]+@[^@]+\.[^@]+")
|
||||
|
||||
|
||||
class BootstrapApplication(object):
|
||||
"""
|
||||
Creates a basic Tool Shed application in order to discover the database connection and use SQL
|
||||
@@ -84,44 +84,15 @@ def create_user(app):
|
||||
|
||||
|
||||
def validate(email, password, username):
|
||||
message = validate_email(email)
|
||||
if not message:
|
||||
message = validate_password(password)
|
||||
if not message:
|
||||
message = validate_publicname(username)
|
||||
message = "\n".join([validate_email_str(email),
|
||||
validate_password_str(password, password),
|
||||
validate_publicname_str(username)]).rstrip()
|
||||
return message
|
||||
|
||||
|
||||
def validate_email(email):
|
||||
"""Validates the email format."""
|
||||
message = ''
|
||||
if not(VALID_EMAIL_RE.match(email)):
|
||||
message = "Please enter a real email address."
|
||||
elif len(email) > 255:
|
||||
message = "Email address exceeds maximum allowable length."
|
||||
return message
|
||||
|
||||
|
||||
def validate_password(password):
|
||||
if len(password) < 6:
|
||||
return "Use a password of at least 6 characters"
|
||||
return ''
|
||||
|
||||
|
||||
def validate_publicname(username):
|
||||
"""Validates the public username."""
|
||||
if len(username) < 3:
|
||||
return "Public name must be at least 3 characters in length"
|
||||
if len(username) > 255:
|
||||
return "Public name cannot be more than 255 characters in length"
|
||||
if not(VALID_PUBLICNAME_RE.match(username)):
|
||||
return "Public name must contain only lower-case letters, numbers and '-'"
|
||||
return ''
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = optparse.OptionParser(description='Create a user with API key.')
|
||||
parser.add_option('-c', dest='config', action='store', help='.ini file to retried toolshed configuration from')
|
||||
parser.add_option('-c', dest='config', action='store', help='.ini file to retrieve toolshed configuration from')
|
||||
(args, options) = parser.parse_args()
|
||||
ini_file = args.config
|
||||
config_parser = ConfigParser({'here': os.getcwd()})
|
||||
|
||||
Reference in New Issue
Block a user