Example #1
0
    def test_counter_from_time_period_wrong_type(self):
        """Test Otp.counter_from_time().

        Check that providing a period that is not numeric or convertable
        to numeric raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
    def test_counter_from_time_period_wrong_type(self):
        """Test Otp.counter_from_time().

        Check that providing a period that is not numeric or convertable
        to numeric raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
Example #3
0
    def test_counter_from_time_bad_period(self):
        """Test Otp.counter_from_time().

        Check that providing a bad period raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(ValueError):
            cut.counter_from_time(period="ABC")
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
    def test_counter_from_time_bad_period(self):
        """Test Otp.counter_from_time().

        Check that providing a bad period raises the appropriate exception.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(ValueError):
            cut.counter_from_time(period="ABC")
        with self.assertRaises(ValueError):
            cut.counter_from_time(period=-10)
        with self.assertRaises(TypeError):
            cut.counter_from_time(period=(6, 3))
Example #5
0
    def test_counter_from_time(self):
        """Test Otp.counter_from_time().

        Check that the generated counter and remaining seconds make sense
        for the given period.

        """
        cut = HOTP()
        counter, remaining_seconds30 = cut.counter_from_time()
        counter30 = int.from_bytes(counter, byteorder='big', signed=False)
        counter, remaining_seconds60 = cut.counter_from_time(60)
        counter60 = int.from_bytes(counter, byteorder='big', signed=False)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(30, remaining_seconds30)
        self.assertLessEqual(0, remaining_seconds30)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(60, remaining_seconds60)
        self.assertLessEqual(0, remaining_seconds60)
        # Check that counter with period 60 is just about 1/2 of counter
        # with period 30
        #
        self.assertLessEqual(counter60 * 2, counter30)
        self.assertGreater(counter60 * 2 + 2, counter30)
    def test_counter_from_time(self):
        """Test Otp.counter_from_time().

        Check that the generated counter and remaining seconds make sense
        for the given period.

        """
        cut = HOTP()
        counter, remaining_seconds30 = cut.counter_from_time()
        counter30 = int.from_bytes(counter, byteorder='big', signed=False)
        counter, remaining_seconds60 = cut.counter_from_time(60)
        counter60 = int.from_bytes(counter, byteorder='big', signed=False)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(30, remaining_seconds30)
        self.assertLessEqual(0, remaining_seconds30)
        # Check that remaining seconds are within [0,period)
        self.assertGreater(60, remaining_seconds60)
        self.assertLessEqual(0, remaining_seconds60)
        # Check that counter with period 60 is just about 1/2 of counter
        # with period 30
        #
        self.assertLessEqual(counter60 * 2, counter30)
        self.assertGreater(counter60 * 2 + 2, counter30)