Ejemplo n.º 1
0
    def test_manipulated_input_full_read(self, secret_key, value, bad_datas,
                                         hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                     BytesIO(bad_data))

            with pytest.raises(VerificationException):
                reader.read()
Ejemplo n.º 2
0
    def test_manipulated_input_incremental_read(self, secret_key, bad_datas, hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(bad_data))

            with pytest.raises(VerificationException):
                bitesize = 100
                while True:
                    if len(reader.read(bitesize)) != bitesize:
                        break
Ejemplo n.º 3
0
    def test_manipulated_input_incremental_read(self, secret_key, bad_datas,
                                                hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                     BytesIO(bad_data))

            with pytest.raises(VerificationException):
                bitesize = 100
                while True:
                    if len(reader.read(bitesize)) != bitesize:
                        break
Ejemplo n.º 4
0
    def test_manipulated_input_full_read(self):
        for n in range(0, 20) + range(-1, -20, -1):
            broken_stored_data_and_hash = _alter_byte(
                self.stored_data_and_hash, n)

            reader = _HMACFileReader(
                hmac.HMAC(self.secret_key, None, self.hashfunc),
                StringIO(broken_stored_data_and_hash))

            with self.assertRaises(VerificationException):
                reader.read()
Ejemplo n.º 5
0
    def test_manipulated_input_full_read(self):
        for n in range(0, 20) + range(-1, -20, -1):
            broken_stored_data_and_hash = _alter_byte(
                self.stored_data_and_hash,
                n
            )

            reader = _HMACFileReader(
                hmac.HMAC(self.secret_key, None, self.hashfunc),
                StringIO(broken_stored_data_and_hash)
            )

            with self.assertRaises(VerificationException):
                reader.read()
Ejemplo n.º 6
0
    def test_manipulated_input_incremental_read(self):
        for n in range(0, 20) + range(-1, -20, -1):
            broken_stored_data_and_hash = _alter_byte(
                self.stored_data_and_hash, n)

            reader = _HMACFileReader(
                hmac.HMAC(self.secret_key, None, self.hashfunc),
                StringIO(broken_stored_data_and_hash))

            with self.assertRaises(VerificationException):
                bitesize = 100
                while True:
                    if len(reader.read(bitesize)) != bitesize:
                        break
Ejemplo n.º 7
0
    def test_reading_with_limit(self):
        # try for different read lengths
        for n in self.reading_lengths:
            buf = StringIO(self.stored_data_and_hash)
            hm = hmac.HMAC(self.secret_key, None, self.hashfunc)

            reader = _HMACFileReader(hm, buf)

            data = ''
            while True:
                r = reader.read(n)
                if '' == r:
                    break
                data += r

            self.assertEqual(data, self.data)
Ejemplo n.º 8
0
    def test_manipulated_input_incremental_read(self):
        for n in range(0, 20) + range(-1, -20, -1):
            broken_stored_data_and_hash = _alter_byte(
                self.stored_data_and_hash,
                n
            )

            reader = _HMACFileReader(
                hmac.HMAC(self.secret_key, None, self.hashfunc),
                StringIO(broken_stored_data_and_hash)
            )

            with self.assertRaises(VerificationException):
                bitesize = 100
                while True:
                    if len(reader.read(bitesize)) != bitesize:
                        break
Ejemplo n.º 9
0
 def setUp(self):
     self.buf = StringIO(self.stored_data_and_hash)
     self.hm = hmac.HMAC(self.secret_key, None, self.hashfunc)
     self.reader = _HMACFileReader(self.hm, self.buf)
Ejemplo n.º 10
0
 def test_input_too_short(self):
     with self.assertRaises(VerificationException):
         reader = _HMACFileReader(
             hmac.HMAC(self.secret_key, None, self.hashfunc),
             StringIO('a')
         )
Ejemplo n.º 11
0
 def test_input_too_short(self, secret_key, hashfunc):
     with pytest.raises(VerificationException):
         _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                         BytesIO(b('a')))
Ejemplo n.º 12
0
 def create_reader(self, stored_blob, secret_key, hashfunc):
     return lambda: _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc),
                                    BytesIO(stored_blob))
Ejemplo n.º 13
0
 def test_input_too_short(self, secret_key, hashfunc):
     with pytest.raises(VerificationException):
         _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(b("a")))
Ejemplo n.º 14
0
    def test_manipulated_input_full_read(self, secret_key, value, bad_datas, hashfunc):
        for bad_data in bad_datas:
            reader = _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(bad_data))

            with pytest.raises(VerificationException):
                reader.read()
Ejemplo n.º 15
0
 def create_reader(self, stored_blob, secret_key, hashfunc):
     return lambda: _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(stored_blob))