certprofile: add tests for config profileId scenarios

Update the certprofile tests to cover the various scenarios
concerning the profileId property in the profile configuration.
The scenarios now explicitly tested are:

- profileId not specified (should succeed)
- mismatched profileId property (should fail)
- multiple profileId properties (should fail)
- one profileId property, matching given ID (should succeed)

https://pagure.io/freeipa/issue/7503

Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Fraser Tweedale
2018-04-18 19:35:49 +10:00
committed by Rob Crittenden
parent a7b18372ed
commit 0f8593354d
3 changed files with 42 additions and 3 deletions

View File

@@ -1,6 +1,5 @@
auth.instance_id=raCertAuth
classId=caEnrollImpl
profileId=caIPAserviceCert_mod
visible=false
desc=This certificate profile is for enrolling server certificates with IPA-RA agent authentication.
enable=true

View File

@@ -222,3 +222,36 @@ class TestImportFromXML(XMLRPC_test):
def test_import_xml(self, xmlprofile):
with pytest.raises(errors.ExecutionError):
xmlprofile.ensure_exists()
# The initial user_profile configuration does not specify profileId.
# This is fine (it gets derived from the profile-id CLI argument),
# but this case was already tested in TestProfileCRUD.
#
# This test case tests various scenarios where the profileId *is*
# specified in the profile configuration. These are:
#
# - mismatched profileId property (should fail)
# - multiple profileId properties (should fail)
# - one profileId property, matching given ID (should succeed)
#
@pytest.mark.tier1
class TestImportProfileIdHandling(XMLRPC_test):
def test_import_with_mismatched_profile_id(self, user_profile):
command = user_profile.make_create_command(
extra_lines=['profileId=bogus']
)
with pytest.raises(errors.ValidationError):
command()
def test_import_with_multiple_profile_id(self, user_profile):
# correct profile id, but two occurrences
prop = u'profileId={}'.format(user_profile.name)
command = user_profile.make_create_command(extra_lines=[prop, prop])
with pytest.raises(errors.ValidationError):
command()
def test_import_with_correct_profile_id(self, user_profile):
prop = u'profileId={}'.format(user_profile.name)
command = user_profile.make_create_command(extra_lines=[prop])
command()

View File

@@ -57,7 +57,14 @@ class CertprofileTracker(Tracker):
content = f.read()
return unicode(content)
def make_create_command(self):
def make_create_command(self, extra_lines=None):
"""
:param extra_lines: list of extra lines to append to profile config.
"""
if extra_lines is None:
extra_lines = []
if not self.profile:
raise RuntimeError('Tracker object without path to profile '
'cannot be used to create profile entry.')
@@ -65,7 +72,7 @@ class CertprofileTracker(Tracker):
return self.make_command('certprofile_import', self.name,
description=self.description,
ipacertprofilestoreissued=self.store,
file=self.profile)
file=u'\n'.join([self.profile] + extra_lines))
def check_create(self, result):
assert_deepequal(dict(