def test_gen_password(self, getpass): """ Generate a password """ pwd_context = get_pwd_context() passwds = ['foo', 'foo', 'bar', 'baz'] getpass.getpass.side_effect = passwds.pop ret = scripts._gen_password() self.assertEqual(len(passwds), 0) self.assertTrue(pwd_context.verify('foo', ret))
def _gen_password(scheme=None, rounds=None): """ Prompt user for a password twice for safety """ pwd_context = get_pwd_context(scheme, rounds) while True: password = getpass.getpass() verify = getpass.getpass() if password == verify: return pwd_context.hash(password) else: print("Passwords do not match!")
def _gen_password(rounds=DEFAULT_ROUNDS): """ Prompt user for a password twice for safety """ pwd_context = get_pwd_context(rounds) while True: password = getpass.getpass() verify = getpass.getpass() if password == verify: return pwd_context.hash(password) else: six.print_("Passwords do not match!")
def test_abstract_methods(self): """ Abstract methods raise NotImplementedError """ access = IMutableAccessBackend(None, pwd_context=get_pwd_context()) with self.assertRaises(NotImplementedError): access.verify_user('a', 'b') with self.assertRaises(NotImplementedError): access.groups() with self.assertRaises(NotImplementedError): access.group_members('a') with self.assertRaises(NotImplementedError): access.is_admin('a') with self.assertRaises(NotImplementedError): access.group_permissions('a') with self.assertRaises(NotImplementedError): access.user_permissions('a') with self.assertRaises(NotImplementedError): access.user_package_permissions('a') with self.assertRaises(NotImplementedError): access.group_package_permissions('a') with self.assertRaises(NotImplementedError): access.user_data() with self.assertRaises(NotImplementedError): access.allow_register() with self.assertRaises(NotImplementedError): access.set_allow_register(True) with self.assertRaises(NotImplementedError): access.register('a', 'b') with self.assertRaises(NotImplementedError): access.pending_users() with self.assertRaises(NotImplementedError): access.approve_user('a') with self.assertRaises(NotImplementedError): access.edit_user_password('a', 'b') with self.assertRaises(NotImplementedError): access.delete_user('a') with self.assertRaises(NotImplementedError): access.set_user_admin('a', True) with self.assertRaises(NotImplementedError): access.edit_user_group('a', 'a', 'add') with self.assertRaises(NotImplementedError): access.create_group('a') with self.assertRaises(NotImplementedError): access.delete_group('a') with self.assertRaises(NotImplementedError): access.edit_user_permission('a', 'b', 'c', True) with self.assertRaises(NotImplementedError): access.edit_group_permission('a', 'b', 'c', True)
def _gen_password(password: str, scheme: str = None, rounds: int = None) -> str: pwd_context = get_pwd_context(scheme, rounds) return pwd_context.hash(password)
from pyramid.authorization import ACLAuthorizationPolicy from pyramid.security import Everyone, Authenticated from pyramid.testing import DummyRequest from sqlalchemy.exc import OperationalError from pypicloud.access import (IAccessBackend, IMutableAccessBackend, ConfigAccessBackend, RemoteAccessBackend, includeme, get_pwd_context) from pypicloud.access.base import group_to_principal from pypicloud.access.ldap_ import LDAPAccessBackend from pypicloud.access.sql import (SQLAccessBackend, User, UserPermission, association_table, GroupPermission, Group, Base) from pypicloud.route import Root pwd_context = get_pwd_context(1000) # pylint: disable=C0103 class PartialEq(object): """ Helper object to compare equality against functools.partial objects """ def __init__(self, obj): self.obj = obj def __eq__(self, other): return self.obj == other.func def __ne__(self, other): return not self.__eq__(other) def __repr__(self): return "partial(%s)" % self.obj