[Zope3-checkins] SVN: Zope3/branches/hdima-password-managers/
Password managers integrated into the mkzopeinstance script
Dmitry Vasiliev
dima at hlabs.spb.ru
Tue Oct 25 08:41:20 EDT 2005
Log message for revision 39611:
Password managers integrated into the mkzopeinstance script
Changed:
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py
UU Zope3/branches/hdima-password-managers/src/zope/app/server/mkzopeinstance.py
_U Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_accesslog.py
UU Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_mkzopeinstance.py
U Zope3/branches/hdima-password-managers/zopeskel/etc/principals.zcml.in
-=-
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py 2005-10-25 04:57:50 UTC (rev 39610)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py 2005-10-25 12:41:20 UTC (rev 39611)
@@ -95,3 +95,10 @@
def encodePassword(self, password):
return sha.new(password).hexdigest()
+
+# Simply registry used by mkzopeinstance script
+managers = [
+ ("Plain Text", PlainTextPasswordManager()),
+ ("MD5", MD5PasswordManager()),
+ ("SHA1", SHA1PasswordManager()),
+]
Modified: Zope3/branches/hdima-password-managers/src/zope/app/server/mkzopeinstance.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/server/mkzopeinstance.py 2005-10-25 04:57:50 UTC (rev 39610)
+++ Zope3/branches/hdima-password-managers/src/zope/app/server/mkzopeinstance.py 2005-10-25 12:41:20 UTC (rev 39611)
@@ -29,6 +29,7 @@
import zope
+from zope.app.authentication import password
from zope.app.applicationcontrol import zopeversion
@@ -100,8 +101,11 @@
if not options.username:
options.username = self.get_username()
+ (options.password_manager,
+ password_manager) = self.get_password_manager()
if not options.password:
options.password = self.get_password()
+ options.password = password_manager.encodePassword(options.password)
# now create the instance!
self.copy_skeleton()
@@ -151,6 +155,31 @@
sys.exit(1)
return password
+ def get_password_manager(self):
+ if self.options.password_manager:
+ for name, manager in password.managers:
+ if name == self.options.password_manager:
+ return (name, manager)
+ print >>sys.stderr, "Unknown password manager!"
+ sys.exit(1)
+
+ self.print_message(PASSWORD_MANAGER_MESSAGE)
+ for i, (name, manager) in enumerate(password.managers):
+ print "% i. %s" % (i + 1, name)
+ print
+ self.need_blank_line = True
+ while 1:
+ password_manager = self.read_input_line(
+ "Password Manager Number: ")
+ if (not password_manager
+ or not password_manager.isdigit()
+ or int(password_manager) - 1 >= len(password.managers)):
+ print >>sys.stderr, "You must select a password manager"
+ continue
+ break
+ index = int(password_manager) - 1
+ return password.managers[index]
+
def print_message(self, message):
if self.need_blank_line:
print
@@ -165,11 +194,12 @@
zope_init = os.path.abspath(zope.__file__)
software_home = os.path.dirname(os.path.dirname(zope_init))
self.replacements = [
- ("<<USERNAME>>", options.username),
- ("<<PASSWORD>>", options.password),
- ("<<PYTHON>>", sys.executable),
+ ("<<USERNAME>>", options.username),
+ ("<<PASSWORD>>", options.password),
+ ("<<PASSWORD_MANAGER>>", options.password_manager),
+ ("<<PYTHON>>", sys.executable),
("<<INSTANCE_HOME>>", options.destination),
- ("<<ZOPE_HOME>>", zope_home),
+ ("<<ZOPE_HOME>>", zope_home),
("<<SOFTWARE_HOME>>", software_home),
]
self.copytree(self.options.skeleton, self.options.destination)
@@ -224,7 +254,12 @@
Please provide a password for the initial administrator account.
"""
+PASSWORD_MANAGER_MESSAGE = """\
+Please select a password manager which will be used for encode the password of
+the initial administrator account.
+"""
+
def parse_args(argv, from_checkout=False):
"""Parse the command line, returning an object representing the input."""
path, prog = os.path.split(os.path.realpath(argv[0]))
@@ -236,6 +271,10 @@
help="the dir in which the instance home should be created")
p.add_option("-s", "--skelsrc", dest="skeleton", metavar="DIR",
help="template skeleton directory")
+ p.add_option("-m", "--password-manager",
+ dest="password_manager", metavar="NAME",
+ help=("set the name of the password manager"
+ " to be used for encode the password"))
p.add_option("-u", "--user", dest="username", metavar="USER:PASSWORD",
help="set the user name and password of the initial user")
options, args = p.parse_args(argv[1:])
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/server/mkzopeinstance.py
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_accesslog.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_mkzopeinstance.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_mkzopeinstance.py 2005-10-25 04:57:50 UTC (rev 39610)
+++ Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_mkzopeinstance.py 2005-10-25 12:41:20 UTC (rev 39611)
@@ -128,6 +128,18 @@
self.assertEqual(options.username, "User")
self.assertEqual(options.password, "Pass")
+ def test_without_password_manager(self):
+ options = self.parse_args([])
+ self.assertEqual(options.password_manager, None)
+
+ def test_password_manager_short(self):
+ options = self.parse_args(["-m", "Manager"])
+ self.assertEqual(options.password_manager, "Manager")
+
+ def test_password_manager_long(self):
+ options = self.parse_args(["--password-manager", "Manager"])
+ self.assertEqual(options.password_manager, "Manager")
+
def test_junk_positional_arg(self):
try:
self.parse_args(["junk"])
@@ -216,6 +228,32 @@
self.failUnless(self.stdout.getvalue())
self.failUnless(app.all_input_consumed())
+ def test_get_password_manager(self):
+ options = self.createOptions()
+ options.password_manager = None
+ app = ControlledInputApplication(options, ["3"])
+ name, pwm = app.get_password_manager()
+ self.assertEqual(name, "SHA1")
+ self.assertEqual(pwm.encodePassword("foo"),
+ "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
+ self.failIf(self.stderr.getvalue())
+ self.failUnless(self.stdout.getvalue())
+ self.failUnless(app.all_input_consumed())
+
+ def test_get_wrong_password_manager(self):
+ options = self.createOptions()
+ options.password_manager = "Unknown"
+ app = ControlledInputApplication(options, [])
+ try:
+ app.get_password_manager()
+ except SystemExit, e:
+ self.assertEqual(e.code, 1)
+ else:
+ self.fail("expected SystemExit")
+ self.failUnless(self.stderr.getvalue())
+ self.failIf(self.stdout.getvalue())
+ self.failUnless(app.all_input_consumed())
+
def test_get_password(self):
options = self.createOptions()
app = ControlledInputApplication(options, ["foo", "foo"])
@@ -303,6 +341,7 @@
class Options(object):
username = "[test-username]"
+ password_manager = "Plain Text"
password = "[test-password]"
destination = None
version = "[test-version]"
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/server/tests/test_mkzopeinstance.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: Zope3/branches/hdima-password-managers/zopeskel/etc/principals.zcml.in
===================================================================
--- Zope3/branches/hdima-password-managers/zopeskel/etc/principals.zcml.in 2005-10-25 04:57:50 UTC (rev 39610)
+++ Zope3/branches/hdima-password-managers/zopeskel/etc/principals.zcml.in 2005-10-25 12:41:20 UTC (rev 39611)
@@ -27,6 +27,7 @@
id="zope.manager"
title="Manager"
login="<<USERNAME>>"
+ password_manager="<<PASSWORD_MANAGER>>"
password="<<PASSWORD>>"
/>
More information about the Zope3-Checkins
mailing list