Beispiel #1
0
    def __init__(self, driver, base_url, file_type, file_content, file_path):
        """Imports the file. Currently the only file_type supported is 'safenet'.
           Either file_content (string) or file_path (string) has to be present.
           If file_content is not None and there is no path then file_content
           is written to a temporary file that is used for the import.
        """
        self.driver = driver
        self.base_url = base_url
        self.file_type = file_type
        self.file_content = file_content
        self.file_path = file_path

        if file_content is not None and file_content != "":
            tf = tempfile.NamedTemporaryFile(delete=False, suffix=".xml")
            tf.write(file_content)
            tf.close()
            self.file_path = tf.name

        self.driver.get(self.base_url + "/manage")
        import_button = self.driver.find_element_by_xpath(u"//ul[@id='menu']//"
                                       "li[a[text()='Import Token File']]")
        time.sleep(1)
        hover(self.driver, import_button)
        time.sleep(1)
        if self.file_type == "safenet":
            self.driver.find_element_by_id("menu_load_aladdin_xml_tokenfile").click()
        else:
            exit(1)
        self.driver.find_element_by_xpath("(//input[@name='file'])[7]").send_keys(self.file_path)
        self.driver.find_element_by_id("button_aladdin_load").click()
Beispiel #2
0
    def test_connection(self):
        """Test the connection with the corresponding button in the UI.
        Return the number of found users.
        """
        self.driver.get(self.base_url + "/manage/")
        time.sleep(1)
        hover(self.driver, self.driver.find_element_by_css_selector('#menu > li'))
        time.sleep(1)
        self.driver.find_element_by_id("menu_edit_resolvers").click()

        resolvers = self.driver.find_elements_by_css_selector("#resolvers_list > ol > li")

        for resolver in resolvers:
            if resolver.text == self.name_for_list:
                resolver.click()

        self.driver.find_element_by_id("button_resolver_edit").click()
        time.sleep(1)
        self.driver.find_element_by_id(self.testbutton_id).click()

        time.sleep(2)
        alert_box = self.driver.find_element_by_id("alert_box_text")
        alert_box_text = alert_box.text
        self.driver.find_element_by_xpath("//button[@type='button' and ancestor::div[@aria-describedby='alert_box']]").click()

        p = re.compile(".*?config seems to be OK! Number of users found: (\d+)")
        m = p.search(alert_box_text)
        if m is None:
            raise Exception("text_connection for " + self.name + " failed: " + alert_box_text)
        return int(m.group(1))
Beispiel #3
0
    def __init__(self, driver, base_url, file_type, file_content, file_path):
        """Imports the file. Currently the only file_type supported is 'safenet'.
           Either file_content (string) or file_path (string) has to be present.
           If file_content is not None and there is no path then file_content
           is written to a temporary file that is used for the import.
        """
        self.driver = driver
        self.base_url = base_url
        self.file_type = file_type
        self.file_content = file_content
        self.file_path = file_path

        if file_content is not None and file_content != "":
            tf = tempfile.NamedTemporaryFile(delete=False, suffix=".xml")
            tf.write(file_content)
            tf.close()
            self.file_path = tf.name

        self.driver.get(self.base_url + "/manage/")
        import_button = self.driver.find_element_by_xpath(u"//ul[@id='menu']//"
                                       "li[a[text()='Import Token File']]")
        time.sleep(1)
        hover(self.driver, import_button)
        time.sleep(1)
        if self.file_type == "safenet":
            self.driver.find_element_by_id("menu_load_aladdin_xml_tokenfile").click()
        else:
            exit(1)
        self.driver.find_element_by_xpath("(//input[@name='file'])[7]").send_keys(self.file_path)
        self.driver.find_element_by_id("button_aladdin_load").click()
Beispiel #4
0
    def test_connection(self):
        """Test the connection with the corresponding button in the UI.
        Return the number of found users.
        """
        self.driver.get(self.base_url + "/manage/")
        time.sleep(1)
        hover(self.driver,
              self.driver.find_element_by_css_selector('#menu > li'))
        time.sleep(1)
        self.driver.find_element_by_id("menu_edit_resolvers").click()

        resolvers = self.driver.find_elements_by_css_selector(
            "#resolvers_list > ol > li")

        for resolver in resolvers:
            if resolver.text == self.name_for_list:
                resolver.click()

        self.driver.find_element_by_id("button_resolver_edit").click()
        time.sleep(1)
        self.driver.find_element_by_id(self.testbutton_id).click()

        time.sleep(2)
        alert_box = self.driver.find_element_by_id("alert_box_text")
        alert_box_text = alert_box.text
        self.driver.find_element_by_xpath(
            "//button[@type='button' and ancestor::div[@aria-describedby='alert_box']]"
        ).click()

        m = re.search("Number of users found: (?P<nusers>\d+)", alert_box_text)
        if m is None:
            raise Exception("text_connection for " + self.name + " failed: " +
                            alert_box_text)
        return int(m.group('nusers'))
