def update_user(private_id, public_id, domain, password, ifc, plaintext=False): callback = Callback() if password: homestead.put_password(private_id, domain, password, callback, plaintext=plaintext) response = callback.wait()[0] if isinstance(response, HTTPError): _log.error( "Failed to update password for private ID %s - HTTP status code %d", private_id, response.code) return False if ifc: homestead.put_filter_criteria(public_id, ifc, callback) response = callback.wait()[0] if isinstance(response, HTTPError): _log.error("Failed to update public ID %s - HTTP status code %d", public_id, response.code) return False return True
def on_get_privates_success(self, responses): _log.debug("Got related private ids") # Body is of format {"public_id": "<public_id>", # "private_ids": ["<private_id_1>", "<private_id_2>"...]} parsed_body = json.loads(responses[0].body) # We only support one private id per public id, so only pull out first in list private_id = parsed_body["private_ids"][0] # Do not expect a response body, as long as there is no error, we are fine self._request_group = HTTPCallbackGroup(self.on_put_password_success, self.on_put_password_failure) homestead.put_password(private_id, self.sip_digest_realm, self.sip_password, self._request_group.callback())
def get_digest_callback(response, sip_uri=sip_uri): """ Handle response to initial GET, only PUT new data if there wasn't anything there. """ global num_responses, num_requests print "%s Get digest response %s" % (sip_uri, response.code) if response.code == 404: print "%s digest needs to be repopulated" % (sip_uri,) homestead.put_password(sip_uri, sip_uri, utils.generate_sip_password(), post_digest_callback) else: inc_resp_count()
def test_put_password_plaintext(self, settings, AsyncHTTPClient): self.standard_setup(settings, AsyncHTTPClient) body = json.dumps({"plaintext_password": "******", "realm": "realm"}) callback = Mock() homestead.put_password(PRIVATE_URI, "realm", "pw", callback, plaintext=True) self.mock_httpclient.fetch.assert_called_once_with( 'http://homestead/private/pri%40foo.bar', ANY, method='PUT', body=body, headers={'Content-Type': 'application/json'}, follow_redirects=False, allow_ipv6=True)
def test_put_password_mainline(self, settings, md5, AsyncHTTPClient): self.standard_setup(settings, AsyncHTTPClient) md5.return_value = "md5_hash" body = json.dumps({"digest" : "md5_hash"}) callback = Mock() homestead.put_password(PRIVATE_URI, "pw", callback) md5.assert_called_once_with("[email protected]:%s:pw" % settings.SIP_DIGEST_REALM) self.mock_httpclient.fetch.assert_called_once_with( 'http://homestead/privatecredentials/pri%40foo.bar/digest', callback, method='PUT', body=body, headers={'Content-Type': 'application/json'})
def on_get_privates_success(self, responses): _log.debug("Got related private ids") # Body is of format {"public_id": "<public_id>", # "private_ids": ["<private_id_1>", "<private_id_2>"...]} parsed_body = json.loads(responses[0].body) # We only support one private id per public id, so only pull out first in list private_id = parsed_body["private_ids"][0] # Do not expect a response body, as long as there is no error, we are fine self._request_group = HTTPCallbackGroup(self.on_put_password_success, self.on_put_password_failure) homestead.put_password(private_id, self.sip_digest_realm, self.sip_password, self._request_group.callback())
def test_put_password_mainline(self, settings, md5, AsyncHTTPClient): self.standard_setup(settings, AsyncHTTPClient) md5.return_value = "md5_hash" body = json.dumps({"digest_ha1": "md5_hash", "realm": "realm"}) callback = Mock() homestead.put_password(PRIVATE_URI, "realm", "pw", callback) md5.assert_called_once_with("[email protected]:realm:pw") self.mock_httpclient.fetch.assert_called_once_with( 'http://homestead/private/pri%40foo.bar', callback, method='PUT', body=body, headers={'Content-Type': 'application/json'}, follow_redirects=False, allow_ipv6=True)
def test_put_password_mainline(self, settings, md5, AsyncHTTPClient): self.standard_setup(settings, AsyncHTTPClient) md5.return_value = "md5_hash" body = json.dumps({"digest_ha1": "md5_hash", "realm": "realm"}) callback = Mock() homestead.put_password(PRIVATE_URI, "realm", "pw", callback) md5.assert_called_once_with("[email protected]:realm:pw") self.mock_httpclient.fetch.assert_called_once_with( 'http://homestead/private/pri%40foo.bar', ANY, method='PUT', body=body, headers={'Content-Type': 'application/json'}, follow_redirects=False, allow_ipv6=True)
def test_put_password_plaintext(self, settings, AsyncHTTPClient): self.standard_setup(settings, AsyncHTTPClient) body = json.dumps({"plaintext_password": "******", "realm": "realm"}) callback = Mock() homestead.put_password(PRIVATE_URI, "realm", "pw", callback, plaintext=True) self.mock_httpclient.fetch.assert_called_once_with( 'http://homestead/private/pri%40foo.bar', ANY, method='PUT', body=body, headers={'Content-Type': 'application/json'}, follow_redirects=False, allow_ipv6=True)
def update_user(private_id, public_id, domain, password, ifc, plaintext=False): callback = Callback() if password: homestead.put_password(private_id, domain, password, callback, plaintext=plaintext) response = callback.wait()[0] if isinstance(response, HTTPError): _log.error("Failed to update password for private ID %s - HTTP status code %d", private_id, response.code) return False if ifc: homestead.put_filter_criteria(public_id, ifc, callback) response = callback.wait()[0] if isinstance(response, HTTPError): _log.error("Failed to update public ID %s - HTTP status code %d", public_id, response.code) return False return True