예제 #1
0
def test_getting_inaccessible_config_gives_None():
    path = 'my_file'
    f = MockFile(path, to_raise=make_IOError(errno.EACCES))

    res = get_config_contents(path, read_func=f.read_file)

    assert not f.error
    assert res is None
예제 #2
0
def test_getting_empty_config_gives_empty_string():
    path = 'my_file'
    f = MockFile(path, content='')

    res = get_config_contents(path, read_func=f.read_file)

    assert not f.error
    assert res == ''
예제 #3
0
def test_getting_nonexistent_config_gives_None():
    path = 'my_file'
    f = MockFile(path, to_raise=make_IOError(errno.ENOENT))

    res = get_config_contents(path, read_func=f.read_file)

    assert not f.error
    assert res is None
예제 #4
0
def test_getting_nonempty_config_gives_the_content():
    path = 'my_file'
    content = 'foo\nbar\n'
    f = MockFile(path, content=content)

    res = get_config_contents(path, read_func=f.read_file)

    assert not f.error
    assert res == content
예제 #5
0
def _get_parsed_configs(read_func=read_file, listdir=os.listdir):
    res = []
    try:
        for fname in listdir(VSFTPD_CONFIG_DIR):
            path = os.path.join(VSFTPD_CONFIG_DIR, fname)
            if not path.endswith('.conf'):
                continue
            content = get_config_contents(path, read_func=read_func)
            if content is None:
                continue
            parsed = _parse_config(path, content)
            if parsed is not None:
                res.append((path, parsed))
    except OSError as e:
        if e.errno != errno.ENOENT:
            api.current_logger().warning(
                'Failed to read vsftpd configuration directory: %s' % e)
    return res