-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve the deferred returned by send_multiResponse and send_multiRes… #239
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,10 +109,11 @@ def send_multiResponse(self, op, handler, *args, **kwargs): | |
|
||
If `handler` is provided, it will receive a LDAP response as | ||
its first argument. The Deferred returned by this function will | ||
never fire. | ||
fire with a result of `None` when the handler returns True to indicate | ||
the final response has been handled. | ||
|
||
If `handler` is not provided, the Deferred returned by this | ||
function will fire with the final LDAP response. | ||
function will fire with the first LDAP response. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was wrong, as is evidenced by the updated |
||
|
||
@param op: the operation to send | ||
@type op: LDAPProtocolRequest | ||
|
@@ -137,9 +138,10 @@ def send_multiResponse_ex(self, op, controls=None, handler=None, *args, **kwargs | |
Send an LDAP operation to the server, expecting one or more | ||
responses. | ||
|
||
If `handler` is provided, it will receive a LDAP response *and* | ||
If `handler` is provided, it will receive an LDAP response *and* | ||
response controls as its first 2 arguments. The Deferred returned | ||
by this function will never fire. | ||
by this function will fire with a result of `None` when the handler | ||
returns True to indicate the final response has been handled. | ||
|
||
If `handler` is not provided, the Deferred returned by this | ||
function will fire with a tuple of the first LDAP response | ||
|
@@ -204,9 +206,11 @@ def handle(self, msg): | |
# Return true to mark request as fully handled | ||
if return_controls: | ||
if handler(msg.value, msg.controls, *args, **kwargs): | ||
d.callback(None) | ||
del self.onwire[msg.id] | ||
else: | ||
if handler(msg.value, *args, **kwargs): | ||
d.callback(None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The functional changes are these two |
||
del self.onwire[msg.id] | ||
|
||
def bind(self, dn="", auth=""): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,7 +192,7 @@ def collect_result_(result): | |
return True | ||
return False | ||
|
||
client.send_multiResponse(op, collect_result_) | ||
d = client.send_multiResponse(op, collect_result_) | ||
expected_value = pureldap.LDAPMessage(op) | ||
expected_value.id -= 1 | ||
expected_bytestring = expected_value.toWire() | ||
|
@@ -203,12 +203,16 @@ def collect_result_(result): | |
) | ||
resp_bytestring = response.toWire() | ||
client.dataReceived(resp_bytestring) | ||
self.assertEqual(response.value, results[0]) | ||
self.assertFalse(d.called) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making sure the deferred is not fired until the multi-response handler returns |
||
|
||
response = pureldap.LDAPMessage( | ||
pureldap.LDAPSearchResultDone(0), id=expected_value.id | ||
) | ||
resp_bytestring = response.toWire() | ||
client.dataReceived(resp_bytestring) | ||
self.assertEqual(response.value, results[1]) | ||
self.assertIsNone(self.successResultOf(d)) | ||
|
||
def test_send_multiResponse_ex(self): | ||
client, transport = self.create_test_client() | ||
|
@@ -229,6 +233,45 @@ def test_send_multiResponse_ex(self): | |
client.dataReceived(resp_bytestring) | ||
self.assertEqual((response.value, response.controls), self.successResultOf(d)) | ||
|
||
def test_send_multiResponse_ex_with_handler(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was no test covering |
||
client, transport = self.create_test_client() | ||
op = self.create_test_search_req() | ||
results = [] | ||
|
||
def collect_result_(result, controls): | ||
results.append((result, controls)) | ||
if isinstance(result, pureldap.LDAPSearchResultDone): | ||
return True | ||
return False | ||
|
||
controls = self.create_paged_search_controls() | ||
d = client.send_multiResponse_ex(op, controls, handler=collect_result_) | ||
expected_value = pureldap.LDAPMessage(op, controls) | ||
expected_value.id -= 1 | ||
expected_bytestring = expected_value.toWire() | ||
self.assertEqual(transport.value(), expected_bytestring) | ||
resp_controls = self.create_paged_search_controls(0, "magic1") | ||
response = pureldap.LDAPMessage( | ||
pureldap.LDAPSearchResultEntry("cn=foo,ou=baz,dc=example,dc=net", {}), | ||
id=expected_value.id, | ||
controls=resp_controls, | ||
) | ||
resp_bytestring = response.toWire() | ||
client.dataReceived(resp_bytestring) | ||
self.assertEqual(results[0], (response.value, resp_controls)) | ||
self.assertFalse(d.called) | ||
|
||
resp_controls = self.create_paged_search_controls(0, "magic2") | ||
response = pureldap.LDAPMessage( | ||
pureldap.LDAPSearchResultDone(0), | ||
id=expected_value.id, | ||
controls=resp_controls, | ||
) | ||
resp_bytestring = response.toWire() | ||
client.dataReceived(resp_bytestring) | ||
self.assertEqual(results[1], (response.value, resp_controls)) | ||
self.assertIsNone(self.successResultOf(d)) | ||
|
||
def test_send_noResponse(self): | ||
client, transport = self.create_test_client() | ||
op = pureldap.LDAPAbandonRequest(id=1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to suggestions on better wording here. I wasn't sure how to say this differently without getting too technical for release notes.