"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.10.5.2/linotpd/src/linotp/tests/functional/test_manage.py" (13 May 2019, 13822 Bytes) of package /linux/misc/LinOTP-release-2.10.5.2.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 """
   29 """
   30 
   31 
   32 import logging
   33 import os
   34 
   35 try:
   36     import json
   37 except ImportError:
   38     import simplejson
   39 
   40 from linotp.tests import TestController, url
   41 
   42 log = logging.getLogger(__name__)
   43 
   44 
   45 class TestManageController(TestController):
   46 
   47     def setUp(self):
   48         '''
   49         resolver: reso1 (my-passwd), reso2 (my-pass2)
   50         realm: realm1, realm2
   51         token: token1 (r1), token2 (r1), token3 (r2)
   52         '''
   53 
   54         TestController.setUp(self)
   55         self.set_config_selftest()
   56 
   57         # remove all other tokens
   58         self.delete_all_token()
   59 
   60         # create resolvers
   61         response = self.app.get(
   62                     url(controller='system', action='setResolver'),
   63                     params={'name': 'reso1',
   64                             'type': 'passwdresolver',
   65                             'fileName': os.path.join(
   66                                             self.fixture_path,
   67                                             'my-passwd')})
   68 
   69         self.assertTrue('"value": true'in response, response)
   70 
   71         response = self.app.get(
   72                     url(controller='system', action='setResolver'),
   73                     params={'name': 'reso2',
   74                             'type': 'passwdresolver',
   75                             'fileName': os.path.join(
   76                                             self.fixture_path,
   77                                             'my-pass2')})
   78         self.assertTrue('"value": true'in response, response)
   79 
   80         # create realms
   81         response = self.app.get(url(controller='system', action='setRealm'),
   82                                 params={'realm': 'realm1',
   83                                         'resolvers':
   84                         'useridresolver.PasswdIdResolver.IdResolver.reso1'})
   85 
   86         log.info(response)
   87         self.assertTrue('"value": true'in response, response)
   88 
   89         response = self.app.get(url(controller='system', action='setRealm'),
   90                                 params={'realm': 'realm2',
   91                                         'resolvers':
   92                         'useridresolver.PasswdIdResolver.IdResolver.reso2'})
   93         log.info(response)
   94         self.assertTrue('"value": true'in response, response)
   95 
   96         # create token
   97         response = self.app.get(url(controller='admin', action='init'),
   98                                 params={'serial': 'token1',
   99                                         'type': 'spass',
  100                                         'pin': 'secret',
  101                                         'user': 'heinz',
  102                                         'realm': 'realm1'
  103                                         })
  104         log.info(response)
  105         self.assertTrue('"value": true'in response, response)
  106 
  107         response = self.app.get(url(controller='admin', action='init'),
  108                                 params={'serial': 'token2',
  109                                         'type': 'spass',
  110                                         'pin': 'secret',
  111                                         'user': 'nick',
  112                                         'realm': 'realm1'
  113                                         })
  114         log.info(response)
  115         self.assertTrue('"value": true'in response, response)
  116 
  117         response = self.app.get(url(controller='admin', action='init'),
  118                                 params={'serial': 'token3',
  119                                         'type': 'spass',
  120                                         'pin': 'secret',
  121                                         'user': 'renate',
  122                                         'realm': 'realm2'
  123                                         })
  124         log.info(response)
  125         self.assertTrue('"value": true'in response, response)
  126 
  127     def tearDown(self):
  128         '''
  129         make the dishes
  130         '''
  131         self.delete_all_token()
  132         self.delete_all_realms()
  133         self.delete_all_resolvers()
  134         return TestController.tearDown(self)
  135 
  136     ###########################################################################
  137     def test_index(self):
  138         '''
  139         Manage: testing index access
  140         '''
  141         response = self.app.get(url(controller='manage', action='index'),
  142                                 params={})
  143         log.info("index response: %r" % response)
  144         self.assertTrue('<title>LinOTP 2 Management</title>'in response,
  145                         response)
  146 
  147     def test_policies(self):
  148         '''
  149         Manage: testing policies tab
  150         '''
  151         response = self.app.get(url(controller='manage', action='policies'),
  152                                 params={})
  153         log.info("policies response: %r" % response)
  154         self.assertTrue('id="policy_export"'in response, response)
  155         self.assertTrue('id="policy_import"'in response, response)
  156         self.assertTrue('id="button_policy_delete"'in response,
  157                         response)
  158 
  159     def test_audit(self):
  160         '''
  161         Manage: testing audit trail
  162         '''
  163         response = self.app.get(url(controller='manage', action='audittrail'),
  164                                 params={})
  165         log.info("audit response: %r" % response)
  166         self.assertTrue('table id="audit_table"'in response, response)
  167         self.assertTrue('view_audit();'in response, response)
  168 
  169     def test_tokenview(self):
  170         '''
  171         Manage: testing tokenview
  172         '''
  173         response = self.app.get(url(controller='manage', action='tokenview'),
  174                                 params={})
  175         log.info("token response: %r" % response)
  176         self.assertTrue('button_losttoken'in response, response)
  177         self.assertTrue('button_tokeninfo'in response, response)
  178         self.assertTrue('button_resync'in response, response)
  179         self.assertTrue('button_tokenrealm'in response, response)
  180         self.assertTrue('table id="token_table"'in response, response)
  181         self.assertTrue('view_token();'in response, response)
  182         self.assertTrue('tokenbuttons();' in response, response)
  183 
  184     def test_userview(self):
  185         '''
  186         Manage: testing userview
  187         '''
  188         response = self.app.get(url(controller='manage', action='userview'),
  189                                 params={})
  190         log.info("user response: %r" % response)
  191         self.assertTrue('table id="user_table"' in response, response)
  192         self.assertTrue('view_user();' in response, response)
  193 
  194     def test_tokenflexi(self):
  195         '''
  196         Manage: testing the tokenview_flexi method
  197         '''
  198         response = self.app.get(url(controller='manage',
  199                                     action='tokenview_flexi'),
  200                                 params={})
  201         self.assertTrue('"total": 3' in response, response)
  202 
  203         # analyse the reply for token info
  204         resp = json.loads(response.body)
  205         tokens = resp.get('result', {}).get('value', {}).get('rows', [])
  206 
  207         match_count = 0
  208         for token in tokens:
  209             if token.get('id') == 'token1':
  210                 self.assertTrue("heinz" in token['cell'], resp)
  211                 match_count += 1
  212             elif token.get('id') == 'token2':
  213                 self.assertTrue("nick" in token['cell'], resp)
  214                 match_count += 1
  215             elif token.get('id') == 'token3':
  216                 self.assertTrue("renate" in token['cell'], resp)
  217                 match_count += 1
  218         self.assertTrue(match_count == 3,
  219                         "Not all matches found in resp %r" % resp)
  220 
  221         # only renates token
  222         response = self.app.get(url(controller='manage',
  223                                     action='tokenview_flexi'),
  224                                 params={'qtype': 'loginname',
  225                                         'query': 'renate'})
  226         testbody = response.body.replace('\n', ' ').replace('\r', '').\
  227                                                         replace("  ", " ")
  228         self.assertTrue('"total": 1' in testbody, testbody)
  229 
  230         # analyse the reply for token info
  231         resp = json.loads(response.body)
  232         tokens = resp.get('result', {}).get('value', {}).get('rows', [])
  233 
  234         match_count = 0
  235         for token in tokens:
  236             if token.get('id') == 'token3':
  237                 self.assertTrue("renate" in token['cell'], resp)
  238                 match_count += 1
  239         self.assertTrue(match_count == 1,
  240                         "Not all matches found in resp %r" % resp)
  241 
  242         # only tokens in realm1
  243         response = self.app.get(url(controller='manage',
  244                                     action='tokenview_flexi'),
  245                                 params={'qtype': 'realm',
  246                                         'query': 'realm1'})
  247         self.assertTrue('"total": 2' in response, response)
  248 
  249         # analyse the reply for token info
  250         resp = json.loads(response.body)
  251         tokens = resp.get('result', {}).get('value', {}).get('rows', [])
  252 
  253         match_count = 0
  254         for token in tokens:
  255             if token.get('id') == 'token1':
  256                 self.assertTrue("heinz" in token['cell'], resp)
  257                 match_count += 1
  258             elif token.get('id') == 'token2':
  259                 self.assertTrue("nick" in token['cell'], resp)
  260                 match_count += 1
  261         self.assertTrue(match_count == 2,
  262                         "Not all matches found in resp %r" % resp)
  263 
  264         # search in all columns
  265         response = self.app.get(url(controller='manage',
  266                                     action='tokenview_flexi'),
  267                                 params={'qtype': 'all',
  268                                         'query': 'token2'})
  269         self.assertTrue('"total": 1' in response, response)
  270 
  271         # analyse the reply for token info
  272         resp = json.loads(response.body)
  273         tokens = resp.get('result', {}).get('value', {}).get('rows', [])
  274 
  275         match_count = 0
  276         for token in tokens:
  277             if token.get('id') == 'token2':
  278                 self.assertTrue("nick" in token['cell'], resp)
  279                 match_count += 1
  280         self.assertTrue(match_count == 1,
  281                         "Not all matches found in resp %r" % resp)
  282 
  283         return
  284 
  285     def test_userflexi(self):
  286         '''
  287         Manage: testing the userview_flexi method
  288         '''
  289         # No realm, no user
  290         response = self.app.get(url(controller='manage',
  291                                     action='userview_flexi'),
  292                                 params={})
  293         log.info("user flexi response 1: %r" % response)
  294         self.assertTrue('"total": 0' in response, response)
  295 
  296         # No realm, no user
  297 
  298         response = self.app.get(url(controller='manage',
  299                                     action='userview_flexi'),
  300                                 params={"page": 1,
  301                                         "rp": 15,
  302                                         "sortname": "username",
  303                                         "sortorder": "asc",
  304                                         "query": "",
  305                                         "qtype": "username",
  306                                         "realm": "realm1"})
  307         self.assertTrue('"id": "heinz"' in response, response)
  308 
  309         response = self.app.get(url(controller='manage',
  310                                     action='userview_flexi'),
  311                                 params={"page": 1,
  312                                         "rp": 15,
  313                                         "sortname": "username",
  314                                         "sortorder": "desc",
  315                                         "query": "",
  316                                         "qtype": "username",
  317                                         "realm": "realm2"})
  318 
  319         self.assertTrue('"id": "renate"' in response, response)
  320 
  321         return
  322 
  323     def test_tokeninfo(self):
  324         '''
  325         Manage: Testing tokeninfo dialog
  326         '''
  327         response = self.app.get(url(controller='manage', action='tokeninfo'),
  328                                 params={"serial": "token1"})
  329         log.info("tokeninfo response: %r" % response)
  330         self.assertTrue('class=tokeninfoOuterTable' in response, response)
  331         self.assertTrue('Heinz Hirtz' in response, response)
  332         self.assertTrue('Heinz Hirtz' in response, response)
  333         self.assertTrue('<td class=tokeninfoOuterTable>LinOtp.'
  334                         'TokenSerialnumber</td> <!-- middle column --> <td '
  335                         'class=tokeninfoOuterTable> token1 </td> <!-- right '
  336                         'column -->' in response, response)
  337 
  338         return
  339 
  340     def test_logout(self):
  341         '''
  342         Manage: testing logout
  343         '''
  344         response = self.app.get(url(controller='manage', action='logout'),
  345                                 params={})
  346         log.info("logout response: %r" % response)
  347         self.assertTrue('302 Found The resource was found at' in response,
  348                         response)
  349 
  350         return