def test_01_test_pop3(domain): with patch('poplib.POP3') as mockpop: mockpop.return_value.list.return_value = ['+OK 1 messages:', ['1 557'], 7] mockpop.return_value.retr.return_value = ['+OK:', ['', 'unittest'], 0] with pytest.raises(exceptions.TestException) as err: pop3.test_pop3(domain.user, domain.domain, domain.password) assert 'Retrieved message does not contain test string' in err.value.message
def test_00_test_pop3(domain): with patch('poplib.POP3') as mockpop: mockpop.return_value.list.return_value = ['+OK 1 messages:', ['1 557'], 7] mockpop.return_value.retr.return_value = ['+OK:', ['', 'da_server_check mail test'], 0] assert "Test message retrieved via Dovecot POP3." in \ pop3.test_pop3(domain.user, domain.domain, domain.password) with patch('poplib.POP3_SSL') as mockpopssl: mockpopssl.return_value.list.return_value = ['+OK 1 messages:', ['1 557'], 7] mockpopssl.return_value.retr.return_value = ['+OK:', ['', 'da_server_check mail test'], 0] assert "Test message retrieved via Dovecot POP3_SSL." in \ pop3.test_pop3(domain.user, domain.domain, domain.password, True)
def main(argv=None): if os.geteuid() != 0: print warning("This script requires root privileges to run.") sys.exit(-1) if argv is None: argv = sys.argv[1:] args = parse_args(argv) domain = user = password = None try: # Detect DirectAdmin. if os.path.isfile("/usr/local/directadmin/conf/directadmin.conf"): print header("DirectAdmin") # Ask the user for a DirectAdmin login information. admin_user = raw_input(bcolors.BOLD + "DirectAdmin admin username: "******"DirectAdmin admin password: "******"/usr/bin/pure-pw"): ret = subprocess.Popen(["/usr/bin/pure-pw", "mkdb", "/etc/pureftpd.pdb", "-f", "/etc/proftpd.passwd"]) ret.wait() # Enable SpamAssassin. directadmin.enable_spamassassin(user, password, domain) else: print error("Only DirectAdmin servers are currently supported!") sys.exit(-1) if args.mysql: print header("MySQL") print ok(directadmin.test_mysql_connection()) if args.php: print header("PHP") print ok(php.check_config()) print ok(php.test_session_handler(user, domain)) print ok(php.test_mod_ruid2(user, domain)) print ok(php.test_mail(user, domain)) if args.pop3: print header("POP3") print ok(pop3.test_pop3(user, domain, password)) print ok(pop3.test_pop3(user, domain, password, ssl=True)) if args.imap: print header("IMAP") print ok(imap.test_imap(user, domain, password)) print ok(imap.test_imap(user, domain, password, ssl=True)) if args.smtp: print header("SMTP") print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=False)) print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=True)) print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=False, start_tls=True)) if '465' in open('/etc/exim.conf').read(): print ok(smtp.test_smtp(user, domain, password, ssl=True, submission=False)) if args.ftp: print header("FTP") print ok(ftp.test_ftp(user, domain, password)) if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] > 6): print ok(ftp.test_ftp(user, domain, password, ssl=True)) if args.spamassassin: print header("SpamAssassin") print ok(spamassassin.test_spamassassin(user, domain, password)) if args.phpmyadmin: print header("phpMyAdmin") print ok(phpmyadmin.test_phpmyadmin()) if args.roundcube: print header("Roundcube") print ok(roundcube.test_roundcube()) # Finally, remove the account alltogether. directadmin.remove_account(admin_user, admin_pass, user) except Exception as err: print error(err) return True