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)
def test_service_description_add(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.add_client_service_description', return_value=ServiceTestData.add_description_response): service_controller = ServiceController() service_controller.app = app service_controller.load_config = (lambda: self.ss_config) service_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) service_controller.add_description() out, err = self.capsys.readouterr() assert out.count("Added service description with type") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
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_service_add_access(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_name='ACME', 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=[ ServiceTestData.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.services_api.ServicesApi.add_service_service_clients', 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()) ]): service_controller = ServiceController() service_controller.app = app service_controller.load_config = ( lambda: self.ss_config) service_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) service_controller.add_access() out, err = self.capsys.readouterr() assert out.count("Added access rights") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
class ClientTestData: add_response = Client(id='DEV:GOV:9876:SUB1', connection_type=ConnectionType.HTTP, has_valid_local_sign_cert=True, instance_id='DEV', member_class='GOV', member_code='9876', subsystem_code='SUB1', member_name='TEST', owner=False, status=ClientStatus.SAVED) update_response = Client(id='DEV:GOV:9876:SUB1', connection_type=ConnectionType.HTTPS, has_valid_local_sign_cert=True, instance_id='DEV', member_class='GOV', member_code='9876', subsystem_code='SUB1', member_name='MAME', owner=False, status=ClientStatus.REGISTERED)
def test_service_update_parameters(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_name='ACME', 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=[ ServiceTestData.add_description_response ]): with mock.patch( 'xrdsst.api.services_api.ServicesApi.update_service', return_value=Service( id='DEV:GOV:9876:SUB1:Petstore', full_service_code='DEV:GOV:9876:SUB1:Petstore', service_code='Petstore', timeout=120, title='title', ssl_auth=False, subjects_count=0, url='url', endpoints=[])): service_controller = ServiceController() service_controller.app = app service_controller.load_config = ( lambda: self.ss_config) service_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) service_controller.update_parameters() out, err = self.capsys.readouterr() assert out.count("Updated service parameters") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
def test_service_description_enable_already_enabled(self): class AlreadyEnabledResponse: status = 409 data = '{"status":409,"error":{"code":"service_description_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=[ ServiceTestData.add_description_response ]): with mock.patch( 'xrdsst.api.service_descriptions_api.ServiceDescriptionsApi.enable_service_description', side_effect=ApiException( http_resp=AlreadyEnabledResponse())): service_controller = ServiceController() service_controller.app = app service_controller.load_config = ( lambda: self.ss_config) service_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) service_controller.enable_description() out, err = self.capsys.readouterr() assert out.count("already enabled") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)
def remote_add_client(self, ss_api_config, client_conf): conn_type = convert_swagger_enum(ConnectionType, client_conf['connection_type']) client = Client(member_class=client_conf['member_class'], member_code=client_conf['member_code'], connection_type=conn_type, member_name=client_conf['member_name'], subsystem_code=client_conf['subsystem_code'] if 'subsystem_code' in client_conf else None, owner=False, has_valid_local_sign_cert=False) client_add = ClientAdd(client=client, ignore_warnings=True) clients_api = ClientsApi(ApiClient(ss_api_config)) try: response = clients_api.add_client(body=client_add) BaseController.log_info("Added client subsystem " + self.partial_client_id(client_conf) + " (got full id " + response.id + ")") return response except ApiException as err: if err.status == 409: BaseController.log_info("Client for '" + self.partial_client_id(client_conf) + "' already exists.") else: BaseController.log_api_error('ClientsApi->add_client', err)
def test_service_apply(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.add_client_service_description', return_value=ServiceTestData.add_description_response): with mock.patch( 'xrdsst.api.clients_api.ClientsApi.get_client_service_descriptions', return_value=[ ServiceTestData.add_description_response ]): with mock.patch( 'xrdsst.api.service_descriptions_api.ServiceDescriptionsApi.enable_service_description', return_value=None): 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.services_api.ServicesApi.add_service_service_clients', 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.services_api.ServicesApi.update_service', return_value=Service( id='DEV:GOV:9876:SUB1:Petstore', full_service_code= 'DEV:GOV:9876:SUB1:Petstore', service_code='Petstore', timeout=120, title='title', ssl_auth=False, subjects_count=0, url='url', endpoints=[])): service_controller = ServiceController( ) service_controller.app = app service_controller.load_config = ( lambda: self.ss_config) service_controller.get_server_status = ( lambda x, y: StatusTestData. server_status_essentials_complete) service_controller.apply() out, err = self.capsys.readouterr() assert out.count( "Added service description with type" ) > 0 assert out.count( "enabled successfully") > 0 assert out.count( "Added access rights") > 0 assert out.count( "Updated service parameters") > 0 with self.capsys.disabled(): sys.stdout.write(out) sys.stderr.write(err)