コード例 #1
0
 def remote_add_service_description(ss_api_config, security_server_conf, client_conf, service_description_conf):
     code = service_description_conf['rest_service_code'] if service_description_conf['rest_service_code'] else None
     description_add = ServiceDescriptionAdd(url=service_description_conf['url'],
                                             rest_service_code=code,
                                             ignore_warnings=True,
                                             type=service_description_conf['type'])
     clients_api = ClientsApi(ApiClient(ss_api_config))
     try:
         client_controller = ClientController()
         client = client_controller.find_client(clients_api, security_server_conf, client_conf)
         if client:
             try:
                 response = clients_api.add_client_service_description(client.id, body=description_add)
                 if response:
                     BaseController.log_info("Added service description with type '" + response.type + "' and url '" + response.url +
                                             "' (got full id " + response.id + ")")
             except ApiException as err:
                 if err.status == 409:
                     BaseController.log_info(ServiceController.SERVICE_DESCRIPTION_FOR + "'" + client_controller.partial_client_id(client_conf) +
                                             "' with url '" + description_add.url +
                                             "' and type '" + description_add.type + "' already exists.")
                 else:
                     BaseController.log_api_error('ClientsApi->add_client_service_description', err)
     except ApiException as find_err:
         BaseController.log_api_error(ClientController.CLIENTS_API_FIND_CLIENTS, find_err)
コード例 #2
0
 def remote_add_service_endpoints(self, ss_api_config, security_server_conf,
                                  client_conf, service_description_conf,
                                  endpoint_conf):
     try:
         clients_api = ClientsApi(ApiClient(ss_api_config))
         client_controller = ClientController()
         client = client_controller.find_client(clients_api,
                                                security_server_conf,
                                                client_conf)
         if client:
             try:
                 service_description = ServiceController(
                 ).get_client_service_description(clients_api, client,
                                                  service_description_conf)
                 if service_description:
                     if service_description.type == ServiceType().WSDL:
                         BaseController.log_info(
                             "Wrong service description, endpoints for WSDL services are not"
                             " allowed, skipped endpoint creation " +
                             EndpointController.FOR_SERVICE + "'" +
                             service_description.url + "'")
                     else:
                         self.remote_add_endpoint(ss_api_config,
                                                  service_description,
                                                  service_description_conf,
                                                  endpoint_conf)
             except ApiException as find_err:
                 BaseController.log_api_error(
                     ClientController.
                     CLIENTS_API_GET_CLIENT_SERVICE_DESCRIPTION, find_err)
     except ApiException as find_err:
         BaseController.log_api_error(
             ClientController.CLIENTS_API_FIND_CLIENTS, find_err)
コード例 #3
0
 def remote_add_endpoints_access(self, ss_api_config, security_server_conf,
                                 client_conf, service_description_conf):
     try:
         client_controller = ClientController()
         clients_api = ClientsApi(ApiClient(ss_api_config))
         client = client_controller.find_client(clients_api,
                                                security_server_conf,
                                                client_conf)
         if client:
             service_clients_candidates = client_controller.get_clients_service_client_candidates(
                 clients_api, client.id, [])
             try:
                 service_controller = ServiceController()
                 clients_api = ClientsApi(ApiClient(ss_api_config))
                 service_description = service_controller.get_client_service_description(
                     clients_api, client, service_description_conf)
                 if service_description.type != ServiceType().WSDL:
                     self.remote_add_endpoint_access(
                         ss_api_config, service_description,
                         service_description_conf,
                         service_clients_candidates)
             except ApiException as find_err:
                 BaseController.log_api_error(
                     ClientController.
                     CLIENTS_API_GET_CLIENT_SERVICE_DESCRIPTION, find_err)
     except ApiException as find_err:
         BaseController.log_api_error(
             ClientController.CLIENTS_API_FIND_CLIENTS, find_err)
コード例 #4
0
 def remote_update_service_parameters(self, ss_api_config, security_server_conf, client_conf, service_description_conf):
     clients_api = ClientsApi(ApiClient(ss_api_config))
     try:
         client_controller = ClientController()
         client = client_controller.find_client(clients_api, security_server_conf, client_conf)
         if client:
             try:
                 service_description = self.get_client_service_description(clients_api, client, service_description_conf)
                 if service_description:
                     for service in service_description.services:
                         self.remote_update_service_parameter(ss_api_config, service_description_conf, service)
             except ApiException as find_err:
                 BaseController.log_api_error(ClientController.CLIENTS_API_GET_CLIENT_SERVICE_DESCRIPTION, find_err)
     except ApiException as find_err:
         BaseController.log_api_error(ClientController.CLIENTS_API_FIND_CLIENTS, find_err)
