def test_restoring_default_config(): content = 'anonymous_enable=NO\n' \ 'tcp_wrappers=NO\n' \ 'strict_ssl_read_eof=NO\n' fileops = MockFileOperations() fileops.files[VSFTPD_DEFAULT_CONFIG_PATH] = content config = VsftpdConfig(path=VSFTPD_DEFAULT_CONFIG_PATH, tcp_wrappers=False, strict_ssl_read_eof=False) facts = VsftpdFacts(default_config_hash='foobar', configs=[config]) migrate_configs(facts, fileops=fileops) assert len(fileops.files_read) == 1 assert VSFTPD_DEFAULT_CONFIG_PATH in fileops.files_read assert len(fileops.files_written) == 1 assert VSFTPD_DEFAULT_CONFIG_PATH in fileops.files_written expected_lines = ['# Commented out by Leapp:', '#anonymous_enable=NO', 'tcp_wrappers=NO', 'strict_ssl_read_eof=NO', '', '# Added by Leapp:', 'anonymous_enable=YES', ''] assert fileops.files[VSFTPD_DEFAULT_CONFIG_PATH] == '\n'.join(expected_lines)
def process(self): facts = next(self.consume(SpamassassinFacts), None) if facts: library.migrate_configs(facts) else: self.log.debug( 'Skipping execution - no SpamassassinFacts message has been produced.' )
def test_migrate_configs(): facts = SpamassassinFacts(spamc_ssl_argument='sslv3', spamd_ssl_version='sslv3', service_overriden=False) fileops = MockFileOperations() fileops.files[SPAMC_CONFIG_FILE] = '--ssl sslv3\n# foo\n-B\n' content = ('# foo\n' + SYSCONFIG_VARIABLE + '="-c --ssl-version sslv3 -hdx"\n' + '# bar \n') fileops.files[SYSCONFIG_SPAMASSASSIN] = content backup_func = MockBackup() library.migrate_configs(facts, fileops, backup_func) assert backup_func.called == 2 assert SPAMC_CONFIG_FILE in backup_func.paths assert SYSCONFIG_SPAMASSASSIN in backup_func.paths assert fileops.files[SPAMC_CONFIG_FILE] == '--ssl\n# foo\n-B\n' expected_content = ('# foo\n' + SYSCONFIG_VARIABLE + '="-c --ssl -hx"\n' + '# bar \n') assert fileops.files[SYSCONFIG_SPAMASSASSIN] == expected_content
def test_setting_strict_ssl_read_eof(): path = '/etc/vsftpd/bar.conf' content = 'local_enable=YES\n' fileops = MockFileOperations() fileops.files[path] = content config = VsftpdConfig(path=path, tcp_wrappers=None, strict_ssl_read_eof=None) facts = VsftpdFacts(configs=[config]) migrate_configs(facts, fileops=fileops) assert path in fileops.files_read assert len(fileops.files_written) == 1 assert path in fileops.files_written expected_lines = ['local_enable=YES', '', '# Added by Leapp:', 'strict_ssl_read_eof=NO', ''] assert fileops.files[path] == '\n'.join(expected_lines)
def test_setting_tcp_wrappers(): path = '/etc/vsftpd/foo.conf' content = 'tcp_wrappers=YES\n' \ 'strict_ssl_read_eof=NO\n' fileops = MockFileOperations() fileops.files[path] = content config = VsftpdConfig(path=path, tcp_wrappers=True, strict_ssl_read_eof=False) facts = VsftpdFacts(configs=[config]) migrate_configs(facts, fileops=fileops) assert path in fileops.files_read assert len(fileops.files_written) == 1 assert path in fileops.files_written expected_lines = ['# Commented out by Leapp:', '#tcp_wrappers=YES', 'strict_ssl_read_eof=NO', '', '# Added by Leapp:', 'tcp_wrappers=NO', ''] assert fileops.files[path] == '\n'.join(expected_lines)
def process(self): try: vsftpd_facts = next(self.consume(VsftpdFacts)) except StopIteration: return library.migrate_configs(vsftpd_facts)