improve Python test to cover low level FascistCheck

Gbp-Pq: Name improve_test_737040.patch
This commit is contained in:
Jan Dittberner 2022-06-04 14:14:21 +08:00 committed by Lu zhiping
parent 6cbfe96595
commit 4fcca984e4
1 changed files with 16 additions and 7 deletions

View File

@ -15,6 +15,13 @@ dictpath = None
class TestModuleFunctions(unittest.TestCase): class TestModuleFunctions(unittest.TestCase):
def test_FascistCheck(self):
try:
cracklib.FascistCheck('test', dictpath=dictpath)
self.fail('expected ValueError')
except ValueError:
pass
def test_VeryFascistCheck(self): def test_VeryFascistCheck(self):
try: try:
cracklib.VeryFascistCheck('test', dictpath=dictpath) cracklib.VeryFascistCheck('test', dictpath=dictpath)
@ -68,7 +75,7 @@ class TestModuleFunctions(unittest.TestCase):
def test_simple_lower(self): def test_simple_lower(self):
for passwd in ['t' * i for i in range( for passwd in ['t' * i for i in range(
cracklib.MIN_LENGTH - cracklib.LOW_CREDIT)]: cracklib.MIN_LENGTH - cracklib.LOW_CREDIT)]:
self.assertEquals( self.assertEquals(
1, cracklib.simple(passwd), 1, cracklib.simple(passwd),
'password {0} should be detected as too simple'.format( 'password {0} should be detected as too simple'.format(
@ -78,7 +85,7 @@ class TestModuleFunctions(unittest.TestCase):
def test_simple_upper(self): def test_simple_upper(self):
for passwd in ['T' * i for i in range( for passwd in ['T' * i for i in range(
cracklib.MIN_LENGTH - cracklib.UP_CREDIT)]: cracklib.MIN_LENGTH - cracklib.UP_CREDIT)]:
self.assertEquals( self.assertEquals(
1, cracklib.simple(passwd), 1, cracklib.simple(passwd),
'password {0} should be detected as too simple'.format( 'password {0} should be detected as too simple'.format(
@ -88,7 +95,7 @@ class TestModuleFunctions(unittest.TestCase):
def test_simple_digit(self): def test_simple_digit(self):
for passwd in ['1' * i for i in range( for passwd in ['1' * i for i in range(
cracklib.MIN_LENGTH - cracklib.DIG_CREDIT)]: cracklib.MIN_LENGTH - cracklib.DIG_CREDIT)]:
self.assertEquals( self.assertEquals(
1, cracklib.simple(passwd), 1, cracklib.simple(passwd),
'password {0} should be detected as too simple'.format( 'password {0} should be detected as too simple'.format(
@ -98,7 +105,7 @@ class TestModuleFunctions(unittest.TestCase):
def test_simple_other(self): def test_simple_other(self):
for passwd in ['#' * i for i in range( for passwd in ['#' * i for i in range(
cracklib.MIN_LENGTH - cracklib.OTH_CREDIT)]: cracklib.MIN_LENGTH - cracklib.OTH_CREDIT)]:
self.assertEquals( self.assertEquals(
1, cracklib.simple(passwd), 1, cracklib.simple(passwd),
'password {0} should be detected as too simple'.format( 'password {0} should be detected as too simple'.format(
@ -109,14 +116,16 @@ class TestModuleFunctions(unittest.TestCase):
def test_simple_combinations(self): def test_simple_combinations(self):
testset = '#a' * (cracklib.MIN_LENGTH // 2) testset = '#a' * (cracklib.MIN_LENGTH // 2)
for passwd in [testset[:i] for i in range( for passwd in [testset[:i] for i in range(
cracklib.MIN_LENGTH - cracklib.LOW_CREDIT - cracklib.OTH_CREDIT)]: cracklib.MIN_LENGTH -
cracklib.LOW_CREDIT -
cracklib.OTH_CREDIT)]:
self.assertEquals( self.assertEquals(
1, cracklib.simple(passwd), 1, cracklib.simple(passwd),
'password {0} should be detected as too simple'.format( 'password {0} should be detected as too simple'.format(
passwd)) passwd))
self.assertEquals(0, cracklib.simple( self.assertEquals(0, cracklib.simple(
testset[:(cracklib.MIN_LENGTH - cracklib.LOW_CREDIT - testset[:(cracklib.MIN_LENGTH - cracklib.LOW_CREDIT -
cracklib.OTH_CREDIT)])) cracklib.OTH_CREDIT)]))
tests.append(TestModuleFunctions) tests.append(TestModuleFunctions)
@ -127,7 +136,7 @@ def run(verbosity=1, repeat=1, use_dictpath=None):
print(('cracklib is installed in: ' + os.path.dirname(__file__))) print(('cracklib is installed in: ' + os.path.dirname(__file__)))
print(('cracklib version: ' + __version__)) print(('cracklib version: ' + __version__))
print((sys.version)) print((sys.version))
dictpath=use_dictpath dictpath = use_dictpath
suite = unittest.TestSuite() suite = unittest.TestSuite()
for cls in tests: for cls in tests: