def test_get_vsftpd_facts_inaccessible_dir():
    listdir = MockListDir(to_raise=make_OSError(errno.EACCES))
    fileops = MockFileOperations()

    facts = library.get_vsftpd_facts(read_func=fileops.read,
                                     listdir=listdir.listdir)

    assert facts.default_config_hash is None
    assert len(facts.configs) == 0
def test_get_vsftpd_facts_empty_dir():
    listdir = MockListDir('/etc/vsftpd', [])
    fileops = MockFileOperations()

    facts = library.get_vsftpd_facts(read_func=fileops.read,
                                     listdir=listdir.listdir)

    assert facts.default_config_hash is None
    assert len(facts.configs) == 0
Exemple #3
0
def test_get_vsftpd_facts_nonexistent_dir():
    listdir = MockListDir(to_raise=make_OSError(errno.ENOENT))
    fileops = MockFileOperations()

    facts = library.get_vsftpd_facts(read_func=fileops.read,
                                     listdir=listdir.listdir)

    assert facts.default_config_hash is None
    assert not facts.configs
def test_get_vsftpd_facts():
    directory = '/etc/vsftpd'
    file_names = ['vsftpd.conf', 'foo.conf', 'bar.conf']
    listdir = MockListDir(directory, file_names)
    fileops = MockFileOperations()
    fileops.files[os.path.join(directory, file_names[0])] = 'anonymous_enable=YES\n' \
                                                            'ca_certs_file=/foo/bar\n'
    fileops.files[os.path.join(directory, file_names[1])] = 'anonymous_enable=NO\n' \
                                                            'tcp_wrappers=YES\n'
    fileops.files[os.path.join(directory, file_names[2])] = 'strict_ssl_read_eof=yes\n' \
                                                            'tcp_wrappers=no\n'

    facts = library.get_vsftpd_facts(read_func=fileops.read,
                                     listdir=listdir.listdir)

    assert facts.default_config_hash == '892bae7b69eb66ec16afe842a15e53a5242155a4'
    assert len(facts.configs) == 3
    used_indices = set()
    for config in facts.configs:
        assert os.path.dirname(config.path) == directory
        file_name = os.path.basename(config.path)
        ix = file_names.index(file_name)
        if ix in used_indices:
            assert False
        used_indices.add(ix)
        if ix == 0:
            assert config.strict_ssl_read_eof is None
            assert config.tcp_wrappers is None
        elif ix == 1:
            assert config.strict_ssl_read_eof is None
            assert config.tcp_wrappers is True
        elif ix == 2:
            assert config.strict_ssl_read_eof is True
            assert config.tcp_wrappers is False
        else:
            assert False
Exemple #5
0
 def process(self):
     installed_rpm_facts = next(self.consume(InstalledRedHatSignedRPM))
     if library.is_processable(installed_rpm_facts):
         self.produce(library.get_vsftpd_facts())