Skip to content

Commit

Permalink
revert "fixed delete_old_dn in mock connections"
Browse files Browse the repository at this point in the history
  • Loading branch information
cannatag committed Jul 8, 2020
1 parent 62e65f5 commit b611441
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions ldap3/strategy/mockBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ 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 @@ -445,18 +439,16 @@ 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]
_replace_rdn_values(request, new_dn, moved_entry)
del self.connection.server.dit[dn]
if delete_old_rdn:
del self.connection.server.dit[dn]
result_code = RESULT_SUCCESS
message = 'entry moved'
moved_entry['entryDN'] = [to_raw(new_dn)]
Expand All @@ -467,10 +459,9 @@ 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])]
_replace_rdn_values(request, new_dn, renamed_entry)
del self.connection.server.dit[dn]
for rdn in safe_rdn(new_dn, decompose=True): # adds rdns to entry attributes
renamed_entry[rdn[0]] = [to_raw(rdn[1])]

result_code = RESULT_SUCCESS
message = 'entry rdn renamed'
else:
Expand Down Expand Up @@ -698,9 +689,6 @@ def _execute_search(self, request):
})
if '+' not in attributes: # remove operational attributes
for op_attr in self.operational_attributes:
if op_attr.lower() in attributes:
# if the op_attr was explicitly requested, then keep it
continue
for i, attr in enumerate(responses[len(responses)-1]['attributes']):
if attr['type'] == op_attr:
del responses[len(responses)-1]['attributes'][i]
Expand Down

0 comments on commit b611441

Please sign in to comment.