Example #1
0
    def delete_service():
        """
        :param self: MainController class object
        :return: None
        ''"""

        self.log('2.2.8 delete_service')

        # Delete WSDL that we added to restore original state.

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_name=client_name,
                                                    client_id=client_id)

        # Find the table that lists all WSDL files and services
        services_table = self.by_id(
            popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
        # Wait until that table is visible (opened in a popup)
        self.wait_until_visible(services_table)
        self.wait_jquery()
        time.sleep(3)
        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        wsdl_element = clients_table_vm.client_services_popup_select_wsdl(
            self, wsdl_index=wsdl_index, wsdl_url=wsdl_url)

        # Get the WSDL URL from wsdl_element text
        if wsdl_url is None:
            wsdl_text = wsdl_element.find_elements_by_tag_name('td')[1].text
            # print wsdl_text
            matches = re.search(popups.CLIENT_DETAILS_POPUP_WSDL_URL_REGEX,
                                wsdl_text)
            wsdl_found_url = matches.group(2)
            # print wsdl_found_url
            self.log('Found WSDL URL: {0}'.format(wsdl_found_url))
        else:
            wsdl_found_url = wsdl_url

        # Find and click the "Delete" button to enable the WSDL.
        self.by_id(popups.CLIENT_DETAILS_POPUP_DELETE_WSDL_BTN_ID).click()

        # A confirmation dialog should open. Confirm the deletion.
        popups.confirm_dialog_click(self)

        # Wait until ajax query finishes
        self.wait_jquery()

        # Now check if we can find the same wsdl or not
        wsdl_found_index = clients_table_vm.find_wsdl_by_name(
            self, wsdl_found_url)
        self.is_none(wsdl_found_index,
                     msg='WSDL {0} was not deleted.'.format(wsdl_found_url))
Example #2
0
    def enable_service():
        """
        :param self: MainController class object
        :return: None
        ''"""

        # TEST PLAN 2.2.2-4 - activate test service WSDL
        self.log('2.2.2-4 - activate test service WSDL')

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_name=client_name,
                                                    client_id=client_id)

        # Find the table that lists all WSDL files and services
        services_table = self.by_id(
            popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
        # Wait until that table is visible (opened in a popup)
        self.wait_until_visible(services_table)

        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        clients_table_vm.client_services_popup_select_wsdl(
            self, wsdl_index=wsdl_index, wsdl_url=wsdl_url)

        # Find and click the "Enable" button to enable the WSDL.
        self.by_id(popups.CLIENT_DETAILS_POPUP_ENABLE_WSDL_BTN_ID).click()

        # Wait until ajax query finishes
        self.wait_jquery()

        # Check if WSDL is really enabled - find the WSDL row by index and
        if wsdl_url is not None:
            wsdl_enabled_index = clients_table_vm.find_wsdl_by_name(
                self, wsdl_url)
        else:
            wsdl_enabled_index = wsdl_index

        if wsdl_enabled_index is None:
            raise RuntimeError('WSDL index not found for {0}'.format(wsdl_url))

        # Find the WSDL row and check if it has class 'disabled'. If it does, it is not enabled. If not, everything worked.
        wsdl_row = clients_table_vm.client_services_popup_get_wsdl(
            self, wsdl_index=wsdl_enabled_index)
        wsdl_is_enabled = 'disabled' not in self.get_classes(wsdl_row)

        # Assertion if wsdl is enabled
        self.is_true(wsdl_is_enabled,
                     msg='WSDL {0} ({1}) is not enabled'.format(
                         wsdl_enabled_index, wsdl_row.text))
    def refresh_existing_wsdl():
        """
        :param self: MainController class object
        :return: None
        ''"""

        # TEST PLAN 2.2.5 - refresh service WSDL
        self.log('*** 2.2.5 / XT-469')

        # Open an SSH connection to the webserver
        webserver_connect(self, ssh_host, ssh_username, ssh_password)

        self.log('2.2.5 initialize with the correct WSDL file: {0}'.format(
            wsdl_correct))
        webserver_set_wsdl(
            self,
            wsdl_source_filename=wsdl_local_path.format(wsdl_correct),
            wsdl_target_filename=wsdl_local_path.format(wsdl_filename))

        # TEST PLAN 2.2.5-1 test query from TS1 client CLIENT1:sub to service bodyMassIndex. Query should succeed.
        self.log(
            '2.2.5-1 test query {0} to bodyMassIndex. Query should succeed.'.
            format(query_filename))
        case.is_true(testclient_http.check_success(),
                     msg='2.2.5-1 test query failed')

        # TEST PLAN 2.2.5-2 delete service bodyMassIndex and refresh WSDL
        self.log('2.2.5-2 delete service bodyMassIndex and refresh WSDL')

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_name=client_name,
                                                    client_id=client_id)

        # Find the table that lists all WSDL files and services
        services_table = self.by_id(
            popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
        # Wait until that table is visible (opened in a popup)
        self.wait_until_visible(services_table)

        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        clients_table_vm.client_services_popup_select_wsdl(
            self, wsdl_index=wsdl_index, wsdl_url=wsdl_url)

        service_row = clients_table_vm.client_services_popup_find_service(
            self,
            wsdl_index=wsdl_index,
            wsdl_url=wsdl_url,
            service_name=service_name)
        service_row_2 = clients_table_vm.client_services_popup_find_service(
            self,
            wsdl_index=wsdl_index,
            wsdl_url=wsdl_url,
            service_name=service_name_2)
        service_rows = clients_table_vm.client_services_popup_get_services_rows(
            self, wsdl_index=wsdl_index, wsdl_url=wsdl_url)

        service_parameters = clients_table_vm.get_service_parameters(
            self, service_row)
        service_parameters_2 = clients_table_vm.get_service_parameters(
            self, service_row_2)

        # TEST PLAN 2.2.5.1 - replace WSDL with a file that gives a validation error
        self.log(
            '2.2.5.1 - replace WSDL with a file that cannot be validated at all: {0}'
            .format(wsdl_error))
        webserver_set_wsdl(
            self,
            wsdl_source_filename=wsdl_local_path.format(wsdl_error),
            wsdl_target_filename=wsdl_local_path.format(wsdl_filename))

        # Click "Refresh" and return status
        warning, error, console = refresh_wsdl()
        self.is_not_none(
            error,
            msg='Invalid WSDL: no error shown for WSDL {0}'.format(wsdl_url))
        self.is_equal(
            error,
            messages.WSDL_REFRESH_ERROR_VALIDATION_FAILED.format(wsdl_url),
            msg='Refresh invalid WSDL: wrong error shown for WSDL {0} : {1}'.
            format(wsdl_url, error))
        self.is_none(
            warning,
            msg='Refresh invalid WSDL: got warning for WSDL {0} : {1}'.format(
                wsdl_url, warning))
        self.is_not_none(
            console,
            msg='Refresh invalid WSDL: no console output for WSDL {0}'.format(
                wsdl_url))
        self.log('Error message: {0}'.format(warning))

        # TEST PLAN 2.2.5.2 - replace WSDL with a file that gives a validation warning
        self.log(
            '2.2.5.2 - replace WSDL with a file that gives a validation warning: {0}'
            .format(wsdl_warning))
        webserver_set_wsdl(
            self,
            wsdl_source_filename=wsdl_local_path.format(wsdl_warning),
            wsdl_target_filename=wsdl_local_path.format(wsdl_filename))
        warning, error, console = refresh_wsdl()
        self.is_none(
            error,
            msg='Refresh WSDL with validator warnings: got error for WSDL {0}'.
            format(wsdl_url))
        self.is_not_none(
            warning,
            msg=
            'Refresh WSDL with validator warnings: no warning shown for WSDL {0} : {1}'
            .format(wsdl_url, warning))
        self.is_none(
            console,
            msg=
            'Refresh WSDL with validator warnings: got console output for WSDL {0} : {1}'
            .format(wsdl_url, console))
        self.log('Warning message: {0}'.format(warning))

        # A warning popup should appear. We will not update the WSDL with a one that does not fully validate.
        self.wait_until_visible(
            type=By.XPATH, element=popups.WARNING_POPUP_CANCEL_XPATH).click()
        self.wait_jquery()

        # TEST PLAN 2.2.5-2 - replace WSDL with a correct file that doesn't include bodyMassIndex service.
        # In the test plan, there are two variants of how to delete the service (v1 and v2). One of them is commenting
        # out bodyMassIndex service and the second is to replace the WSDL with one that only contains service
        # xroadGetRandom. As the outcome is the same and only relies on parsing the XML (parser just ignores commented-out
        # blocks), we're just using variant 2 (v2 - replacing the WSDL with one that only contains xroadGetRandom).
        # If it is necessary to test both, the full 2.2.5-2 block may be duplicated and wsdl_missing_service variable
        # should be replaced or updated with one that specifies a file with commented-out bodyMassIndex.
        self.log(
            '2.2.5-2 - replace WSDL with a file that only contains xroadGetRandom: {0}'
            .format(wsdl_missing_service))

        webserver_set_wsdl(
            self,
            wsdl_source_filename=wsdl_local_path.format(wsdl_missing_service),
            wsdl_target_filename=wsdl_local_path.format(wsdl_filename))

        # Click "Refresh" and return status
        warning, error, console = refresh_wsdl()

        # Check if warning message is correct.
        warning_message_is_correct = warning.startswith(
            messages.WSDL_REFRESH_WARNING_DELETING_SERVICES.format(
                wsdl_missing_service))

        self.is_none(
            error,
            msg='Refresh WSDL (xroadGetRandom): got error for WSDL {0} : {1}'.
            format(wsdl_missing_service, error))
        self.is_not_none(
            warning,
            msg='Refresh WSDL (xroadGetRandom): no warning shown for WSDL {0}'.
            format(wsdl_missing_service))
        self.is_equal(
            warning_message_is_correct,
            True,
            msg=
            'Refresh WSDL (xroadGetRandom): wrong error shown for WSDL {0} : {1}'
            .format(wsdl_missing_service, warning))
        self.is_none(
            console,
            msg=
            'Refresh WSDL (xroadGetRandom): got console output for WSDL {0} : {1}'
            .format(wsdl_missing_service, console))

        # A warning dialog should be open. Confirm the deletion by clicking "Continue".
        self.wait_until_visible(
            type=By.XPATH,
            element=popups.WARNING_POPUP_CONTINUE_XPATH).click()

        # Wait until the settings are saved.
        self.wait_jquery()

        # TEST PLAN 2.2.5-3 test query from TS1 client CLIENT1:sub to service bodyMassIndex. Query should fail.
        self.log(
            '2.2.5-3 test query {0} to service bodyMassIndex. Query should fail.'
            .format(query_filename))
        case.is_true(testclient_http.check_fail(),
                     msg='2.2.5-3 test query succeeded')

        # TEST PLAN 2.2.5-4 add service bodyMassIndex to service WSDL and refresh the service. UI should notify about
        # an added service. NB! Service settings must not change.

        self.log(
            '2.2.5-4 add service bodyMassIndex to service WSDL and refresh the service: {0}'
            .format(wsdl_correct))

        webserver_set_wsdl(
            self,
            wsdl_source_filename=wsdl_local_path.format(wsdl_correct),
            wsdl_target_filename=wsdl_local_path.format(wsdl_filename))

        # Click "Refresh" and return status
        warning, error, console = refresh_wsdl()

        # Check if warning message is correct.
        warning_message_is_correct = warning.startswith(
            messages.WSDL_REFRESH_WARNING_ADDING_SERVICES.format(wsdl_correct))

        self.is_none(
            error,
            msg=
            'Refresh WSDL (xroadGetRandom, bodyMassIndex): got error for WSDL {0} : {1}'
            .format(wsdl_correct, error))
        self.is_not_none(
            warning,
            msg=
            'Refresh WSDL (xroadGetRandom, bodyMassIndex): no warning shown for WSDL {0}'
            .format(wsdl_correct))
        self.is_equal(
            warning_message_is_correct,
            True,
            msg=
            'Refresh WSDL (xroadGetRandom, bodyMassIndex): wrong error shown for WSDL {0} : {1}'
            .format(wsdl_correct, warning))
        self.is_none(
            console,
            msg=
            'Refresh WSDL (xroadGetRandom): got console output for WSDL {0} : {1}'
            .format(wsdl_correct, console))

        # A warning dialog should be open. Confirm the deletion by clicking "Continue".
        self.wait_until_visible(
            type=By.XPATH,
            element=popups.WARNING_POPUP_CONTINUE_XPATH).click()

        # Wait until the settings are saved.
        self.wait_jquery()

        # Verify that the settings are not overwritten with default values.
        # Find the service row again because deleting and re-enabling might have reordered the services.
        service_row = clients_table_vm.client_services_popup_find_service(
            self,
            wsdl_index=wsdl_index,
            wsdl_url=wsdl_url,
            service_name=service_name)
        service_row_2 = clients_table_vm.client_services_popup_find_service(
            self,
            wsdl_index=wsdl_index,
            wsdl_url=wsdl_url,
            service_name=service_name_2)

        new_service_parameters = clients_table_vm.get_service_parameters(
            self, service_row)
        new_service_parameters_2 = clients_table_vm.get_service_parameters(
            self, service_row_2)

        self.is_equal(
            service_parameters_2['url'],
            new_service_parameters_2['url'],
            msg='Service URLs are not equal, old={0}, new={1}'.format(
                service_parameters_2['url'], new_service_parameters_2['url']))
        self.is_equal(
            service_parameters_2['timeout'],
            new_service_parameters_2['timeout'],
            msg='Service timeouts are not equal, old={0}, new={1}'.format(
                service_parameters_2['timeout'],
                new_service_parameters_2['timeout']))

        popups.close_all_open_dialogs(self)

        # TEST PLAN 2.2.5-5 set bodyMassIndex address and ACL (give access to CLIENT1:sub)
        self.log(
            '2.2.5-5 set bodyMassIndex address and ACL (give access to client)'
        )

        add_acl = add_to_acl_2_1_8.test_add_subjects(
            self,
            client=client,
            client_id=client_id,
            wsdl_url=wsdl_url,
            service_name=service_name,
            service_subjects=[requester_id],
            remove_data=False,
            allow_remove_all=False)
        add_acl()

        # TEST PLAN 2.2.5-6 test queries from TS1 client CLIENT1:sub to services bodyMassIndex and xroadGetRandom.
        # Both queries should succeed.
        self.log(
            '2.2.5-6 test query {0} to service bodyMassIndex. Query should succeed.'
            .format(query_filename))
        case.is_true(testclient_http.check_success(),
                     msg='2.2.5-6 test query failed')

        self.log(
            '2.2.5-6 test query 2 {0} to service xroadGetRandom. Query should succeed.'
            .format(query_2_filename))
        case.is_true(testclient_http_2.check_success(),
                     msg='2.2.5-6 test query 2 failed')
    def delete_tls():
        self.reload_webdriver(url=ss1_host,
                              username=ss1_user,
                              password=ss1_pass)

        self.log('2.2.7 delete_tls')
        self.log('2.2.7-delete setting {0} connection type to HTTP'.format(
            client_id))

        # Open "Security Server Clients" page
        self.by_css(sidebar.CLIENTS_BTN_CSS).click()

        # Wait until list is loaded
        self.wait_jquery()

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_internal_servers(
            self, client_id=client_id)

        # Set connection type to HTTPS_NO_AUTH (SSLNOAUTH)
        self.is_true(clients_table_vm.client_servers_popup_set_connection(
            self, 'NOSSL'),
                     msg='2.2.7-delete-2 Failed to set connection type')

        # Delete all internal certificates
        clients_table_vm.client_servers_popup_delete_tls_certs(self)

        # Switch to Security server 2
        self.reload_webdriver(url=ss2_host,
                              username=ss2_user,
                              password=ss2_pass)

        # Open "Security Server Clients" page
        self.by_css(sidebar.CLIENTS_BTN_CSS).click()

        # Wait until list is loaded
        self.wait_jquery()

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_id=provider_id)

        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        service_row = clients_table_vm.client_services_popup_find_service(
            self, wsdl_url=wsdl_url, service_name=testservice_name)

        # Click on the service row to select it
        service_row.click()

        # Open service parameters by finding the "Edit" button and clicking it.
        edit_service_button = self.by_id(
            popups.CLIENT_DETAILS_POPUP_EDIT_WSDL_BTN_ID)

        # Click the "Edit" button to open "Edit Service Parameters" popup
        edit_service_button.click()

        warning, error = configure_service_2_2_2.edit_service(
            self, service_url=new_service_url)
        case.is_none(
            error, msg='2.2.7-14 Got error when trying to update service URL')

        # Click tab "Internal Servers"
        self.by_css(clients_table_vm.INTERNAL_CERTS_TAB_TITLE_CSS).click()

        # Wait until everything is loaded.
        self.wait_jquery()

        # Delete all internal certificates
        clients_table_vm.client_servers_popup_delete_tls_certs(self)
    def local_tls():
        """
        :param self: MainController class object
        :return: None
        ''"""

        # TEST PLAN 2.2.7 test local TLS
        self.log('*** 2.2.7 / XT-471')

        self.reload_webdriver(url=ss1_host,
                              username=ss1_user,
                              password=ss1_pass)

        certs_filename = self.get_download_path(certs_download_filename)

        ss1_filename = self.get_download_path(certs_ss1_filename)
        ss2_filename = self.get_download_path(certs_ss2_filename)

        ss2_certs_directory_abs = self.get_download_path(ss2_certs_directory)

        # Create directory if not exists
        if not os.path.isdir(ss2_certs_directory_abs):
            os.mkdir(ss2_certs_directory_abs)

        self.remove_files([
            certs_filename, ss1_filename, ss2_filename, ss2_certs_directory_abs
        ])

        created_files = [certs_filename]

        self.start_mock_service()

        # TEST PLAN 2.2.7-1 generate new internal TLS key.
        self.log('2.2.7-1 generate new internal TLS key.')

        # Click "System Parameters" in sidebar
        self.by_css(sidebar.SYSTEM_PARAMETERS_BTN_CSS).click()

        # Click "Generate New TLS Key" button
        self.wait_until_visible(
            ss_system_parameters.GENERATE_INTERNAL_TLS_KEY_BUTTON_ID,
            type=By.ID).click()

        # A confirmation dialog should open. Confirm the question.
        popups.confirm_dialog_click(self)

        # Wait until the TLS certificate has been generated.
        self.wait_jquery()

        self.log('2.2.7-1 new key has been generated, downloading certificate')

        # If file already exists, delete it first
        if os.path.isfile(certs_filename):
            os.remove(certs_filename)

        # Find and click the "Export" button. Download should start automatically.
        self.by_id(
            ss_system_parameters.EXPORT_INTERNAL_TLS_CERT_BUTTON_ID).click()

        # Check if file exists every 0.5 seconds or until limit has passed.
        start_time = time.time()
        while True:
            if os.path.isfile(certs_filename):
                break
            if time.time() - start_time > download_time_limit:
                # Raise AssertionError
                raise AssertionError(
                    'Download time limit of {0} seconds passed for file {1}'.
                    format(download_time_limit, certs_download_filename))
            time.sleep(download_check_interval)

        os.rename(certs_filename, ss1_filename)

        created_files.append(ss1_filename)
        self.log('2.2.7-1 certificate archive has been downloaded, extracting')

        # We're here, so download succeeded.
        # Extract the archive (tgz format) to downloads directory.
        with tarfile.open(ss1_filename, 'r:gz') as tar:
            # tarfile.extractall does not overwrite files so we need to extract them one by one.
            for fileobj in tar:
                filename = os.path.join(os.path.dirname(fileobj.name),
                                        os.path.basename(fileobj.name))
                file_target = self.get_download_path(filename)
                if os.path.isfile(file_target):
                    os.remove(file_target)
                created_files.append(file_target)
                tar.extract(fileobj, self.get_download_path())

        self.log('2.2.7-1 certificate archive has been extracted')

        # TEST PLAN 2.2.7-2 setting connection type to HTTPS_NO_AUTH
        self.log('2.2.7-2 setting {0} connection type to HTTPS_NO_AUTH'.format(
            client_id))

        # Open "Security Server Clients" page
        self.by_css(sidebar.CLIENTS_BTN_CSS).click()

        # Wait until list is loaded
        self.wait_jquery()

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_internal_servers(
            self, client_id=client_id)

        # Set connection type to HTTPS_NO_AUTH (SSLNOAUTH)
        case.is_true(clients_table_vm.client_servers_popup_set_connection(
            self, 'SSLNOAUTH'),
                     msg='2.2.7-2 Failed to set connection type')

        # TEST PLAN 2.2.7-3 test query from TS1:CLIENT1:sub to test service. Query should fail.
        self.log('2.2.7-3 test query {0} to test service. Query should fail.'.
                 format(query_filename))

        case.is_true(testclient_http.check_fail(),
                     msg='2.2.7-3 test query succeeded')

        # TEST PLAN 2.2.7-4/5 test query to test service using SSL and client certificate. Query should succeed.
        self.log(
            '2.2.7-4/5 test query to test service using SSL and client certificate. Query should succeed.'
        )
        case.is_true(testclient_https.check_success(),
                     msg='2.2.7-5 test query failed')

        # TEST PLAN 2.2.7-6 setting connection type to HTTPS
        self.log(
            '2.2.7-6 setting {0} connection type to HTTPS'.format(client_id))

        # Set connection type to HTTPS (SSLAUTH)
        case.is_true(clients_table_vm.client_servers_popup_set_connection(
            self, 'SSLAUTH'),
                     msg='2.2.7-6 Failed to set connection type')

        # TEST PLAN 2.2.7-7 test query to test service using SSL and client certificate. Query should fail.
        self.log(
            '2.2.7-7 test query to test service using SSL and client certificate. Query should fail.'
        )
        case.is_true(testclient_https.check_fail(),
                     msg='2.2.7-7 test query succeeded')

        # TEST PLAN 2.2.7-8 upload certificate to TS1 client CLIENT1:sub
        self.log(
            '2.2.7-8 upload certificate to TS1 client {0}'.format(client_id))

        # Find the "Add" button and click it.
        self.by_id(
            popups.CLIENT_DETAILS_POPUP_INTERNAL_SERVERS_ADD_CERTIFICATE_BTN_ID
        ).click()

        # Get the upload button
        upload_button = self.by_id(popups.FILE_UPLOAD_BROWSE_BUTTON_ID)
        xroad.fill_upload_input(self, upload_button, client_cert_path)

        submit_button = self.by_id(popups.FILE_UPLOAD_SUBMIT_BUTTON_ID)
        submit_button.click()

        # TEST PLAN 2.2.7-9 test query to test service using SSL and client certificate. Query should succeed.
        self.log(
            '2.2.7-9 test query to test service using SSL and client certificate. Query should succeed.'
        )

        # Set client certificate and key
        testclient_https.client_certificate = (client_cert_path,
                                               client_key_path)

        case.is_true(testclient_https.check_success(),
                     msg='2.2.7-9 test query failed')

        # TEST PLAN 2.2.7-10 set test client to use TS2 TLS certificate
        self.log('2.2.7-10 set test client to use TS2 TLS certificate')

        # First, get the certificate. For this, we need to get webdriver to go to TS2
        self.reload_webdriver(url=ss2_host,
                              username=ss2_user,
                              password=ss2_pass)

        # Click "System Parameters" in sidebar
        self.by_css(sidebar.SYSTEM_PARAMETERS_BTN_CSS).click()

        self.wait_jquery()

        self.log('2.2.7-10 downloading TS2 certificate')

        if os.path.isfile(certs_filename):
            os.remove(certs_filename)

        # Find and click the "Export" button. Download should start automatically.
        self.by_id(
            ss_system_parameters.EXPORT_INTERNAL_TLS_CERT_BUTTON_ID).click()

        # Check if file exists every 0.5 seconds or until limit has passed.
        start_time = time.time()
        while True:
            if os.path.isfile(certs_filename):
                break
            if time.time() - start_time > download_time_limit:
                # Raise AssertionError
                raise AssertionError(
                    'Download time limit of {0} seconds passed for file {1}'.
                    format(download_time_limit, certs_download_filename))
            time.sleep(download_check_interval)

        os.rename(certs_filename, ss2_filename)

        created_files.append(ss2_filename)
        self.log(
            '2.2.7-10 certificate archive has been downloaded, extracting')

        # We're here, so download succeeded.

        # Extract the archive (tgz format) to downloads directory.
        with tarfile.open(ss2_filename, 'r:gz') as tar:
            # tarfile.extractall does not overwrite files so we need to extract them one by one.
            for fileobj in tar:
                filename = self.get_download_path(
                    os.path.join(ss2_certs_directory,
                                 os.path.dirname(fileobj.name),
                                 os.path.basename(fileobj.name)))
                file_target = self.get_download_path(filename)
                if os.path.isfile(file_target):
                    os.remove(file_target)
                created_files.append(file_target)
                tar.extract(fileobj,
                            self.get_download_path(ss2_certs_directory))

        self.log('2.2.7-10 certificate archive has been extracted')

        # TEST PLAN 2.2.7-11 test query to test service using SSL and TS2 certificate. Query should fail.
        self.log(
            '2.2.7-11 test query to test service using SSL and client certificate, verify TS2. Query should fail.'
        )

        try:
            testclient_https_ss2.check_fail()
            case.is_true(
                False,
                msg='2.2.7-11 test query failed but not with an SSLError.')
        except SSLError:
            # We're actually hoping to get an SSLError so we're good.
            pass

        # TEST PLAN 2.2.7-12/13 test query to test service using SSL and TS1 certificate. Query should succeed.
        self.log(
            '2.2.7-12/13 test query to test service using SSL and client certificate, verify TS1. Query should succeed.'
        )

        case.is_true(testclient_https.check_success(),
                     msg='2.2.7-13 test query failed')

        # TEST PLAN 2.2.7-14 TS2 test service is configured from http to https. TLS check disabled.
        self.log(
            '2.2.7-14 TS2 test service is configured from http to https. TLS check disabled.'
            .format(new_service_url))

        # Open "Security Server Clients" page
        self.by_css(sidebar.CLIENTS_BTN_CSS).click()

        # Wait until list is loaded
        self.wait_jquery()

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_id=provider_id)

        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        service_row = clients_table_vm.client_services_popup_find_service(
            self, wsdl_url=wsdl_url, service_name=testservice_name)

        # Click on the service row to select it
        service_row.click()

        # Open service parameters by finding the "Edit" button and clicking it.
        edit_service_button = self.by_id(
            popups.CLIENT_DETAILS_POPUP_EDIT_WSDL_BTN_ID)

        # Click the "Edit" button to open "Edit Service Parameters" popup
        edit_service_button.click()

        warning, error = configure_service_2_2_2.edit_service(
            self, service_url=new_service_url, verify_tls=False)
        case.is_none(
            error, msg='2.2.7-14 Got error when trying to update service URL')

        # TEST PLAN 2.2.7-15 test query to test service using SSL and TS1 certificate. Query should succeed.
        self.log(
            '2.2.7-15 test query to test service using SSL and client certificate. Query should succeed.'
        )
        case.is_true(testclient_https.check_success(),
                     msg='2.2.7-15 test query failed')

        # TEST PLAN 2.2.7-16 TS2 test service is as https with TLS certificate check enabled.

        # Click the "Edit" button to open "Edit Service Parameters" popup
        edit_service_button.click()

        configure_service_2_2_2.edit_service(self,
                                             service_url=new_service_url,
                                             verify_tls=True)

        # TEST PLAN 2.2.7-17 test query to test service using SSL and TS1 certificate. Query should succeed.
        self.log(
            '2.2.7-17 test query to test service using SSL and client certificate. Query should fail.'
        )

        case.is_true(testclient_https.check_fail(faults=[
            'Server.ServerProxy.ServiceFailed.SslAuthenticationFailed'
        ]),
                     msg='2.2.7-17 test query succeeded')

        # TEST PLAN 2.2.7-18 import test service TLS certificate to security server TS2
        self.log(
            '2.2.7-18 import test service TLS certificate to security server TS2'
        )

        # Click tab "Internal Servers"
        self.by_css(clients_table_vm.INTERNAL_CERTS_TAB_TITLE_CSS).click()

        # Wait until everything is loaded.
        self.wait_jquery()

        # Find the "Add" button and click it.
        self.by_id(
            popups.CLIENT_DETAILS_POPUP_INTERNAL_SERVERS_ADD_CERTIFICATE_BTN_ID
        ).click()

        # Get the upload button
        upload_button = self.by_id(popups.FILE_UPLOAD_BROWSE_BUTTON_ID)
        xroad.fill_upload_input(self, upload_button, mock_cert_path)

        submit_button = self.by_id(popups.FILE_UPLOAD_SUBMIT_BUTTON_ID)
        submit_button.click()

        # TEST PLAN 2.2.7-19 test query to test service using SSL and client certificate. Should succeed.
        self.log(
            '2.2.7-19 test query to test service using SSL and client certificate. Query should succeed.'
        )

        case.is_true(testclient_https.check_success(),
                     msg='2.2.7-19 test query failed')

        # Remove all created files
        if delete_created_files:
            self.log('2.2.7 removing downloaded files')
            self.remove_files(created_files)
