Esempio n. 1
0
 def test_get_ifcs(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     callback = Mock()
     homestead.get_filter_criteria(PUBLIC_URI, callback)
     self.mock_httpclient.fetch.assert_called_once_with(IFC_URL,
                                                        callback,
                                                        method="GET")
Esempio n. 2
0
 def test_get_ifcs(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     callback = Mock()
     homestead.get_filter_criteria(PUBLIC_URI, callback)
     self.mock_httpclient.fetch.assert_called_once_with(IFC_URL,
                                                        ANY,
                                                        method="GET",
                                                        follow_redirects=False,
                                                        allow_ipv6=True)
Esempio n. 3
0
def display_user(public_id, short=False, quiet=False):
    success = True
    callback = Callback()

    if not short:
        conditional_print(not quiet, "Public User ID %s:" % (public_id))

    homestead.get_associated_privates(public_id, callback)
    response = callback.wait()[0]
    public_id_missing = (response.code == 404)
    if response.code == 200:
        private_ids = json.loads(response.body)
        for private_id in private_ids['private_ids']:
            homestead.get_digest(private_id, callback)
            response = callback.wait()[0]
            if response.code == 200:
                av = json.loads(response.body)
                if 'digest_ha1' in av:
                    password = av['digest_ha1']
                    if 'plaintext_password' in av:
                        password += " (%s)" % (av['plaintext_password'],)
                    if short:
                        conditional_print(not quiet, "%s/%s: %s" % (public_id, private_id, password))
                    else:
                        conditional_print(not quiet, "  Private User ID %s:" % (private_id,))
                        conditional_print(not quiet, "    HA1 digest: %s" % (password,))
            else:
                _log.error("Failed to retrieve digest for private ID %s - HTTP status code %d", private_id, response.code)
                success = False
    else:
        _log.error("Failed to retrieve private IDs for public ID %s - HTTP status code %d", public_id, response.code)
        success = False

    # Default to True so that if we don't check, we may still report that no
    # information was found.
    filter_criteria_missing = True
    if not short:
        homestead.get_filter_criteria(public_id, callback)
        response = callback.wait()[0]
        filter_criteria_missing = (response.code == 404)
        if response.code == 200:
            ifc = xml.dom.minidom.parseString(response.body)
            ifc_str = ifc.toprettyxml(indent="  ")
            ifc_str = "\n".join(filter(lambda l: l.strip() != "", ifc_str.split("\n")))
            ifc_str = "    " + ifc_str.replace("\n", "\n    ")

            conditional_print(not quiet, "  iFC:")
            conditional_print(not quiet, ifc_str)
        else:
            _log.error("Failed to retrieve iFC for public ID %s - HTTP status code %d", public_id, response.code)
            success = False

    if filter_criteria_missing and public_id_missing:
        _log.error("Failed to find any information for public ID %s.", public_id)

    return success
Esempio n. 4
0
def display_user(public_id, short=False, quiet=False):
    success = True
    callback = Callback()

    if not short:
        conditional_print(not quiet, "Public User ID %s:" % (public_id))

    homestead.get_associated_privates(public_id, callback)
    response = callback.wait()[0]
    public_id_missing = (response.code == 404)
    if response.code == 200:
        private_ids = json.loads(response.body)
        for private_id in private_ids['private_ids']:
            homestead.get_digest(private_id, callback)
            response = callback.wait()[0]
            if response.code == 200:
                av = json.loads(response.body)
                if 'digest_ha1' in av:
                    password = av['digest_ha1']
                    if 'plaintext_password' in av:
                        password += " (%s)" % (av['plaintext_password'],)
                    if short:
                        conditional_print(not quiet, "%s/%s: %s" % (public_id, private_id, password))
                    else:
                        conditional_print(not quiet, "  Private User ID %s:" % (private_id,))
                        conditional_print(not quiet, "    HA1 digest: %s" % (password,))
            else:
                _log.error("Failed to retrieve digest for private ID %s - HTTP status code %d", private_id, response.code)
                success = False
    else:
        _log.error("Failed to retrieve private IDs for public ID %s - HTTP status code %d", public_id, response.code)
        success = False

    # Default to True so that if we don't check, we may still report that no
    # information was found.
    filter_criteria_missing = True
    if not short:
        homestead.get_filter_criteria(public_id, callback)
        response = callback.wait()[0]
        filter_criteria_missing = (response.code == 404)
        if response.code == 200:
            ifc = defusedxml.minidom.parseString(response.body)
            ifc_str = ifc.toprettyxml(indent="  ")
            ifc_str = "\n".join(filter(lambda l: l.strip() != "", ifc_str.split("\n")))
            ifc_str = "    " + ifc_str.replace("\n", "\n    ")

            conditional_print(not quiet, "  iFC:")
            conditional_print(not quiet, ifc_str)
        else:
            _log.error("Failed to retrieve iFC for public ID %s - HTTP status code %d", public_id, response.code)
            success = False

    if filter_criteria_missing and public_id_missing:
        _log.error("Failed to find any information for public ID %s.", public_id)

    return success
Esempio n. 5
0
 def test_get_ifcs(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     callback = Mock()
     homestead.get_filter_criteria(PUBLIC_URI, callback)
     self.mock_httpclient.fetch.assert_called_once_with(
         IFC_URL,
         ANY,
         method="GET",
         follow_redirects=False,
         allow_ipv6=True)
Esempio n. 6
0
 def put_ifc_callback(response, sip_uri=sip_uri):
     """
     Handle put response, report errors, issue a final GET to 
     check we succeeded.
     """
     global num_responses, num_requests, errors
     print "%s Put ifc response %s" % (sip_uri, response.code)
     if response.code // 100 != 2:
         print >> sys.stderr, "%s Bad response %s" % (sip_uri, response)
         errors += 1
     homestead.get_filter_criteria(sip_uri, check_callback)
Esempio n. 7
0
def ensure_valid_ifc(sip_uri, **kwargs):
    """
    Check if a line has valid IFC, populate with default if not
    """
    print "Verifying IFC for %s" % sip_uri
    global pending_requests
    pending_requests+=1
    def put_default_ifc():
        print "Adding default IFC for %s" % sip_uri
        stats["Missing IFCs re-created"] += 1
        global pending_requests
        pending_requests+=1
        homestead.put_filter_criteria(sip_uri,
                                      ifcs.generate_ifcs(settings.SIP_DIGEST_REALM),
                                      logging_handler)
    homestead.get_filter_criteria(sip_uri,
                                  create_get_handler(sip_uri, on_not_found=put_default_ifc))
Esempio n. 8
0
def ensure_valid_ifc(sip_uri, **kwargs):
    """
    Check if a line has valid IFC, populate with default if not
    """
    print "Verifying IFC for %s" % sip_uri
    global pending_requests
    pending_requests += 1

    def put_default_ifc():
        print "Adding default IFC for %s" % sip_uri
        stats["Missing IFCs re-created"] += 1
        global pending_requests
        pending_requests += 1
        homestead.put_filter_criteria(
            sip_uri, ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)),
            logging_handler)

    homestead.get_filter_criteria(
        sip_uri, create_get_handler(sip_uri, on_not_found=put_default_ifc))
Esempio n. 9
0
def standalone():
    global num_responses, num_requests

    db_sess = connection.Session()
    c = db_sess.execute("SELECT number FROM numbers where OWNER_ID is not NULL;")

    def inc_resp_count():
        global num_responses, num_requests
        num_responses += 1
        print "%s responses outstanding" % (num_requests - num_responses)
        if num_responses == num_requests:
            print "Last response"
            print "There were %d errors" % errors
            io_loop.stop()

    for (sip_uri,) in c:
        print "%s Sending request" % (sip_uri,)

        def get_ifc_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 ifc response %s" % (sip_uri, response.code)
            if response.code == 404:
                print "%s ifc needs to be repopulated" % (sip_uri,)
                homestead.put_filter_criteria(sip_uri, ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)), put_ifc_callback)
            else:
                inc_resp_count()

        def put_ifc_callback(response, sip_uri=sip_uri):
            """
            Handle put response, report errors, issue a final GET to 
            check we succeeded.
            """
            global num_responses, num_requests, errors
            print "%s Put ifc response %s" % (sip_uri, response.code)
            if response.code // 100 != 2:
                print >> sys.stderr, "%s Bad response %s" % (sip_uri, response)
                errors += 1
            homestead.get_filter_criteria(sip_uri, check_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 post_digest_callback(response, sip_uri=sip_uri):
            """
            Handle post response, report errors, issue a final GET to 
            check we succeeded.
            """
            global num_responses, num_requests, errors
            print "%s Post digest response %s" % (sip_uri, response.code)
            if response.code // 100 != 2:
                print >> sys.stderr, "%s Bad response %s" % (sip_uri, response)
                errors += 1
            homestead.get_digest(sip_uri, check_callback)

        def check_callback(response, sip_uri=sip_uri):
            """
            Handle response to the check request, reports errors.
            """
            global num_responses, num_requests, errors
            print "%s Check response %s" % (sip_uri, response.code)
            if response.code != 200:
                print >> sys.stderr, "%s Bad response %s" % (sip_uri, response)
                errors += 1
            inc_resp_count()

        num_requests += 2
        homestead.get_digest(sip_uri, get_digest_callback)
        homestead.get_filter_criteria(sip_uri, get_ifc_callback)
    print "Finished queuing requests."