def test_unset_mutable_property(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') incoming_repo = {'metadata_expire': 2000} update_action.update_repo(existing_repo, incoming_repo) self.assertEqual(2000, existing_repo['metadata_expire'])
def test_update_when_repo_not_modified_on_mutable(self, mock_file): self._inject_mock_invalid_consumer() mock_file = mock_file.return_value modified_repo = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) server_repo = Repo('x', [('gpgcheck', 'original')]) mock_file.section = MagicMock(side_effect=[modified_repo, server_repo]) def stub_content(): return [ Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key'), ('name', 'test')]) ] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content current = update_action.perform() # confirming that the assessed value does change when repo file # is the same as the server value file. self.assertEqual('new', current.repo_updates[0]['gpgcheck']) # this is the ending server value file. written_repo = mock_file.update.call_args[0][0] self.assertEqual('new', written_repo['gpgcheck']) self.assertEqual(None, written_repo['gpgkey'])
def test_only_allow_content_of_type_yum(self): update_action = RepoUpdateActionCommand() content = update_action.get_all_content(baseurl="http://example.com", ca_cert=None) self.assertTrue(self._find_content(content, "c1") is not None) self.assertTrue(self._find_content(content, "c5") is None) self.assertTrue(self._find_content(content, "c6") is None)
def test_update_when_repo_modified_on_mutable(self, mock_get_repo_file_classes): self._inject_mock_invalid_consumer() modified_repo = Repo('x', [('gpgcheck', 'unoriginal'), ('gpgkey', 'some_key')]) server_repo = Repo('x', [('gpgcheck', 'original')]) mock_file = MagicMock() mock_file.CONTENT_TYPES = [None] mock_file.fix_content = lambda x: x mock_file.section.side_effect = [modified_repo, server_repo] mock_class = MagicMock(return_value=mock_file) mock_get_repo_file_classes.return_value = [(mock_class, mock_class)] def stub_content(): return [Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key'), ('name', 'test')])] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content current = update_action.perform() # confirming that the assessed value does not change when repo file # is different from the server value file. self.assertEqual('unoriginal', current.repo_updates[0]['gpgcheck']) # this is the ending server value file written_repo = mock_file.update.call_args[0][0] self.assertEqual('new', written_repo['gpgcheck']) self.assertEqual(None, written_repo['gpgkey'])
def test_unset_immutable_property(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') incoming_repo = {'name': "woof"} update_action.update_repo(existing_repo, incoming_repo) self.assertEqual("woof", existing_repo['name'])
def test_ui_repoid_vars(self): update_action = RepoUpdateActionCommand() content = update_action.get_content(self.stub_ent_cert, "http://example.com", None) c4 = self._find_content(content, 'c4') self.assertEquals('some path', c4['ui_repoid_vars']) c2 = self._find_content(content, 'c2') self.assertEquals(None, c2['ui_repoid_vars'])
def test_gpg_key(self): update_action = RepoUpdateActionCommand() content = update_action.get_content(self.stub_ent_cert, "http://example.com", None) c4 = self._find_content(content, 'c4') self.assertEquals('http://example.com/gpg.key', c4['gpgkey']) self.assertEquals('1', c4['gpgcheck'])
def test_gpgcheck_is_mutable(self): update_action = RepoUpdateActionCommand() self._inject_mock_invalid_consumer() existing_repo = Repo('testrepo') existing_repo['gpgcheck'] = "0" incoming_repo = {'gpgcheck': "1"} update_action.update_repo(existing_repo, incoming_repo) self.assertEqual("0", existing_repo['gpgcheck'])
def test_gpg_key(self): update_action = RepoUpdateActionCommand() content = update_action.get_all_content(baseurl="http://example.com", ca_cert=None) c4 = self._find_content(content, 'c4') self.assertEqual('http://example.com/gpg.key', c4['gpgkey']) self.assertEqual('1', c4['gpgcheck'])
def test_overrides_trump_ent_cert(self): update_action = RepoUpdateActionCommand() update_action.overrides = {'x': {'gpgcheck': 'blah'}} r = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) self.assertEqual('original', r['gpgcheck']) update_action._set_override_info(r) self.assertEqual('blah', r['gpgcheck']) self.assertEqual('some_key', r['gpgkey'])
def test_ui_repoid_vars(self): update_action = RepoUpdateActionCommand() content = update_action.get_all_content(baseurl="http://example.com", ca_cert=None) c4 = self._find_content(content, 'c4') self.assertEqual('some path', c4['ui_repoid_vars']) c2 = self._find_content(content, 'c2') self.assertEqual(None, c2['ui_repoid_vars'])
def test_mutable_property_in_repo_but_not_in_cert(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') existing_repo['metadata_expire'] = 1000 incoming_repo = {} update_action.update_repo(existing_repo, incoming_repo) self.assertEqual(1000, existing_repo['metadata_expire'])
def test_set_immutable_property_now_empty(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') existing_repo['proxy_username'] = "******" incoming_repo = {} update_action.update_repo(existing_repo, incoming_repo) self.assertFalse("proxy_username" in list(existing_repo.keys()))
def test_mutable_property_is_server(self): update_action = RepoUpdateActionCommand() self._inject_mock_invalid_consumer() existing_repo = Repo('testrepo') server_val_repo = Repo('servertestrepo') existing_repo['metadata_expire'] = 1000 server_val_repo['metadata_expire'] = 1000 incoming_repo = {'metadata_expire': 2000} update_action.update_repo(existing_repo, incoming_repo, server_val_repo) self.assertEqual(2000, existing_repo['metadata_expire'])
def test_repo_update_forbidden_when_registered(self): existing_repo = Repo('testrepo') existing_repo['proxy_username'] = "******" incoming_repo = {'proxy_username': '******'} update_action = RepoUpdateActionCommand() update_action.override_supported = True self.assertRaises(UnsupportedOperationException, update_action.update_repo, existing_repo, incoming_repo)
def test_set_immutable_property_now_not_in_cert(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') existing_repo['proxy_username'] = "******" incoming_repo = {} update_action.update_repo(existing_repo, incoming_repo) # Immutable properties should be always be added/updated, # and removed if undefined in the new repo definition. self.assertFalse("proxy_username" in list(existing_repo.keys()))
def test_overrides_trump_existing(self): update_action = RepoUpdateActionCommand() update_action.overrides = {'x': {'gpgcheck': 'blah'}} values = [('gpgcheck', 'original'), ('gpgkey', 'some_key')] old_repo = Repo('x', values) new_repo = Repo(old_repo.id, values) update_action._set_override_info(new_repo) self.assertEqual('original', old_repo['gpgcheck']) update_action.update_repo(old_repo, new_repo) self.assertEqual('blah', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
def test_set_mutable_property_now_not_in_cert(self): self._inject_mock_invalid_consumer() update_action = RepoUpdateActionCommand() existing_repo = Repo('testrepo') existing_repo['metadata_expire'] = "blah" incoming_repo = {} update_action.update_repo(existing_repo, incoming_repo) # re comments in repolib # Mutable properties should be added if not currently defined, # otherwise left alone. self.assertTrue("metadata_expire" in list(existing_repo.keys()))
def test_no_gpg_key(self): update_action = RepoUpdateActionCommand() content = update_action.get_content(self.stub_ent_cert, "http://example.com", None) c1 = self._find_content(content, 'c1') self.assertEquals('', c1['gpgkey']) self.assertEquals('0', c1['gpgcheck']) c2 = self._find_content(content, 'c2') self.assertEquals('', c2['gpgkey']) self.assertEquals('0', c2['gpgcheck'])
def test_no_gpg_key(self): update_action = RepoUpdateActionCommand() content = update_action.get_all_content(baseurl="http://example.com", ca_cert=None) c1 = self._find_content(content, 'c1') self.assertEqual('', c1['gpgkey']) self.assertEqual('0', c1['gpgcheck']) c2 = self._find_content(content, 'c2') self.assertEqual('', c2['gpgkey']) self.assertEqual('0', c2['gpgcheck'])
def test_overrides_trump_ent_cert(self): update_action = RepoUpdateActionCommand() update_action.overrides = [{ 'contentLabel': 'x', 'name': 'gpgcheck', 'value': 'blah' }] r = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) self.assertEquals('original', r['gpgcheck']) update_action._set_override_info(r) self.assertEquals('blah', r['gpgcheck']) self.assertEquals('some_key', r['gpgkey'])
def test_non_default_overrides_added_to_existing(self): ''' Test that overrides for values that aren't found in Repo.PROPERTIES are written to existing repos ''' update_action = RepoUpdateActionCommand() update_action.written_overrides.overrides = {} update_action.overrides = {'x': {'somekey': 'someval'}} old_repo = Repo('x', []) new_repo = Repo(old_repo.id, []) update_action._set_override_info(new_repo) update_action.update_repo(old_repo, new_repo) self.assertEqual('someval', old_repo['somekey'])
def test_non_default_override_removed_deleted(self): ''' Test that overrides for values that aren't found in Repo.PROPERTIES are removed from redhat.repo once the override is removed ''' update_action = RepoUpdateActionCommand() update_action.written_overrides.overrides = {'x': {'somekey': 'someval'}} update_action.overrides = {} old_repo = Repo('x', [('somekey', 'someval')]) new_repo = Repo(old_repo.id, []) update_action._set_override_info(new_repo) update_action.update_repo(old_repo, new_repo) self.assertFalse('somekey' in old_repo)
def test_overrides_removed_revert_to_default(self): update_action = RepoUpdateActionCommand() update_action.written_overrides.overrides = {'x': {'gpgcheck': 'blah'}} update_action.overrides = {} old_repo = Repo('x', [('gpgcheck', 'blah'), ('gpgkey', 'some_key')]) new_repo = Repo(old_repo.id, [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) update_action._set_override_info(new_repo) # The value from the current repo file (with the old override) should exist pre-update self.assertEqual('blah', old_repo['gpgcheck']) update_action.update_repo(old_repo, new_repo) # Because the override has been removed, the value is reset to the default self.assertEqual('original', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
def test_overrides_removed_and_edited(self): update_action = RepoUpdateActionCommand() update_action.written_overrides.overrides = {'x': {'gpgcheck': 'override_value'}} update_action.overrides = {} old_repo = Repo('x', [('gpgcheck', 'hand_edit'), ('gpgkey', 'some_key')]) new_repo = Repo(old_repo.id, [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) update_action._set_override_info(new_repo) # The value from the current repo file (with the old hand edit) should exist pre-update self.assertEqual('hand_edit', old_repo['gpgcheck']) update_action.update_repo(old_repo, new_repo) # Because the current value doesn't match the override, we don't modify it self.assertEqual('hand_edit', old_repo['gpgcheck']) self.assertEqual('some_key', old_repo['gpgkey'])
def test_update_when_new_repo(self, mock_file): mock_file = mock_file.return_value mock_file.section.return_value = None def stub_content(): return [Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')])] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content update_report = update_action.perform() written_repo = mock_file.add.call_args[0][0] self.assertEquals('original', written_repo['gpgcheck']) self.assertEquals('some_key', written_repo['gpgkey']) self.assertEquals(1, update_report.updates())
def test_update_when_not_registered_and_existing_repo(self, mock_file): self._inject_mock_invalid_consumer() mock_file = mock_file.return_value mock_file.section.return_value = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) def stub_content(): return [Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key'), ('name', 'test')])] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content update_action.perform() written_repo = mock_file.update.call_args[0][0] self.assertEquals('original', written_repo['gpgcheck']) self.assertEquals('new_key', written_repo['gpgkey'])
def test_update_when_registered_and_existing_repo(self, mock_file): mock_file = mock_file.return_value mock_file.section.return_value = Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')]) def stub_content(): return [Repo('x', [('gpgcheck', 'new'), ('gpgkey', 'new_key')])] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content update_action.override_supported = True update_report = update_action.perform() written_repo = mock_file.update.call_args[0][0] self.assertEquals('new', written_repo['gpgcheck']) self.assertEquals('new_key', written_repo['gpgkey']) self.assertEquals(1, update_report.updates())
def test_update_when_new_repo(self, mock_get_repo_files): mock_file = MagicMock() mock_file.CONTENT_TYPES = [None] mock_file.fix_content = lambda x: x mock_file.section.return_value = None mock_get_repo_files.return_value = [(mock_file, mock_file)] def stub_content(): return [Repo('x', [('gpgcheck', 'original'), ('gpgkey', 'some_key')])] update_action = RepoUpdateActionCommand() update_action.get_unique_content = stub_content update_report = update_action.perform() written_repo = mock_file.add.call_args[0][0] self.assertEqual('original', written_repo['gpgcheck']) self.assertEqual('some_key', written_repo['gpgkey']) self.assertEqual(1, update_report.updates())
def test_override_cache_update_skipped_when_overrides_not_supported_on_server(self): inj.provide(inj.OVERRIDE_STATUS_CACHE, Mock()) override_cache_mock = inj.require(inj.OVERRIDE_STATUS_CACHE) mock_uep = Mock() mock_uep.supports_resource = Mock(return_value=False) mock_uep.getCertificates = Mock(return_value=[]) mock_uep.getCertificateSerials = Mock(return_value=[]) mock_uep.getRelease = Mock(return_value={'releaseVer': "dummyrelease"}) self.set_consumer_auth_cp(mock_uep) RepoUpdateActionCommand() # No cache calls should be made if overrides are not supported self.assertFalse(override_cache_mock.read_cache.called) self.assertFalse(override_cache_mock.load_status.called)