def test_create_consumer_payload(self, m_config): local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' repo.repo_obj = Mock(repo_id='bar', display_name='foo') config = {'https_ca': 'pear', 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True} binding_config = {} cert_file = os.path.join(self.working_dir, "orange_file") mock_server_conf = {'server': {'server_name': 'apple'}} m_config.get.side_effect = lambda section, key: mock_server_conf[section][key] with open(cert_file, 'w') as filewriter: filewriter.write("orange") result = local_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'pear', 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } self.assertDictEqual(result, target)
def test_create_consumer_payload(self): local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = {'https_ca': 'pear', 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True} binding_config = {} pulp_server_config.set('server', 'server_name', 'apple') cert_file = os.path.join(self.working_dir, "orange_file") with open(cert_file, 'w') as filewriter: filewriter.write("orange") pulp_server_config.set('security', 'ssl_ca_certificate', cert_file) result = local_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'orange', 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } compare_dict(result, target)
def test_create_consumer_payload_no_https_ca_no_ssl_ca(self, m_config): """Assert if there is no 'https_ca' key and no 'ssl_ca_certificate', None is used.""" local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' repo.repo_obj = Mock(repo_id='bar', display_name='foo') config = { 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True } binding_config = {} mock_server_conf = { 'server': {'server_name': 'apple'}, 'security': {'ssl_ca_certificate': 'this/path/will/get/you/nowhere'} } m_config.get.side_effect = lambda section, key: mock_server_conf[section][key] result = local_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': None, 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } self.assertDictEqual(result, target)
def test_create_consumer_payload_global_auth(self, mock_load_config): test_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = { 'https_ca': 'pear', 'gpgkey': 'kiwi', 'http': True, 'https': True } binding_config = {} pulp_server_config.set('server', 'server_name', 'apple') pulp_server_config.set('security', 'ssl_ca_certificate', 'orange') repo_auth_config = ConfigParser.SafeConfigParser() repo_auth_config.add_section('repos') repo_auth_config.set('repos', 'global_cert_location', self.working_dir) mock_load_config.return_value = repo_auth_config with open(os.path.join(self.working_dir, 'pulp-global-repo.cert'), 'w+') as cert_file: cert_file.write('cert') with open(os.path.join(self.working_dir, 'pulp-global-repo.key'), 'w+') as cert_file: cert_file.write('key') with open(os.path.join(self.working_dir, 'pulp-global-repo.ca'), 'w+') as cert_file: cert_file.write('ca') result = test_distributor.create_consumer_payload( repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'pear', 'relative_path': '/pulp/repos/bar', 'gpg_keys': { 'pulp.key': 'kiwi' }, 'protocols': ['http', 'https'], 'repo_name': 'foo', 'client_cert': None, 'global_auth_cert': 'cert', 'global_auth_key': 'key', 'global_auth_ca': 'ca' } compare_dict(result, target)
def test_create_consumer_payload_global_auth(self, mock_load_config, m_config): test_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' repo.repo_obj = Mock(repo_id='bar', display_name='foo') config = {'https_ca': 'pear', 'gpgkey': 'kiwi', 'http': True, 'https': True} m_config.config = ConfigParser.SafeConfigParser() m_config.config.add_section('server') m_config.config.set('server', 'server_name', 'apple') m_config.config.add_section('security') m_config.config.set('security', 'ssl_ca_certificate', 'orange') binding_config = {} repo_auth_config = ConfigParser.SafeConfigParser() repo_auth_config.add_section('repos') repo_auth_config.set('repos', 'global_cert_location', self.working_dir) mock_load_config.return_value = repo_auth_config with open(os.path.join(self.working_dir, 'pulp-global-repo.cert'), 'w+') as cert_file: cert_file.write('cert') with open(os.path.join(self.working_dir, 'pulp-global-repo.key'), 'w+') as cert_file: cert_file.write('key') with open(os.path.join(self.working_dir, 'pulp-global-repo.ca'), 'w+') as cert_file: cert_file.write('ca') result = test_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'pear', 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'protocols': ['http', 'https'], 'repo_name': 'foo', 'client_cert': None, 'global_auth_cert': 'cert', 'global_auth_key': 'key', 'global_auth_ca': 'ca' } compare_dict(result, target)
def test_distributor_removed(self, mock_http, mock_https, mock_master, remove_cert): mock_http.return_value = os.path.join(self.working_dir, 'http') mock_https.return_value = os.path.join(self.working_dir, 'https') mock_master.return_value = os.path.join(self.working_dir, 'master') os.makedirs(mock_http.return_value) os.makedirs(mock_https.return_value) os.makedirs(mock_master.return_value) os.makedirs(os.path.join(self.working_dir, 'working')) test_distributor = YumHTTPDistributor() repo = Mock() repo.id = 'bar' repo.working_dir = os.path.join(self.working_dir, 'working') config = {} test_distributor.distributor_removed(repo, config) self.assertEquals(0, len(os.listdir(self.working_dir))) remove_cert.assert_called_with(repo, config)
def test_create_consumer_payload(self): local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = { 'https_ca': 'pear', 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True } binding_config = {} cert_file = os.path.join(self.working_dir, "orange_file") with mock_config.patch({ 'server': { 'server_name': 'apple' }, 'security': { 'ssl_ca_certificate': cert_file } }): with open(cert_file, 'w') as filewriter: filewriter.write("orange") result = local_distributor.create_consumer_payload( repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'orange', 'relative_path': '/pulp/repos/bar', 'gpg_keys': { 'pulp.key': 'kiwi' }, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } compare_dict(result, target)