mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Provide a better error message when deleting nonexistent attributes
If --delattr is used on an attribute that's not present on an entry, and --{set,add}attr isn't being used on that same attribute, say that there's "no such attribute" instead of "<attribute> does not contain <value>". https://fedorahosted.org/freeipa/ticket/2699
This commit is contained in:
parent
1af36da933
commit
51bd68eaf5
@ -906,6 +906,16 @@ last, after all sets and adds."""),
|
||||
)
|
||||
except errors.NotFound:
|
||||
self.obj.handle_not_found(*keys)
|
||||
|
||||
# Provide a nice error message when user tries to delete an
|
||||
# attribute that does not exist on the entry (and user is not
|
||||
# adding it)
|
||||
names = set(n.lower() for n in old_entry)
|
||||
del_nonexisting = delattrs - (names | setattrs | addattrs)
|
||||
if del_nonexisting:
|
||||
raise errors.ValidationError(name=del_nonexisting.pop(),
|
||||
error=_('No such attribute on this entry'))
|
||||
|
||||
for attr in needldapattrs:
|
||||
entry_attrs[attr] = old_entry.get(attr, [])
|
||||
|
||||
|
@ -518,4 +518,37 @@ class test_attr(Declarative):
|
||||
error='must be an integer'),
|
||||
),
|
||||
|
||||
dict(
|
||||
desc='Try deleting bogus attribute',
|
||||
command=('config_mod', [], dict(delattr=u'bogusattribute=xyz')),
|
||||
expected=errors.ValidationError(name='bogusattribute',
|
||||
error='No such attribute on this entry'),
|
||||
),
|
||||
|
||||
dict(
|
||||
desc='Try deleting empty attribute',
|
||||
command=('config_mod', [],
|
||||
dict(delattr=u'ipaCustomFields=See Also,seealso,false')),
|
||||
expected=errors.ValidationError(name='ipacustomfields',
|
||||
error='No such attribute on this entry'),
|
||||
),
|
||||
|
||||
dict(
|
||||
desc='Set and delete one value, plus try deleting a missing one',
|
||||
command=('config_mod', [], dict(
|
||||
delattr=[u'ipaCustomFields=See Also,seealso,false',
|
||||
u'ipaCustomFields=Country,c,false'],
|
||||
addattr=u'ipaCustomFields=See Also,seealso,false')),
|
||||
expected=errors.AttrValueNotFound(attr='ipacustomfields',
|
||||
value='Country,c,false'),
|
||||
),
|
||||
|
||||
dict(
|
||||
desc='Try to delete an operational attribute with --delattr',
|
||||
command=('config_mod', [], dict(
|
||||
delattr=u'creatorsName=cn=directory manager')),
|
||||
expected=errors.DatabaseError(
|
||||
desc='Server is unwilling to perform', info=''),
|
||||
),
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user