Example #1
0
 def test_directory_content_only_fixed_hash(self):
     hasher = FileDirectoryListHasher(hashfunc="sha256",
                                      use_relative_paths=False,
                                      hash_directory_names=False,
                                      hash_file_names=False)
     hash = hasher.hash([self.test_dir1])
     ascii_hash = base64.b32encode(hash).decode("ASCII")
     self.assertEqual("TM2V22T326TCTLQ537BZAOR3I5NVHXE6IDJ4TXPCJPTUGDTI5WYQ====", ascii_hash)
Example #2
0
 def test_directory_with_relative_paths_fixed_hash(self):
     hasher = FileDirectoryListHasher(hashfunc="sha256",
                                      use_relative_paths=True,
                                      hash_directory_names=True,
                                      hash_file_names=True)
     hash = hasher.hash([self.test_dir1])
     ascii_hash = base64.b32encode(hash).decode("ASCII")
     self.assertEqual("VIN3VCPDX7DAC4GD37IDF4KQTCDNNH72QV5PARVGGQ4OMB4DZTLA====", ascii_hash)
Example #3
0
 def test_file_with_path(self):
     hasher = FileDirectoryListHasher(hashfunc="sha256",
                                      use_relative_paths=False,
                                      hash_directory_names=True,
                                      hash_file_names=True)
     hash = hasher.hash([TEST_FILE])
     ascii_hash = base64.b32encode(hash).decode("ASCII")
     self.assertEqual("AOBF7HELTYAPHBEW6HQQ74N3BKGSNZTJXB4MTOEROHO5VH6YYJOA====", ascii_hash)
Example #4
0
 def test_file_content_only_fixed_hash(self):
     hasher = FileDirectoryListHasher(hashfunc="sha256",
                                      use_relative_paths=False,
                                      hash_directory_names=False,
                                      hash_file_names=False)
     hash = hasher.hash([TEST_FILE])
     ascii_hash = base64.b32encode(hash).decode("ASCII")
     self.assertEqual("SVGVUSP5ODM3RPG3GXJFEJTYFGKX67XX7JWHJ6EEDG64L2BCBH2A====", ascii_hash)
Example #5
0
 def test_directory_without_relative_paths_not_equal(self):
     hasher = FileDirectoryListHasher(hashfunc="sha256",
                                      use_relative_paths=False,
                                      hash_directory_names=True,
                                      hash_file_names=True)
     hash1 = hasher.hash([self.test_dir1])
     hash2 = hasher.hash([self.test_dir2])
     ascii_hash1 = base64.b32encode(hash1).decode("ASCII")
     ascii_hash2 = base64.b32encode(hash2).decode("ASCII")
     self.assertNotEqual(ascii_hash1, ascii_hash2)
Example #6
0
 def _generate_build_context_hash(self):
     files_directories_list_hasher = \
         FileDirectoryListHasher(hashfunc="sha256",
                                 hash_file_names=True,
                                 hash_directory_names=True,
                                 hash_permissions=True,
                                 use_relative_paths=True)
     files_directories_to_hash = list(self.image_description.mapping_of_build_files_and_directories.values()) + \
                                 [str(self.image_description.dockerfile)]
     self.logger.debug("Task %s: files_directories_list_hasher %s",
                       self.task_id, files_directories_to_hash)
     hash_of_build_context = files_directories_list_hasher.hash(
         files_directories_to_hash)
     self.logger.debug("Task %s: hash_of_build_context %s", self.task_id,
                       self._encode_hash(hash_of_build_context))
     return hash_of_build_context
Example #7
0
 def test_directory_file_names_not_equal_to_dir_names(self):
     hasher_content_only = \
         FileDirectoryListHasher(hashfunc="sha256",
                                 use_relative_paths=True,
                                 hash_directory_names=False,
                                 hash_file_names=True)
     hasher_with_paths = \
         FileDirectoryListHasher(hashfunc="sha256",
                                 use_relative_paths=True,
                                 hash_directory_names=True,
                                 hash_file_names=False)
     hash1_content_only = hasher_content_only.hash([self.test_dir1])
     hash2_with_paths = hasher_with_paths.hash([self.test_dir2])
     ascii_hash1_content_only = base64.b32encode(hash1_content_only).decode("ASCII")
     ascii_hash2_with_paths = base64.b32encode(hash2_with_paths).decode("ASCII")
     self.assertNotEqual(ascii_hash1_content_only, ascii_hash2_with_paths)