Esempio n. 1
0
    def test_convert_base32_bad_chars(self):
        """Test Otp.convert_base32_secret_key().

        Check that an input base32 encoded string that is not encoded correctly
        throws the expected exception.

        """
        cut = HOTP()
        # First be certain the method works with a correct base32-encoded
        # input string
        #
        in_string = "ABCDEFGH"
        cut.convert_base32_secret_key(in_string)
        # Then check that it throws the expected exception with an
        # incorrectly coded input string.
        #
        # lower case not acceptable
        in_string = "abcdefgh"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
        # numbers outside 2-7 not acceptable
        in_string = "ABCDEFG1"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
        # padding character elsewhere than end of string
        in_string = "ABCD=FGH"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
Esempio n. 2
0
    def test_convert_base32_bad_chars(self):
        """Test Otp.convert_base32_secret_key().

        Check that an input base32 encoded string that is not encoded correctly
        throws the expected exception.

        """
        cut = HOTP()
        # First be certain the method works with a correct base32-encoded
        # input string
        #
        in_string = "ABCDEFGH"
        cut.convert_base32_secret_key(in_string)
        # Then check that it throws the expected exception with an
        # incorrectly coded input string.
        #
        # lower case not acceptable
        in_string = "abcdefgh"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
        # numbers outside 2-7 not acceptable
        in_string = "ABCDEFG1"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
        # padding character elsewhere than end of string
        in_string = "ABCD=FGH"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
Esempio n. 3
0
    def test_convert_base32_too_long(self):
        """Test Otp.convert_base32_secret_key().

        Check that an input base32 encoded string that is not multiples of 8
        characters in length (too long) throws the expected exception.

        """
        cut = HOTP()
        # First be certain the method works with a correct base32-encoded
        # input string
        #
        in_string = "ABCDEFGH"
        cut.convert_base32_secret_key(in_string)
        # Then check that it throws the expected exception with an
        # incorrectly sized input string.
        #
        in_string = "ABCDEFGHA"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
Esempio n. 4
0
    def test_convert_base32_too_long(self):
        """Test Otp.convert_base32_secret_key().

        Check that an input base32 encoded string that is not multiples of 8
        characters in length (too long) throws the expected exception.

        """
        cut = HOTP()
        # First be certain the method works with a correct base32-encoded
        # input string
        #
        in_string = "ABCDEFGH"
        cut.convert_base32_secret_key(in_string)
        # Then check that it throws the expected exception with an
        # incorrectly sized input string.
        #
        in_string = "ABCDEFGHA"
        with self.assertRaises(ValueError):
            cut.convert_base32_secret_key(in_string)
Esempio n. 5
0
    def test_convert_base32_32_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 32 character
        base32 encoded secret

        """
        cut = HOTP()
        in_string = "nf2c a2lt ebqw y3ba mzxx k3df mqqh k4bo"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"it is all fouled up."
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 6
0
    def test_convert_base32_16_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 16 character
        base32 encoded secret.

        """
        cut = HOTP()
        in_string = "mfzw s5dv mf2g s33o"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"asituation"
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 7
0
    def test_convert_base32_32_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 32 character
        base32 encoded secret

        """
        cut = HOTP()
        in_string = "nf2c a2lt ebqw y3ba mzxx k3df mqqh k4bo"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"it is all fouled up."
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 8
0
    def test_convert_base32_16_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 16 character
        base32 encoded secret.

        """
        cut = HOTP()
        in_string = "mfzw s5dv mf2g s33o"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"asituation"
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 9
0
    def test_convert_base32_64_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 64 character
        base32 encoded secret

        """
        cut = HOTP()
        in_string = "knux i5lb oruw 63ra nzxx e3lb nqwc a2lu e5zs" + \
            " aylm nqqg m33v nrsw iidv oaqd ulji"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"Situation normal, it\'s all fouled up :-("
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 10
0
    def test_convert_base32_26_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 26 character
        base32 encoded secret, which requires padding the base32 secret
        before decoding

        """
        cut = HOTP()
        in_string = "onux i5lb oruw 63ra nzxx e3lb nq"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"situation normal"
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 11
0
    def test_convert_base32_64_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 64 character
        base32 encoded secret

        """
        cut = HOTP()
        in_string = "knux i5lb oruw 63ra nzxx e3lb nqwc a2lu e5zs" + \
            " aylm nqqg m33v nrsw iidv oaqd ulji"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"Situation normal, it\'s all fouled up :-("
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 12
0
    def test_convert_base32_26_chars(self):
        """Test Otp.convert_base32_secret_key().

        Typical input string lengths are 16, 26, 32, and 64 significant
        (ignoring padding) base32 characters. This tests a 26 character
        base32 encoded secret, which requires padding the base32 secret
        before decoding

        """
        cut = HOTP()
        in_string = "onux i5lb oruw 63ra nzxx e3lb nq"
        in_string = "".join(in_string.split()).upper()
        expected_bytes = b"situation normal"
        actual_bytes = cut.convert_base32_secret_key(in_string)
        self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 13
0
    def test_convert_base32(self):
        """Test Otp.convert_base32_secret_key().

        Check that expected byte strings are produced from base32 incoded
        strings.

        Uses test data and expected results from RFC4648, section10.

        """
        cut = HOTP()
        test_data = ((b"", ""), (b"f", "MY======"), (b"fo", "MZXQ===="),
                     (b"foo", "MZXW6==="), (b"foob", "MZXW6YQ="),
                     (b"fooba", "MZXW6YTB"), (b"foobar", "MZXW6YTBOI======"))
        for expected_bytes, in_string in test_data:
            actual_bytes = cut.convert_base32_secret_key(in_string)
            self.assertEqual(expected_bytes, actual_bytes)
Esempio n. 14
0
    def test_convert_base32(self):
        """Test Otp.convert_base32_secret_key().

        Check that expected byte strings are produced from base32 incoded
        strings.

        Uses test data and expected results from RFC4648, section10.

        """
        cut = HOTP()
        test_data = (
            (b"", ""),
            (b"f", "MY======"),
            (b"fo", "MZXQ===="),
            (b"foo", "MZXW6==="),
            (b"foob", "MZXW6YQ="),
            (b"fooba", "MZXW6YTB"),
            (b"foobar", "MZXW6YTBOI======"))
        for expected_bytes, in_string in test_data:
            actual_bytes = cut.convert_base32_secret_key(in_string)
            self.assertEqual(expected_bytes, actual_bytes)