Esempio n. 1
0
def test_get_response_with_error_status_codes(monkeypatch):
    class TestResponse():
        status_code = 504

        def json(self):
            return {'description': 'error 100'}

    monkeypatch.setattr(requests, 'get', lambda v: TestResponse())
    monkeypatch.setattr(requests, 'post', lambda v: v)
    monkeypatch.setattr(detectem.utils, 'SETUP_SPLASH', False)

    with pytest.raises(SplashError):
        get_response('http://domain.tld', PluginCollection())
Esempio n. 2
0
def test_get_response_with_error_status_codes(monkeypatch):
    class TestResponse:
        status_code = 504

        def json(self):
            return {"description": "error 100"}

    monkeypatch.setattr(requests, "get", lambda v: TestResponse())
    monkeypatch.setattr(requests, "post", lambda v: v)
    monkeypatch.setattr(detectem.utils, "SETUP_SPLASH", False)

    with pytest.raises(SplashError):
        get_response("http://domain.tld", PluginCollection())
Esempio n. 3
0
def test_create_lua_script():
    class BlaPlugin():
        name = 'bla'
        js_matchers = [{'check': 'bla', 'version': 'bla.version'}]

    plugins = PluginCollection()
    plugins.add(BlaPlugin())

    script = create_lua_script(plugins)
    assert script

    js_data = json.dumps(BlaPlugin.js_matchers)
    assert js_data in script
Esempio n. 4
0
def test_create_lua_script():
    class BlaPlugin(Plugin):
        name = 'bla'
        matchers = [{'dom': ('bla', 'bla.version')}]

    plugins = PluginCollection()
    plugins.add(BlaPlugin())

    script = create_lua_script(plugins)
    assert script

    assert '"name": "bla"' in script
    assert '"check_statement": "bla"' in script
    assert '"version_statement": "bla.version"' in script
Esempio n. 5
0
def test_get_response(monkeypatch):
    class TestResponse():
        status_code = 200

        def json(self):
            return {'har': {}, 'softwares': [], 'scripts': {}}

    monkeypatch.setattr(requests, 'get', lambda v: TestResponse())
    monkeypatch.setattr(requests, 'post', lambda v: v)
    monkeypatch.setattr(detectem.utils, 'SETUP_SPLASH', False)

    response = get_response('http://domain.tld', PluginCollection())
    assert response
    assert 'har' in response
    assert 'softwares' in response
Esempio n. 6
0
def test_get_response(monkeypatch):
    class TestResponse:
        status_code = 200

        def json(self):
            return {"har": {}, "softwares": [], "scripts": {}}

    monkeypatch.setattr(requests, "get", lambda v: TestResponse())
    monkeypatch.setattr(requests, "post", lambda v: v)
    monkeypatch.setattr(detectem.utils, "SETUP_SPLASH", False)

    response = get_response("http://domain.tld", PluginCollection())
    assert response
    assert "har" in response
    assert "softwares" in response
Esempio n. 7
0
 def _create_detector(self, har, plugins):
     pc = PluginCollection()
     for p in plugins:
         pc.add(p)
     return Detector({"har": har, "softwares": []}, pc, self.URL)