Beispiel #1
0
    def test_lookup_url_malicious(self):

        url = 'http://malware.testing.google.test/testing/malware/'
        info("Requested url - {}".format(url))
        l = lookup_url(url)
        assert_type(l, dict, "Check if proper dict is returned")
        assert_not_empty(l, "Check if response is not empty")
        field = "url"
        expected = url
        assert_dict_contains_key(l, field, "Check if url is in response")
        assert_equal(l[field], expected, "Check if proper url is returned")
        field = "malicious"
        expected = True
        assert_dict_contains_key(l, field, "Check if malicious is in response")
        assert_equal(l[field], expected, "Check if proper status is returned")
Beispiel #2
0
    def test_lookup_url(self):

        url = "google.com"
        info("Requested url - {}".format(url))
        l = lookup_url(url)
        assert_type(l, dict, "Check if proper dict is returned")
        assert_not_empty(l, "Check if response is not empty")
        field = "url"
        expected = url
        assert_dict_contains_key(l, field, "Check if url is in response")
        assert_equal(l[field], expected, "Check if proper url is returned")
        field = "malicious"
        expected = False
        assert_dict_contains_key(l, field, "Check if malicious is in response")
        assert_equal(l[field], expected, "Check if proper status is returned")
Beispiel #3
0
def get_sfbrowsing_details(url_body):
    try:
        jsonschema.validate(url_body, details_url_schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise BadRequest(exc.message)

    try:
        results = safebrowsing.lookup_url(url_body.get('url'))
    except safebrowsing.ApiKeyException as exc:
        log.error(exc)
        raise Unauthorized(exc.message)

    if not results:
        return _no_data_response()

    response_text = {
        "details": results
    }
    return Response(json.dumps(response_text), 200, mimetype="application/json")
def verify_safebrowsing(URL):
    try:
        return lookup_url(URL).get('malicious')
    except SafeBrowsingException:
        return False