mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Merge branch 'develop' into path_hash_prefix
This commit is contained in:
commit
4ab867efda
45 changed files with 147 additions and 168 deletions
3
setup.py
3
setup.py
|
|
@ -76,7 +76,8 @@
|
|||
'tuf.pushtools',
|
||||
'tuf.pushtools.transfer',
|
||||
'tuf.repo',
|
||||
'tuf.tests'
|
||||
'tuf.tests',
|
||||
'tuf.tests.system_tests'
|
||||
],
|
||||
scripts=[
|
||||
'tuf/repo/quickstart.py',
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@
|
|||
import optparse
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.client.updater
|
||||
import tuf.log
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@
|
|||
import shutil
|
||||
import time
|
||||
|
||||
import tuf
|
||||
import tuf.conf
|
||||
import tuf.download
|
||||
import tuf.formats
|
||||
|
|
@ -118,7 +119,7 @@
|
|||
import tuf.sig
|
||||
import tuf.util
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
logger = logging.getLogger('tuf.client.updater')
|
||||
|
||||
|
||||
class Updater(object):
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@
|
|||
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.client.updater
|
||||
|
||||
# Uncomment the line below to enable printing of debugging information.
|
||||
#tuf.log.set_log_level(logging.DEBUG)
|
||||
logger = logging.getLogger('tuf.cient.basic_client')
|
||||
|
||||
|
||||
# Set the local repository directory containing the metadata files.
|
||||
tuf.conf.repository_directory = '.'
|
||||
|
|
|
|||
|
|
@ -24,12 +24,13 @@
|
|||
"""
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
# Import tuf Exceptions.
|
||||
import tuf
|
||||
import tuf.log
|
||||
|
||||
# Import tuf logger to log warning messages.
|
||||
import logging
|
||||
logger = logging.getLogger('tuf.hash')
|
||||
|
||||
# The list of hash libraries imported successfully.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.rsa_key
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
# may be modified with 'set_filehandler_log_level()'. '_DEFAULT_LOG_FILENAME'
|
||||
# will be opened in append mode.
|
||||
file_handler = logging.FileHandler(_DEFAULT_LOG_FILENAME)
|
||||
file_handler.setLevel(_DEFAULT_LOG_LEVEL)
|
||||
file_handler.setLevel(_DEFAULT_FILE_LOG_LEVEL)
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
# Set the logger and its settings.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
import os
|
||||
import urllib
|
||||
|
||||
import tuf
|
||||
import tuf.util
|
||||
import tuf.formats
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
import sys
|
||||
import optparse
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.pushtools.pushtoolslib
|
||||
import tuf.pushtools.transfer.scp
|
||||
|
|
|
|||
|
|
@ -151,4 +151,4 @@ def read_config_file(filename, config_type):
|
|||
message = 'Invalid "config_type" argument. Supported: '+repr(CONFIG_TYPES)
|
||||
raise tuf.Error(message)
|
||||
|
||||
return config_dict
|
||||
return config_dict
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@
|
|||
import logging
|
||||
import optparse
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.keydb
|
||||
import tuf.roledb
|
||||
|
|
@ -165,7 +166,7 @@
|
|||
import tuf.pushtools.pushtoolslib
|
||||
|
||||
# See 'log.py' to learn how logging is handled in TUF.
|
||||
logger = logging.getLogger('tuf.receive')
|
||||
logger = logging.getLogger('tuf.pushtools.receivetools.receive')
|
||||
|
||||
|
||||
def receive(config_filepath):
|
||||
|
|
@ -257,7 +258,7 @@ def receive(config_filepath):
|
|||
|
||||
for directory_name, path in directories_to_check.items():
|
||||
if not os.path.exists(path):
|
||||
message = directory_name+' directory does not exist: '+str(path)
|
||||
message = directory_name+' directory does not exist: '+repr(path)
|
||||
logger.error(message)
|
||||
raise tuf.Error(message)
|
||||
|
||||
|
|
@ -270,13 +271,13 @@ def receive(config_filepath):
|
|||
# Process all the pushes for each of the pushroots.
|
||||
for pushroot in pushroots:
|
||||
if not os.path.exists(pushroot):
|
||||
logger.error('The pushroot '+str(pushroot)+' does not exist. Skipping.')
|
||||
logger.error('The pushroot '+repr(pushroot)+' does not exist. Skipping.')
|
||||
continue
|
||||
|
||||
# Add the 'processed' and 'processing' directories if not present.
|
||||
# These directories must exist so that we can properly process
|
||||
# a push.
|
||||
logger.debug('Looking for pushes in pushroot '+str(pushroot))
|
||||
logger.debug('Looking for pushes in pushroot '+repr(pushroot))
|
||||
if not os.path.exists(os.path.join(pushroot, 'processed')):
|
||||
os.mkdir(os.path.join(pushroot, 'processed'))
|
||||
if not os.path.exists(os.path.join(pushroot, 'processing')):
|
||||
|
|
@ -297,7 +298,7 @@ def receive(config_filepath):
|
|||
# Ensure the 'info' file exists. A successful push operation creates
|
||||
# and saves this 'info' file to the push directory.
|
||||
if not os.path.exists(os.path.join(pushpath, 'info')):
|
||||
message = 'Skipping incomplete push '+str(pushpath)+' (no info file).'
|
||||
message = 'Skipping incomplete push '+repr(pushpath)+' (no info file).'
|
||||
logger.warn(message)
|
||||
continue
|
||||
|
||||
|
|
@ -313,7 +314,7 @@ def receive(config_filepath):
|
|||
|
||||
# Done. Log the result of processing the pushes for 'pushroot'.
|
||||
message = 'Completed processing of all pushes. Push successes = '+\
|
||||
str(success_count)+', failures = '+str(failure_count)+'.'
|
||||
repr(success_count)+', failures = '+repr(failure_count)+'.'
|
||||
logger.info(message)
|
||||
|
||||
|
||||
|
|
@ -364,11 +365,11 @@ def _process_new_push(pushroot, pushname, metadata_directory,
|
|||
|
||||
"""
|
||||
|
||||
logger.info('Processing '+str(pushroot)+'/'+str(pushname))
|
||||
logger.info('Processing '+repr(pushroot)+'/'+repr(pushname))
|
||||
|
||||
# Move the pushed directory to the 'processing' directory.
|
||||
pushpath = os.path.join(pushroot, 'processing', pushname)
|
||||
logger.debug('Moving push directory to '+str(pushpath))
|
||||
logger.debug('Moving push directory to '+repr(pushpath))
|
||||
if os.path.isdir(pushpath) or os.path.isfile(pushpath):
|
||||
os.remove(pushpath)
|
||||
os.rename(os.path.join(pushroot, pushname), pushpath)
|
||||
|
|
@ -418,14 +419,14 @@ def _process_new_push(pushroot, pushname, metadata_directory,
|
|||
finally:
|
||||
file_object.close()
|
||||
|
||||
message = 'Could not process: '+str(pushroot)+'/'+str(pushname)
|
||||
message = 'Could not process: '+repr(pushroot)+'/'+repr(pushname)
|
||||
logger.exception(message)
|
||||
return False
|
||||
|
||||
# On success or failure, move 'pushpath' to the processed directory.
|
||||
finally:
|
||||
processedpath = os.path.join(pushroot, 'processed', pushname)
|
||||
logger.debug('Moving push directory to '+str(processedpath))
|
||||
logger.debug('Moving push directory to '+repr(processedpath))
|
||||
if os.path.isdir(processedpath) or os.path.isfile(processedpath):
|
||||
os.remove(processedpath)
|
||||
os.rename(pushpath, processedpath)
|
||||
|
|
@ -575,17 +576,17 @@ def _process_copied_push(pushpath, metadata_directory,
|
|||
|
||||
# Allowing equality makes testing/development easier.
|
||||
if formatted_timestamp > new_formatted_timestamp:
|
||||
message = 'Existing metadata timestamp '+str(timestamp)+' is newer '+\
|
||||
'than the new metadata\'s timestamp '+str(new_timestamp)
|
||||
message = 'Existing metadata timestamp '+repr(timestamp)+' is newer '+\
|
||||
'than the new metadata\'s timestamp '+repr(new_timestamp)
|
||||
raise tuf.Error(message)
|
||||
else:
|
||||
message = 'New metadata timestamp is '+str(new_timestamp)+'. '+\
|
||||
' Replacing old metadata with timestamp '+str(timestamp)
|
||||
message = 'New metadata timestamp is '+repr(new_timestamp)+'. '+\
|
||||
' Replacing old metadata with timestamp '+repr(timestamp)
|
||||
logger.debug(message)
|
||||
|
||||
# There appears to be no 'targets.txt' metadata file on the repository.
|
||||
else:
|
||||
message = 'The old targets metadata file '+str(targets_metadatapath)+'. '+\
|
||||
message = 'The old targets metadata file '+repr(targets_metadatapath)+'. '+\
|
||||
'doesn\'t exist in the repo. Skipping the timestamp check.'
|
||||
logger.warn(message)
|
||||
|
||||
|
|
@ -594,10 +595,10 @@ def _process_copied_push(pushpath, metadata_directory,
|
|||
formatted_expiration = tuf.formats.parse_time(expiration)
|
||||
|
||||
if formatted_expiration <= time.time():
|
||||
message = 'Pushed metadata expired at '+str(expiration)
|
||||
message = 'Pushed metadata expired at '+repr(expiration)
|
||||
raise tuf.Error(message)
|
||||
else:
|
||||
message = 'Metadata will expire at '+str(expiration)
|
||||
message = 'Metadata will expire at '+repr(expiration)
|
||||
logger.debug(message)
|
||||
|
||||
# Verify the signatures of the new targets metadata.
|
||||
|
|
@ -608,11 +609,11 @@ def _process_copied_push(pushpath, metadata_directory,
|
|||
# Log the status of the signatures. For example, the number of good,
|
||||
# bad, untrusted, unknown, signatures.
|
||||
status = tuf.sig.get_signature_status(new_targets_signable, 'targets')
|
||||
logger.debug(str(status))
|
||||
logger.debug(repr(status))
|
||||
|
||||
# Log the number of targets specified in the new targets metadata file.
|
||||
targets_count = len(new_targets_signable['signed']['targets'].keys())
|
||||
message = 'Number of targets specified: '+str(targets_count)
|
||||
message = 'Number of targets specified: '+repr(targets_count)
|
||||
logger.info(message)
|
||||
|
||||
# Verify the files of the new targets metadata file.
|
||||
|
|
@ -625,39 +626,39 @@ def _process_copied_push(pushpath, metadata_directory,
|
|||
# Check that the target was provided.
|
||||
if not os.path.exists(targetpath):
|
||||
message = 'The specified target file was not provided: '+\
|
||||
str(target_relativepath)
|
||||
repr(target_relativepath)
|
||||
raise tuf.Error(message)
|
||||
|
||||
# Check the target's size. A valid size is required of target files.
|
||||
target_size = os.path.getsize(targetpath)
|
||||
if target_size != target_info['length']:
|
||||
message = 'The size of target file '+str(target_relativepath)+\
|
||||
' is incorrect: was '+str(target_size)+', expected '+\
|
||||
str(target_info['length'])
|
||||
message = 'The size of target file '+repr(target_relativepath)+\
|
||||
' is incorrect: was '+repr(target_size)+', expected '+\
|
||||
repr(target_info['length'])
|
||||
raise tuf.Error(message)
|
||||
else:
|
||||
message = 'Size of target '+str(targetpath)+' is correct '+\
|
||||
'('+str(target_size)+' bytes).'
|
||||
message = 'Size of target '+repr(targetpath)+' is correct '+\
|
||||
'('+repr(target_size)+' bytes).'
|
||||
logger.debug(message)
|
||||
|
||||
# Check hashes. Valid target files is required.
|
||||
hash_count = len(target_info['hashes'].items())
|
||||
if hash_count == 0:
|
||||
message = str(targetpath)+' contains an empty hashes dictionary.'
|
||||
message = repr(targetpath)+' contains an empty hashes dictionary.'
|
||||
raise tuf.Error(message)
|
||||
else:
|
||||
logger.debug(str(hash_count)+' hash(es) to check.')
|
||||
logger.debug(repr(hash_count)+' hash(es) to check.')
|
||||
|
||||
for algorithm, digest in target_info['hashes'].items():
|
||||
digest_object = tuf.hash.digest_filename(targetpath, algorithm=algorithm)
|
||||
if digest_object.hexdigest() != digest:
|
||||
message = str(algorithm)+' hash does not match: '+\
|
||||
' was '+str(digest_object.hexdigest())+', expected '+\
|
||||
str(digest)
|
||||
message = repr(algorithm)+' hash does not match: '+\
|
||||
' was '+repr(digest_object.hexdigest())+', expected '+\
|
||||
repr(digest)
|
||||
raise tuf.Error(message)
|
||||
else:
|
||||
message = str(algorithm)+' hash of target '+str(targetpath)+\
|
||||
' is correct ('+str(digest)+').'
|
||||
message = repr(algorithm)+' hash of target '+repr(targetpath)+\
|
||||
' is correct ('+repr(digest)+').'
|
||||
logger.debug(message)
|
||||
|
||||
# At this point, the targets metadata and all specified files have been
|
||||
|
|
@ -673,14 +674,14 @@ def _process_copied_push(pushpath, metadata_directory,
|
|||
source_path = os.path.join(push_temporary_directory, targets_basename,
|
||||
target_relativepath)
|
||||
destination_path = os.path.join(targets_directory, target_relativepath)
|
||||
logger.info('Adding target to repository: '+str(destination_path))
|
||||
logger.info('Adding target to repository: '+repr(destination_path))
|
||||
destination_directory = os.path.dirname(destination_path)
|
||||
if not os.path.exists(destination_directory):
|
||||
os.mkdir(destination_directory)
|
||||
shutil.copy(source_path, destination_path)
|
||||
|
||||
# Copy the new targets metadata file into place on the repository.
|
||||
message = 'Adding new targets metadata to repository: '+str(targets_metadatapath)
|
||||
message = 'Adding new targets metadata to repository: '+repr(targets_metadatapath)
|
||||
logger.info(message)
|
||||
shutil.copy(new_targets_metadatapath, targets_metadatapath)
|
||||
|
||||
|
|
@ -745,7 +746,7 @@ def _remove_old_files(targets_metadatapath, pushname,
|
|||
for target_relativepath in targets_signable['signed']['targets'].keys():
|
||||
targetpath = os.path.join(targets_directory, target_relativepath)
|
||||
backup_targetpath = os.path.join(backup_targetsdirectory, target_relativepath)
|
||||
message = 'Backing up target '+str(targetpath)+' to '+str(backup_targetpath)
|
||||
message = 'Backing up target '+repr(targetpath)+' to '+repr(backup_targetpath)
|
||||
logger.info(message)
|
||||
|
||||
# Move the old target file to the backup directory. Create any
|
||||
|
|
@ -760,13 +761,13 @@ def _remove_old_files(targets_metadatapath, pushname,
|
|||
raise tuf.Error(str(e))
|
||||
os.rename(targetpath, backup_targetpath)
|
||||
else:
|
||||
message = 'The old target '+str(targetpath)+' doesn\'t exist in the repo.'
|
||||
message = 'The old target '+repr(targetpath)+' doesn\'t exist in the repo.'
|
||||
logger.warn(message)
|
||||
|
||||
# Backup the old 'targets.txt' metadata file.
|
||||
backup_targets_metadatafile = os.path.join(backup_destdirectory, 'targets.txt')
|
||||
message = 'Backing up old metadata '+str(targets_metadatapath)+\
|
||||
' to '+str(backup_targets_metadatafile)
|
||||
message = 'Backing up old metadata '+repr(targets_metadatapath)+\
|
||||
' to '+repr(backup_targets_metadatafile)
|
||||
logger.info(message)
|
||||
if os.path.isfile(backup_targets_metadatafile):
|
||||
os.remove(backup_targets_metadatafile)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
import tempfile
|
||||
import time
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@
|
|||
import tuf.log
|
||||
|
||||
# See 'log.py' to learn how logging is handled in TUF.
|
||||
logger = logging.getLogger('tuf')
|
||||
logger = logging.getLogger('tuf.quickstart')
|
||||
|
||||
# Set the default file names for the top-level roles.
|
||||
# For instance: in 'signerlib.py', ROOT_FILENAME = 'root.txt'.
|
||||
|
|
|
|||
|
|
@ -58,16 +58,17 @@
|
|||
import errno
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.repo.signerlib
|
||||
import tuf.repo.keystore
|
||||
import tuf.util
|
||||
import tuf.log
|
||||
|
||||
json = tuf.util.import_json()
|
||||
|
||||
# See 'log.py' to learn how logging is handled in TUF.
|
||||
logger = logging.getLogger('tuf.signercli')
|
||||
|
||||
json = tuf.util.import_json()
|
||||
|
||||
# The maximum number of attempts the user has to enter
|
||||
# valid input.
|
||||
MAX_INPUT_ATTEMPTS = 3
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
import ConfigParser
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.hash
|
||||
import tuf.rsa_key
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@
|
|||
|
||||
"""
|
||||
|
||||
import tuf.formats
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.log
|
||||
|
||||
# See 'tuf.log' to learn how logging is handled in TUF.
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@
|
|||
import evpy.signature
|
||||
import evpy.envelope
|
||||
|
||||
import tuf
|
||||
|
||||
# Digest objects needed to generate hashes.
|
||||
import tuf.hash
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
"""
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.keydb
|
||||
import tuf.roledb
|
||||
|
|
|
|||
|
|
@ -24,11 +24,9 @@
|
|||
import random
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
|
||||
DELAY = 1
|
||||
|
||||
|
||||
|
||||
# HTTP request handler.
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
|
|
@ -76,4 +74,4 @@ def run(port):
|
|||
else:
|
||||
port = get_random_port()
|
||||
|
||||
run(port)
|
||||
run(port)
|
||||
|
|
|
|||
|
|
@ -40,11 +40,6 @@
|
|||
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class ArbitraryPackageAlert(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -149,4 +144,4 @@ def test_arbitrary_package_attack(TUF=False):
|
|||
test_arbitrary_package_attack(TUF=True)
|
||||
|
||||
except ArbitraryPackageAlert, error:
|
||||
print error
|
||||
print error
|
||||
|
|
|
|||
|
|
@ -43,12 +43,6 @@
|
|||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class EndlessDataAttack(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -27,18 +27,17 @@
|
|||
import tempfile
|
||||
import time
|
||||
|
||||
import util_test_tools
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.tests.system_tests.util_test_tools
|
||||
import tuf.repo.keystore
|
||||
import tuf.repo.signerlib as signerlib
|
||||
import tuf.repo.signercli as signercli
|
||||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
version = 1
|
||||
|
||||
|
||||
class ExtraneousDependenciesAttackAlert(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -27,21 +27,16 @@
|
|||
import tempfile
|
||||
import util_test_tools
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.repo.signerlib as signerlib
|
||||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class IndefiniteFreezeAttackAlert(Exception):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
EXPIRATION = 1 # second(s)
|
||||
version = 1
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,6 @@
|
|||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class MixAndMatchAttackAlert(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -195,4 +190,4 @@ def test_mix_and_match_attack(TUF=False):
|
|||
try:
|
||||
test_mix_and_match_attack(TUF=True)
|
||||
except MixAndMatchAttackAlert, error:
|
||||
print error
|
||||
print error
|
||||
|
|
|
|||
|
|
@ -38,16 +38,10 @@
|
|||
import urllib
|
||||
import tempfile
|
||||
|
||||
import util_test_tools
|
||||
import tuf.tests.system_tests.util_test_tools as util_test_tools
|
||||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class TestSetupError(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -189,4 +183,4 @@ def test_replay_attack(TUF=False):
|
|||
try:
|
||||
test_replay_attack(TUF=True)
|
||||
except ReplayAttackAlert, error:
|
||||
print error
|
||||
print error
|
||||
|
|
|
|||
|
|
@ -42,15 +42,10 @@
|
|||
import subprocess
|
||||
from multiprocessing import Process
|
||||
|
||||
import util_test_tools
|
||||
import tuf.tests.system_tests.util_test_tools as util_test_tools
|
||||
from tuf.interposition import urllib_tuf
|
||||
|
||||
|
||||
# Disable logging.
|
||||
util_test_tools.disable_logging()
|
||||
|
||||
|
||||
|
||||
class SlowRetrievalAttackAlert(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -72,7 +67,8 @@ def test_slow_retrieval_attack(TUF=False):
|
|||
# Launch the server.
|
||||
port = random.randint(30000, 45000)
|
||||
command = ['python', 'slow_retrieval_server.py', str(port)]
|
||||
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
|
||||
server_process = subprocess.Popen(command, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
time.sleep(.1)
|
||||
|
||||
try:
|
||||
|
|
@ -134,4 +130,4 @@ def test_slow_retrieval_attack(TUF=False):
|
|||
try:
|
||||
test_slow_retrieval_attack(TUF=True)
|
||||
except SlowRetrievalAttackAlert, error:
|
||||
print error
|
||||
print error
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@
|
|||
import subprocess
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.interposition
|
||||
import tuf.util
|
||||
import tuf.client.updater
|
||||
|
|
@ -144,13 +145,7 @@
|
|||
import tuf.repo.signerlib as signerlib
|
||||
import tuf.repo.keystore as keystore
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable logging for cleaner output.
|
||||
def disable_logging():
|
||||
logging.getLogger('tuf')
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
logger = logging.getLogger('tuf.tests.system_tests.util_test_tools')
|
||||
|
||||
PASSWD = 'test'
|
||||
version = 1
|
||||
|
|
@ -174,7 +169,8 @@ def init_repo(tuf=False, port=None):
|
|||
# Start a simple server pointing to the repository directory.
|
||||
port = random.randint(30000, 45000)
|
||||
command = ['python', '-m', 'SimpleHTTPServer', str(port)]
|
||||
server_proc = subprocess.Popen(command, stderr=subprocess.PIPE)
|
||||
server_proc = subprocess.Popen(command, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
# Tailor url for the repository. In order to download a 'file.txt'
|
||||
# from 'reg_repo' do: url+'reg_repo/file.txt'
|
||||
|
|
|
|||
|
|
@ -19,12 +19,9 @@
|
|||
|
||||
NOTE: Make sure test_download.py is ran in 'tuf/tests/' directory.
|
||||
Otherwise, module that launches simple server would not be found.
|
||||
|
||||
"""
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.download as download
|
||||
import tuf.tests.unittest_toolbox as unittest_toolbox
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -37,11 +34,12 @@
|
|||
import SocketServer
|
||||
import SimpleHTTPServer
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.download as download
|
||||
import tuf.tests.unittest_toolbox as unittest_toolbox
|
||||
|
||||
# Disable/Enable logging. Comment-out to Enable logging.
|
||||
logging.getLogger('tuf')
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_download')
|
||||
|
||||
|
||||
class TestDownload(unittest_toolbox.Modified_TestCase):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
import unittest
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.schema
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@
|
|||
import tempfile
|
||||
import unittest
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.hash
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
logger = logging.getLogger('tuf.test_hash')
|
||||
|
||||
|
||||
if not 'hashlib' in tuf.hash._supported_libraries:
|
||||
logger.warn('Not testing hashlib: could not be imported.')
|
||||
|
|
|
|||
|
|
@ -19,15 +19,13 @@
|
|||
import unittest
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.rsa_key
|
||||
import tuf.keydb
|
||||
import tuf.log
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_keydb')
|
||||
|
||||
|
||||
# Generate the three keys to use in our test cases.
|
||||
|
|
|
|||
|
|
@ -21,16 +21,14 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.repo.keystore
|
||||
import tuf.rsa_key
|
||||
import tuf.formats
|
||||
import tuf.util
|
||||
import tuf.log
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_keystore')
|
||||
|
||||
# We'll need json module for testing '_encrypt()' and '_decrypt()'
|
||||
# internal function.
|
||||
|
|
|
|||
|
|
@ -24,20 +24,17 @@
|
|||
import ConfigParser
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.pushtools.push as push
|
||||
import tuf.pushtools.transfer.scp as scp
|
||||
import tuf.pushtools.pushtoolslib as pushtoolslib
|
||||
import system_tests.util_test_tools as util_test_tools
|
||||
import tuf.tests.system_tests.util_test_tools as util_test_tools
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
logger = logging.getLogger('tuf.test_push')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
class TestPush(unittest.TestCase):
|
||||
src_push_dict = {}
|
||||
logger.info(scp.transfer)
|
||||
|
||||
ORIGINAL_PUSH_CONFIG = pushtoolslib.PUSH_CONFIG
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@
|
|||
import tempfile
|
||||
import unittest
|
||||
import ConfigParser
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.formats
|
||||
import tuf.pushtools.pushtoolslib as pushtoolslib
|
||||
|
||||
logger = logging.getLogger('tuf.test_pushtoolslib')
|
||||
|
||||
|
||||
class TestPushtoolslib(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -25,19 +25,19 @@
|
|||
import shutil
|
||||
import unittest
|
||||
import logging
|
||||
import tuf.repo.quickstart as quickstart
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.repo.quickstart as quickstart
|
||||
import tuf.util
|
||||
import tuf.tests.unittest_toolbox
|
||||
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
logger = logging.getLogger('tuf.test_quickstart')
|
||||
unit_tbox = tuf.tests.unittest_toolbox.Modified_TestCase
|
||||
|
||||
|
||||
logger.info('from test_quickstart')
|
||||
|
||||
class TestQuickstart(unit_tbox):
|
||||
def test_1_get_password(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -16,20 +16,18 @@
|
|||
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.formats
|
||||
import tuf.rsa_key
|
||||
import tuf.roledb
|
||||
import tuf.log
|
||||
|
||||
logger = logging.getLogger('tuf.test_roledb')
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
# Generate the three keys to use in our test cases.
|
||||
KEYS = []
|
||||
|
|
|
|||
|
|
@ -23,10 +23,14 @@
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.formats
|
||||
import tuf.rsa_key
|
||||
|
||||
logger = logging.getLogger('tuf.test_rsa_key')
|
||||
|
||||
RSA_KEY = tuf.rsa_key
|
||||
FORMAT_ERROR_MSG = 'tuf.FormatError was raised! Check object\'s format.'
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.schema
|
||||
|
||||
logger = logging.getLogger('tuf.test_schema')
|
||||
|
||||
|
||||
class TestSchema(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
|
|
@ -17,13 +17,19 @@
|
|||
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.formats
|
||||
import tuf.keydb
|
||||
import tuf.roledb
|
||||
import tuf.rsa_key
|
||||
import tuf.sig
|
||||
|
||||
logger = logging.getLogger('tuf.test_sig')
|
||||
|
||||
# Setup the keys to use in our test cases.
|
||||
KEYS = []
|
||||
|
|
|
|||
|
|
@ -42,28 +42,25 @@ class guarantees the order of unit tests. So that, 'test_something_A'
|
|||
import unittest
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.formats
|
||||
import tuf.util
|
||||
import tuf.repo.keystore as keystore
|
||||
import tuf.repo.signerlib as signerlib
|
||||
|
||||
# Module to test: signercli.py
|
||||
import tuf.repo.signercli as signercli
|
||||
|
||||
# Helper module unittest_toolbox.py
|
||||
import tuf.tests.unittest_toolbox as unittest_toolbox
|
||||
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_signercli')
|
||||
|
||||
# Populating 'rsa_keystore' and 'rsa_passwords' dictionaries.
|
||||
# We will need them when creating keystore directories.
|
||||
unittest_toolbox.Modified_TestCase.bind_keys_to_roles()
|
||||
|
||||
|
||||
|
||||
class TestSignercli(unittest_toolbox.Modified_TestCase):
|
||||
# SETUP
|
||||
original_prompt = signercli._prompt
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@
|
|||
import logging
|
||||
import unittest
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.util
|
||||
import tuf.formats as formats
|
||||
import tuf.repo.signerlib as signerlib
|
||||
|
|
@ -61,12 +63,7 @@
|
|||
|
||||
import tuf.tests.unittest_toolbox
|
||||
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_signerlib')
|
||||
|
||||
# 'unittest_toolbox.Modified_TestCase' is too long, I'll set it to 'unit_tbox'.
|
||||
unit_tbox = tuf.tests.unittest_toolbox.Modified_TestCase
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ class guarantees the order of unit tests. So that, 'test_something_A'
|
|||
import logging
|
||||
import unittest
|
||||
|
||||
|
||||
import tuf
|
||||
import tuf.log
|
||||
import tuf.util
|
||||
import tuf.formats
|
||||
import tuf.repo.keystore as keystore
|
||||
|
|
@ -51,11 +54,7 @@ class guarantees the order of unit tests. So that, 'test_something_A'
|
|||
import tuf.tests.repository_setup as setup
|
||||
import tuf.tests.unittest_toolbox as unittest_toolbox
|
||||
|
||||
logger = logging.getLogger('tuf')
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_updater')
|
||||
|
||||
# References to roledb and keydb dictionaries (improve readability).
|
||||
roledb = tuf.roledb
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@
|
|||
import tuf.util as util
|
||||
import tuf.tests.unittest_toolbox as unittest_toolbox
|
||||
|
||||
# Disable all logging calls of level CRITICAL and below.
|
||||
# Comment the line below to enable logging.
|
||||
logging.disable(logging.CRITICAL)
|
||||
logger = logging.getLogger('tuf.test_util')
|
||||
|
||||
|
||||
class TestUtil(unittest_toolbox.Modified_TestCase):
|
||||
|
|
|
|||
|
|
@ -158,11 +158,6 @@ def setUp(self):
|
|||
|
||||
|
||||
def tearDown(self):
|
||||
# Removing 'tuf.log' file from current working directory.
|
||||
tuf_log_path = os.path.join(os.getcwd(), 'tuf.log')
|
||||
if os.path.exists(tuf_log_path):
|
||||
os.unlink(tuf_log_path)
|
||||
|
||||
for cleanup_function in self._cleanup:
|
||||
# Perform clean up by executing clean-up functions.
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
import logging
|
||||
import tempfile
|
||||
|
||||
import tuf
|
||||
import tuf.hash
|
||||
import tuf.conf
|
||||
import tuf.formats
|
||||
|
|
|
|||
Loading…
Reference in a new issue