def test_03_test_mail(mock_open, mock_chown, domain): with patch('requests.get') as get: get_return = collections.namedtuple('get_return', 'text, status_code') get_return.text = 'OK' get_return.status_code = 200 get.return_value = get_return with patch('pwd.getpwnam'): assert "mail sent succesfully" in php.test_mail(domain.user, domain.domain) get_return.status_code = 500 get.return_value = get_return # Again with modified return handler for session. with pytest.raises(exceptions.TestException) as err: php.test_mail(domain.user, domain.domain) assert "Unexpected response from getting" in err.value.message # Again with proper statuscode but other text. get_return.status_code = 200 get_return.text = 'test' with pytest.raises(exceptions.TestException) as err: php.test_mail(domain.user, domain.domain) assert "mail could not be sent" in err.value.message # Again with non-existing user. with pytest.raises(exceptions.TestException) as err: php.test_mail(domain.user, domain.domain) assert "User %s does not seem to exist on this system." % domain.user in err.value.message
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