コード例 #5
0
    def test_client_add_new_member(self):
        with XRDSSTTest() as app:
            new_config = copy.deepcopy(self.ss_config)
            new_config["security_server"][0]["clients"].append({
                'member_class':
                'NEW_GOV',
                'member_code':
                '1111',
                'member_name':
                'NEW_TEST',
                'connection_type':
                'HTTPS'
            })

            with mock.patch('xrdsst.api.clients_api.ClientsApi.add_client',
                            return_value=ClientTestData.add_response):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: new_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.add()

                out, err = self.capsys.readouterr()
                assert out.count("Added client") > 0
                with self.capsys.disabled():
                    sys.stdout.write(out)
                    sys.stderr.write(err)
コード例 #6
0
    def test_client_register_already_registered(self):
        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.clients_api.ClientsApi.find_clients',
                            return_value=[
                                Client(id='DEV:GOV:9876:SUB1',
                                       instance_id='DEV',
                                       member_class='GOV',
                                       member_code='9876',
                                       member_name='TEST',
                                       subsystem_code='SUB1',
                                       connection_type=ConnectionType.HTTP,
                                       status=ClientStatus.REGISTERED,
                                       owner=True,
                                       has_valid_local_sign_cert=True)
                            ]):
                with mock.patch(
                        'xrdsst.api.clients_api.ClientsApi.register_client',
                        return_value=None):
                    client_controller = ClientController()
                    client_controller.app = app
                    client_controller.load_config = (lambda: self.ss_config)
                    client_controller.get_server_status = (
                        lambda x, y: StatusTestData.
                        server_status_essentials_complete)
                    client_controller.register()

                    out, err = self.capsys.readouterr()
                    assert out.count("already registered") > 0

                    with self.capsys.disabled():
                        sys.stdout.write(out)
                        sys.stderr.write(err)
コード例 #7
0
    def test_client_add_already_existing(self):
        class AlreadyExistingResponse:
            status = 409
            data = '{"status":409,"error":{"code":"certificate_already_exists"}}'
            reason = None

            def getheaders(self):
                return None

        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.clients_api.ClientsApi.add_client',
                            side_effect=ApiException(
                                http_resp=AlreadyExistingResponse())):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: self.ss_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.add()

                out, err = self.capsys.readouterr()
                assert out.count("already exists") > 0

                with self.capsys.disabled():
                    sys.stdout.write(out)
                    sys.stderr.write(err)
コード例 #8
0
 def step_subsystem_register(self):
     with XRDSSTTest() as app:
         client_controller = ClientController()
         client_controller.app = app
         for security_server in self.config["security_server"]:
             configuration = client_controller.create_api_config(security_server, self.config)
             for client in security_server["clients"]:
                 client_controller.remote_register_client(configuration, security_server, client)
コード例 #9
0
 def remote_enable_service_description(self, ss_api_config, security_server_conf, client_conf, service_description_conf):
     clients_api = ClientsApi(ApiClient(ss_api_config))
     service_descriptions_api = ServiceDescriptionsApi(ApiClient(ss_api_config))
     try:
         client_controller = ClientController()
         client = client_controller.find_client(clients_api, security_server_conf, client_conf)
         if client:
             try:
                 service_description = self.get_client_service_description(clients_api, client, service_description_conf)
                 if service_description:
                     try:
                         service_descriptions_api.enable_service_description(service_description.id)
                         BaseController.log_info(ServiceController.SERVICE_DESCRIPTION_FOR + "'" + client_controller.partial_client_id(client_conf) +
                                                 "' with id: '" + service_description.id + "' enabled successfully.")
                     except ApiException as err:
                         if err.status == 409:
                             BaseController.log_info(ServiceController.SERVICE_DESCRIPTION_FOR + "'" + client_controller.partial_client_id(client_conf) +
                                                     "' with id: '" + service_description.id + "' already enabled.")
                         else:
                             BaseController.log_api_error('ServiceDescriptionsApi->enable_service_description', err)
             except ApiException as find_err:
                 BaseController.log_api_error(ClientController.CLIENTS_API_GET_CLIENT_SERVICE_DESCRIPTION, find_err)
     except ApiException as find_err:
         BaseController.log_api_error(ClientController.CLIENTS_API_FIND_CLIENTS, find_err)
