예제 #1
0
def test_HttpResponseWorker_addMPOM_3():
    # Should add default processResult module method to internal dict
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    worker.addMPOM(tm, 'GET', '/test/test.html')
    assert worker.methods_paths_options_modules == [[
        'GET', '/test/test.html', {}, tm.processResult
    ]]
예제 #2
0
def test_HttpResponseWorker_addMPOM_4():
    # Should throw error if we try to add the same module method for the same path twice
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    worker.addMPOM(tm, 'GET', '/test/test.html')
    assertRaisesMessage(
        Exception,
        'Module "TestModule" tried to add the same callable "processResult" for the same path "/test/test.html" twice',
        worker.addMPOM, tm, 'GET', '/test/test.html')
예제 #3
0
def test_HttpResponseWorker_addMPOM_5():
    # Should be possible to bind a module callable on a POST method with some additional options
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    worker.addMPOM(tm, 'POST', '/test/test.html', {'user-agent': 'Firefox 10'})
    assert worker.methods_paths_options_modules == [[
        'POST', '/test/test.html', {
            'user-agent': 'Firefox 10'
        }, tm.processResult
    ]]
예제 #4
0
def test_HttpResponseWorker_addMPOM_2():
    # Should throw error if requested method is not recognized
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    assertRaisesMessage(
        Exception,
        'Illegal method "PET" for module "TestModule" and path "/test/test.html"',
        worker.addMPOM, tm, 'PET', '/test/test.html')
예제 #5
0
def main():
    #logger.LOG_LEVELS_FILES['debug.txt'] = [
    #    logger.LOG_INFO,
    #    logger.LOG_WARN,
    #    logger.LOG_ERROR,
    #    logger.LOG_DEBUG,
    #    logger.LOG_SILLY
    #]
    logger.LOG_LEVELS_FILES['error.txt'] = [logger.LOG_ERROR]
    logger.LOG_LEVELS_FILES['warn.txt'] = [logger.LOG_WARN]
    logger.LOG_LEVELS_STDOUT = logger._LOG_ALL

    logger.attach()

    waiters = [
        #RandomIPv4Waiter({'ports': (80,8080)})
        RangeFileWaiter({
            'ports': (80, 8080),
            'file': 'range.txt'
        })
    ]
    workers = [HttpResponseWorker({'timeout': 3})]

    s = Scanner(waiters, workers, 1)
    s.run()
예제 #6
0
def test_HttpResponseWorker_registerModules_1():
    # Should automatically register all mpoms returned from module.registerModules()
    worker = HttpResponseWorker({'timeout': 3, 'modules': [tm]})
    assert worker.methods_paths_options_modules == [[
        'GET', '/', {}, tm.processResult
    ], ['GET', '/test', {
        'user-agent': 'test'
    }, tm.otherProcessResult], ['POST', '/blubb', {}, tm.processResult]]
예제 #7
0
def test_HttpResponseWorker_addMPOM_6():
    # Should be possible to bind an non standard module callable
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    c2 = lambda *kargs: True
    worker.addMPOM(tm, 'GET', '/test/test.html')
    worker.addMPOM(tm, 'GET', '/test/test.html', {}, c2)
    assert worker.methods_paths_options_modules == [[
        'GET', '/test/test.html', {}, tm.processResult, c2
    ]]
예제 #8
0
def test_HttpResponseWorker_addMPOM_7():
    # Should be possible to bind another module callable to the same route but
    # with different options
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    c2 = lambda *kargs: True
    worker.addMPOM(tm, 'GET', '/test/test.html', {}, tm.processResult, c2)
    worker.addMPOM(tm, 'GET', '/test/test.html', {'user-agent': 'Foobar'}, c2)
    assert worker.methods_paths_options_modules == [[
        'GET', '/test/test.html', {}, tm.processResult, c2
    ], ['GET', '/test/test.html', {
        'user-agent': 'Foobar'
    }, c2]]
예제 #9
0
def test_HttpResponseWorker_addMPOM_1():
    worker = HttpResponseWorker({'timeout': 3, 'modules': []})
    assert worker.methods_paths_options_modules == []