コード例 #1
0
def test_escape_root(tmp_path):
    td = str(tmp_path)
    cm = FileContentsManager(root_dir=td)
    # make foo, bar next to root
    with open(os.path.join(cm.root_dir, '..', 'foo'), 'w') as f:
        f.write('foo')
    with open(os.path.join(cm.root_dir, '..', 'bar'), 'w') as f:
        f.write('bar')

    with pytest.raises(HTTPError) as e:
        cm.get('..')
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.get('foo/../../../bar')
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.delete('../foo')
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.rename('../foo', '../bar')
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.save(model={
            'type': 'file',
            'content': u'',
            'format': 'text',
        },
                path='../foo')
    expected_http_error(e, 404)
コード例 #2
0
def test_escape_root(tmp_path):
    td = str(tmp_path)
    cm = FileContentsManager(root_dir=td)
    # make foo, bar next to root
    with open(os.path.join(cm.root_dir, "..", "foo"), "w") as f:
        f.write("foo")
    with open(os.path.join(cm.root_dir, "..", "bar"), "w") as f:
        f.write("bar")

    with pytest.raises(HTTPError) as e:
        cm.get("..")
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.get("foo/../../../bar")
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.delete("../foo")
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.rename("../foo", "../bar")
    expected_http_error(e, 404)

    with pytest.raises(HTTPError) as e:
        cm.save(model={
            "type": "file",
            "content": u"",
            "format": "text",
        },
                path="../foo")
    expected_http_error(e, 404)
コード例 #3
0
def test_good_symlink(tmp_path):
    td = str(tmp_path)
    cm = FileContentsManager(root_dir=td)
    parent = 'test good symlink'
    name = 'good symlink'
    path = '{0}/{1}'.format(parent, name)
    _make_dir(cm, parent)

    file_model = cm.new(path=parent + '/zfoo.txt')

    # create a good symlink
    symlink(cm, file_model['path'], path)
    symlink_model = cm.get(path, content=False)
    dir_model = cm.get(parent)
    assert sorted(dir_model['content'],
                  key=lambda x: x['name']) == [symlink_model, file_model]
コード例 #4
0
def test_good_symlink(tmp_path):
    td = str(tmp_path)
    cm = FileContentsManager(root_dir=td)
    parent = "test good symlink"
    name = "good symlink"
    path = "{0}/{1}".format(parent, name)
    _make_dir(cm, parent)

    file_model = cm.new(path=parent + "/zfoo.txt")

    # create a good symlink
    symlink(cm, file_model["path"], path)
    symlink_model = cm.get(path, content=False)
    dir_model = cm.get(parent)
    assert sorted(dir_model["content"], key=lambda x: x["name"]) == [
        symlink_model,
        file_model,
    ]
コード例 #5
0
def test_bad_symlink(tmp_path):
    td = str(tmp_path)

    cm = FileContentsManager(root_dir=td)
    path = 'test bad symlink'
    _make_dir(cm, path)

    file_model = cm.new_untitled(path=path, ext='.txt')

    # create a broken symlink
    symlink(cm, "target", '%s/%s' % (path, 'bad symlink'))
    model = cm.get(path)

    contents = {content['name']: content for content in model['content']}
    assert 'untitled.txt' in contents
    assert contents['untitled.txt'] == file_model
    assert 'bad symlink' in contents
コード例 #6
0
def test_bad_symlink(tmp_path):
    td = str(tmp_path)

    cm = FileContentsManager(root_dir=td)
    path = "test bad symlink"
    _make_dir(cm, path)

    file_model = cm.new_untitled(path=path, ext=".txt")

    # create a broken symlink
    symlink(cm, "target", "%s/%s" % (path, "bad symlink"))
    model = cm.get(path)

    contents = {content["name"]: content for content in model["content"]}
    assert "untitled.txt" in contents
    assert contents["untitled.txt"] == file_model
    assert "bad symlink" in contents