mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-11-16 13:35:39 +01:00
Fix version comparison and update tests.
This commit is contained in:
parent
407ddbd7ea
commit
262c65b7be
@ -506,7 +506,7 @@ class SSH(object):
|
||||
if other is None:
|
||||
return 1
|
||||
if isinstance(other, self.__class__):
|
||||
other = '{0}{1}'.format(other.version, other.patch)
|
||||
other = '{0}{1}'.format(other.version, other.patch or '')
|
||||
else:
|
||||
other = str(other)
|
||||
mx = re.match(r'^([\d\.]+\d+)(.*)$', other)
|
||||
|
@ -22,32 +22,63 @@ class TestVersionCompare(object):
|
||||
|
||||
def test_dropbear_compare_version_pre_years(self):
|
||||
s = self.get_dropbear_software('0.44')
|
||||
assert s.compare_version(None) == 1
|
||||
assert s.compare_version('') == 1
|
||||
assert s.compare_version('0.43') > 0
|
||||
assert s.compare_version('0.44') == 0
|
||||
assert s.compare_version(s) == 0
|
||||
assert s.compare_version('0.45') < 0
|
||||
assert s.between_versions('0.43', '0.45')
|
||||
assert s.between_versions('0.43', '0.43') is False
|
||||
assert s.between_versions('0.45', '0.43') is False
|
||||
|
||||
def test_dropbear_compare_version_with_years(self):
|
||||
s = self.get_dropbear_software('2015.71')
|
||||
assert s.compare_version('2014.67') > 0
|
||||
assert s.compare_version(None) == 1
|
||||
assert s.compare_version('') == 1
|
||||
assert s.compare_version('2014.66') > 0
|
||||
assert s.compare_version('2015.71') == 0
|
||||
assert s.compare_version(s) == 0
|
||||
assert s.compare_version('2016.74') < 0
|
||||
assert s.between_versions('2014.67', '2016.74')
|
||||
assert s.between_versions('2014.66', '2016.74')
|
||||
assert s.between_versions('2014.66', '2015.69') is False
|
||||
assert s.between_versions('2016.74', '2014.66') is False
|
||||
|
||||
def test_dropbear_compare_version_mixed(self):
|
||||
s = self.get_dropbear_software('0.53.1')
|
||||
assert s.compare_version(None) == 1
|
||||
assert s.compare_version('') == 1
|
||||
assert s.compare_version('0.53') > 0
|
||||
assert s.compare_version('0.53.1') == 0
|
||||
assert s.compare_version(s) == 0
|
||||
assert s.compare_version('2011.54') < 0
|
||||
assert s.between_versions('0.53', '2011.54')
|
||||
assert s.between_versions('0.53', '0.53') is False
|
||||
assert s.between_versions('2011.54', '0.53') is False
|
||||
|
||||
def test_dropbear_compare_version_patchlevel(self):
|
||||
s1 = self.get_dropbear_software('0.44')
|
||||
s2 = self.get_dropbear_software('0.44test3')
|
||||
assert s1.compare_version(None) == 1
|
||||
assert s1.compare_version('') == 1
|
||||
assert s1.compare_version('0.44') == 0
|
||||
assert s1.compare_version(s1) == 0
|
||||
assert s1.compare_version('0.43') > 0
|
||||
assert s1.compare_version('0.44test4') > 0
|
||||
assert s1.between_versions('0.44test4', '0.45')
|
||||
assert s1.between_versions('0.43', '0.44test4') is False
|
||||
assert s1.between_versions('0.45', '0.44test4') is False
|
||||
assert s2.compare_version(None) == 1
|
||||
assert s2.compare_version('') == 1
|
||||
assert s2.compare_version('0.44test3') == 0
|
||||
assert s2.compare_version(s2) == 0
|
||||
assert s2.compare_version('0.44') < 0
|
||||
assert s2.compare_version('0.44test4') < 0
|
||||
assert s2.between_versions('0.43', '0.44')
|
||||
assert s2.between_versions('0.43', '0.44test2') is False
|
||||
assert s2.between_versions('0.44', '0.43') is False
|
||||
assert s1.compare_version(s2) > 0
|
||||
assert s2.compare_version(s1) < 0
|
||||
|
||||
def test_dropbear_compare_version_sequential(self):
|
||||
versions = []
|
||||
@ -87,19 +118,28 @@ class TestVersionCompare(object):
|
||||
|
||||
def test_openssh_compare_version_simple(self):
|
||||
s = self.get_openssh_software('3.7.1')
|
||||
assert s.compare_version(None) == 1
|
||||
assert s.compare_version('') == 1
|
||||
assert s.compare_version('3.7') > 0
|
||||
assert s.compare_version('3.7.1') == 0
|
||||
assert s.compare_version(s) == 0
|
||||
assert s.compare_version('3.8') < 0
|
||||
assert s.between_versions('3.7', '3.8')
|
||||
assert s.between_versions('3.6', '3.7') is False
|
||||
assert s.between_versions('3.8', '3.7') is False
|
||||
|
||||
def test_openssh_compare_version_patchlevel(self):
|
||||
s1 = self.get_openssh_software('2.1.1')
|
||||
s2 = self.get_openssh_software('2.1.1p2')
|
||||
assert s1.compare_version(s1) == 0
|
||||
assert s2.compare_version(s2) == 0
|
||||
assert s1.compare_version('2.1.1p1') == 0
|
||||
assert s1.compare_version('2.1.1p2') == 0
|
||||
assert s2.compare_version('2.1.1') == 0
|
||||
assert s2.compare_version('2.1.1p1') > 0
|
||||
assert s2.compare_version('2.1.1p3') < 0
|
||||
assert s1.compare_version(s2) == 0
|
||||
assert s2.compare_version(s1) == 0
|
||||
|
||||
def test_openbsd_compare_version_sequential(self):
|
||||
versions = []
|
||||
@ -137,10 +177,15 @@ class TestVersionCompare(object):
|
||||
|
||||
def test_libssh_compare_version_simple(self):
|
||||
s = self.get_libssh_software('0.3')
|
||||
assert s.compare_version(None) == 1
|
||||
assert s.compare_version('') == 1
|
||||
assert s.compare_version('0.2') > 0
|
||||
assert s.compare_version('0.3') == 0
|
||||
assert s.compare_version(s) == 0
|
||||
assert s.compare_version('0.3.1') < 0
|
||||
assert s.between_versions('0.2', '0.3.1')
|
||||
assert s.between_versions('0.1', '0.2') is False
|
||||
assert s.between_versions('0.3.1', '0.2') is False
|
||||
|
||||
def test_libssh_compare_version_sequential(self):
|
||||
versions = []
|
||||
|
Loading…
Reference in New Issue
Block a user