From a7dc98bf77d7b3e49bc85a0ba196fb3de6b4a72b Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Mar 05 2020 14:43:08 +0000
Subject: use only gssapi_login in CLI


Fixes: https://pagure.io/koji/issue/1906

---

diff --git a/cli/koji_cli/lib.py b/cli/koji_cli/lib.py
index c2cc6c8..7b000d4 100644
--- a/cli/koji_cli/lib.py
+++ b/cli/koji_cli/lib.py
@@ -575,17 +575,12 @@ def activate_session(session, options):
     elif options.authtype == "kerberos" or has_krb_creds() and options.authtype is None:
         try:
             if getattr(options, 'keytab', None) and getattr(options, 'principal', None):
-                session.krb_login(principal=options.principal, keytab=options.keytab,
-                                  proxyuser=runas)
+                session.gssapi_login(principal=options.principal, keytab=options.keytab,
+                                     proxyuser=runas)
             else:
-                session.krb_login(proxyuser=runas)
+                session.gssapi_login(proxyuser=runas)
         except socket.error as e:
             warn(_("Could not connect to Kerberos authentication service: %s") % e.args[1])
-        except Exception as e:
-            if krbV is not None and isinstance(e, krbV.Krb5Error):
-                error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0]))
-            else:
-                raise
     if not noauth and not session.logged_in:
         error(_("Unable to log in, no authentication methods available"))
     ensure_connection(session)
diff --git a/tests/test_cli/test_activate_session.py b/tests/test_cli/test_activate_session.py
index 707d43d..b1ee20a 100644
--- a/tests/test_cli/test_activate_session.py
+++ b/tests/test_cli/test_activate_session.py
@@ -34,6 +34,7 @@ class TestActivateSession(unittest.TestCase):
         session.login.assert_not_called()
         session.ssl_login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
 
     def test_activate_session_ssl(self):
         session = mock.MagicMock()
@@ -48,6 +49,7 @@ class TestActivateSession(unittest.TestCase):
                     proxyuser=None)
         session.login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
 
     def test_activate_session_ssl_implicit(self):
         session = mock.MagicMock()
@@ -63,6 +65,7 @@ class TestActivateSession(unittest.TestCase):
                     proxyuser=None)
         session.login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
 
     def test_activate_session_pw(self):
         session = mock.MagicMock()
@@ -72,6 +75,7 @@ class TestActivateSession(unittest.TestCase):
         session.login.assert_called_once_with()
         session.ssl_login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
 
     def test_activate_session_pw_implicit(self):
         session = mock.MagicMock()
@@ -82,6 +86,7 @@ class TestActivateSession(unittest.TestCase):
         session.login.assert_called_once_with()
         session.ssl_login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
 
     def test_activate_session_krb(self):
         session = mock.MagicMock()
@@ -91,7 +96,8 @@ class TestActivateSession(unittest.TestCase):
         activate_session(session, options)
         session.login.assert_not_called()
         session.ssl_login.assert_not_called()
-        session.krb_login.assert_called_once_with(proxyuser=None)
+        session.krb_login.assert_not_called()
+        session.gssapi_login.assert_called_once_with(proxyuser=None)
 
     def test_activate_session_krb_implicit(self):
         session = mock.MagicMock()
@@ -102,7 +108,8 @@ class TestActivateSession(unittest.TestCase):
         activate_session(session, options)
         session.login.assert_not_called()
         session.ssl_login.assert_not_called()
-        session.krb_login.assert_called_once_with(proxyuser=None)
+        session.krb_login.assert_not_called()
+        session.gssapi_login.assert_called_once_with(proxyuser=None)
 
     def test_activate_session_krb_keytab(self):
         session = mock.MagicMock()
@@ -112,7 +119,8 @@ class TestActivateSession(unittest.TestCase):
         activate_session(session, options)
         session.login.assert_not_called()
         session.ssl_login.assert_not_called()
-        session.krb_login.assert_called_once_with(principal='PRINCIPAL',
+        session.krb_login.assert_not_called()
+        session.gssapi_login.assert_called_once_with(principal='PRINCIPAL',
                     keytab='KEYTAB', proxyuser=None)
 
     def test_activate_session_no_method(self):
@@ -124,4 +132,5 @@ class TestActivateSession(unittest.TestCase):
         session.login.assert_not_called()
         session.ssl_login.assert_not_called()
         session.krb_login.assert_not_called()
+        session.gssapi_login.assert_not_called()
         self.error.assert_called_once()

