...
 
# -*- coding: utf-8 -*-
"""
stuff for testing
"""
import unittest
# from setuptools
import pkg_resources
from ekca_service.__about__ import PASSWORD_PLUGIN_NAMESPACE, OTP_PLUGIN_NAMESPACE
class PasswordPluginTestCase(unittest.TestCase):
"""
base unit test class (not directly used)
"""
plugin_name = None
def setUp(self):
self.password_plugins = {
entry_point.name: entry_point.load()
for entry_point
in pkg_resources.iter_entry_points(PASSWORD_PLUGIN_NAMESPACE)
}
class OTPPluginTestCase(unittest.TestCase):
"""
base unit test class (not directly used)
"""
plugin_name = None
def setUp(self):
self.otp_plugins = {
entry_point.name: entry_point.load()
for entry_point in pkg_resources.iter_entry_points(OTP_PLUGIN_NAMESPACE)
}
......@@ -3,45 +3,33 @@
Test EKCA service OTP plugin classes
"""
import unittest
import logging
# from setuptools
import pkg_resources
import ekca_service.plugins.otp.base
from ekca_service.plugins.otp.base import OTPCheckFailed
from ekca_service.__about__ import OTP_PLUGIN_NAMESPACE
class OTPPluginTestCase(unittest.TestCase):
"""
base unit test class (not directly used)
"""
otp_module = ''
def setUp(self):
self.otp_plugins = {
entry_point.name: entry_point.load()
for entry_point in pkg_resources.iter_entry_points(OTP_PLUGIN_NAMESPACE)
}
from ekca_service.test import OTPPluginTestCase
class TestDummyPlugin(OTPPluginTestCase):
plugin_name = 'dummy'
def test001_plugin_registration(self):
self.assertIn('dummy', self.otp_plugins)
self.assertEqual(self.otp_plugins['dummy'], ekca_service.plugins.otp.base.Dummy)
self.assertIn(self.plugin_name, self.otp_plugins)
self.assertEqual(self.otp_plugins[self.plugin_name], ekca_service.plugins.otp.base.Dummy)
def test002_check_default(self):
otp_checker = self.otp_plugins['dummy']({}, logging.getLogger())
otp_checker = self.otp_plugins[self.plugin_name]({}, logging.getLogger())
for opt_value in ekca_service.plugins.otp.base.Dummy.values_default.split(' '):
self.assertEqual(otp_checker.check('foobar', opt_value), None)
with self.assertRaises(OTPCheckFailed):
otp_checker.check('foobar', 'foobar')
def test003_check_custom(self):
otp_checker = self.otp_plugins['dummy']({'OTP_DUMMY_VALUES':' 424242 , ABCD123456789 abcdefG '}, logging.getLogger())
otp_checker = self.otp_plugins[self.plugin_name](
{'OTP_DUMMY_VALUES':' 424242 , ABCD123456789 abcdefG '},
logging.getLogger(),
)
self.assertEqual(otp_checker.check('foobar', '424242'), None)
self.assertEqual(otp_checker.check('foobar', 'ABCD123456789'), None)
self.assertEqual(otp_checker.check('foobar', 'abcdefG'), None)
......
......@@ -7,45 +7,32 @@ import unittest
import logging
from collections import defaultdict
# from setuptools
import pkg_resources
import ekca_service.plugins.password.base
from ekca_service.plugins.password.base import PasswordCheckFailed
from ekca_service.__about__ import PASSWORD_PLUGIN_NAMESPACE
from ekca_service.test import PasswordPluginTestCase
DUMMY_EMPTY_USER_ENTRY = dict(attributes=defaultdict(lambda: []))
class PasswordPluginTestCase(unittest.TestCase):
"""
base unit test class (not directly used)
"""
def setUp(self):
self.password_plugins = {
entry_point.name: entry_point.load()
for entry_point
in pkg_resources.iter_entry_points(PASSWORD_PLUGIN_NAMESPACE)
}
class TestDummyPlugin(PasswordPluginTestCase):
plugin_name = 'dummy'
def test001_plugin_registration(self):
self.assertIn('dummy', self.password_plugins)
self.assertEqual(self.password_plugins['dummy'], ekca_service.plugins.password.base.Dummy)
self.assertIn(self.plugin_name, self.password_plugins)
self.assertEqual(self.password_plugins[self.plugin_name], ekca_service.plugins.password.base.Dummy)
def test002_check_default(self):
password_checker = self.password_plugins['dummy']({}, logging.getLogger())
password_checker = self.password_plugins[self.plugin_name]({}, logging.getLogger())
for opt_value in ekca_service.plugins.password.base.Dummy.values_default.split(' '):
self.assertEqual(password_checker.check('foobar', opt_value, '127.0.0.1'), DUMMY_EMPTY_USER_ENTRY)
with self.assertRaises(PasswordCheckFailed):
password_checker.check('foobar', 'foobar', '127.0.0.1')
def test003_check_custom(self):
password_checker = self.password_plugins['dummy']({'PASSWORD_DUMMY_VALUES':' 424242 , ABCD123456789 abcdefG '}, logging.getLogger())
password_checker = self.password_plugins[self.plugin_name]({'PASSWORD_DUMMY_VALUES':' 424242 , ABCD123456789 abcdefG '}, logging.getLogger())
self.assertEqual(password_checker.check('foobar', '424242', '127.0.0.1'), DUMMY_EMPTY_USER_ENTRY)
self.assertEqual(password_checker.check('foobar', 'ABCD123456789', '127.0.0.1'), DUMMY_EMPTY_USER_ENTRY)
self.assertEqual(password_checker.check('foobar', 'abcdefG', '127.0.0.1'), DUMMY_EMPTY_USER_ENTRY)
......