From 2475eb0c621d2227ed934b50153215300b9964e1 Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 25 Feb 2015 07:39:13 -0700 Subject: [PATCH] ipatests: Add tests for valid and invalid ipa-advise - Add test for invalid run of the ipa-advise command - Add tests for valid runs of the ipa-advise command https://fedorahosted.org/freeipa/ticket/4029 --- ipatests/test_integration/test_advise.py | 127 +++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 ipatests/test_integration/test_advise.py diff --git a/ipatests/test_integration/test_advise.py b/ipatests/test_integration/test_advise.py new file mode 100644 index 0000000000000000000000000000000000000000..197e3ff1518f7944f497570a8a067aa53fcf45d6 --- /dev/null +++ b/ipatests/test_integration/test_advise.py @@ -0,0 +1,127 @@ +# Authors: +# Gabe Alford +# +# Copyright (C) 2013 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# FIXME: Pylint errors +# pylint: disable=no-member + +import re +from ipatests.test_integration import tasks +from ipatests.test_integration.base import IntegrationTest + + +class BaseTestAdvice(IntegrationTest): + """ + Tests ipa-advise output. + """ + advice_id = None + raiseerr = None + advice_regex = '' + topology = 'line' + + def test_advice(self): + # Obtain the advice from the server + tasks.kinit_admin(self.master) + result = self.master.run_command(['ipa-advise', self.advice_id], + raiseonerr=self.raiseerr) + + if not result.stdout_text: + advice = result.stderr_text + else: + advice = result.stdout_text + + assert re.search(self.advice_regex, advice, re.S) + +# Base classes with attributes that are specific for each ipa-advise test + + +class BaseTestInvalidAdvice(object): + advice_id = 'invalid-advise-param' + advice_regex = "invalid[\s]+\'advice\'.*" + raiseerr = False + + +class BaseTestFedoraAuthconfig(object): + advice_id = 'config-fedora-authconfig' + advice_regex = "\#\!\/bin\/sh.*" \ + "authconfig[\s]+\-\-enableldap[\s]+" \ + "\-\-ldapserver\=.*[\s]+\-\-enablerfc2307bis[\s]+" \ + "\-\-enablekrb5" + + +class BaseTestFreeBSDNSSPAM(object): + advice_id = 'config-freebsd-nss-pam-ldapd' + advice_regex = "\#\!\/bin\/sh.*" \ + "pkg_add[\s]+\-r[\s]+nss\-pam\-ldapd[\s]+curl.*" \ + "\/usr\/local\/etc\/rc\.d\/nslcd[\s]+restart" + + +class BaseTestGenericNSSPAM(object): + advice_id = 'config-generic-linux-nss-pam-ldapd' + advice_regex = "\#\!\/bin\/sh.*" \ + "apt\-get[\s]+\-y[\s]+install[\s]+wget[\s]+openssl[\s]+" \ + "libnss\-ldapd[\s]+libpam\-ldapd[\s]+nslcd.*" \ + "service[\s]+nscd[\s]+stop[\s]+\&\&[\s]+service[\s]+" \ + "nslcd[\s]+restart" + + +class BaseTestGenericSSSDBefore19(object): + advice_id = 'config-generic-linux-sssd-before-1-9' + advice_regex = "\#\!\/bin\/sh.*" \ + "apt\-get[\s]+\-y[\s]+install sssd wget openssl.*" \ + "service[\s]+sssd[\s]+start" + + +class BaseTestRedHatNSS(object): + advice_id = 'config-redhat-nss-ldap' + advice_regex = "\#\!\/bin\/sh.*" \ + "yum[\s]+install[\s]+\-y[\s]+wget[\s]+openssl[\s]+nss_ldap" \ + "[\s]+authconfig.*authconfig[\s]+\-\-updateall" \ + "[\s]+\-\-enableldap[\s]+\-\-enableldapauth[\s]+" \ + "\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" + + +class BaseTestRedHatNSSPAM(object): + advice_id = 'config-redhat-nss-pam-ldapd' + advice_regex = "\#\!\/bin\/sh.*" \ + "yum[\s]+install[\s]+\-y[\s]+wget[\s]+openssl[\s]+" \ + "nss\-pam\-ldapd[\s]+pam_ldap[\s]+authconfig.*" \ + "authconfig[\s]+\-\-updateall[\s]+" \ + "\-\-enableldap[\s]+\-\-enableldapauth[\s]+" \ + "\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" + + +class BaseTestRedHatSSSDBefore19(object): + advice_id = 'config-redhat-sssd-before-1-9' + advice_regex = "\#\!\/bin\/sh.*" \ + "yum[\s]+install[\s]+\-y[\s]+sssd[\s]+authconfig[\s]+" \ + "wget[\s]+openssl.*service[\s]+sssd[\s]+start" + +# The actual ipa-advise tests + + +class TestAdvice(BaseTestInvalidAdvice, + BaseTestFedoraAuthconfig, + BaseTestFreeBSDNSSPAM, + BaseTestGenericNSSPAM, + BaseTestGenericSSSDBefore19, + BaseTestRedHatNSS, + BaseTestRedHatNSSPAM, + BaseTestRedHatSSSDBefore19, + BaseTestAdvice): + pass -- 1.8.3.1