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()
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
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()
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()
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
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)
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
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)
def test_input_too_short(self): with self.assertRaises(VerificationException): reader = _HMACFileReader( hmac.HMAC(self.secret_key, None, self.hashfunc), StringIO('a') )
def test_input_too_short(self, secret_key, hashfunc): with pytest.raises(VerificationException): _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(b('a')))
def create_reader(self, stored_blob, secret_key, hashfunc): return lambda: _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(stored_blob))
def test_input_too_short(self, secret_key, hashfunc): with pytest.raises(VerificationException): _HMACFileReader(hmac.HMAC(secret_key, None, hashfunc), BytesIO(b("a")))