"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.11/linotpd/src/linotp/tests/functional/test_resolver/test_sql_resolver.py" (12 Nov 2019, 5214 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 
   27 """
   28 sql resolver tests
   29 """
   30 
   31 import logging
   32 import json
   33 
   34 from .sql_test_controller import SQLTestController
   35 
   36 log = logging.getLogger(__name__)
   37 
   38 
   39 class SQLResolverTest(SQLTestController):
   40 
   41     def setUp(self):
   42         """ create an sql user table some users and the sql resolver """
   43 
   44         SQLTestController.setUp(self)
   45         self.setUpSQL()
   46 
   47         return
   48 
   49     def tearDown(self):
   50         """ drop the users and the user table """
   51 
   52         self.dropUsers()
   53         self.delete_all_token()
   54 
   55         return SQLTestController.tearDown(self)
   56 
   57     def test_sqlresolver_with_uid_as_int(self):
   58         """
   59         test that we can use an sql resolver with the uid defined as int
   60         """
   61 
   62         user = 'hey1'
   63         serial = 'sql_hmac_test_token'
   64         realm = 'sqlRealm'
   65 
   66         # ------------------------------------------------------------------ --
   67 
   68         # create the User schema with id field as integer
   69 
   70         self.createUserTable(schema_additions={'id': 'integer'})
   71 
   72         # ------------------------------------------------------------------ --
   73 
   74         self.addUsers(usercount=2)
   75 
   76         # ------------------------------------------------------------------ --
   77 
   78         # define resolver and realm
   79 
   80         self.addSqlResolver('my_sql_users')
   81         self.addSqlRealm(realm, 'my_sql_users', defaultRealm=True)
   82 
   83         # ------------------------------------------------------------------ --
   84 
   85         # create token for user 'hey1'
   86 
   87         params = {
   88             'type': 'hmac',
   89             'genkey': 1,
   90             'user': user,
   91             'realm': realm,
   92             'serial': serial,
   93             'pin': 'mypin'
   94         }
   95         response = self.make_admin_request('init', params=params)
   96 
   97         self.assertTrue('false' not in response.body, response)
   98 
   99         # ------------------------------------------------------------------ --
  100 
  101         # create the required selfservice policy
  102 
  103         params = {
  104             'name': 'my_selfservice_pol',
  105             'action': 'reset',
  106             'scope': 'selfservice',
  107             'user': '*',
  108             'realm': '*',
  109             }
  110 
  111         response = self.make_system_request('setPolicy', params=params)
  112         self.assertTrue('false' not in response.body)
  113 
  114         # ------------------------------------------------------------------ --
  115 
  116         # run a wrong login, so that the token failcount increments
  117 
  118         params = {
  119             'user': user,
  120             'pass': 'mypin123456'
  121             }
  122 
  123         response = self.make_validate_request('check', params=params)
  124         self.assertTrue('"value": false' in response)
  125 
  126         # ------------------------------------------------------------------ --
  127 
  128         # verify that the token count is incremented to 1
  129 
  130         params = {
  131             'serial': serial
  132             }
  133 
  134         response = self.make_admin_request('show', params=params)
  135         jresp = json.loads(response.body)
  136         token_info = jresp.get(
  137             'result', {}).get(
  138                 'value', {}).get(
  139                     'data',[{}])[0]
  140         self.assertTrue(token_info.get( "LinOtp.FailCount", -1) == 1)
  141 
  142         # ------------------------------------------------------------------ --
  143 
  144         # now login to the selfservice and run the token reset
  145 
  146         auth_user = {'login': user,
  147                      'realm': realm,
  148                      'password': 'geheim1'}
  149 
  150         params = {'serial': serial}
  151 
  152         response = self.make_userselfservice_request('reset',
  153                                                      params=params,
  154                                                      auth_user=auth_user,
  155                                                      new_auth_cookie=True)
  156 
  157         self.assertTrue('false' not in response, response)
  158 
  159         # ------------------------------------------------------------------ --
  160 
  161         # verify that the token count is reset to 0
  162 
  163         params = {
  164             'serial': serial
  165             }
  166 
  167         response = self.make_admin_request('show', params=params)
  168         jresp = json.loads(response.body)
  169         token_info = jresp.get(
  170             'result', {}).get(
  171                 'value', {}).get(
  172                     'data',[{}])[0]
  173         self.assertTrue(token_info.get( "LinOtp.FailCount", -1) == 0)
  174 
  175         return
  176 
  177 # eof