"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.10.5.3/linotpd/src/linotp/tests/integration/linotp_selenium_helper/set_config.py" (24 Jun 2019, 2512 Bytes) of package /linux/misc/LinOTP-release-2.10.5.3.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 SetConfig class to call system/setConfig"""
   27 
   28 import logging
   29 import requests
   30 from requests.auth import HTTPDigestAuth
   31 from helper import get_session
   32 
   33 
   34 LOG = logging.getLogger(__name__)
   35 
   36 
   37 class SetConfig:
   38 
   39     def __init__(self, http_protocol, http_host, http_port, http_username, http_password):
   40         """Initializes the class with the required values to call
   41            https://.../system/setConfig
   42         """
   43         self.auth = HTTPDigestAuth(http_username, http_password)
   44         url = http_protocol + "://" + http_host
   45         if http_port:
   46             url += ':' + http_port
   47         url += '/'
   48         self.set_config_url = url + "system/setConfig?"
   49         self.session = get_session(url, http_username, http_password)
   50 
   51     def setConfig(self, parameters):
   52         """Sets the config with the parameters
   53            return True if result.value and result.status is True
   54         """
   55         parameters['session'] = self.session
   56         r = requests.get(self.set_config_url,
   57                          params=parameters,
   58                          cookies={'admin_session': self.session},
   59                          auth=self.auth,
   60                          verify=False)
   61         if r.status_code != 200:
   62             return False
   63         return_json = r.json()
   64         if (return_json is None or
   65                'result' not in return_json or
   66                'value' not in return_json['result'] or
   67                'status' not in return_json['result']):
   68             raise Exception("Invalid return value: %r" % return_json)
   69         return (return_json['result']['status'])
   70