示例#1
0
def test_mangle_request_edit_len(req, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = "GET / HTTP/1.1\r\n" "Test-Head: FOOBIE\n" "Content-Length: 4\n\r\n" "BBBBAAAA"
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)

    assert new_req.full_request == ("GET / HTTP/1.1\r\n" "Test-Head: FOOBIE\r\n" "Content-Length: 8\r\n\r\n" "BBBBAAAA")
示例#2
0
def test_mangle_request_drop(req, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = ""
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)

    assert new_req is None
示例#3
0
def test_mangle_request_drop(req, mock_deep_save, mock_tempfile, ignore_edit,
                             ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = ''
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)

    assert new_req is None
示例#4
0
def test_mangle_request_edit(req, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = "GET / HTTP/1.1\r\n" "Content-Length: 4\r\n\r\n" "BBBB"
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)
    assert not mock_deep_save.called
    assert tfile_obj.called
    assert tfile_instance.write.called
    assert tfile_instance.write.call_args == ((r.full_request,),)
    assert new_open.called
    assert fake_file.read.called

    assert new_req.full_request == new_contents
示例#5
0
def test_mangle_request_edit(req, mock_deep_save, mock_tempfile, ignore_edit,
                             ignore_delete):
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = ('GET / HTTP/1.1\r\n' 'Content-Length: 4\r\n\r\n' 'BBBB')
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)
    assert not mock_deep_save.called
    assert tfile_obj.called
    assert tfile_instance.write.called
    assert tfile_instance.write.call_args == ((r.full_request, ), )
    assert new_open.called
    assert fake_file.read.called

    assert new_req.full_request == new_contents
示例#6
0
def test_mangle_request_edit_len(req, mock_deep_save, mock_tempfile,
                                 ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = ('GET / HTTP/1.1\r\n'
                    'Test-Head: FOOBIE\n'
                    'Content-Length: 4\n\r\n'
                    'BBBBAAAA')
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)

    assert new_req.full_request == ('GET / HTTP/1.1\r\n'
                                    'Test-Head: FOOBIE\r\n'
                                    'Content-Length: 8\r\n\r\n'
                                    'BBBBAAAA')
示例#7
0
def test_mangle_request_edit_newlines(req, mock_deep_save, mock_tempfile,
                                      ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req
    new_contents = ('GET / HTTP/1.1\r\n'
                    'Test-Head: FOOBIE\n'
                    'Content-Length: 4\n\r\n'
                    'BBBB')
    fake_file.read.return_value = new_contents
    new_req = yield async_mangle_request(r)

    assert new_req.full_request == ('GET / HTTP/1.1\r\n'
                                    'Test-Head: FOOBIE\r\n'
                                    'Content-Length: 4\r\n\r\n'
                                    'BBBB')
    assert new_req.headers['Test-Head'] == 'FOOBIE'