예제 #1
0
def test_get_detection_results_with_splash_error(mocker):
    mocker.patch(
        'detectem.cli.get_response',
        side_effect=SplashError('test')
    )

    with pytest.raises(SplashError):
        get_detection_results('http://domain.tld', timeout=30, metadata=True)
예제 #2
0
def test_get_detection_ok(mocker):
    class FakeDetector:
        def __init__(*args):
            pass

        def get_results(**kwargs):
            return [1, 2, 3]

    mocker.patch('detectem.cli.get_response', return_value=1)
    mocker.patch('detectem.cli.Detector', return_value=FakeDetector)

    rs = get_detection_results('http://domain.tld', timeout=30, metadata=True)
    assert rs == [1, 2, 3]
예제 #3
0
def test_get_detection_ok(mocker):
    class FakeDetector:
        def __init__(*args):
            pass

        def get_results(**kwargs):
            return [1, 2, 3]

    mocker.patch("detectem.cli.get_response", return_value=1)
    mocker.patch("detectem.cli.Detector", return_value=FakeDetector)

    rs = get_detection_results("http://domain.tld", timeout=30, metadata=True)
    assert rs == {"url": "http://domain.tld", "softwares": [1, 2, 3]}
예제 #4
0
def do_detection():
    url = request.forms.get('url')
    metadata = request.forms.get('metadata')

    metadata = bool(metadata == '1')

    try:
        result = get_detection_results(url,
                                       timeout=SPLASH_TIMEOUT,
                                       metadata=metadata)
    except (SplashError, NoPluginsError) as e:
        result = {'error': e.msg}

    return json.dumps(result)
예제 #5
0
파일: ws.py 프로젝트: GTrunSec/detectem
def do_detection():
    # Url is mandatory
    url = request.forms.get("url")
    if not url:
        return json.dumps({"error": "You must provide `url` parameter."})

    # metadata is optional
    metadata = request.forms.get("metadata", "0")
    metadata = bool(metadata == "1")

    # timeout is optional
    timeout = request.forms.get("timeout", type=int)
    if not timeout:
        timeout = SPLASH_TIMEOUT

    try:
        result = get_detection_results(url, timeout=timeout, metadata=metadata)
    except (SplashError, NoPluginsError) as e:
        result = {"error": e.msg}

    return json.dumps(result)
예제 #6
0
파일: ws.py 프로젝트: jellex/detectem
def do_detection():
    # Url is mandatory
    url = request.forms.get('url')
    if not url:
        return json.dumps({'error': 'You must provide `url` parameter.'})

    # metadata is optional
    metadata = request.forms.get('metadata', '0')
    metadata = bool(metadata == '1')

    # timeout is optional
    timeout = request.forms.get('timeout', type=int)
    if not timeout:
        timeout = SPLASH_TIMEOUT

    try:
        result = get_detection_results(url, timeout=timeout, metadata=metadata)
    except (SplashError, NoPluginsError) as e:
        result = {'error': e.msg}

    return json.dumps(result)
예제 #7
0
def test_get_detection_results_with_no_plugins(mocker):
    mocker.patch('detectem.cli.load_plugins', return_value=[])

    with pytest.raises(NoPluginsError):
        get_detection_results('http://domain.tld', timeout=30, metadata=True)
예제 #8
0
파일: ws.py 프로젝트: rtobar/detectem
def do_detection():
    url = request.forms.get('url')
    metadata = request.forms.get('metadata')

    metadata = bool(metadata == '1')
    return get_detection_results(url, format='json', metadata=metadata)