Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed duplicate functions in TUF #804

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/test_developer_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_create_new_project(self):
# I will use the same key as the one provided in the repository
# tool tests for the root role, but this is not a root role...
root_key_path = os.path.join(keystore_path,'root_key.pub')
project_key = developer_tool.import_rsa_publickey_from_file(root_key_path)
project_key = securesystemslib.interface.import_rsa_publickey_from_file(root_key_path)

# Test create new project with a key added by default.
project = developer_tool.create_new_project(project_name, metadata_directory,
Expand Down Expand Up @@ -230,15 +230,15 @@ def test_add_verification_keys(self):
keystore_path = os.path.join('repository_data', 'keystore')
first_verification_key_path = os.path.join(keystore_path,'root_key.pub')
first_verification_key = \
developer_tool.import_rsa_publickey_from_file(first_verification_key_path)
securesystemslib.interface.import_rsa_publickey_from_file(first_verification_key_path)

project.add_verification_key(first_verification_key)


# Add another verification key (should expect exception.)
second_verification_key_path = os.path.join(keystore_path, 'snapshot_key.pub')
second_verification_key = \
developer_tool.import_ed25519_publickey_from_file(second_verification_key_path)
securesystemslib.interface.import_ed25519_publickey_from_file(second_verification_key_path)

self.assertRaises(securesystemslib.exceptions.Error,
project.add_verification_key,(second_verification_key))
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_write(self):
keystore_path = os.path.join('repository_data', 'keystore')
project_key_path = os.path.join(keystore_path, 'root_key.pub')
project_key = \
developer_tool.import_rsa_publickey_from_file(project_key_path)
securesystemslib.interface.import_rsa_publickey_from_file(project_key_path)


# Call status (for the sake of doing it and to improve test coverage by
Expand All @@ -292,12 +292,12 @@ def test_write(self):
# Add another verification key (should expect exception.)
delegation_key_path = os.path.join(keystore_path, 'snapshot_key.pub')
delegation_key = \
developer_tool.import_ed25519_publickey_from_file(delegation_key_path)
securesystemslib.interface.import_ed25519_publickey_from_file(delegation_key_path)

# Add a subdelegation.
subdelegation_key_path = os.path.join(keystore_path, 'timestamp_key.pub')
subdelegation_key = \
developer_tool.import_ed25519_publickey_from_file(subdelegation_key_path)
securesystemslib.interface.import_ed25519_publickey_from_file(subdelegation_key_path)

# Add a delegation.
project.delegate('delegation', [delegation_key], [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_key_revocation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def _load_role_keys(keystore_directory):

# Import the top-level and delegated role public keys.
role_keys['root']['public'] = \
repo_tool.import_rsa_publickey_from_file(root_key_file+'.pub')
securesystemslib.interface.import_rsa_publickey_from_file(root_key_file+'.pub')
role_keys['targets']['public'] = \
repo_tool.import_ed25519_publickey_from_file(targets_key_file + '.pub')
role_keys['snapshot']['public'] = \
Expand Down
50 changes: 25 additions & 25 deletions tests/test_repository_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def test_generate_and_write_rsa_keypair(self):
temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory)
test_keypath = os.path.join(temporary_directory, 'rsa_key')

repo_lib.generate_and_write_rsa_keypair(test_keypath, password='pw')
securesystemslib.interface.generate_and_write_rsa_keypair(test_keypath, password='pw')
self.assertTrue(os.path.exists(test_keypath))
self.assertTrue(os.path.exists(test_keypath + '.pub'))

# Ensure the generated key files are importable.
imported_pubkey = \
repo_lib.import_rsa_publickey_from_file(test_keypath + '.pub')
securesystemslib.interface.import_rsa_publickey_from_file(test_keypath + '.pub')
self.assertTrue(securesystemslib.formats.RSAKEY_SCHEMA.matches(imported_pubkey))

imported_privkey = \
Expand All @@ -122,23 +122,23 @@ def test_generate_and_write_rsa_keypair(self):
# Custom 'bits' argument.
os.remove(test_keypath)
os.remove(test_keypath + '.pub')
repo_lib.generate_and_write_rsa_keypair(test_keypath, bits=2048,
securesystemslib.interface.generate_and_write_rsa_keypair(test_keypath, bits=2048,
password='pw')
self.assertTrue(os.path.exists(test_keypath))
self.assertTrue(os.path.exists(test_keypath + '.pub'))


# Test improperly formatted arguments.
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.generate_and_write_rsa_keypair,
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.interface.generate_and_write_rsa_keypair,
3, bits=2048, password='pw')
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.generate_and_write_rsa_keypair,
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.interface.generate_and_write_rsa_keypair,
test_keypath, bits='bad', password='pw')
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.generate_and_write_rsa_keypair,
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.interface.generate_and_write_rsa_keypair,
test_keypath, bits=2048, password=3)


