From 59b3eb0433b85f554ba999487288ad18a2be33e0 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 8 May 2018 07:44:23 -0400 Subject: [PATCH] Add tests for ipa-restore with DM password validation check ipa-restore should validate the DM password before executing the restoration. This adds two test cases: 1. Restore with a bad DM password 2. Restore with dirsrv down so password cannot be checked Related: https://pagure.io/freeipa/issue/7136 Signed-off-by: Rob Crittenden Reviewed-By: Christian Heimes --- .../test_backup_and_restore.py | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py index c1199f211..c10e42aea 100644 --- a/ipatests/test_integration/test_backup_and_restore.py +++ b/ipatests/test_integration/test_backup_and_restore.py @@ -482,10 +482,9 @@ class TestBackupAndRestoreWithReplica(IntegrationTest): "systemctl", "disable", "oddjobd" ]) - dirman_password = self.master.config.dirman_password self.master.run_command( ["ipa-restore", backup_path], - stdin_text=dirman_password + '\nyes' + stdin_text='yes' ) status = self.master.run_command([ @@ -547,3 +546,36 @@ class TestUserrootFilesOwnership(IntegrationTest): unexp_str = "CRITICAL: db2ldif failed:" assert cmd.returncode == 0 assert unexp_str not in cmd.stdout_text + + +class TestBackupAndRestoreDMPassword(IntegrationTest): + """Negative tests for incorrect DM password""" + topology = 'star' + + def test_restore_bad_dm_password(self): + """backup, uninstall, restore, wrong DM password (expect failure)""" + with restore_checker(self.master): + backup_path = backup(self.master) + + # No uninstall, just pure restore, the only case where + # prompting for the DM password matters. + result = self.master.run_command(['ipa-restore', backup_path], + stdin_text='badpass\nyes', + raiseonerr=False) + assert result.returncode == 1 + + def test_restore_dirsrv_not_running(self): + """backup, restore, dirsrv not running (expect failure)""" + + # Flying blind without the restore_checker so we can have + # an error thrown when dirsrv is down. + backup_path = backup(self.master) + + self.master.run_command(['ipactl', 'stop']) + + dirman_password = self.master.config.dirman_password + result = self.master.run_command( + ['ipa-restore', backup_path], + stdin_text=dirman_password + '\nyes', + raiseonerr=False) + assert result.returncode == 1