|
Packit |
6f3914 |
# -*- coding: utf-8 -*-
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# Copyright (C) 2014-2018 Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit |
6f3914 |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit |
6f3914 |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit |
6f3914 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
6f3914 |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit |
6f3914 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit |
6f3914 |
# Public License for more details. You should have received a copy of the
|
|
Packit |
6f3914 |
# GNU General Public License along with this program; if not, write to the
|
|
Packit |
6f3914 |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6f3914 |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit |
6f3914 |
# source code or documentation are not subject to the GNU General Public
|
|
Packit |
6f3914 |
# License and may only be used or replicated with the express permission of
|
|
Packit |
6f3914 |
# Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
from __future__ import absolute_import
|
|
Packit |
6f3914 |
from __future__ import unicode_literals
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import os
|
|
Packit |
6f3914 |
import tempfile
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import dnf.crypto
|
|
Packit |
6f3914 |
import dnf.util
|
|
Packit |
6f3914 |
import dnf.yum.misc
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import tests.support
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
FINGERPRINT = '0BE49FAF9C955F4F1A98D14B24362A8492530C8E'
|
|
Packit |
6f3914 |
KEYFILE = tests.support.resource_path('keys/key.pub')
|
|
Packit |
6f3914 |
KEYFILE_URL = 'file://%s' % KEYFILE
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class CryptoTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
PUBRING_DIR = None
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@classmethod
|
|
Packit |
6f3914 |
def setUpClass(cls):
|
|
Packit |
6f3914 |
cls.PUBRING_DIR = tempfile.mkdtemp()
|
|
Packit |
6f3914 |
with open(KEYFILE, 'rb') as keyfile:
|
|
Packit |
6f3914 |
keyinfo = dnf.crypto.rawkey2infos(keyfile)[0]
|
|
Packit |
6f3914 |
dnf.yum.misc.import_key_to_pubring(
|
|
Packit |
6f3914 |
keyinfo.raw_key, keyinfo.short_id, gpgdir=cls.PUBRING_DIR,
|
|
Packit |
6f3914 |
make_ro_copy=False)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@classmethod
|
|
Packit |
6f3914 |
def tearDownClass(cls):
|
|
Packit |
6f3914 |
dnf.util.rm_rf(cls.PUBRING_DIR)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_keyids_from_pubring(self):
|
|
Packit |
6f3914 |
ids = dnf.crypto.keyids_from_pubring(self.PUBRING_DIR)
|
|
Packit |
6f3914 |
self.assertIn('24362A8492530C8E', ids)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_printable_fingerprint(self):
|
|
Packit |
6f3914 |
self.assertEqual(dnf.crypto._printable_fingerprint(FINGERPRINT),
|
|
Packit |
6f3914 |
'0BE4 9FAF 9C95 5F4F 1A98 D14B 2436 2A84 9253 0C8E')
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_pubring_dir(self):
|
|
Packit |
6f3914 |
self.assertNotEqual(os.environ.get('GNUPGHOME'), self.PUBRING_DIR)
|
|
Packit |
6f3914 |
with dnf.crypto.pubring_dir(self.PUBRING_DIR):
|
|
Packit |
6f3914 |
self.assertEqual(os.environ['GNUPGHOME'], self.PUBRING_DIR)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_rawkey2infos(self):
|
|
Packit |
6f3914 |
with open(KEYFILE, 'rb') as keyfile:
|
|
Packit |
6f3914 |
info = dnf.crypto.rawkey2infos(keyfile)[0]
|
|
Packit |
6f3914 |
self.assertEqual(info.fingerprint, FINGERPRINT)
|
|
Packit |
6f3914 |
self.assertEqual(info.short_id, '92530C8E')
|
|
Packit |
6f3914 |
self.assertEqual(info.rpm_id, '92530c8e')
|
|
Packit |
6f3914 |
self.assertIn(b'Frmy6HXUL\n', info.raw_key)
|
|
Packit |
6f3914 |
self.assertEqual(info.timestamp, 1408534646)
|
|
Packit |
6f3914 |
self.assertEqual(info.userid, 'Dandy Fied <dnf@example.com>')
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_retrieve(self):
|
|
Packit |
6f3914 |
keyinfos = dnf.crypto.retrieve(KEYFILE_URL)
|
|
Packit |
6f3914 |
self.assertLength(keyinfos, 1)
|
|
Packit |
6f3914 |
keyinfo = keyinfos[0]
|
|
Packit |
6f3914 |
self.assertEqual(keyinfo.url, KEYFILE_URL)
|