# Test invalid 'bits' argument.
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.generate_and_write_rsa_keypair,
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.interface.generate_and_write_rsa_keypair,
test_keypath, bits=1024, password='pw')


Expand Down Expand Up @@ -188,7 +188,7 @@ def test_import_rsa_publickey_from_file(self):
'root_key.pub')
self.assertTrue(os.path.exists(key_filepath))

imported_rsa_key = repo_lib.import_rsa_publickey_from_file(key_filepath)
imported_rsa_key = securesystemslib.interface.import_rsa_publickey_from_file(key_filepath)
self.assertTrue(securesystemslib.formats.RSAKEY_SCHEMA.matches(imported_rsa_key))


Expand All @@ -201,14 +201,14 @@ def test_import_rsa_publickey_from_file(self):
# Non-existent key file.
nonexistent_keypath = os.path.join(temporary_directory,
'nonexistent_keypath')
self.assertRaises(IOError, repo_lib.import_rsa_publickey_from_file,
self.assertRaises(IOError, securesystemslib.interface.import_rsa_publickey_from_file,
nonexistent_keypath)

# Invalid key file argument.
invalid_keyfile = os.path.join(temporary_directory, 'invalid_keyfile')
with open(invalid_keyfile, 'wb') as file_object:
file_object.write(b'bad keyfile')
self.assertRaises(securesystemslib.exceptions.Error, repo_lib.import_rsa_publickey_from_file,
self.assertRaises(securesystemslib.exceptions.Error, securesystemslib.interface.import_rsa_publickey_from_file,
invalid_keyfile)


Expand All @@ -219,25 +219,25 @@ def test_generate_and_write_ed25519_keypair(self):
temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory)
test_keypath = os.path.join(temporary_directory, 'ed25519_key')

repo_lib.generate_and_write_ed25519_keypair(test_keypath, password='pw')
securesystemslib.interface.generate_and_write_ed25519_keypair(test_keypath, password='pw')
self.assertTrue(os.path.exists(test_keypath))
self.assertTrue(os.path.exists(test_keypath + '.pub'))

# Ensure the generated key files are importable.
imported_pubkey = \
repo_lib.import_ed25519_publickey_from_file(test_keypath + '.pub')
securesystemslib.interface.import_ed25519_publickey_from_file(test_keypath + '.pub')
self.assertTrue(securesystemslib.formats.ED25519KEY_SCHEMA.matches(imported_pubkey))

imported_privkey = \
repo_lib.import_ed25519_privatekey_from_file(test_keypath, 'pw')
securesystemslib.interface.import_ed25519_privatekey_from_file(test_keypath, 'pw')
self.assertTrue(securesystemslib.formats.ED25519KEY_SCHEMA.matches(imported_privkey))


# Test improperly formatted arguments.
self.assertRaises(securesystemslib.exceptions.FormatError,
repo_lib.generate_and_write_ed25519_keypair,
securesystemslib.interface.generate_and_write_ed25519_keypair,
3, password='pw')
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.generate_and_write_rsa_keypair,
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.interface.generate_and_write_rsa_keypair,
test_keypath, password=3)


Expand All @@ -247,31 +247,31 @@ def test_import_ed25519_publickey_from_file(self):
# Generate ed25519 keys that can be imported.
temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory)
ed25519_keypath = os.path.join(temporary_directory, 'ed25519_key')
repo_lib.generate_and_write_ed25519_keypair(ed25519_keypath, password='pw')
securesystemslib.interface.generate_and_write_ed25519_keypair(ed25519_keypath, password='pw')

