Пример #1
0
    def test_update_share_server_security_service_not_supported(self):
        new_security_service = db_utils.create_security_service()
        current_security_service = db_utils.create_security_service()
        share_server = db_utils.create_share_server()
        share_instances = []
        share_instance_access_rules = []
        network_info = {}

        mock_check_update = self.mock_object(
            self._driver, 'check_update_share_server_security_service',
            mock.Mock(return_value=False))

        self.assertRaises(exception.ManilaException,
                          self._driver.update_share_server_security_service,
                          self._context,
                          share_server,
                          network_info,
                          share_instances,
                          share_instance_access_rules,
                          new_security_service,
                          current_security_service=current_security_service)

        mock_check_update.assert_called_once_with(
            self._context,
            share_server,
            network_info,
            share_instances,
            share_instance_access_rules,
            new_security_service,
            current_security_service=current_security_service)
    def test_update_security_service(self):
        share_server = db_utils.create_share_server()
        current_security_service = db_utils.create_security_service()
        new_security_service = db_utils.create_security_service()

        mock_ldap_bind = self.mock_object(self.security_service_helper,
                                          'ldap_bind')

        self.security_service_helper.update_security_service(
            share_server['id'], current_security_service, new_security_service)

        mock_ldap_bind.assert_called_once_with(share_server['id'],
                                               new_security_service)
Пример #3
0
    def test__check_if_all_fields_are_updatable(self, keys, expected_result):

        current_security_service = db_utils.create_security_service()
        new_security_service = db_utils.create_security_service()

        mock_get_keys = self.mock_object(
            self._driver, '_get_different_security_service_keys',
            mock.Mock(return_value=keys))

        result = self._driver._check_if_all_fields_are_updatable(
            current_security_service, new_security_service)

        self.assertEqual(expected_result, result)
        mock_get_keys.assert_called_once_with(current_security_service,
                                              new_security_service)
    def _setup_test_ldap_bind_tests(self):
        share_server = db_utils.create_security_service()
        security_service = db_utils.create_security_service()
        ldap_get_info = {
            'ss_password': security_service['password'],
            'ss_user': security_service['user']
        }
        expected_cmd = [
            "docker", "exec",
            "%s" % share_server['id'], "ldapwhoami", "-x", "-H",
            "ldap://localhost:389", "-D",
            "cn=%s,dc=example,dc=com" % ldap_get_info["ss_user"], "-w",
            "%s" % ldap_get_info["ss_password"]
        ]

        return share_server, security_service, ldap_get_info, expected_cmd
Пример #5
0
    def test__get_different_security_service_keys(self):
        sec_service_keys = ['dns_ip', 'server', 'domain', 'user', 'password',
                            'ou']
        current_security_service = {}
        [current_security_service.update({key: key + '_1'})
         for key in sec_service_keys]
        new_security_service = {}
        [new_security_service.update({key: key + '_2'})
         for key in sec_service_keys]

        db_utils.create_security_service(**current_security_service)
        db_utils.create_security_service(**new_security_service)

        different_keys = self._driver._get_different_security_service_keys(
            current_security_service, new_security_service)

        [self.assertIn(key, different_keys) for key in sec_service_keys]
Пример #6
0
    def test_update_share_server_security_service(self, with_current_service):
        new_security_service = db_utils.create_security_service()
        current_security_service = (db_utils.create_security_service()
                                    if with_current_service else None)
        share_server = db_utils.create_share_server()
        fake_container_name = 'fake_name'
        network_info = {}
        share_instances = []
        share_instance_access_rules = []

        mock_check_update = self.mock_object(
            self._driver, 'check_update_share_server_security_service',
            mock.Mock(return_value=True))
        mock_get_container_name = self.mock_object(
            self._driver, '_get_container_name',
            mock.Mock(return_value=fake_container_name))
        mock_setup = self.mock_object(self._driver, 'setup_security_services')
        mock_update_sec_service = self.mock_object(
            self._driver.security_service_helper, 'update_security_service')

        self._driver.update_share_server_security_service(
            self._context,
            share_server,
            network_info,
            share_instances,
            share_instance_access_rules,
            new_security_service,
            current_security_service=current_security_service)

        mock_check_update.assert_called_once_with(
            self._context,
            share_server,
            network_info,
            share_instances,
            share_instance_access_rules,
            new_security_service,
            current_security_service=current_security_service)
        mock_get_container_name.assert_called_once_with(share_server['id'])
        if with_current_service:
            mock_update_sec_service.assert_called_once_with(
                fake_container_name, current_security_service,
                new_security_service)
        else:
            mock_setup.assert_called_once_with(fake_container_name,
                                               [new_security_service])
    def test_ldap_get_info(self):
        security_service = db_utils.create_security_service()
        expected_ldap_get_info = {
            'ss_password': security_service['password'],
            'ss_user': security_service['user']
        }

        ldap_get_info = self.security_service_helper.ldap_get_info(
            security_service)

        self.assertEqual(expected_ldap_get_info, ldap_get_info)