def test_inequality(self): kp = KeyPair("/etc/pki/entitlement/9000.pem", "/etc/pki/entitlement/9000-key.pem") kp2 = KeyPair("/etc/pki/entitlement/9001.pem", "/etc/pki/entitlement/9001-key.pem") self.assertNotEqual(kp, kp2) self.assertNotEqual(kp, "somestring")
def test_all_together_now(self): cert1 = '1234.pem' key1 = '1234-key.pem' cert2 = '12345.pem' key2 = '12345-key.pem' old_cert = '444.cert' old_key = '444.key' old_key2 = 'another.key' self._touch(self.src_certs_dir, cert1) self._touch(self.src_certs_dir, key1) self._touch(self.src_certs_dir, cert2) self._touch(self.src_certs_dir, key2) self._touch(self.dest_dir, old_cert) self._touch(self.dest_dir, old_key) self._touch(self.dest_dir, old_key2) kp = KeyPair(join(self.src_certs_dir, cert1), join(self.src_certs_dir, key1)) kp2 = KeyPair(join(self.src_certs_dir, cert2), join(self.src_certs_dir, key2)) self.container_dir.sync([kp, kp2]) self.assertTrue(exists(join(self.dest_dir, '1234.cert'))) self.assertTrue(exists(join(self.dest_dir, '1234.key'))) self.assertTrue(exists(join(self.dest_dir, '12345.cert'))) self.assertTrue(exists(join(self.dest_dir, '12345.key'))) self.assertFalse(exists(join(self.dest_dir, '444.cert'))) self.assertFalse(exists(join(self.dest_dir, '444.key'))) self.assertEqual(4, len(self.report.added)) self.assertEqual(3, len(self.report.removed))
def test_cdn_ca_symlink_already_exists(self): cert1 = '1234.pem' key1 = '1234-key.pem' self._touch(self.src_certs_dir, cert1) self._touch(self.src_certs_dir, key1) kp = KeyPair(join(self.src_certs_dir, cert1), join(self.src_certs_dir, key1)) self.container_dir.sync([kp]) expected_symlink = join(self.dest_dir, "%s.crt" % os.path.splitext(CA_NAME)[0]) # Run it again, the symlink already exists: with mock.patch("os.symlink") as mock_link: with mock.patch("os.path.exists") as mock_exists: # Make the real os.path.exists call unless the module is asking # about the symlink which should already exist in this test def side_effects(path): if path == expected_symlink: return True return os.path.exists(path) mock_exists.side_effects = side_effects self.container_dir.sync([kp]) self.assertFalse(mock_link.called)
def test_first_install(self): cert1 = '1234.pem' key1 = '1234-key.pem' self._touch(self.src_certs_dir, cert1) self._touch(self.src_certs_dir, key1) kp = KeyPair(join(self.src_certs_dir, cert1), join(self.src_certs_dir, key1)) self.container_dir.sync([kp]) self.assertTrue(exists(join(self.dest_dir, '1234.cert'))) self.assertTrue(exists(join(self.dest_dir, '1234.key'))) self.assertEqual(2, len(self.report.added))
def test_cdn_ca_symlink(self, mock_link): cert1 = '1234.pem' key1 = '1234-key.pem' self._touch(self.src_certs_dir, cert1) self._touch(self.src_certs_dir, key1) kp = KeyPair(join(self.src_certs_dir, cert1), join(self.src_certs_dir, key1)) self.container_dir.sync([kp]) expected_symlink = join(self.dest_dir, "%s.crt" % os.path.splitext(CA_NAME)[0]) mock_link.assert_called_once_with(RH_CDN_CA, expected_symlink)
def test_unique_paths_with_dupes(self): cert1 = self._mock_cert('5001') cert2 = self._mock_cert('5002') cert3 = self._mock_cert('5003') content1 = self._create_content('content1', cert1) content2 = self._create_content('content2', cert1) content3 = self._create_content('content3', cert2) # This content is provided by two other certs: content1_dupe = self._create_content('content1', cert2) content1_dupe2 = self._create_content('content1', cert3) contents = [ content1, content2, content3, content1_dupe, content1_dupe2 ] cmd = ContainerContentUpdateActionCommand(None, ['cdn.example.org'], self.host_cert_dir) cert_paths = cmd._get_unique_paths(contents) self.assertEqual(3, len(cert_paths)) self.assertTrue(KeyPair(cert1.path, cert1.key_path()) in cert_paths) self.assertTrue(KeyPair(cert2.path, cert2.key_path()) in cert_paths) self.assertTrue(KeyPair(cert3.path, cert3.key_path()) in cert_paths)
def test_cdn_ca_doesnt_exist_no_symlink(self): cert1 = '1234.pem' key1 = '1234-key.pem' self._touch(self.src_certs_dir, cert1) self._touch(self.src_certs_dir, key1) kp = KeyPair(join(self.src_certs_dir, cert1), join(self.src_certs_dir, key1)) # Mock that /etc/rhsm/ca/redhat-entitlement-authority.pem doesn't exist: self.container_dir._rh_cdn_ca_exists = mock.Mock(return_value=False) self.container_dir.sync([kp]) expected_symlink = join(self.dest_dir, "%s.crt" % os.path.splitext(CA_NAME)[0]) self.assertFalse(exists(expected_symlink))
def test_mixmatched_base_filenames(self): kp = KeyPair("/etc/pki/entitlement/9000.1.2014-a.pem", "/etc/pki/entitlement/9000.1.2014-a-key.pem") self.assertEqual("9000.1.2014-a.cert", kp.dest_cert_filename) self.assertEqual("9000.1.2014-a.key", kp.dest_key_filename)
def test_equality(self): kp = KeyPair("/etc/pki/entitlement/9000.pem", "/etc/pki/entitlement/9000-key.pem") kp2 = KeyPair("/etc/pki/entitlement/9000.pem", "/etc/pki/entitlement/9000-key.pem") self.assertEqual(kp, kp2)
def test_expected_filenames_weird_filenames(self): kp = KeyPair("/etc/pki/entitlement/9000.1.2014-a.pem", "/etc/pki/entitlement/9000.1.2014-a-key.pem") self.assertEqual("9000.1.2014-a.cert", kp.dest_cert_filename) self.assertEqual("9000.1.2014-a.key", kp.dest_key_filename)
def test_expected_filenames_weird_extensions(self): kp = KeyPair("/etc/pki/entitlement/9000.crt", "/etc/pki/entitlement/9000-key.crt") self.assertEqual("9000.cert", kp.dest_cert_filename) self.assertEqual("9000.key", kp.dest_key_filename)