def step_add_endpoints_access(self, client_id): endpoint_controller = EndpointController() for security_server in self.config["security_server"]: configuration = endpoint_controller.create_api_config(security_server, self.config) for client in security_server["clients"]: if "service_descriptions" in client: for service_description in client["service_descriptions"]: endpoint_controller.remote_add_endpoints_access(configuration, service_description, client, service_description) description = get_service_description(self.config, client_id) service_clients = get_endpoint_service_clients(self.config, description["services"][0]["endpoints"][4]["id"]) assert len(service_clients) == 1 assert str(service_clients[0]["id"]) == "DEV:security-server-owners"
def step_add_service_endpoints(self, client_id): endpoint_controller = EndpointController() for security_server in self.config["security_server"]: configuration = endpoint_controller.create_api_config(security_server, self.config) for client in security_server["clients"]: if "service_descriptions" in client: for service_description in client["service_descriptions"]: if "endpoints" in service_description: for endpoint in service_description["endpoints"]: endpoint_controller.remote_add_service_endpoints(configuration, security_server, client, service_description, endpoint) description = get_service_description(self.config, client_id) assert len(description["services"][0]["endpoints"]) == 5 assert str(description["services"][0]["endpoints"][4]["path"]) == "/testPath" assert str(description["services"][0]["endpoints"][4]["method"]) == "POST"
def test_endpoint_add_access_already_added(self): class AlreadyEnabledResponse: status = 409 data = '{"status":409,"error":{"code":"service_endpoint_already_enabled"}}' reason = None def getheaders(self): return None 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', 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.get_client_service_descriptions', return_value=[ EndpointTestData.add_description_response ]): with mock.patch( 'xrdsst.api.clients_api.ClientsApi.find_service_client_candidates', return_value=[ ServiceClient( id='DEV:security-server-owners', name='Security server owners', local_group_code=None, service_client_type=ServiceClientType. GLOBALGROUP, rights_given_at=datetime.now().isoformat()) ]): with mock.patch( 'xrdsst.api.endpoints_api.EndpointsApi.add_endpoint_service_clients', side_effect=ApiException( http_resp=AlreadyEnabledResponse())): endpoint_controller = EndpointController() endpoint_controller.app = app endpoint_controller.load_config = ( lambda: self.ss_config) endpoint_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) endpoint_controller.add_access() out, err = self.capsys.readouterr() assert out.count("already added") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
def test_endpoint_add_access_endpoint_not_found(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', subsystem_code='SUB1', connection_type=ConnectionType.HTTP, status=ClientStatus.REGISTERED, owner=True, has_valid_local_sign_cert=True) ]): service_description = copy.deepcopy( EndpointTestData.add_description_response) service_description.services[0].endpoints[0].method = 'GET' with mock.patch( 'xrdsst.api.clients_api.ClientsApi.get_client_service_descriptions', return_value=[service_description]): with mock.patch( 'xrdsst.api.clients_api.ClientsApi.find_service_client_candidates', return_value=[ ServiceClient( id='DEV:security-server-owners', name='Security server owners', local_group_code=None, service_client_type=ServiceClientType. GLOBALGROUP, rights_given_at=datetime.now().isoformat()) ]): with mock.patch( 'xrdsst.api.endpoints_api.EndpointsApi.add_endpoint_service_clients', return_value=EndpointTestData. add_access_response): endpoint_controller = EndpointController() endpoint_controller.app = app endpoint_controller.load_config = ( lambda: self.ss_config) endpoint_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) endpoint_controller.add_access() out, err = self.capsys.readouterr() assert out.count("endpoint not found") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
def step_add_endpoints_access(self, client_id): with XRDSSTTest() as app: endpoint_controller = EndpointController() endpoint_controller.app = app endpoint_controller.load_config = (lambda: self.config) endpoint_controller.add_access() description = get_service_description(self.config, client_id) service_clients = get_endpoint_service_clients( self.config, description["services"][0]["endpoints"][4]["id"]) assert len(service_clients) == 1
def step_add_service_endpoints(self, client_id): with XRDSSTTest() as app: endpoint_controller = EndpointController() endpoint_controller.app = app endpoint_controller.load_config = (lambda: self.config) endpoint_controller.add() description = get_service_description(self.config, client_id) assert len(description["services"][0]["endpoints"]) == 5 assert str(description["services"][0]["endpoints"][4] ["path"]) == "/testPath" assert str( description["services"][0]["endpoints"][4]["method"]) == "POST"
def test_endpoint_add_access_not_valid_candidate(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', 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.get_client_service_descriptions', return_value=[ EndpointTestData.add_description_response ]): with mock.patch( 'xrdsst.api.clients_api.ClientsApi.find_service_client_candidates', return_value=[]): with mock.patch( 'xrdsst.api.endpoints_api.EndpointsApi.add_endpoint_service_clients', return_value=EndpointTestData. add_access_response): endpoint_controller = EndpointController() endpoint_controller.app = app endpoint_controller.load_config = ( lambda: self.ss_config) endpoint_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) endpoint_controller.add_access() out, err = self.capsys.readouterr() assert out.count("no valid candidate found") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)