示例#1
0
 def test_reader_with_verifier(self):
     content = b'XXX'
     image = six.BytesIO(content)
     verifier = mock.MagicMock(name='mock_verifier')
     reader = vm_store._Reader(image, verifier)
     reader.read()
     verifier.update.assert_called_with(content)
 def test_reader_with_verifier(self):
     content = b'XXX'
     image = six.BytesIO(content)
     verifier = mock.MagicMock(name='mock_verifier')
     reader = vm_store._Reader(image, self.hash_algo, verifier)
     reader.read()
     verifier.update.assert_called_with(content)
示例#3
0
 def test_reader_partial(self):
     content = b'XXX'
     image = six.BytesIO(content)
     expected_checksum = hashlib.md5(b'X').hexdigest()
     reader = vm_store._Reader(image)
     ret = reader.read(1)
     self.assertEqual(b'X', ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(1, reader.size)
示例#4
0
 def test_reader_full(self):
     content = b'XXX'
     image = six.BytesIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     reader = vm_store._Reader(image)
     ret = reader.read()
     self.assertEqual(content, ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(len(content), reader.size)
 def test_reader_partial(self):
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5('X').hexdigest()
     reader = vm_store._Reader(image)
     ret = reader.read(1)
     self.assertEqual('X', ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(1, reader.size)
 def test_reader_full(self):
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     reader = vm_store._Reader(image)
     ret = reader.read()
     self.assertEqual(content, ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(len(content), reader.size)
 def test_reader_partial(self):
     content = b'XXX'
     image = six.BytesIO(content)
     expected_checksum = hashlib.md5(b'X').hexdigest()
     expected_multihash = hashlib.sha256(b'X').hexdigest()
     reader = vm_store._Reader(image, self.hash_algo)
     ret = reader.read(1)
     self.assertEqual(b'X', ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(expected_multihash, reader.os_hash_value.hexdigest())
     self.assertEqual(1, reader.size)
 def test_reader_partial(self):
     content = b'XXX'
     image = six.BytesIO(content)
     expected_checksum = hashlib.md5(b'X').hexdigest()
     expected_multihash = hashlib.sha256(b'X').hexdigest()
     reader = vm_store._Reader(image, self.hash_algo)
     ret = reader.read(1)
     self.assertEqual(b'X', ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(expected_multihash, reader.os_hash_value.hexdigest())
     self.assertEqual(1, reader.size)
 def test_reader_full(self):
     content = b'XXX'
     image = six.BytesIO(content)
     expected_checksum = secretutils.md5(content,
                                         usedforsecurity=False).hexdigest()
     expected_multihash = hashlib.sha256(content).hexdigest()
     reader = vm_store._Reader(image, self.hash_algo)
     ret = reader.read()
     self.assertEqual(content, ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(expected_multihash, reader.os_hash_value.hexdigest())
     self.assertEqual(len(content), reader.size)
示例#10
0
 def test_reader_size(self):
     """Test that the image reader takes into account the specified size."""
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     reader = vm_store._Reader(image, checksum, blocksize=1)
     ret = reader.read(size=3)
     self.assertEqual('1\r\n', ret)
     ret = reader.read(size=1)
     self.assertEqual('X', ret)
     ret = reader.read()
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(image.len, reader.size)
     self.assertTrue(reader.closed)
示例#11
0
 def test_reader_size(self):
     """Test that the image reader takes into account the specified size."""
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     reader = vm_store._Reader(image, checksum, blocksize=1)
     ret = reader.read(size=3)
     self.assertEqual('1\r\n', ret)
     ret = reader.read(size=1)
     self.assertEqual('X', ret)
     ret = reader.read()
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(image.len, reader.size)
     self.assertTrue(reader.closed)
示例#12
0
 def test_reader_image_larger_blocksize(self):
     """
     Test that the image file reader returns the expected chunks when
     the block size specified is smaller than the image.
     """
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     last_chunk = '0\r\n\r\n'
     reader = vm_store._Reader(image, checksum, blocksize=1)
     ret = reader.read()
     expected_chunk = '1\r\nX\r\n'
     self.assertEqual('%s%s%s%s' % (expected_chunk, expected_chunk,
                                    expected_chunk, last_chunk), ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(image.len, reader.size)
     self.assertTrue(reader.closed)
示例#13
0
 def test_reader_image_larger_blocksize(self):
     """
     Test that the image file reader returns the expected chunks when
     the block size specified is smaller than the image.
     """
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     last_chunk = '0\r\n\r\n'
     reader = vm_store._Reader(image, checksum, blocksize=1)
     ret = reader.read()
     expected_chunk = '1\r\nX\r\n'
     self.assertEqual(
         '%s%s%s%s' %
         (expected_chunk, expected_chunk, expected_chunk, last_chunk), ret)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertEqual(image.len, reader.size)
     self.assertTrue(reader.closed)
示例#14
0
 def test_reader_image_fits_in_blocksize(self):
     """
     Test that the image file reader returns the expected chunk of data
     when the block size is larger than the image.
     """
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     reader = vm_store._Reader(image, checksum)
     ret = reader.read()
     expected_chunk = '%x\r\n%s\r\n' % (len(content), content)
     last_chunk = '0\r\n\r\n'
     self.assertEqual('%s%s' % (expected_chunk, last_chunk), ret)
     self.assertEqual(image.len, reader.size)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertTrue(reader.closed)
     ret = reader.read()
     self.assertEqual(image.len, reader.size)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertTrue(reader.closed)
     self.assertEqual('', ret)
示例#15
0
 def test_reader_image_fits_in_blocksize(self):
     """
     Test that the image file reader returns the expected chunk of data
     when the block size is larger than the image.
     """
     content = 'XXX'
     image = six.StringIO(content)
     expected_checksum = hashlib.md5(content).hexdigest()
     checksum = hashlib.md5()
     reader = vm_store._Reader(image, checksum)
     ret = reader.read()
     expected_chunk = '%x\r\n%s\r\n' % (len(content), content)
     last_chunk = '0\r\n\r\n'
     self.assertEqual('%s%s' % (expected_chunk, last_chunk), ret)
     self.assertEqual(image.len, reader.size)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertTrue(reader.closed)
     ret = reader.read()
     self.assertEqual(image.len, reader.size)
     self.assertEqual(expected_checksum, reader.checksum.hexdigest())
     self.assertTrue(reader.closed)
     self.assertEqual('', ret)