Beispiel #5
0
    def __init__(self, name, driver, base_url):
        """Initialize values and open the menu in the UI"""
        self.name = name
        self.driver = driver
        self.base_url = base_url
        self.name_for_list = ""
        self.testbutton_id = ""

        #Open the LinOTP manage interface and the UserIdResolver menu
        driver.get(self.base_url + "/manage/")
        time.sleep(1)
        hover(self.driver, self.driver.find_element_by_css_selector('#menu > li'))
        time.sleep(1)
        driver.find_element_by_id("menu_edit_resolvers").click()
        driver.find_element_by_id("button_resolver_new").click()
Beispiel #6
0
    def __init__(self, name, driver, base_url):
        """Initialize values and open the menu in the UI"""
        self.name = name
        self.driver = driver
        self.base_url = base_url
        self.name_for_list = ""
        self.testbutton_id = ""

        #Open the LinOTP manage interface and the UserIdResolver menu
        driver.get(self.base_url + "/manage/")
        time.sleep(1)
        hover(self.driver,
              self.driver.find_element_by_css_selector('#menu > li'))
        time.sleep(1)
        driver.find_element_by_id("menu_edit_resolvers").click()
        driver.find_element_by_id("button_resolver_new").click()
Beispiel #7
0
 def create(self, driver, base_url):
     """Opens the LinOTP manage interface and the UserIdResolver menu"""
     driver.get(base_url + "/manage/")
     hover(driver, driver.find_element_by_css_selector("#menu > li"))
     driver.find_element_by_id("menu_edit_realms").click()
     driver.find_element_by_id("button_realms_new").click()
     driver.find_element_by_id("realm_name").clear()
     driver.find_element_by_id("realm_name").send_keys(self.name)
     elements = driver.find_elements_by_css_selector("#resolvers_in_realms_select > li")
     resolver_names = [resolver.name_for_list for resolver in self.resolvers]
     ActionChains(driver).key_down(Keys.CONTROL).perform()
     for element in elements:
         if element.text in resolver_names:
             element.click()
     ActionChains(driver).key_up(Keys.CONTROL).perform()
     driver.find_element_by_id("button_editrealms_save").click()
     driver.find_element_by_id("button_realms_close").click()
Beispiel #8
0
    def _activate_dialog(self, reload_page, toplevel_selector, menu_id,
                         dialog_id):
        """
        Activate the given menu item and check the dialog id.

        :param toplevel_selector: The CSS selector of the first menu.
        :param menu_id: The ID of the menu element
        :param dialog_id: The ID of the dialog that pops up
        """
        if reload_page or not self._is_url_open():
            self.open_manage()
        menu_element = self.find_by_css(toplevel_selector)
        helper.hover(self.driver, menu_element)
        self.find_by_id(menu_id).click()

        assert self.driver.find_element_by_id(
            dialog_id), 'Dialog id needs to be present: %s' % (dialog_id, )
Beispiel #9
0
 def create(self, driver, base_url):
     """Opens the LinOTP manage interface and the UserIdResolver menu"""
     driver.get(base_url + "/manage/")
     time.sleep(1)
     hover(driver, driver.find_element_by_css_selector('#menu > li'))
     time.sleep(1)
     driver.find_element_by_id("menu_edit_realms").click()
     driver.find_element_by_id("button_realms_new").click()
     driver.find_element_by_id("realm_name").clear()
     driver.find_element_by_id("realm_name").send_keys(self.name)
     elements = driver.find_elements_by_css_selector(
         "#resolvers_in_realms_select > li"
     )
     resolver_names = [resolver.name_for_list for resolver in self.resolvers]
     ActionChains(driver).key_down(Keys.CONTROL).perform()
     for element in elements:
         if element.text in resolver_names:
             element.click()
     ActionChains(driver).key_up(Keys.CONTROL).perform()
     driver.find_element_by_id("button_editrealms_save").click()
     driver.find_element_by_id("button_realms_close").click()