def test_create_tuf_client_directory(self): # Test normal case. temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory) repository_directory = os.path.join('repository_data', 'repository') client_directory = os.path.join(temporary_directory, 'client') repo_lib.create_tuf_client_directory(repository_directory, client_directory) self.assertTrue(os.path.exists(client_directory)) metadata_directory = os.path.join(client_directory, 'metadata') current_directory = os.path.join(metadata_directory, 'current') previous_directory = os.path.join(metadata_directory, 'previous') self.assertTrue(os.path.exists(client_directory)) self.assertTrue(os.path.exists(metadata_directory)) self.assertTrue(os.path.exists(current_directory)) self.assertTrue(os.path.exists(previous_directory)) # Test improperly formatted arguments. self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.create_tuf_client_directory, 3, client_directory) self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.create_tuf_client_directory, repository_directory, 3) # Test invalid argument (i.e., client directory already exists.) self.assertRaises(tuf.exceptions.RepositoryError, repo_lib.create_tuf_client_directory, repository_directory, client_directory) # Test invalid client metadata directory (i.e., non-errno.EEXIST exceptions # should be re-raised.) shutil.rmtree(metadata_directory) # Save the original metadata directory name so that it can be restored # after testing. metadata_directory_name = repo_lib.METADATA_DIRECTORY_NAME repo_lib.METADATA_DIRECTORY_NAME = '/' # Creation of the '/' directory is forbidden on all supported OSs. The '/' # argument to create_tuf_client_directory should cause it to re-raise a # non-errno.EEXIST exception. self.assertRaises((OSError, tuf.exceptions.RepositoryError), repo_lib.create_tuf_client_directory, repository_directory, '/') # Restore the metadata directory name in repo_lib. repo_lib.METADATA_DIRECTORY_NAME = metadata_directory_name
def test_create_tuf_client_directory(self): # Test normal case. temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory) repository_directory = os.path.join('repository_data', 'repository') client_directory = os.path.join(temporary_directory, 'client') repo_lib.create_tuf_client_directory(repository_directory, client_directory) self.assertTrue(os.path.exists(client_directory)) metadata_directory = os.path.join(client_directory, 'metadata') current_directory = os.path.join(metadata_directory, 'current') previous_directory = os.path.join(metadata_directory, 'previous') self.assertTrue(os.path.exists(client_directory)) self.assertTrue(os.path.exists(metadata_directory)) self.assertTrue(os.path.exists(current_directory)) self.assertTrue(os.path.exists(previous_directory)) # Test improperly formatted arguments. self.assertRaises(tuf.FormatError, repo_lib.create_tuf_client_directory, 3, client_directory) self.assertRaises(tuf.FormatError, repo_lib.create_tuf_client_directory, repository_directory, 3) # Test invalid argument (i.e., client directory already exists.) self.assertRaises(tuf.RepositoryError, repo_lib.create_tuf_client_directory, repository_directory, client_directory) # Test invalid client metadata directory (i.e., non-errno.EEXIST exceptions # should be re-raised.) shutil.rmtree(metadata_directory) current_client_directory_mode = os.stat(client_directory)[stat.ST_MODE] # Remove write access for the client directory so that the 'metadata' # directory cannot be created. create_tuf_client_directory() should # re-raise the 'OSError' (i.e., errno.EACCES) exception and only handle # errno.EEXIST. os.chmod(client_directory, current_client_directory_mode & ~stat.S_IWUSR) self.assertRaises(OSError, repo_lib.create_tuf_client_directory, repository_directory, client_directory) # Reset the client directory's mode. os.chmod(client_directory, current_client_directory_mode)
def test_create_tuf_client_directory(self): # Test normal case. temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory) repository_directory = os.path.join("repository_data", "repository") client_directory = os.path.join(temporary_directory, "client") repo_lib.create_tuf_client_directory(repository_directory, client_directory) self.assertTrue(os.path.exists(client_directory)) metadata_directory = os.path.join(client_directory, "metadata") current_directory = os.path.join(metadata_directory, "current") previous_directory = os.path.join(metadata_directory, "previous") self.assertTrue(os.path.exists(client_directory)) self.assertTrue(os.path.exists(metadata_directory)) self.assertTrue(os.path.exists(current_directory)) self.assertTrue(os.path.exists(previous_directory)) # Test improperly formatted arguments. self.assertRaises(tuf.FormatError, repo_lib.create_tuf_client_directory, 3, client_directory) self.assertRaises(tuf.FormatError, repo_lib.create_tuf_client_directory, repository_directory, 3) # Test invalid argument (i.e., client directory already exists.) self.assertRaises( tuf.RepositoryError, repo_lib.create_tuf_client_directory, repository_directory, client_directory ) # Test invalid client metadata directory (i.e., non-errno.EEXIST exceptions # should be re-raised.) shutil.rmtree(metadata_directory) current_client_directory_mode = os.stat(client_directory)[stat.ST_MODE] # Remove write access for the client directory so that the 'metadata' # directory cannot be created. create_tuf_client_directory() should # re-raise the 'OSError' (i.e., errno.EACCES) exception and only handle # errno.EEXIST. os.chmod(client_directory, current_client_directory_mode & ~stat.S_IWUSR) self.assertRaises(OSError, repo_lib.create_tuf_client_directory, repository_directory, client_directory) # Reset the client directory's mode. os.chmod(client_directory, current_client_directory_mode)
def create_tuf_client_directory(repository_directory, client_directory): return repo_lib.create_tuf_client_directory(repository_directory, client_directory)