Ejemplo n.º 1
0
def add_users_to_system(ssh_host, ssh_username, ssh_password, users):
    '''
    Adds test users to system over SSH connection.
    :param ssh_host: str - SSH server hostname
    :param ssh_username: str - SSH username
    :param ssh_password: str - SSH password
    :param users: dict - user data
    :return: None
    '''
    # Create new SSH connection
    client = ssh_server_actions.get_client(ssh_host, ssh_username,
                                           ssh_password)
    try:
        # Add users
        user = users['user1']
        ssh_user_actions.add_user(client=client,
                                  username=user[USERNAME],
                                  password=user[PASSWORD],
                                  group=user['group'])
        user = users['user2']
        ssh_user_actions.add_user(client=client,
                                  username=user[USERNAME],
                                  password=user[PASSWORD],
                                  group=user['group'])
        user = users['user3']
        ssh_user_actions.add_user(client=client,
                                  username=user[USERNAME],
                                  password=user[PASSWORD],
                                  group=user['group'])
    finally:
        # Close SSH connection
        client.close()
Ejemplo n.º 2
0
def remove_users_from_system(ssh_host, ssh_username, ssh_password, users):
    '''
    Removes created users from the system.
    :param ssh_host: str - SSH server hostname
    :param ssh_username: str - SSH username
    :param ssh_password: str - SSH password
    :param users: dict - user data
    :return: None
    '''
    client = ssh_server_actions.get_client(ssh_host, ssh_username,
                                           ssh_password)
    try:
        ssh_user_actions.delete_user(client, username=users['user1'][USERNAME])
        ssh_user_actions.delete_user(client, username=users['user2'][USERNAME])
        ssh_user_actions.delete_user(client, username=users['user3'][USERNAME])
    finally:
        client.close()
Ejemplo n.º 3
0
def check_logs_for(self, ssh_host, ssh_username, ssh_password, event, user):
    '''
    Checks if an event for user was logged in the system.
    :param self: MainController object
    :param ssh_host: str - SSH server hostname
    :param ssh_username: str - SSH username
    :param ssh_password: str - SSH password
    :param event: str - event to look for in the logs
    :param user: str - username to look for in the logs
    :return: bool - True if event was logged; False otherwise
    '''
    time.sleep(10)
    s_client = ssh_server_actions.get_client(ssh_host, ssh_username,
                                             ssh_password)
    log = ssh_server_actions.get_log_lines(s_client, self.xroad_audit_log, 1)
    s_client.close()
    self.log(log)
    date_time = datetime.strptime(' '.join([log['date'], log['time']]),
                                  "%Y-%m-%d %H:%M:%S")
    datetime.strptime(datetime.strftime(date_time, "%Y-%m-%d %H:%M:%S.000000"),
                      '%Y-%m-%d %H:%M:%S.%f')
    return (log['msg_service'] == 'X-Road Proxy UI') & (log['data']['event'] == event) & \
           (log['data']['user'] == user), log['data'], date_time
