def test_mailtest_dry_run(self): try: tasks.ipa_epn(self.master, mailtest=True, dry_run=True) except CalledProcessError as e: assert 'You cannot specify' in e.stderr else: raise AssertionError('--mail-test and --dry-run aren\'t supposed ' 'to succeed')
def test_EPN_authenticated(self, cleanupmail): """Enable authentication and test that mail is delivered """ epn_conf = USER_EPN_CONF.format( user=self.master.config.admin_name, password=self.master.config.admin_password, ) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail(self.master, i, "Hi test user,\n\nYour password will expire")
def test_EPN_authenticated(self, cleanupmail): """Enable authentication and test that mail is delivered """ epn_conf = textwrap.dedent(''' [global] smtp_user={user} smtp_password={password} '''.format(user=self.master.config.admin_name, password=self.master.config.admin_password)) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail(self.master, i, "Hi test user,\n\nYour password will expire")
def test_EPN_ssl(self, cleanupmail): """Configure with ssl and test delivery """ epn_conf = SSL_EPN_CONF.format( server=self.master.hostname, user=self.master.config.admin_name, password=self.master.config.admin_password, ) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) configure_ssl(self.master) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail( self.master, i, "Hi test user,\nYour login entry user%d is going" % i)
def test_EPN_delay_config(self, cleanupmail): """Test the smtp_delay configuration option """ epn_conf = DEFAULT_EPN_CONF + textwrap.dedent("""\ smtp_delay=A """) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) result = tasks.ipa_epn(self.master, raiseonerr=False) assert "could not convert string to float: 'A'" in result.stderr_text epn_conf = DEFAULT_EPN_CONF + textwrap.dedent("""\ smtp_delay=-1 """) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) result = tasks.ipa_epn(self.master, raiseonerr=False) assert "smtp_delay cannot be less than zero" in result.stderr_text
def test_EPN_starttls(self, cleanupmail): """Configure with starttls and test delivery """ epn_conf = textwrap.dedent(''' [global] smtp_user={user} smtp_password={password} smtp_security=starttls '''.format(user=self.master.config.admin_name, password=self.master.config.admin_password)) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) configure_starttls(self.master) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail(self.master, i, "Hi test user,\nYour login entry user%d is going" % i)
def test_EPN_template(self, cleanupmail): """Modify the template to ensure changes are applied. """ exp_msg = textwrap.dedent(''' Hi {{ first }} {{last}}, Your login entry {{uid}} is going to expire on {{ expiration }}. Please change it soon. Your friendly neighborhood admins. ''') self.master.put_file_contents('/etc/ipa/epn/expire_msg.template', exp_msg) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail(self.master, i, "Hi test user,\nYour login entry user%d is going" % i)
def test_EPN_starttls_client_cert(self, cleanupmail): """Configure with starttls + client certificate and test delivery """ epn_conf = (STARTTLS_EPN_CONF + CLIENT_CERT_EPN_CONF).format( server=self.master.hostname, user=self.master.config.admin_name, password=self.master.config.admin_password, client_cert=SMTP_CLIENT_CERT, client_key=SMTP_CLIENT_KEY, client_key_pass=SMTP_CLIENT_KEY_PASS, ) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) tasks.ipa_epn(self.master) for i in self.notify_ttls: validate_mail( self.master, i, "Hi test user,\nYour login entry user%d is going" % i)
def test_mailtest(self, cleanupmail): """Execute mailtest to validate mail is working Set of of our pre-created users as the smtp_admin to receive the mail, run ipa-epn --mailtest, then validate the result. Using a non-expired user here, user2, to receive the result. """ epn_conf = (USER_EPN_CONF + textwrap.dedent("""\ smtp_admin=user2@{domain} """)).format( user=self.master.config.admin_name, password=self.master.config.admin_password, domain=self.master.domain.name, ) self.master.put_file_contents('/etc/ipa/epn.conf', epn_conf) tasks.ipa_epn(self.master, mailtest=True) validate_mail(self.master, 2, "Hi SAMPLE USER,\nYour login entry SAUSER is going")
def _check_epn_output( self, host, dry_run=False, from_nbdays=None, to_nbdays=None, raiseonerr=True, ): result = tasks.ipa_epn(host, raiseonerr=raiseonerr, dry_run=dry_run, from_nbdays=from_nbdays, to_nbdays=to_nbdays) json.dumps(json.loads(result.stdout_text), ensure_ascii=False) return (result.stdout_text, result.stderr_text)
def _check_epn_output(self, host, dry_run=False, mailtest=False, from_nbdays=None, to_nbdays=None, raiseonerr=True, validatejson=True): result = tasks.ipa_epn(host, from_nbdays=from_nbdays, to_nbdays=to_nbdays, mailtest=mailtest, dry_run=dry_run, raiseonerr=raiseonerr) if validatejson: json.dumps(json.loads(result.stdout_text), ensure_ascii=False) return (result.stdout_text, result.stderr_text, result.returncode)