Beispiel #1
0
    def test_verify_image_failure(self, md5_mock, open_mock):
        image_info = self._build_fake_image_info()
        md5_mock.return_value.hexdigest.return_value = 'wrong hash'
        image_location = '/foo/bar'

        verified = standby._verify_image(image_info, image_location)
        self.assertFalse(verified)
        self.assertEqual(md5_mock.call_count, 1)
Beispiel #2
0
    def test_verify_image_success(self, md5_mock, sha1_mock, open_mock):
        image_info = self._build_fake_image_info()
        image_info['hashes']['sha1'] = image_info['hashes']['md5']
        hexdigest_mock = md5_mock.return_value.hexdigest
        hexdigest_mock.return_value = image_info['hashes']['md5']
        hexdigest_mock = sha1_mock.return_value.hexdigest
        hexdigest_mock.return_value = image_info['hashes']['sha1']
        image_location = '/foo/bar'

        verified = standby._verify_image(image_info, image_location)
        self.assertTrue(verified)
        # make sure we only check one hash, even though both are valid
        self.assertEqual(md5_mock.call_count + sha1_mock.call_count, 1)