From 74a1ca08eec90a6393bd5898b0747b87185e77e4 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Mon, 12 Sep 2016 19:23:27 +0300 Subject: [PATCH] Create tests for Dropbear SSH version comparison. --- test/conftest.py | 10 +++++ test/test_version_compare.py | 77 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 test/conftest.py create mode 100644 test/test_version_compare.py diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..cf81150 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os, sys +import pytest + +@pytest.fixture(scope='module') +def ssh_audit(): + __rdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') + sys.path.append(os.path.abspath(__rdir)) + return __import__('ssh-audit') diff --git a/test/test_version_compare.py b/test/test_version_compare.py new file mode 100644 index 0000000..c643d88 --- /dev/null +++ b/test/test_version_compare.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import pytest + +class TestVersionCompare(object): + @pytest.fixture(autouse=True) + def init(self, ssh_audit): + self.ssh = ssh_audit.SSH + + def get_dropbear_software(self, v): + b = self.ssh.Banner.parse('SSH-2.0-dropbear_{0}'.format(v)) + return self.ssh.Software.parse(b) + + def test_dropbear_compare_version_pre_years(self): + s = self.get_dropbear_software('0.44') + assert s.compare_version('0.43') > 0 + assert s.compare_version('0.44') == 0 + assert s.compare_version('0.45') < 0 + assert s.between_versions('0.43', '0.45') == True + + 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('2015.71') == 0 + assert s.compare_version('2016.74') < 0 + assert s.between_versions('2014.67', '2016.74') == True + + def test_dropbear_compare_version_mixed(self): + s = self.get_dropbear_software('0.53.1') + assert s.compare_version('0.53') > 0 + assert s.compare_version('0.53.1') == 0 + assert s.compare_version('2011.54') < 0 + assert s.between_versions('0.53', '2011.54') == True + + 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('0.43') > 0 + assert s1.compare_version('0.44test4') > 0 + assert s2.compare_version('0.44') < 0 + assert s2.compare_version('0.44test4') < 0 + + def test_dropbear_compare_version_sequential(self): + versions = [] + for i in range(28, 44): + versions.append('0.{0}'.format(i)) + for i in range(1, 5): + versions.append('0.44test{0}'.format(i)) + for i in range(44, 49): + versions.append('0.{0}'.format(i)) + versions.append('0.48.1') + for i in range(49, 54): + versions.append('0.{0}'.format(i)) + versions.append('0.53.1') + for v in ['2011.54', '2012.55']: + versions.append(v) + for i in range(56, 61): + versions.append('2013.{0}'.format(i)) + for v in ['2013.61test', '2013.62']: + versions.append(v) + for i in range(63, 67): + versions.append('2014.{0}'.format(i)) + for i in range(67, 72): + versions.append('2015.{0}'.format(i)) + for i in range(72, 75): + versions.append('2016.{0}'.format(i)) + l = len(versions) + for i in range(l): + v = versions[i] + s = self.get_dropbear_software(v) + assert s.compare_version(v) == 0 + if i - 1 >= 0: + vbefore = versions[i - 1] + assert s.compare_version(vbefore) > 0 + if i + 1 < l: + vnext = versions[i + 1] + assert s.compare_version(vnext) < 0