imported_ed25519_key = \
repo_lib.import_ed25519_publickey_from_file(ed25519_keypath + '.pub')
securesystemslib.interface.import_ed25519_publickey_from_file(ed25519_keypath + '.pub')
self.assertTrue(securesystemslib.formats.ED25519KEY_SCHEMA.matches(imported_ed25519_key))


# Test improperly formatted argument.
self.assertRaises(securesystemslib.exceptions.FormatError,
repo_lib.import_ed25519_publickey_from_file, 3)
securesystemslib.interface.import_ed25519_publickey_from_file, 3)


# Test invalid argument.
# Non-existent key file.
nonexistent_keypath = os.path.join(temporary_directory,
'nonexistent_keypath')
self.assertRaises(IOError, repo_lib.import_ed25519_publickey_from_file,
self.assertRaises(IOError, securesystemslib.interface.import_ed25519_publickey_from_file,
nonexistent_keypath)

# Invalid key file argument.
invalid_keyfile = os.path.join(temporary_directory, 'invalid_keyfile')
with open(invalid_keyfile, 'wb') as file_object:
file_object.write(b'bad keyfile')

self.assertRaises(securesystemslib.exceptions.Error, repo_lib.import_ed25519_publickey_from_file,
self.assertRaises(securesystemslib.exceptions.Error, securesystemslib.interface.import_ed25519_publickey_from_file,
invalid_keyfile)

# Invalid public key imported (contains unexpected keytype.)
Expand All @@ -287,7 +287,7 @@ def test_import_ed25519_publickey_from_file(self):
file_object.write(json.dumps(ed25519key_metadata_format).encode('utf-8'))

self.assertRaises(securesystemslib.exceptions.FormatError,
repo_lib.import_ed25519_publickey_from_file,
securesystemslib.interface.import_ed25519_publickey_from_file,
ed25519_keypath + '.pub')


Expand All @@ -297,7 +297,7 @@ def test_import_ed25519_privatekey_from_file(self):
# Generate ed25519 keys that can be imported.
temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory)
ed25519_keypath = os.path.join(temporary_directory, 'ed25519_key')
repo_lib.generate_and_write_ed25519_keypair(ed25519_keypath, password='pw')
securesystemslib.interface.generate_and_write_ed25519_keypair(ed25519_keypath, password='pw')

imported_ed25519_key = \
repo_lib.import_ed25519_privatekey_from_file(ed25519_keypath, 'pw')
Expand Down Expand Up @@ -419,10 +419,10 @@ def test_get_target_hash(self):
for filepath, target_hash in six.iteritems(expected_target_hashes):
self.assertTrue(securesystemslib.formats.RELPATH_SCHEMA.matches(filepath))
self.assertTrue(securesystemslib.formats.HASH_SCHEMA.matches(target_hash))
self.assertEqual(repo_lib.get_target_hash(filepath), target_hash)
self.assertEqual(securesystemslib.util.get_target_hash(filepath), target_hash)

# Test for improperly formatted argument.
self.assertRaises(securesystemslib.exceptions.FormatError, repo_lib.get_target_hash, 8)
self.assertRaises(securesystemslib.exceptions.FormatError, securesystemslib.util.get_target_hash, 8)



Expand Down Expand Up @@ -710,7 +710,7 @@ def test_sign_metadata(self):
# Sign with a valid, but not a threshold, key.
targets_public_keypath = os.path.join(keystore_path, 'targets_key.pub')
targets_public_key = \
repo_lib.import_ed25519_publickey_from_file(targets_public_keypath)
securesystemslib.interface.import_ed25519_publickey_from_file(targets_public_keypath)

# sign_metadata() expects the private key 'root_metadata' to be in
# 'tuf.keydb'. Remove any public keys that may be loaded before
Expand Down
28 changes: 14 additions & 14 deletions tests/test_repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_writeall(self):
timestamp_pubkey_path = os.path.join(keystore_directory, 'timestamp_key.pub')
role1_pubkey_path = os.path.join(keystore_directory, 'delegation_key.pub')

root_pubkey = repo_tool.import_rsa_publickey_from_file(root_pubkey_path)
root_pubkey = securesystemslib.interface.import_rsa_publickey_from_file(root_pubkey_path)
targets_pubkey = \
repo_tool.import_ed25519_publickey_from_file(targets_pubkey_path)
snapshot_pubkey = \
Expand Down Expand Up @@ -568,7 +568,7 @@ def test_keys(self):
# Test keys() getter after a verification key has been loaded.
key_path = os.path.join('repository_data',
'keystore', 'snapshot_key.pub')
key_object = repo_tool.import_ed25519_publickey_from_file(key_path)
key_object = securesystemslib.interface.import_ed25519_publickey_from_file(key_path)
self.metadata.add_verification_key(key_object)

keyid = key_object['keyid']
Expand Down Expand Up @@ -597,7 +597,7 @@ def test_signing_keys(self):
def test_add_verification_key(self):
# Add verification key and verify that it was added via (role).keys.
key_path = os.path.join('repository_data', 'keystore', 'snapshot_key.pub')
key_object = repo_tool.import_ed25519_publickey_from_file(key_path)
key_object = securesystemslib.interface.import_ed25519_publickey_from_file(key_path)
self.metadata.add_verification_key(key_object)

keyid = key_object['keyid']
Expand Down Expand Up @@ -644,7 +644,7 @@ def test_remove_verification_key(self):
# Add verification key so that remove_verifiation_key() can be tested.
key_path = os.path.join('repository_data',
'keystore', 'snapshot_key.pub')
key_object = repo_tool.import_ed25519_publickey_from_file(key_path)
key_object = securesystemslib.interface.import_ed25519_publickey_from_file(key_path)
self.metadata.add_verification_key(key_object)

keyid = key_object['keyid']
Expand Down Expand Up @@ -688,7 +688,7 @@ def test_load_signing_key(self):
# Test non-private key.
key_path = os.path.join('repository_data',
'keystore', 'snapshot_key.pub')
key_object = repo_tool.import_ed25519_publickey_from_file(key_path)
key_object = securesystemslib.interface.import_ed25519_publickey_from_file(key_path)
self.assertRaises(securesystemslib.exceptions.Error, self.metadata.load_signing_key, key_object)


Expand Down Expand Up @@ -961,7 +961,7 @@ def test_call(self):
# through __call__(). Example: {targets_object}('role1').
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Create Targets() object to be tested.
Expand All @@ -984,7 +984,7 @@ def test_get_delegated_rolenames(self):
# return.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')
target2_filepath = os.path.join(self.targets_directory, 'file2.txt')

Expand Down Expand Up @@ -1024,7 +1024,7 @@ def test_delegations(self):
# return.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Set needed arguments by delegate().
Expand Down Expand Up @@ -1200,7 +1200,7 @@ def test_delegate(self):
# delegate().
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')
target2_filepath = os.path.join(self.targets_directory, 'file2.txt')

Expand Down Expand Up @@ -1281,7 +1281,7 @@ def test_delegate_hashed_bins(self):
# Test normal case.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Set needed arguments by delegate_hashed_bins().
Expand Down Expand Up @@ -1336,7 +1336,7 @@ def test_add_target_to_bin(self):
repository_name = 'test_repository'
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'targets_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Set needed arguments by delegate_hashed_bins().
Expand Down Expand Up @@ -1421,7 +1421,7 @@ def test_remove_target_from_bin(self):
# Delegate the hashed bins so that add_target_to_bin() can be tested.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'targets_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Set needed arguments by delegate_hashed_bins().
Expand Down Expand Up @@ -1477,7 +1477,7 @@ def test_add_paths(self):
# path to.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)

# Set needed arguments by delegate().
public_keys = [public_key]
Expand Down Expand Up @@ -1534,7 +1534,7 @@ def test_revoke(self):
# Perform a delegation so that revoke() has a delegation to revoke.
keystore_directory = os.path.join('repository_data', 'keystore')
public_keypath = os.path.join(keystore_directory, 'snapshot_key.pub')
public_key = repo_tool.import_ed25519_publickey_from_file(public_keypath)
public_key = securesystemslib.interface.import_ed25519_publickey_from_file(public_keypath)
target1_filepath = os.path.join(self.targets_directory, 'file1.txt')

# Set needed arguments by delegate().
Expand Down
Loading