Beispiel #1
0
    def test_02_token(self):
        r = get_token_list()
        self.assertTrue("privacyidea.lib.tokens.totptoken" in r, r)
        self.assertTrue("privacyidea.lib.tokens.hotptoken" in r, r)

        # check modules
        mlist = get_token_module_list()
        mod_name = "privacyidea.lib.tokens.totptoken"
        exec("import %s" % mod_name)
        module = eval(mod_name)
        self.assertTrue(module in mlist, mlist)

#        r = get_resolver_classes()
#        self.assertTrue(UserResolver in r, r)
#        self.assertTrue(PWResolver in r, r)

        # get_token_class_dict
        (classes, types) = get_token_class_dict()
        self.assertTrue('privacyidea.lib.tokens.hotptoken.HotpTokenClass'
                        in classes, classes)
        self.assertTrue(classes.get(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass') ==
                        HotpTokenClass, classes)
        self.assertTrue('privacyidea.lib.tokens.totptoken.TotpTokenClass'
                        in classes, classes)
        self.assertTrue(classes.get(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass') ==
                        TotpTokenClass, classes)

        self.assertTrue('privacyidea.lib.tokens.hotptoken.HotpTokenClass'
                        in types, types)
        self.assertTrue('privacyidea.lib.tokens.totptoken.TotpTokenClass'
                        in types, types)
        self.assertTrue(types.get('privacyidea.lib.tokens.hotptoken'
                                  '.HotpTokenClass') == "hotp", types)
        self.assertTrue(types.get('privacyidea.lib.tokens.totptoken'
                                  '.TotpTokenClass') == "totp", types)

        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)
        # Now the resolver types are contained.
        self.assertTrue("pi_token_types" in current_app.config,
                        current_app.config)
        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)

        # At the beginning the token classes are not cached.
        self.assertFalse("pi_token_classes" in current_app.config,
                         current_app.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)
        # Now the token classes are cached
        self.assertTrue("pi_token_classes" in current_app.config,
                        current_app.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)
Beispiel #2
0
    def test_02_token(self):
        r = get_token_list()
        self.assertTrue("privacyidea.lib.tokens.totptoken" in r, r)
        self.assertTrue("privacyidea.lib.tokens.hotptoken" in r, r)

        # check modules
        mlist = get_token_module_list()
        mod_name = "privacyidea.lib.tokens.totptoken"
        module = importlib.import_module(mod_name)
        self.assertTrue(module in mlist, mlist)

        #        r = get_resolver_classes()
        #        self.assertTrue(UserResolver in r, r)
        #        self.assertTrue(PWResolver in r, r)

        # get_token_class_dict
        (classes, types) = get_token_class_dict()
        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.hotptoken.HotpTokenClass') ==
            HotpTokenClass, classes)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.totptoken.TotpTokenClass') ==
            TotpTokenClass, classes)

        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in types, types)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in types, types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.hotptoken'
                      '.HotpTokenClass') == "hotp", types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.totptoken'
                      '.TotpTokenClass') == "totp", types)

        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)

        # token classes are cached with calling 'get_token_types()'
        self.assertTrue("pi_token_classes" in this.config, this.config)
        self.assertTrue("pi_token_types" in this.config, this.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)
    def test_02_token(self):
        r = get_token_list()
        self.assertTrue("privacyidea.lib.tokens.totptoken" in r, r)
        self.assertTrue("privacyidea.lib.tokens.hotptoken" in r, r)

        # check modules
        mlist = get_token_module_list()
        mod_name = "privacyidea.lib.tokens.totptoken"
        module = importlib.import_module(mod_name)
        self.assertTrue(module in mlist, mlist)

