mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
Change Password param so (password, confirm_password) can be passed to _convert_scalar()
This commit is contained in:
parent
a3a0c0ae33
commit
b35849b47d
@ -736,6 +736,15 @@ class NoSuchNamespaceError(InvocationError):
|
|||||||
format = _('api has no such namespace: %(name)r')
|
format = _('api has no such namespace: %(name)r')
|
||||||
|
|
||||||
|
|
||||||
|
class PasswordMismatch(InvocationError):
|
||||||
|
"""
|
||||||
|
**3011** Raise when password and password confirmation don't match.
|
||||||
|
"""
|
||||||
|
|
||||||
|
errno = 3011
|
||||||
|
format = _('Passwords do not match')
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 4000 - 4999: Execution errors
|
# 4000 - 4999: Execution errors
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ from util import make_repr
|
|||||||
from request import ugettext
|
from request import ugettext
|
||||||
from plugable import ReadOnly, lock, check_name
|
from plugable import ReadOnly, lock, check_name
|
||||||
from errors import ConversionError, RequirementError, ValidationError
|
from errors import ConversionError, RequirementError, ValidationError
|
||||||
|
from errors import PasswordMismatch
|
||||||
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
|
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
@ -1145,6 +1146,14 @@ class Password(Str):
|
|||||||
A parameter for passwords (stored in the ``unicode`` type).
|
A parameter for passwords (stored in the ``unicode`` type).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def _convert_scalar(self, value, index=None):
|
||||||
|
if isinstance(value, (tuple, list)) and len(value) == 2:
|
||||||
|
(p1, p2) = value
|
||||||
|
if p1 != p2:
|
||||||
|
raise PasswordMismatch(name=self.name, index=index)
|
||||||
|
value = p1
|
||||||
|
return super(Password, self)._convert_scalar(value, index)
|
||||||
|
|
||||||
|
|
||||||
class Enum(Param):
|
class Enum(Param):
|
||||||
"""
|
"""
|
||||||
|
@ -1065,6 +1065,17 @@ class test_Password(ClassChecker):
|
|||||||
assert o.pattern is None
|
assert o.pattern is None
|
||||||
assert o.password is True
|
assert o.password is True
|
||||||
|
|
||||||
|
def test_convert_scalar(self):
|
||||||
|
"""
|
||||||
|
Test the `ipalib.parameters.Password._convert_scalar` method.
|
||||||
|
"""
|
||||||
|
o = self.cls('my_password')
|
||||||
|
e = raises(errors.PasswordMismatch, o._convert_scalar, [u'one', u'two'])
|
||||||
|
assert e.name == 'my_password'
|
||||||
|
assert e.index is None
|
||||||
|
assert o._convert_scalar([u'one', u'one']) == u'one'
|
||||||
|
assert o._convert_scalar(u'one') == u'one'
|
||||||
|
|
||||||
|
|
||||||
class test_StrEnum(ClassChecker):
|
class test_StrEnum(ClassChecker):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user