예제 #1
0
    def test_generate_code_from_counter_counter_bad(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to invalid counter value.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(self.secret, -1)
예제 #2
0
    def test_generate_code_from_counter_counter_wrong_type(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to wrong counter type.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(self.secret, "abcdefgh")
예제 #3
0
    def test_generate_code_from_counter_secret_wrong_type(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to wrong secret type.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.generate_code_from_counter(1.234, self.expected[0][0])
예제 #4
0
    def test_generate_code_from_counter_code_length_wrong_type(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to wrong code_length type.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.generate_code_from_counter(
                self.secret, self.expected[0][0], code_length=(6, 3))
예제 #5
0
    def test_generate_code_from_counter_counter_bad(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to invalid counter value.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, -1)
예제 #6
0
    def test_generate_code_from_counter_counter_wrong_type(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to wrong counter type.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, "abcdefgh")
예제 #7
0
    def test_generate_code_from_counter_secret_wrong_type(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to wrong secret type.

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.generate_code_from_counter(
                1.234, self.expected[0][0])
예제 #8
0
    def test_generate_code_from_counter_code_length_not_numeric(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to non-numeric code_length.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, self.expected[0][0], code_length="abc")
예제 #9
0
    def test_generate_code_from_counter_secret_wrong_base32_length(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to secret string that is invalid
        base32 encoding (too long, bad padding).

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQAAA", self.expected[0][0])
예제 #10
0
    def test_generate_code_from_counter_secret_bad_base32(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to secret string that is invalid
        base32 encoding.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                "GEZDGNBVGY1TQOJQGEZDGNBVGY1TQOJQ", self.expected[0][0])
예제 #11
0
    def test_generate_code_from_counter_counter_long(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to counter byte string that is
        too short.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, bytes.fromhex("010203040506070809"))
예제 #12
0
    def test_generate_code_from_counter_secret_wrong_base32_length(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to secret string that is invalid
        base32 encoding (too long, bad padding).

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQAAA", self.expected[0][0])
예제 #13
0
    def test_generate_code_from_counter_secret_bad_base32(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to secret string that is invalid
        base32 encoding.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter("GEZDGNBVGY1TQOJQGEZDGNBVGY1TQOJQ",
                                           self.expected[0][0])
예제 #14
0
    def test_generate_code_from_counter_counter_long(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to counter byte string that is
        too short.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(self.secret,
                                           bytes.fromhex("010203040506070809"))
예제 #15
0
    def test_generate_code_from_counter_code_length_out_of_range(self):
        """Test Otp.generate_code_from_counter().

        Check for appropriate exception to out-of-range code_length.

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, self.expected[0][0], code_length="0")
        with self.assertRaises(ValueError):
            cut.generate_code_from_counter(
                self.secret, self.expected[0][0], code_length=11)
예제 #16
0
    def test_generate_code_from_counter_integer_b32_secret(self):
        """Test Otp.generate_code_from_counter().

        Check that the RFC4226 test cases work for generate_code_from_counter()
        when passed counter as an integer and secret as base32 string.

        """
        cut = HOTP()
        # test with counter as integer value and secret as base32 string
        #
        for i in range(0, 10):
            code_string = cut.generate_code_from_counter(self.secret_base32, i)
            self.assertEqual(self.expected[i][3], code_string)
예제 #17
0
    def test_generate_code_from_counter_integer_b32_secret(self):
        """Test Otp.generate_code_from_counter().

        Check that the RFC4226 test cases work for generate_code_from_counter()
        when passed counter as an integer and secret as base32 string.

        """
        cut = HOTP()
        # test with counter as integer value and secret as base32 string
        #
        for i in range(0, 10):
            code_string = cut.generate_code_from_counter(self.secret_base32, i)
            self.assertEqual(self.expected[i][3], code_string)
예제 #18
0
    def test_generate_code_from_counter_byte_string(self):
        """Test Otp.generate_code_from_counter().

        Check that the RFC4226 test cases work for generate_code_from_counter()
        when passed counter as a byte string and secret as byte string.

        """
        cut = HOTP()
        # test with counter as byte string and secret as byte string.
        #
        for i in range(0, 10):
            code_string = cut.generate_code_from_counter(
                self.secret, self.expected[i][0])
            self.assertEqual(self.expected[i][3], code_string)
예제 #19
0
    def test_generate_code_from_counter_byte_string(self):
        """Test Otp.generate_code_from_counter().

        Check that the RFC4226 test cases work for generate_code_from_counter()
        when passed counter as a byte string and secret as byte string.

        """
        cut = HOTP()
        # test with counter as byte string and secret as byte string.
        #
        for i in range(0, 10):
            code_string = cut.generate_code_from_counter(
                self.secret, self.expected[i][0])
            self.assertEqual(self.expected[i][3], code_string)