Skip to content

Commit

Permalink
fixed delete_old_dn in mock connections
Browse files Browse the repository at this point in the history
  • Loading branch information
cannatag committed Jul 6, 2020
1 parent efa700a commit 62e65f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions _changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- added iso_format parameter to utils.format_json to return dates in ISO format (thanks Hugh)
- fixed issue with Referral attributes not returned by the referral server (thanks Nazarii)
- fixed lost error message in auto_bind (thanks cfelder)
- fixed delete_old_dn in mock connections (thanks kpinc)

# 2.7 - 2020.03.01
- tested against Python 3.8.1 and pyasn1 0.4.8
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/source/modifydn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ In the ldap3 library the signature for the Delete operation is::

* relative_dn: new relative dn of the entry

* delete_old_dn: remove the previous dn (defaults to True)
* delete_old_dn: delete_old_dn: alter the entry so that those attributes appearing in the new dn are given values to match the values of the new dn's components (defaults to True)

* new_superior: the new container of the entry

Expand Down
21 changes: 15 additions & 6 deletions ldap3/strategy/mockBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def random_cookie():
return to_raw(SystemRandom().random())[-6:]


def _replace_rdn_values(request, new_dn, entry):
if bool(request['deleteOldRdn']):
for rdn in safe_rdn(new_dn, decompose=True):
entry[rdn[0]] = [to_raw(rdn[1])]


class PagedSearchSet(object):
def __init__(self, response, size, criticality):
self.size = size
Expand Down Expand Up @@ -439,16 +445,18 @@ def mock_modify_dn(self, request_message, controls):
request = modify_dn_request_to_dict(request_message)
dn = safe_dn(request['entry'])
new_rdn = request['newRdn']
delete_old_rdn = request['deleteOldRdn']
# delete_old_rdn = request['deleteOldRdn']
new_superior = safe_dn(request['newSuperior']) if request['newSuperior'] else ''
dn_components = to_dn(dn)
if dn in self.connection.server.dit:
if new_superior and new_rdn: # performs move in the DIT
new_dn = safe_dn(dn_components[0] + ',' + new_superior)
self.connection.server.dit[new_dn] = self.connection.server.dit[dn].copy()
moved_entry = self.connection.server.dit[new_dn]
if delete_old_rdn:
del self.connection.server.dit[dn]
# if delete_old_rdn:
# del self.connection.server.dit[dn]
_replace_rdn_values(request, new_dn, moved_entry)
del self.connection.server.dit[dn]
result_code = RESULT_SUCCESS
message = 'entry moved'
moved_entry['entryDN'] = [to_raw(new_dn)]
Expand All @@ -459,9 +467,10 @@ def mock_modify_dn(self, request_message, controls):
del self.connection.server.dit[dn]
renamed_entry['entryDN'] = [to_raw(new_dn)]

for rdn in safe_rdn(new_dn, decompose=True): # adds rdns to entry attributes
renamed_entry[rdn[0]] = [to_raw(rdn[1])]

# for rdn in safe_rdn(new_dn, decompose=True): # adds rdns to entry attributes
# renamed_entry[rdn[0]] = [to_raw(rdn[1])]
_replace_rdn_values(request, new_dn, renamed_entry)
del self.connection.server.dit[dn]
result_code = RESULT_SUCCESS
message = 'entry rdn renamed'
else:
Expand Down

0 comments on commit 62e65f5

Please sign in to comment.