def test_04_remove_account(domain): mocked_open = mock_open(read_data='user=foo\npasswd=bar\nSSL=1\nport=1234\n') with patch('__builtin__.open', mocked_open): with patch('requests.post') as post: assert directadmin.remove_account("", "", domain.user) # Again but with false credentials. postreturn = collections.namedtuple('post', 'text, status_code') postreturn.text = "DirectAdmin Login Page" post.return_value = postreturn with pytest.raises(exceptions.TestException) as err: directadmin.remove_account("", "", domain.user) assert 'DirectAdmin username or password incorrect' in err.value.message # Again but with an account we already deleted. postreturn.text = "error=1" post.return_value = postreturn with pytest.raises(exceptions.TestException) as err: directadmin.remove_account("", "", domain.user) assert 'Unable to delete DirectAdmin user %s' % 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