From 47c2b94d685af5677b06a8c71390027867cdcd9d Mon Sep 17 00:00:00 2001
From: Anuja More <amore@redhat.com>
Date: Wed, 30 May 2018 16:42:49 +0530
Subject: [PATCH] ipa-ca-install invalid input for option --external-cert-file

Signed-off-by: Anuja More <amore@redhat.com>
---
 .freeipa-pr-ci.yaml                        | 11 +++++++++
 ipatests/test_integration/test_commands.py | 37 ++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/.freeipa-pr-ci.yaml b/.freeipa-pr-ci.yaml
index 21f1c004d7..2bfc0637dd 100644
--- a/.freeipa-pr-ci.yaml
+++ b/.freeipa-pr-ci.yaml
@@ -207,3 +207,14 @@ jobs:
         timeout: 3600
         topology: *master_1repl_1client
 
+  fedora-28/test_commands:
+    requires: [fedora-28/build]
+    priority: 50
+    job:
+      class: RunPytest
+      args:
+        build_url: '{fedora-28/build_url}'
+        test_suite: test_integration/test_commands.py
+        template: *ci-master-f28
+        timeout: 3600
+        topology: *master_1repl_1client
diff --git a/ipatests/test_integration/test_commands.py b/ipatests/test_integration/test_commands.py
index 7a4d7b9956..e73f6f2f58 100644
--- a/ipatests/test_integration/test_commands.py
+++ b/ipatests/test_integration/test_commands.py
@@ -133,3 +133,40 @@ def test_change_sysaccount_password_issue7561(self):
 
         tasks.ldappasswd_sysaccount_change(sysuser, original_passwd,
                                            new_passwd, master)
+
+
+class TestIPACAInstallCommand(IntegrationTest):
+    """ ipa-ca-install command using option --external-cert-file
+
+    Install replica without setup-ca option. On replica install ca
+    using ipa-ca-install with --external-cert-file by providing
+    invalid cert or non-existing file.
+    If executed command with non-existing file, invalid file etc,
+    it should through error.
+
+    related to https://pagure.io/freeipa/issue/6985
+    """
+
+    def install_ca_replica(self, host, path):
+
+        tasks.install_master(self.master)
+        replica = self.replcas[0]
+
+        # install ca with non-existing cert
+        tasks.install_replica(self.master, replica, setup_ca=False)
+        result1 = tasks.install_ca(replica, cert_files='abc.crt')
+        assert result1 != 0
+
+        # install ca with invalid cert
+        tasks.uninstall_master(replica)
+        contents = (
+            '-----BEGIN CERTIFICATE-----\n'
+            'sdnmsdkfbsdifbsdbasdsdSDDDasdmnd\n'
+            '-----END CERTIFICATE-----')
+
+        cert1 = tempfile.mkdtemp(suffix='abc.crt', dir=paths.TMP)
+        replica.put_file_contents(cert1, contents)
+        tasks.install_replica(self.master, replica, setup_ca=False)
+        result1 = tasks.install_ca(replica, cert_files=cert1)
+        assert result1 != 0
+