Ejemplo n.º 4
0
    def test_case(self):
        # TEST PLAN 2.11.1 logging maintenance actions in central server
        self.log('*** 2.11.1 / XT-518')

        # Save users to MainController
        self.users = users

        # Get the first user
        user = users['user1']

        # Extract client parameters from ID, save names
        client = xroad.split_xroad_subsystem(client_id)
        client['name'] = client_name
        client['name2'] = client_name2

        # Create SSH session
        ssh_client = ssh_server_actions.get_client(ssh_host, ssh_username,
                                                   ssh_password)
        self.log('Adding users to system')

        # Add test users to the system so the test can be run separately from others
        add_users_to_system(self, ssh_client)

        # By default, there is no error.
        error = False

        try:
            # TEST PLAN 2.11.1-1 log in to central server UI as user1
            self.log('2.11.1-1 logging in to central server as user1')
            check_login(self, ssh_client, None, users['user1'])

            # TEST PLAN 2.11.1-2 adding new member to central server
            self.log('2.11.1-2 adding new member to central server')
            add_member_to_cs(self, ssh_client, user, member=client)

            # TEST PLAN 2.11.1-3 adding new subsystem to the member
            self.log('2.11.1-3 adding new subsystem to the member')
            add_subsystem_to_member(self, ssh_client, user, member=client)

            # TEST PLAN 2.11.1-4, 2.11.1-5 change member name (empty and non-empty)
            self.log(
                '2.11.1-4, 2.11.1-5 change member name (empty and non-empty)')
            change_member_name(self, ssh_client, user, member=client)

            # TEST PLAN 2.11.1-6 log out and then log in to central server UI as user2
            self.log('2.11.1-6 logging out, then logging in as user2')
            user = users['user2']
            check_login(self,
                        ssh_client,
                        logout_user=users['user1'],
                        login_user=user)

            # TEST PLAN 2.11.1-7, 2.11.1-8 add new group (failure and success test)
            self.log(
                '2.11.1-7, 2.11.1-8 add new group (failure and success test)')
            add_group(self, ssh_client, user, group)

            # TEST PLAN 2.11.1-9 add the new subsystem to the new group
            self.log('2.11.1-9 add the subsystem to the new group')
            add_client_to_group(self,
                                ssh_client,
                                user,
                                member=client,
                                group=group)

            # TEST PLAN 2.11.1-10 add new registration request for the new subsystem
            self.log(
                '2.11.1-10 add new registration request for the new subsystem')
            self.driver.get(self.url)
            register_subsystem_to_security_server(self,
                                                  ssh_client,
                                                  user,
                                                  member=client,
                                                  server_id=server_id)

            # TEST PLAN 2.11.1-11 log out, then log in to central server as user3
            self.log(
                '2.11.1-11 log out, then log in to central server as user3')
            user = users['user3']
            check_login(self,
                        ssh_client,
                        logout_user=users['user2'],
                        login_user=user)

            # TEST PLAN 2.11.1-12 remove the registration request for the new subsystem
            self.log(
                '2.11.1-12 remove the registration request for the new subsystem'
            )
            remove_subsystem_registration_request(self, ssh_client, user,
                                                  server_id)

            # TEST PLAN 2.11.1-13 delete the member from central server
            self.log('2.11.1-13 delete the member from central server')
            delete_client(self, ssh_client, user, member=client)

            # TEST PLAN 2.11.1-14 checks are done in the corresponding functions.
        except:
            # Had an error, set error to be True and print traceback.
            traceback.print_exc()
            error = True
        finally:
            # Always remove data
            try:
                # Remove test data that may have been partially created on error
                if error:
                    # Remove member
                    try:
                        self.log('2.11.1-del remove member')
                        delete_client(self, ssh_client, user, member=client)
                    except:
                        self.log('2.11.1-del removing member failed')

                    # Revoke all requests (loop until done)
                    try:
                        self.log('2.11.1-del revoking requests')
                        self.reset_webdriver(self.config.get('cs.host'),
                                             self.config.get('cs.user'),
                                             self.config.get('cs.pass'))
                        self.wait_jquery()
                        self.wait_until_visible(
                            type=By.CSS_SELECTOR,
                            element=sidebar.MANAGEMENT_REQUESTS_CSS).click()
                        self.wait_jquery()
                        time.sleep(5)

                        try:
                            td = self.by_xpath(
                                members_table.get_requests_row_by_td_text(
                                    'SUBMITTED FOR APPROVAL'))
                        except:
                            td = None

                        try:
                            while td is not None:
                                td.click()
                                self.wait_until_visible(
                                    type=By.ID,
                                    element=members_table.
                                    MANAGEMENT_REQUEST_DETAILS_BTN_ID).click()
                                self.wait_jquery()
                                time.sleep(1)
                                self.log('2.11.1-del revoking request')
                                self.wait_until_visible(
                                    type=By.XPATH,
                                    element=members_table.
                                    DECLINE_REQUEST_BTN_XPATH).click()
                                self.wait_jquery()
                                popups.confirm_dialog_click(self)
                                time.sleep(5)
                                try:
                                    td = self.by_xpath(
                                        members_table.
                                        get_requests_row_by_td_text(
                                            'SUBMITTED FOR APPROVAL'))
                                except:
                                    td = None
                        except:
                            traceback.print_exc()

                    except:
                        self.log('2.11.1-del Deleting client failed')
            except:
                self.log('2.11.1-del Deleting client failed')
            try:
                self.log('2.11.1-del Deleting group')
                remove_group(self, group)
            except:
                self.log('2.11.1-del Deleting group failed')
            self.log('2.11.1-del closing SSH connection')
            ssh_client.close()
            if error:
                # Got an error before, fail the test
                assert False, '2.11.1 failed'