From 67c5a9058a358ed4fc3bdf8842841260d5a06520 Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Oct 17 2017 14:27:02 +0000
Subject: Remove fedora cert


Kerberos authentication is used by dist-git and lookaside already.
Remove cert related code.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>

---

diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py
index e7a0450..4acd564 100644
--- a/fedpkg/__init__.py
+++ b/fedpkg/__init__.py
@@ -13,7 +13,6 @@ import pyrpkg
 import os
 import git
 import re
-import fedora_cert
 import platform
 import subprocess
 
@@ -31,26 +30,16 @@ class Commands(pyrpkg.Commands):
 
         self.source_entry_type = 'bsd'
 
-    @cached_property
-    def cert_file(self):
-        """A client-side certificate for SSL authentication
-
-        We override this from pyrpkg because we actually need a client-side
-        certificate.
-        """
-        path = os.path.expanduser('~/.fedora.cert')
-        if os.path.exists(path):
-            return path
+    def load_user(self):
+        """This sets the user attribute, based on the Fedora SSL cert."""
+        fedora_upn = os.path.expanduser('~/.fedora.upn')
+        if os.path.exists(fedora_upn):
+            with open(fedora_upn, 'r') as f:
+                self._user = f.read().strip()
         else:
-            return None
-
-    @cached_property
-    def ca_cert(self):
-        """A CA certificate to authenticate the server in SSL connections
-
-        We now use the system trust list.
-        """
-        return None
+            self.log.debug('Could not get user from .fedora.upn, falling back'
+                           ' to default method')
+            super(Commands, self).load_user()
 
     @cached_property
     def lookasidecache(self):
@@ -59,8 +48,7 @@ class Commands(pyrpkg.Commands):
         We override this because we need a different download path.
         """
         return FedoraLookasideCache(
-            self.lookasidehash, self.lookaside, self.lookaside_cgi,
-            client_cert=self.cert_file, ca_cert=self.ca_cert)
+            self.lookasidehash, self.lookaside, self.lookaside_cgi)
 
     # Overloaded property loaders
     def load_rpmdefines(self):
@@ -138,15 +126,6 @@ class Commands(pyrpkg.Commands):
         else:
             super(Commands, self).load_container_build_target()
 
-    def load_user(self):
-        """This sets the user attribute, based on the Fedora SSL cert."""
-        try:
-            self._user = fedora_cert.read_user_cert()
-        except Exception as e:
-            self.log.debug('Could not read Fedora cert, falling back to '
-                           'default method: %s' % e)
-            super(Commands, self).load_user()
-
     def _tag2version(self, dest_tag):
         """ get the '26' part of 'f26-foo' string """
         return dest_tag.split('-')[0].replace('f', '')
diff --git a/fedpkg/lookaside.py b/fedpkg/lookaside.py
index c679151..12ccd7b 100644
--- a/fedpkg/lookaside.py
+++ b/fedpkg/lookaside.py
@@ -18,11 +18,9 @@ from pyrpkg.lookaside import CGILookasideCache
 
 
 class FedoraLookasideCache(CGILookasideCache):
-    def __init__(self, hashtype, download_url, upload_url,
-                 client_cert=None, ca_cert=None):
+    def __init__(self, hashtype, download_url, upload_url):
         super(FedoraLookasideCache, self).__init__(
-            hashtype, download_url, upload_url, client_cert=client_cert,
-            ca_cert=ca_cert)
+            hashtype, download_url, upload_url)
 
         self.download_path = (
             '%(name)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s')
diff --git a/test/test_commands.py b/test/test_commands.py
index e2abf5a..3c3529b 100644
--- a/test/test_commands.py
+++ b/test/test_commands.py
@@ -14,9 +14,7 @@ import unittest
 from pyrpkg.errors import rpkgError
 from fedpkg import _get_bodhi_version
 from utils import CommandTestCase
-from mock import patch
-from mock import Mock
-from mock import PropertyMock
+from mock import call, patch, Mock, PropertyMock, mock_open
 
 
 class TestDetermineRuntimeEnv(CommandTestCase):
@@ -117,20 +115,26 @@ class TestLoadUser(CommandTestCase):
         super(TestLoadUser, self).setUp()
         self.cmd = self.make_commands()
 
-    @patch('fedora_cert.read_user_cert')
-    def test_load_from_load_fedora_cert(self, read_user_cert):
-        read_user_cert.return_value = 'someone'
-
-        self.cmd.load_user()
-        self.assertEqual('someone', self.cmd._user)
-
-    @patch('fedora_cert.read_user_cert')
+    @patch('os.path.expanduser')
+    @patch('os.path.exists')
+    def test_load_from_fedora_upn(self, exists, expanduser):
+        exists.return_value = True
+        expanduser.return_value = '/home/user/.fedora.upn'
+        with patch('__builtin__.open', mock_open(read_data='user')) as m:
+            self.cmd.load_user()
+        m.assert_has_calls([
+            call(expanduser.return_value, 'r')
+        ])
+        self.assertEqual('user', self.cmd._user)
+
+    @patch('os.path.expanduser')
+    @patch('os.path.exists')
     @patch('os.getuid')
     @patch('pwd.getpwuid')
     def test_fall_back_to_super_load_user(
-            self, getpwuid, getuid, read_user_cert):
+            self, getpwuid, getuid, exists, expanduser):
+        exists.return_value = False
         getpwuid.return_value = ('someone', None)
-        read_user_cert.side_effect = Exception
 
         self.cmd.load_user()
         self.assertEqual('someone', self.cmd._user)