#        r = get_resolver_classes()
#        self.assertTrue(UserResolver in r, r)
#        self.assertTrue(PWResolver in r, r)

        # get_token_class_dict
        (classes, types) = get_token_class_dict()
        self.assertTrue('privacyidea.lib.tokens.hotptoken.HotpTokenClass'
                        in classes, classes)
        self.assertTrue(classes.get(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass') ==
                        HotpTokenClass, classes)
        self.assertTrue('privacyidea.lib.tokens.totptoken.TotpTokenClass'
                        in classes, classes)
        self.assertTrue(classes.get(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass') ==
                        TotpTokenClass, classes)

        self.assertTrue('privacyidea.lib.tokens.hotptoken.HotpTokenClass'
                        in types, types)
        self.assertTrue('privacyidea.lib.tokens.totptoken.TotpTokenClass'
                        in types, types)
        self.assertTrue(types.get('privacyidea.lib.tokens.hotptoken'
                                  '.HotpTokenClass') == "hotp", types)
        self.assertTrue(types.get('privacyidea.lib.tokens.totptoken'
                                  '.TotpTokenClass') == "totp", types)

        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)

        # token classes are cached with calling 'get_token_types()'
        self.assertTrue("pi_token_classes" in this.config, this.config)
        self.assertTrue("pi_token_types" in this.config, this.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)
    def test_02_token(self):
        r = get_token_list()
        self.assertTrue("privacyidea.lib.tokens.totptoken" in r, r)
        self.assertTrue("privacyidea.lib.tokens.hotptoken" in r, r)

        # check modules
        mlist = get_token_module_list()
        mod_name = "privacyidea.lib.tokens.totptoken"
        module = importlib.import_module(mod_name)
        self.assertTrue(module in mlist, mlist)

        #        r = get_resolver_classes()
        #        self.assertTrue(UserResolver in r, r)
        #        self.assertTrue(PWResolver in r, r)

        # get_token_class_dict
        (classes, types) = get_token_class_dict()
        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.hotptoken.HotpTokenClass') ==
            HotpTokenClass, classes)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.totptoken.TotpTokenClass') ==
            TotpTokenClass, classes)

        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in types, types)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in types, types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.hotptoken'
                      '.HotpTokenClass') == "hotp", types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.totptoken'
                      '.TotpTokenClass') == "totp", types)

        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)

        # token classes are cached with calling 'get_token_types()'
        self.assertTrue("pi_token_classes" in this.config, this.config)
        self.assertTrue("pi_token_types" in this.config, this.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)

        # Test custom token types
        with self.app_context:
            self.app.config['PI_TOKEN_MODULES'] = 'tests.testdata.fancytoken'
            r = get_token_list()
            self.assertIn("tests.testdata.fancytoken", r, r)
            mlist = get_token_module_list()
            mod = importlib.import_module('tests.testdata.fancytoken')
            self.assertTrue(mod in mlist, mlist)
            (classes, types) = get_token_class_dict()
            self.assertIn('tests.testdata.fancytoken.FancyTokenClass', classes,
                          classes)
            self.assertIn('tests.testdata.fancytoken.FancyTokenClass', types,
                          types)
            self.assertEqual(
                types['tests.testdata.fancytoken.FancyTokenClass'], 'fancy',
                types)
            self.app.config.pop('PI_TOKEN_MODULES')
Beispiel #5
0
    def test_02_token(self):
        r = get_token_list()
        self.assertTrue("privacyidea.lib.tokens.totptoken" in r, r)
        self.assertTrue("privacyidea.lib.tokens.hotptoken" in r, r)

        # check modules
        mlist = get_token_module_list()
        mod_name = "privacyidea.lib.tokens.totptoken"
        module = importlib.import_module(mod_name)
        self.assertTrue(module in mlist, mlist)

        #        r = get_resolver_classes()
        #        self.assertTrue(UserResolver in r, r)
        #        self.assertTrue(PWResolver in r, r)

        # get_token_class_dict
        (classes, types) = get_token_class_dict()
        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.hotptoken.HotpTokenClass') ==
            HotpTokenClass, classes)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in classes,
            classes)
        self.assertTrue(
            classes.get('privacyidea.lib.tokens.totptoken.TotpTokenClass') ==
            TotpTokenClass, classes)

        self.assertTrue(
            'privacyidea.lib.tokens.hotptoken.HotpTokenClass' in types, types)
        self.assertTrue(
            'privacyidea.lib.tokens.totptoken.TotpTokenClass' in types, types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.hotptoken'
                      '.HotpTokenClass') == "hotp", types)
        self.assertTrue(
            types.get('privacyidea.lib.tokens.totptoken'
                      '.TotpTokenClass') == "totp", types)

        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)
        # Now the resolver types are contained.
        self.assertTrue("pi_token_types" in current_app.config,
                        current_app.config)
        types = get_token_types()
        self.assertTrue("totp" in types, types)
        self.assertTrue("hotp" in types, types)

        # At the beginning the token classes are not cached.
        self.assertFalse("pi_token_classes" in current_app.config,
                         current_app.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)
        # Now the token classes are cached
        self.assertTrue("pi_token_classes" in current_app.config,
                        current_app.config)
        r = get_token_classes()
        self.assertTrue(TotpTokenClass in r, r)
        self.assertTrue(HotpTokenClass in r, r)