コード例 #1
0
ファイル: test_hotp.py プロジェクト: zombig/authenticator
    def test_code_from_hash_with_alternate_lengths(self):
        """Test Otp.code_from_hash().

        Try with alternate code lengths.

        """
        cut = HOTP()
        # code_length 1
        #
        should_be = ("4", "2", "2", "9", "4", "6", "2", "3", "1", "9")
        for i in range(0, 10):
            code = cut.code_from_hash(self.expected[i][2], 1)
            self.assertEqual(should_be[i], code)
        # code_length 9
        #
        should_be = (
            "284755224",
            "094287082",
            "137359152",
            "726969429",
            "640338314",
            "868254676",
            "918287922",
            "082162583",
            "673399871",
            "645520489")
        for i in range(0, 10):
            code = cut.code_from_hash(self.expected[i][2], 9)
            self.assertEqual(should_be[i], code)
コード例 #2
0
    def test_code_from_hash_wrong_length(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.code_from_hash(bytes.fromhex("abcdef"))
コード例 #3
0
    def test_code_from_hash_bad_hash(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.code_from_hash("abc")
コード例 #4
0
    def test_code_from_hash_long_code_length(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.code_from_hash(self.expected[0][2], 11)
コード例 #5
0
    def test_code_from_hash_wrong_length(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.code_from_hash(bytes.fromhex("abcdef"))
コード例 #6
0
    def test_code_from_hash_bad_hash(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(TypeError):
            cut.code_from_hash("abc")
コード例 #7
0
    def test_code_from_hash_long_code_length(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        with self.assertRaises(ValueError):
            cut.code_from_hash(self.expected[0][2], 11)
コード例 #8
0
    def test_code_from_hash(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        for i in range(0, 10):
            code = cut.code_from_hash(self.expected[i][2])
            self.assertEqual(self.expected[i][3], code)
コード例 #9
0
    def test_code_from_hash(self):
        """Test Otp.code_from_hash().

        Check that the RFC4226 test cases work for code_from_hash()

        """
        cut = HOTP()
        for i in range(0, 10):
            code = cut.code_from_hash(self.expected[i][2])
            self.assertEqual(self.expected[i][3], code)