示例#1
0
def test_local_opens():
    def change(env):
        res_ok(env)
        eq_('13', open(tempcwd('somefile')).read().strip())
        ok_(os.path.exists(tempcwd('./not_existing')))

    def nochange(env):
        res_re(1)(env)
        eq_('42', open(tempcwd('somefile')).read().strip())
        ok_(not os.path.exists(tempcwd('./not_existing')))

    # Test that this is in fact unsafe
    yield _test_exec, '/openrw.c', DetailedUnprotectedExecutor(), change, {}

    if ENABLE_SANDBOXES:
        yield _test_exec, '/open.c', SupervisedExecutor(), \
                res_rv('opening files'), {}
        yield _test_exec, '/openrw.c', SupervisedExecutor(), \
                res_rv('opening files'), {}
        yield _test_exec, '/open.c', \
                SupervisedExecutor(allow_local_open=True), res_ok, {}
        yield _test_exec, '/openrw.c', \
                SupervisedExecutor(allow_local_open=True), nochange, {}
        yield _test_exec, '/open2.c', \
                SupervisedExecutor(allow_local_open=True), res_re(1), {}
示例#2
0
文件: inwer.py 项目: xneby/sioworkers
def _run_inwer(environ, use_sandboxes=False):
    command = [tempcwd('inwer')]
    if use_sandboxes:
        executor = SupervisedExecutor()
    else:
        executor = DetailedUnprotectedExecutor()
    return _run_in_executor(environ, command, executor, ignore_errors=True)
示例#3
0
def test_uploading_out():
    with TemporaryCwd():
        upload_files()
        renv = compile_and_run('/add_print.c', {
            'in_file': '/input',
            'out_file': '/output',
            'upload_out': True,
        }, DetailedUnprotectedExecutor())
        print_env(renv)

        ft.download({'path': '/output'}, 'path', 'd_out')
        in_('84', open(tempcwd('d_out')).read())
示例#4
0
def test_zip():
    with TemporaryCwd():
        upload_files()
        compile_and_run(
            "/echo.c", {
                'in_file': '/input.zip',
                'out_file': '/output',
                'exec_mem_limit': 102400
            }, DetailedUnprotectedExecutor())
        ft.download({'in_file': '/input'}, 'in_file', 'out.expected')
        ft.download({'out_file': '/output'}, 'out_file', 'out.real')
        ok_(filecmp.cmp(tempcwd('out.expected'), tempcwd('out.real')))
示例#5
0
def test_truncating_output():
    with TemporaryCwd():
        upload_files()
        checker_bin = compile('/chk-output-too-long.c',
                '/chk-output-too-long.e')['out_file']
    with TemporaryCwd():
        renv = compile_and_run('/output-too-long.c', {
                'in_file': '/input',
                'check_output': True,
                'hint_file': '/input',
                'chk_file': checker_bin,
                }, DetailedUnprotectedExecutor(), use_sandboxes=False)
        length = len(renv['result_string'])
        if length > RESULT_STRING_LENGTH_LIMIT:
            raise AssertionError("result_string too long, %d > %d"
                    % (length, RESULT_STRING_LENGTH_LIMIT))
示例#6
0
 def _test():
     with TemporaryCwd():
         upload_files()
         checker_bin = compile(checker, '/chk.e')['out_file']
     with TemporaryCwd():
         executor = SupervisedExecutor(use_program_return_code=True) if \
                 sandboxed else DetailedUnprotectedExecutor()
         renv = compile_and_run('/add_print.c', {
                 'in_file': '/input',
                 'check_output': True,
                 'hint_file': '/hint',
                 'chk_file': checker_bin,
                 'untrusted_checker': True,
         }, executor, use_sandboxes=sandboxed)
         print_env(renv)
         if callback:
             callback(renv)
示例#7
0
def run(environ):
    return common.run(environ,
                      DetailedUnprotectedExecutor(),
                      use_sandboxes=False)