コード例 #10
0
 def step_subsystem_update_parameters(self):
     with XRDSSTTest() as app:
         client_controller = ClientController()
         client_controller.app = app
         client = get_client(self.config)
         assert client["connection_type"] == 'HTTP'
         self.config["security_server"][0]["clients"][0][
             "connection_type"] = 'HTTPS'
         client_controller.load_config = (lambda: self.config)
         client_controller.update()
         client = get_client(self.config)
         assert client["connection_type"] == 'HTTPS'
         self.config["security_server"][0]["clients"][0][
             "connection_type"] = 'HTTP'
コード例 #11
0
    def test_client_register_not_found(self):
        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.clients_api.ClientsApi.find_clients',
                            return_value=[]):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: self.ss_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.register()

                out, err = self.capsys.readouterr()
                assert out.count("not found") > 0

                with self.capsys.disabled():
                    sys.stdout.write(out)
                    sys.stderr.write(err)
コード例 #12
0
    def test_subsystem_add(self):
        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.clients_api.ClientsApi.add_client',
                            return_value=ClientTestData.add_response):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: self.ss_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.add()

                out, err = self.capsys.readouterr()
                assert out.count("Added client") > 0

                with self.capsys.disabled():
                    sys.stdout.write(out)
                    sys.stderr.write(err)
コード例 #13
0
    def step_subsystem_update_parameters(self):
        with XRDSSTTest() as app:
            client_controller = ClientController()
            client_controller.app = app

            client = get_client(self.config)
            assert client["connection_type"] == 'HTTP'
            self.config["security_server"][0]["clients"][0]["connection_type"] = 'HTTPS'

            for security_server in self.config["security_server"]:
                configuration = client_controller.create_api_config(security_server, self.config)
                for client in security_server["clients"]:
                    client_controller.remote_update_client(configuration, security_server, client)

            client = get_client(self.config)
            assert client["connection_type"] == 'HTTPS'
            self.config["security_server"][0]["clients"][0]["connection_type"] = 'HTTP'
コード例 #14
0
 def step_subsystem_add_client(self):
     with XRDSSTTest() as app:
         client_controller = ClientController()
         client_controller.app = app
         client_controller.load_config = (lambda: self.config)
         client_controller.add()
コード例 #15
0
    def test_registration_disabled_at_management_services_provider(self):
        class ServerProxyHasServiceDisabledResponse:
            status = 500
            data = '{"status":500,"error":{"code":"core.Server.ServerProxy.ServiceDisabled","metadata":["Service SERVICE:DEV/GOV/9876/MANAGEMENT/clientReg is disabled: BOFH"]}}'
            reason = ''

            def getheaders(self):
                headers = HTTPHeaderDict()
                headers.add('x-road-ui-correlation-id', 'ddddaaaa0011ffff')
                headers.add('Content-Type', 'application/json')

                return headers

            @staticmethod
            def as_extended_exception():
                api_ex = ApiException(
                    http_resp=ServerProxyHasServiceDisabledResponse())
                api_ex.api_call = {
                    'method': 'PUT',
                    'resource_path': '/clients/{id}/register',
                    'path_params': 'GOV:9876:SUB1',
                    'query_params': '',
                    'header_params': '',
                    'controller_func': 'client.py#remote_register_client',
                    'module_func': 'clients_api.py#register_client'
                }

                return api_ex

        with XRDSSTTest() as app:
            with mock.patch(
                    'xrdsst.api.clients_api.ClientsApi.register_client',
                    side_effect=ServerProxyHasServiceDisabledResponse.
                    as_extended_exception()):
                client_controller = ClientController()
                client_controller.app = app
                client_controller.load_config = (lambda: self.ss_config)
                client_controller.get_server_status = (
                    lambda x, y: StatusTestData.
                    server_status_essentials_complete)
                client_controller.register()

                out, err = self.capsys.readouterr()
                assert err.count("FAILED") > 0
                assert err.count(
                    "PUT /clients/{id}/register @ clients_api.py#register_client <- client.py#remote_register_client"
                ) == 2
                assert err.count("INTERNAL_SERVER_ERROR (500)") == 2
                assert err.count(
                    "error_code 'core.Server.ServerProxy.ServiceDisabled'"
                ) == 2
                assert err.count(
                    "Service SERVICE:DEV/GOV/9876/MANAGEMENT/clientReg is disabled: BOFH"
                ) == 2
                assert err.count(
                    server_error_map.get(
                        'core.Server.ServerProxy.ServiceDisabled')) == 2

                assert err.count(ascii_art['message_flow'][2]) == 2
                assert err.count(ascii_art['message_flow'][3]) == 2
                assert err.count(ascii_art['message_flow'][4]) == 2