"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.11/linotpd/src/linotp/tests/integration/linotp_selenium_helper/policy.py" (12 Nov 2019, 3426 Bytes) of package /linux/misc/LinOTP-release-2.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- coding: utf-8 -*-
    2 #
    3 #    LinOTP - the open source solution for two factor authentication
    4 #    Copyright (C) 2010 - 2019 KeyIdentity GmbH
    5 #
    6 #    This file is part of LinOTP server.
    7 #
    8 #    This program is free software: you can redistribute it and/or
    9 #    modify it under the terms of the GNU Affero General Public
   10 #    License, version 3, as published by the Free Software Foundation.
   11 #
   12 #    This program is distributed in the hope that it will be useful,
   13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 #    GNU Affero General Public License for more details.
   16 #
   17 #    You should have received a copy of the
   18 #               GNU Affero General Public License
   19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   20 #
   21 #
   22 #    E-mail: linotp@keyidentity.com
   23 #    Contact: www.linotp.org
   24 #    Support: www.keyidentity.com
   25 #
   26 """Contains Policy class"""
   27 
   28 import time
   29 
   30 from manage_elements import ManageTab
   31 from helper import select, fill_form_element
   32 
   33 
   34 class PolicyManager(ManageTab):
   35     policy_entries_css_selector = "table#policy_table > tbody > tr"
   36     policy_delete_button_id = "button_policy_delete"
   37 
   38     TAB_INDEX = 3
   39 
   40     def clear_policies_via_api(self):
   41         """
   42         Get all policies via API call
   43         and delete all by policy name.
   44         """
   45 
   46         # Get the policies in json format
   47         json_response = self.manage.admin_api_call("system/getPolicy")
   48 
   49         policies = json_response["result"]["value"]
   50         if(policies):
   51             for curr_policy in policies:
   52                 self.manage.admin_api_call("system/delPolicy",
   53                                            {'name': policies[curr_policy]['name']})
   54 
   55     def clear_policies(self):
   56         self.open_tab()
   57 
   58         while True:
   59             policies = self.driver.find_elements_by_css_selector(
   60                 self.policy_entries_css_selector)
   61             if not policies:
   62                 break
   63             self.delete_policy(policies[0])
   64             time.sleep(1)
   65 
   66     def delete_policy(self, p):
   67         p.click()
   68         self.find_by_id(self.policy_delete_button_id).click()
   69         self.wait_for_grid_loading()
   70 
   71     def set_new_policy(self, policy):
   72         """
   73         Create a policy using the UI elements
   74         """
   75         self.open_tab()
   76         driver = self.driver
   77 
   78         policy_active_cb = self.find_by_id("policy_active")
   79         if not policy_active_cb.is_selected():
   80             policy_active_cb.click()
   81 
   82         fill_form_element(driver, "policy_name", policy.name)
   83 
   84         scope_select = self.find_by_id('policy_scope_combo')
   85         select(driver, scope_select, policy.scope)
   86 
   87         fill_form_element(driver, "policy_action", policy.action)
   88         fill_form_element(driver, "policy_realm", policy.realm)
   89         fill_form_element(driver, "policy_name", policy.name)
   90         fill_form_element(driver, "policy_user", policy.user)
   91         self.find_by_id("button_policy_add").click()
   92         self.wait_for_waiting_finished()
   93 
   94 
   95 class Policy(object):
   96     """Creates a LinOTP Policy"""
   97 
   98     def __init__(self, manage_ui, name, scope, action, realm, user="*"):
   99         """Opens the LinOTP manage interface and creates a Policy"""
  100         self.name = name
  101         self.scope = scope
  102         self.action = action
  103         self.realm = realm
  104         self.user = user
  105 
  106         manage_ui.policy_view.set_new_policy(self)