Example #6
0
    def configure_service():
        """
        :param self: MainController class object
        :return: None
        ''"""

        # TEST PLAN 2.2.2 configure test service
        self.log('*** 2.2.2 / XT-466')

        self.reload_webdriver(url=ss2_host,
                              username=ss2_user,
                              password=ss2_pass)

        # TEST PLAN 2.2.2-1 add test service WSDL
        self.log('2.2.2-1 add test service WSDL')

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self,
                                                    client_name=client_name,
                                                    client_id=client_id)

        # Find the table that lists all WSDL files and services
        services_table = self.by_id(
            popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
        # Wait until that table is visible (opened in a popup)
        self.wait_jquery()
        self.wait_until_visible(services_table)

        # Test precondition: the WSDL has not been added already. Check if finding service with wsdl_correct_url
        # returns None (= not found).
        self.is_none(
            clients_table_vm.find_wsdl_by_name(self, wsdl_correct_url),
            msg=
            'WSDL {0} has already been added. Remove the service and try again.'
            .format(wsdl_correct_url))

        if check_add_errors:
            # TEST PLAN 2.2.2.1 error 1 - trying to add WSDL with an incorrect URL
            self.log(
                '2.2.2.1 error 1 add WSDL with an incorrect URL: {0}'.format(
                    wsdl_incorrect_url))
            warning, error, console = add_wsdl(self, wsdl_incorrect_url)
            self.is_not_none(
                error,
                msg='Incorrect URL: no error shown for WSDL {0}'.format(
                    wsdl_incorrect_url))
            self.is_equal(
                error,
                messages.WSDL_ERROR_INVALID_URL.format(wsdl_incorrect_url),
                msg='Incorrect URL: wrong error shown for WSDL {0} : {1}'.
                format(wsdl_incorrect_url, error))
            self.is_none(
                warning,
                msg='Incorrect URL: got warning for WSDL {0} : {1}'.format(
                    wsdl_incorrect_url, warning))
            self.is_none(
                console,
                msg='Incorrect URL: got console output for WSDL {0} : {1}'.
                format(wsdl_incorrect_url, console))
            self.log('Error message: {0}'.format(warning))

            # TEST PLAN 2.2.2.1 error 2 - trying to add WSDL with a URL that doesn't return a WSDL file
            self.log('2.2.2.1 error 2 add WSDL with a URL that doesn'
                     't return a WSDL file: {0}'.format(wsdl_malformed_url))
            warning, error, console = add_wsdl(self, wsdl_malformed_url)
            self.is_not_none(
                error,
                msg='Add duplicate WSDL: no error shown for WSDL {0}'.format(
                    wsdl_malformed_url))
            self.is_equal(
                error,
                messages.WSDL_ERROR_INCORRECT_WSDL.format(wsdl_malformed_url),
                msg='Incorrect WSDL: wrong error shown for WSDL {0} : {1}'.
                format(wsdl_malformed_url, error))
            self.is_none(
                warning,
                msg='Incorrect WSDL: got warning for WSDL {0} : {1}'.format(
                    wsdl_malformed_url, warning))
            self.is_none(
                console,
                msg='Incorrect WSDL: got console output for WSDL {0} : {1}'.
                format(wsdl_malformed_url, console))
            self.log('Error message: {0}'.format(warning))

            # TEST PLAN 2.2.2.1 error 3 - trying to add a WSDL with a URL that has already been added

        # TEST PLAN 2.2.2-1 - First let's add the unique WSDL and it should succeed. (Validation comes later)
        self.log(
            '2.2.2-1 add (unique) WSDL with URL: {0}'.format(wsdl_correct_url))
        warning, error, console = add_wsdl(self, wsdl_correct_url)
        self.is_none(
            error,
            msg='Add unique WSDL: got error for WSDL {0} : {1}'.format(
                wsdl_correct_url, error))
        self.is_none(
            warning,
            msg='Add unique WSDL: got warning for WSDL {0} : {1}'.format(
                wsdl_correct_url, warning))
        self.is_none(
            console,
            msg='Add unique WSDL: got console output for WSDL {0} : {1}'.
            format(wsdl_correct_url, console))

        if check_add_errors:
            # TEST PLAN 2.2.2.1 error 3 - trying to add a WSDL with a URL that has already been added

            # Second, the same WSDL file. We should get an error.
            self.log(
                '2.2.2.1 error 3 add a WSDL with a URL that has already been added: {0}'
                .format(wsdl_correct_url))
            warning, error, console = add_wsdl(
                self, wsdl_correct_url)  # This should give an error
            self.is_not_none(
                error,
                msg='Add duplicate WSDL: no error shown for WSDL {0}'.format(
                    wsdl_correct_url))
            self.is_equal(
                error,
                messages.WSDL_ERROR_ADDRESS_EXISTS.format(wsdl_correct_url),
                msg='Add duplicate WSDL: wrong error shown for WSDL {0} : {1}'.
                format(wsdl_correct_url, error))
            self.is_none(
                warning,
                msg='Add duplicate WSDL: got warning for WSDL {0} : {1}'.
                format(wsdl_correct_url, warning))
            self.is_none(
                console,
                msg='Add duplicate WSDL: got console output for WSDL {0} : {1}'
                .format(wsdl_correct_url, console))
            self.log('Error message: {0}'.format(warning))

            # TEST PLAN 2.2.2.1 error 4 - trying to add a WSDL that is a different URL but the service is already defined
            self.log(
                '2.2.2.1 error 4 add a WSDL that is a different URL but the service is already defined: {0}'
                .format(wsdl_duplicate_url))
            warning, error, console = add_wsdl(
                self, wsdl_duplicate_url
            )  # This should give an error about duplicate service
            error_message_is_correct = error.startswith(
                messages.WSDL_ERROR_DUPLICATE_SERVICE.format(
                    wsdl_duplicate_url))
            self.is_not_none(
                error,
                msg='Add duplicate service: no error shown for WSDL {0}'.
                format(wsdl_duplicate_url))
            self.is_equal(
                error_message_is_correct,
                True,
                msg='Add duplicate service: wrong error shown for WSDL {0} : {1}'
                .format(wsdl_duplicate_url, error))
            self.is_none(
                warning,
                msg='Add duplicate service: got warning for WSDL {0} : {1}'.
                format(wsdl_duplicate_url, warning))
            self.is_none(
                console,
                msg=
                'Add duplicate service: got console output for WSDL {0} : {1}'.
                format(wsdl_duplicate_url, console))
            self.log('Error message: {0}'.format(warning))

            # TEST PLAN 2.2.2.1 error 5 - trying to add WSDL that cannot be validated at all
            self.log(
                '2.2.2.1 error 5 add WSDL that cannot be validated at all: {0}'
                .format(wsdl_error_url))
            warning, error, console = add_wsdl(self, wsdl_error_url)
            self.is_not_none(
                error,
                msg='Add invalid WSDL: no error shown for WSDL {0}'.format(
                    wsdl_error_url))
            self.is_equal(
                error,
                messages.WSDL_ERROR_VALIDATION_FAILED.format(wsdl_error_url),
                msg='Add invalid WSDL: wrong error shown for WSDL {0} : {1}'.
                format(wsdl_error_url, error))
            self.is_none(
                warning,
                msg='Add invalid WSDL: got warning for WSDL {0} : {1}'.format(
                    wsdl_error_url, warning))
            self.is_not_none(
                console,
                msg=
                'Add invalid WSDL: no console output shown for WSDL {0} : {1}'.
                format(wsdl_error_url, console))
            self.log('Error message: {0}'.format(error))
            self.log('Console output: {0}'.format(console))

            # TEST PLAN 2.2.2.1 error 6 - trying to add WSDL that gives a validator warning
            self.log(
                '2.2.2.1 error 6 add WSDL that gives a validator warning: {0}'.
                format(wsdl_warning_url))
            warning, error, console = add_wsdl(self, wsdl_warning_url)
            self.is_none(
                error,
                msg='Add WSDL with validator warnings: got error for WSDL {0}'.
                format(wsdl_warning_url))
            self.is_not_none(
                warning,
                msg=
                'Add WSDL with validator warnings: no warning shown for WSDL {0} : {1}'
                .format(wsdl_warning_url, warning))
            self.is_none(
                console,
                msg=
                'Add WSDL with validator warnings: got console output for WSDL {0} : {1}'
                .format(wsdl_warning_url, console))
            self.log('Warning message: {0}'.format(warning))

            # We're not adding the WSDL that gives us warnings, so find the "Cancel" button and click it.
            self.wait_until_visible(
                type=By.XPATH,
                element=popups.WARNING_POPUP_CANCEL_XPATH).click()
            self.wait_jquery()

            # Now we need to cancel the "Add WSDL" popup. Find the "Cancel" button and click it.
            self.wait_until_visible(
                type=By.XPATH,
                element=popups.ADD_WSDL_POPUP_CANCEL_BTN_XPATH).click()

        # TEST PLAN 2.2.2-1 VALIDATION - Check if our unique WSDL has been successfully added
        self.log('2.2.2-1 validation - checking if WSDL was added: {0}'.format(
            wsdl_correct_url))

        wsdl_index = clients_table_vm.find_wsdl_by_name(self, wsdl_correct_url)
        self.log('WSDL table row index: {0}'.format(wsdl_index))

        # Check if wsdl_index is not None - if it is, we didn't find the WSDL in the list after adding it.
        self.is_not_none(
            wsdl_index,
            msg='WSDL not found in services table after adding: {0}'.format(
                wsdl_correct_url))

        # Get the WSDL tr (table row) element from services table
        wsdl_row = clients_table_vm.client_services_popup_get_wsdl(
            self, wsdl_index=wsdl_index)

        # TEST PLAN 2.2.2.1 subtask - verify that the row starts with "WSDL DISABLED" and is in red letter (we're
        # checking if the class is "disabled" - this sets the color)

        # Get the service code td (table cell) element (this should start with WSDL DISABLED)
        wsdl_service_code = wsdl_row.find_elements_by_tag_name('td')[1]
        self.is_equal(
            wsdl_service_code.text.startswith(wsdl_disabled_prefix),
            True,
            msg='Added WSDL row does not start with "WSDL DISABLED": {0}'.
            format(wsdl_correct_url))

        # Get the row classes to check if "disabled" is in this list. This is the class that makes the row text red.
        wsdl_row_classes = self.get_classes(wsdl_row)
        self.is_equal(
            wsdl_disabled_class in wsdl_row_classes,
            True,
            msg='Added WSDL row does not have class "disabled": {0}'.format(
                wsdl_correct_url))

        # Select the WSDL by clicking on the row
        wsdl_row.click()

        # Open service parameters by finding the "Edit" button and clicking it.
        edit_wsdl_button = self.by_id(
            popups.CLIENT_DETAILS_POPUP_EDIT_WSDL_BTN_ID)

        if check_edit_errors:
            edit_wsdl_button.click()

            # TEST PLAN 2.2.2.2 error 1 - trying to add WSDL that cannot be validated at all
            self.log(
                '2.2.2.2 error 1 trying to set WSDL URL that cannot be validated at all: {0}'
                .format(wsdl_error_url))
            warning, error, console = edit_wsdl(self, wsdl_error_url)
            self.is_not_none(
                error,
                msg='Set invalid WSDL: no error shown for WSDL {0}'.format(
                    wsdl_error_url))
            self.is_equal(
                error,
                messages.WSDL_EDIT_ERROR_VALIDATION_FAILED.format(
                    wsdl_error_url),
                msg='Set invalid WSDL: wrong error shown for WSDL {0} : {1}'.
                format(wsdl_error_url, error))
            self.is_none(
                warning,
                msg='Set invalid WSDL: got warning for WSDL {0} : {1}'.format(
                    wsdl_error_url, warning))
            self.is_not_none(
                console,
                msg=
                'Set invalid WSDL: no console output shown for WSDL {0} : {1}'.
                format(wsdl_error_url, console))
            self.log('Error message: {0}'.format(error))
            self.log('Console output: {0}'.format(console))

            # TEST PLAN 2.2.2.2 error 2 - trying to update WSDL that gives a validator warning
            self.log(
                '2.2.2.2 error 2 trying to set WSDL URL that gives a validator warning: {0}'
                .format(wsdl_warning_url))
            warning, error, console = edit_wsdl(self, wsdl_warning_url)
            self.is_none(
                error,
                msg='Set WSDL with validator warnings: got error for WSDL {0}'.
                format(wsdl_warning_url))
            self.is_not_none(
                warning,
                msg=
                'Set WSDL with validator warnings: no warning shown for WSDL {0} : {1}'
                .format(wsdl_warning_url, warning))
            self.is_none(
                console,
                msg=
                'Set WSDL with validator warnings: got console output for WSDL {0} : {1}'
                .format(wsdl_warning_url, console))
            self.log('Warning message: {0}'.format(warning))

            # We're not adding the WSDL that gives us warnings, so find the "Cancel" button and click it.
            self.wait_until_visible(
                type=By.XPATH,
                element=popups.WARNING_POPUP_CANCEL_XPATH).click()
            self.wait_jquery()

            # Close "Edit WSDL Parameters" dialog by finding the "Cancel" button and clicking it.
            self.wait_until_visible(
                type=By.XPATH,
                element=popups.EDIT_WSDL_POPUP_CANCEL_BTN_XPATH).click()

        # TEST PLAN 2.2.2-2 Editing service parameters
        self.log('2.2.2-2 Editing service parameters')

        # Find the service under the specified WSDL in service list (and expand the WSDL services list if not open yet)
        service_row = clients_table_vm.client_services_popup_find_service(
            self, wsdl_index=wsdl_index, service_name=service_name)

        # Click on the service row to select it
        service_row.click()

        # Click the "Edit" button to open "Edit Service Parameters" popup
        edit_wsdl_button.click()

        # Wait until "Edit Service Parameters" popup opens
        self.wait_until_visible(type=By.XPATH,
                                element=popups.EDIT_SERVICE_POPUP_XPATH)

        # Find the "Service URL" and "Timeout" inputs. Get the service URL and timeout as we need them later.
        service_url = self.by_id(
            popups.EDIT_SERVICE_POPUP_URL_ID).get_attribute('value')
        service_timeout = self.by_id(
            popups.EDIT_SERVICE_POPUP_TIMEOUT_ID).get_attribute('value')

        modified_service_url = service_url

        if check_parameter_errors:
            # TEST PLAN 2.2.2.3 Test edit service parameters errors
            self.log('2.2.2.3 Test edit service parameters errors')

            # Append URL parameter db=CLIENT_CODE to the url

            # Let's be ready that the service may already have some parameters so check if a question mark exists or not.
            if '?' in modified_service_url:
                # We already have parameters, append to the list
                modified_service_url += '&'
            else:
                # No parameters, start a parameter string with a question mark
                modified_service_url += '?'

            # Append client code to service URL
            modified_service_url += urllib.urlencode(
                {service_url_additional_parameter: client['code']})

            # TEST PLAN 2.2.2.3 error 1 Try to set invalid URL and original (correct) service timeout. Should get an error.
            self.log(
                '2.2.2.3 error 1 trying to set invalid service URL {0}'.format(
                    service_invalid_url))
            warning, error = edit_service(self, service_invalid_url,
                                          service_timeout)
            self.is_not_none(
                error,
                msg='Set invalid service URL: no error shown for URL {0}'.
                format(service_invalid_url))
            self.is_equal(
                error,
                messages.SERVICE_EDIT_INVALID_URL.format(service_invalid_url),
                msg=
                'Set invalid service URL: wrong error shown for URL {0} : {1}'.
                format(service_invalid_url, error))
            self.is_none(
                warning,
                msg='Set invalid service URL: got warning for URL {0} : {1}'.
                format(modified_service_url, warning))
            # If any error messages are shown, close them.
            messages.close_error_messages(self)

            # TEST PLAN 2.2.2.3 error 2 Try to set invalid service timeout. Should get an error.
            for timeout in service_invalid_timeouts:
                self.log(
                    '2.2.2.3 error 2 Trying to set invalid timeout {0}'.format(
                        timeout))
                warning, error = edit_service(self, modified_service_url,
                                              timeout)
                self.is_not_none(
                    error,
                    msg='Set invalid timeout: no error shown for timeout {0}'.
                    format(timeout))
                self.is_equal(
                    error,
                    messages.SERVICE_EDIT_INVALID_TIMEOUT.format(timeout),
                    msg=
                    'Set invalid service URL: wrong error shown for timeout {0} : {1}'
                    .format(timeout, error))
                self.is_none(
                    warning,
                    msg=
                    'Set invalid service URL: got warning for timeout {0} : {1}'
                    .format(timeout, warning))
                # If any error messages are shown, close them.
                messages.close_error_messages(self)

            # TEST PLAN 2.2.2.3 error 3 Try to set infinite service timeout. Should get a warning.
            self.log(
                '2.2.2.3 error 3 Trying to set infinite service timeout: {0}'.
                format(service_infinite_timeout))
            warning, error = edit_service(self, modified_service_url,
                                          service_infinite_timeout)
            self.is_none(
                error,
                msg='Set infinite service timeout: got error for timeout {0}'.
                format(service_infinite_timeout))
            self.is_not_none(
                warning,
                msg='Set infinite service timeout: no warning for timeout {0}'.
                format(service_infinite_timeout))
            self.is_equal(
                warning,
                messages.SERVICE_EDIT_INFINITE_TIMEOUT_WARNING.format(
                    service_infinite_timeout),
                msg=
                'Set infinite service timeout: wrong warning shown for timeout {0} : {1}'
                .format(service_infinite_timeout, error))
            # If any error messages are shown, close them.
            messages.close_error_messages(self)

            # We're not saving the service with an infinite timeout, so find the "Cancel" button and click it.
            self.wait_until_visible(
                type=By.XPATH,
                element=popups.WARNING_POPUP_CANCEL_XPATH).click()
            self.wait_jquery()

        # Try to set modified service URL and original service timeout. Should get no errors or warnings.
        self.log('Trying to set service timeout {1}, URL {0}'.format(
            modified_service_url, service_timeout))
        warning, error = edit_service(self, modified_service_url,
                                      service_timeout)
        self.is_none(
            error,
            msg='Edit service: got error for timeout {1}, URL {0}'.format(
                modified_service_url, service_timeout))
        self.is_none(
            warning,
            msg='Edit service: got warning for timeout {2}, URL {0} : {1}'.
            format(modified_service_url, warning, service_timeout))
        # If any error messages are shown, close them.
        messages.close_error_messages(self)
    def xroad_member_access():
        """
        :param self: MainController class object
        :return: None
        ''"""

        self.log('*** 2.2.9 / XT-473')

        # TEST PLAN 2.2.9 - giving access to XRoad member

        # TEST PLAN 2.2.9-1 test query from TS2 client TS2OWNER:sub to service bodyMassIndex. Query should fail.
        self.log(
            '2.2.9-1 test query {0} to service bodyMassIndex. Query should fail.'
            .format(query_filename))

        case.is_true(testclient.check_fail(),
                     msg='2.2.9-1 test query succeeded')

        # TEST PLAN 2.2.9-2 set bodyMassIndex address and ACL (give access to TS2OWNER:sub)
        self.log(
            '2.2.9-2 set bodyMassIndex address and ACL (give access to {0}'.
            format(requester_id))

        add_acl = add_to_acl_2_1_8.test_add_subjects(
            self,
            client=client,
            wsdl_url=wsdl_url,
            service_name=service_name,
            service_subjects=[requester_id],
            remove_data=False,
            allow_remove_all=False)
        try:
            # Try to add subject to ACL
            add_acl()

            # TEST PLAN 2.2.9-3 test query from TS2 client TS2OWNER:sub to service bodyMassIndex. Query should succeed.
            self.log(
                '2.2.9-3 test query {0} to service bodyMassIndex. Query should succeed.'
                .format(query_filename))

            case.is_true(testclient.check_success(),
                         msg='2.2.9-3 test query failed')
        finally:
            # Always try to remove access

            # TEST PLAN 2.2.9-4 Remove added subject from test service ACL
            self.log('2.2.9-4 Remove added subject from test service ACL.')

            # Open client popup using shortcut button to open it directly at Services tab.
            clients_table_vm.open_client_popup_services(self,
                                                        client_id=client_id)

            # Find the table that lists all WSDL files and services
            services_table = self.by_id(
                popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
            # Wait until that table is visible (opened in a popup)
            self.wait_until_visible(services_table)

            # Find the WSDL, expand it and select service
            clients_table_vm.client_services_popup_open_wsdl_acl(
                self,
                services_table=services_table,
                service_name=service_name,
                wsdl_index=wsdl_index,
                wsdl_url=wsdl_url)

            add_to_acl_2_1_8.remove_subjects_from_acl(self, [requester_id],
                                                      select_duplicate=True)

        # This is not in the specification but we should still check if removal was successful.
        # TEST PLAN 2.2.9-4 test query from TS2 client TS2OWNER:sub to service bodyMassIndex. Query should fail.
        self.log(
            '2.2.9-4 test query {0} to service bodyMassIndex. Query should fail.'
            .format(query_filename))
        case.is_true(testclient.check_fail(),
                     msg='2.2.9-4 test query succeeded')
Example #8
0
    def add_all_to_acl():
        """
        :param self: MainController class object
        :return: None
        ''"""

        self.log('2.1.8 add all to ACL')

        # Select duplicate elements (if database, for some reason, contains duplicate IDs). Not actually configurable
        # but can be moved to parameters if necessary.
        select_duplicate = True

        #
        # TEST PLAN 2.1.8-1 Security server clients view: choose a client and open their Services tab.
        #

        # Open client popup using shortcut button to open it directly at Services tab.
        clients_table_vm.open_client_popup_services(self, client_id=client_id)

        # Find the table that lists all WSDL files and services
        services_table = self.by_id(
            popups.CLIENT_DETAILS_POPUP_SERVICES_TABLE_ID)
        # Wait until that table is visible (opened in a popup)
        self.wait_until_visible(services_table)

        # Find the WSDL, expand it and select service
        clients_table_vm.client_services_popup_open_wsdl_acl(
            self,
            services_table=services_table,
            service_index=service_index,
            service_name=service_name,
            wsdl_index=wsdl_index,
            wsdl_url=wsdl_url)

        # A popup has been opened that lists current services. This may load for a few seconds with big lists.

        # We'll wait until the "Add subjects" button is visible (popup is open and list has been fully loaded)
        self.wait_until_visible(
            popups.
            CLIENT_DETAILS_POPUP_EXISTING_ACL_SUBJECTS_ADD_SUBJECTS_BTN_CSS,
            type=By.ID,
            timeout=20)

        # As we need to check that only the subjects that we add later make it to this list, we get the current list of
        # subjects for later comparison.
        current_subjects = get_current_acl_subjects(self)
        self.log('Current ACL subjects: {0}'.format(
            ', '.join(current_subjects)))

        #
        # TEST PLAN 2.1.8-2 Do an empty search to show all subjects that are registered in the system.
        #
        search_all_subjects(self)

        #
        # TEST PLAN 2.1.8-3. Click "Add All to ACL" button to add all listed subjects to ACL.
        #

        self.added_subjects = add_all_subjects_to_acl(self)

        # Wait until ajax query that adds the subjects finishes
        self.wait_jquery()

        #
        # TEST PLAN 2.1.8-4. Check if ACL list has been updated and only the subjects we selected have been added.
        #
        all_subjects_added, added_subjects_count = verify_added_subjects(
            self,
            current_subjects,
            self.added_subjects,
            strict_check_duplicates=True)

        #
        # TEST PLAN general: UNDO THE CHANGES WE MADE
        #

        # Restore the original subject list
        if remove_data:
            self.log('Added subject count: {0}'.format(len(
                self.added_subjects)))
            restore_original_subject_list(self,
                                          current_subjects,
                                          self.added_subjects,
                                          allow_remove_all,
                                          remove_duplicates=select_duplicate)
        else:
            self.log('Not restoring original ACL subject list')

        # Close all open dialogs (pre-logout, not essential)
        popups.close_all_open_dialogs(self)

        # Assertion if all selected subjects were added and found in the new subject list.
        self.is_true(
            all_subjects_added,
            msg='Some subjects were not added, tried to add {0}, succeeded {1}'
            .format(len(self.added_subjects), added_subjects_count))