summaryrefslogtreecommitdiffstats
path: root/base/kra/functional
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2015-08-16 19:00:00 +0200
committerChristian Heimes <cheimes@redhat.com>2015-08-17 21:14:11 +0200
commitf98ca7fa1903e12a4b2c49a70163077b3560dc1d (patch)
treea3446113d3a7d32c5ce79b1b359d5353ec49afee /base/kra/functional
parent71148b8f79a5d6ba0c949a3ca0acf5aec6321f0a (diff)
downloadpki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.tar.gz
pki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.tar.xz
pki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.zip
Py3 modernization: libmodernize.fixes.fix_print
Replace print statement with Python 3's print() function. For Python 2 'from __future__ import print_function' turns the print statement into Python 3 compatible print function. See https://www.python.org/dev/peps/pep-3105/
Diffstat (limited to 'base/kra/functional')
-rw-r--r--base/kra/functional/drmclient_deprecated.py33
-rwxr-xr-xbase/kra/functional/drmtest.py147
2 files changed, 91 insertions, 89 deletions
diff --git a/base/kra/functional/drmclient_deprecated.py b/base/kra/functional/drmclient_deprecated.py
index 99c70a184..0ebece27d 100644
--- a/base/kra/functional/drmclient_deprecated.py
+++ b/base/kra/functional/drmclient_deprecated.py
@@ -35,6 +35,7 @@ A sample test execution is provided at the end of the file.
'''
from __future__ import absolute_import
+from __future__ import print_function
from lxml import etree
import nss.nss as nss
import httplib
@@ -486,7 +487,7 @@ class KRA:
return encoding_ctx, decoding_ctx
def debug(self, message, *args):
- print message % args
+ print(message % args)
def _request(self, url, port, operation, args):
"""
@@ -1044,11 +1045,11 @@ test_kra = KRA(work_dir, kra_host, kra_port, kra_nickname)
# list requests
requests = test_kra.list_key_requests()
-print requests
+print(requests)
# get transport cert
transport_cert = test_kra.get_transport_cert()
-print transport_cert
+print(transport_cert)
# archive symmetric key
f = open(work_dir + "/" + options_file)
@@ -1058,44 +1059,44 @@ response = test_kra.archive_security_data(
client_id,
wrapped_key,
"symmetricKey")
-print response
+print(response)
# list keys with client_id
response = test_kra.list_security_data(client_id, "active")
-print response
+print(response)
# create recovery request
key_id = response.keys()[0]
-print key_id
+print(key_id)
response = test_kra.submit_recovery_request(key_id)
-print response
+print(response)
# approve recovery request
request_id = response['request_id']
test_kra.approve_recovery_request(request_id)
# test invalid request
-print "Testing invalid request ID"
+print("Testing invalid request ID")
try:
response = test_kra.retrieve_security_data("INVALID")
- print "Failure: No exception thrown"
+ print("Failure: No exception thrown")
except CertificateOperationError as e:
if 'Error in retrieving security data (Bad Request)' == e.error:
- print "Success: " + e.error
+ print("Success: " + e.error)
else:
- print "Failure: Wrong error message: " + e.error
+ print("Failure: Wrong error message: " + e.error)
# retrieve key
response = test_kra.retrieve_security_data(request_id)
-print response
-print "retrieved data is " + base64.encodestring(response['data'])
+print(response)
+print("retrieved data is " + base64.encodestring(response['data']))
# read original symkey from file
f = open(work_dir + "/" + symkey_file)
orig_key = f.read()
-print "orig key is " + orig_key
+print("orig key is " + orig_key)
if orig_key.strip() == base64.encodestring(response['data']).strip():
- print "Success: the keys match"
+ print("Success: the keys match")
else:
- print "Failure: keys do not match"
+ print("Failure: keys do not match")
diff --git a/base/kra/functional/drmtest.py b/base/kra/functional/drmtest.py
index 1d7eb3270..6fe05ab43 100755
--- a/base/kra/functional/drmtest.py
+++ b/base/kra/functional/drmtest.py
@@ -33,6 +33,7 @@ See drmtest.readme.txt.
"""
from __future__ import absolute_import
+from __future__ import print_function
import base64
import getopt
import random
@@ -52,36 +53,36 @@ from pki.kra import KRAClient
def print_key_request(request):
""" Prints the relevant fields of a KeyRequestInfo object """
- print "RequestURL: " + str(request.request_url)
- print "RequestType: " + str(request.request_type)
- print "RequestStatus: " + str(request.request_status)
- print "KeyURL: " + str(request.key_url)
+ print("RequestURL: " + str(request.request_url))
+ print("RequestType: " + str(request.request_type))
+ print("RequestStatus: " + str(request.request_status))
+ print("KeyURL: " + str(request.key_url))
def print_key_info(key_info):
""" Prints the relevant fields of a KeyInfo object """
- print "Key URL: " + str(key_info.key_url)
- print "Client Key ID: " + str(key_info.client_key_id)
- print "Algorithm: " + str(key_info.algorithm)
- print "Status: " + str(key_info.status)
- print "Owner Name: " + str(key_info.owner_name)
- print "Size: " + str(key_info.size)
+ print("Key URL: " + str(key_info.key_url))
+ print("Client Key ID: " + str(key_info.client_key_id))
+ print("Algorithm: " + str(key_info.algorithm))
+ print("Status: " + str(key_info.status))
+ print("Owner Name: " + str(key_info.owner_name))
+ print("Size: " + str(key_info.size))
if key_info.public_key is not None:
- print "Public key: "
- print
+ print("Public key: ")
+ print()
pub_key = base64.encodestring(key_info.public_key)
- print pub_key
+ print(pub_key)
def print_key_data(key_data):
""" Prints the relevant fields of a KeyData object """
- print "Key Algorithm: " + str(key_data.algorithm)
- print "Key Size: " + str(key_data.size)
- print "Nonce Data: " + base64.encodestring(key_data.nonce_data)
- print "Wrapped Private Data: " + \
- base64.encodestring(key_data.encrypted_data)
+ print("Key Algorithm: " + str(key_data.algorithm))
+ print("Key Size: " + str(key_data.size))
+ print("Nonce Data: " + base64.encodestring(key_data.nonce_data))
+ print("Wrapped Private Data: " +
+ base64.encodestring(key_data.encrypted_data))
if key_data.data is not None:
- print "Private Data: " + base64.encodestring(key_data.data)
+ print("Private Data: " + base64.encodestring(key_data.data))
def run_test(protocol, hostname, port, client_cert, certdb_dir,
@@ -100,8 +101,8 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
# Get transport cert and insert in the certdb
transport_nick = "kra transport cert"
transport_cert = kraclient.system_certs.get_transport_cert()
- print "Subject DN: " + transport_cert.subject_dn
- print transport_cert.encoded
+ print("Subject DN: " + transport_cert.subject_dn)
+ print(transport_cert.encoded)
crypto.import_cert(transport_nick, transport_cert)
# initialize the certdb for crypto operations
@@ -112,7 +113,7 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
keyclient.set_transport_cert(transport_nick)
# Test 2: Get key request info
- print "Now getting key request"
+ print("Now getting key request")
try:
key_request = keyclient.get_request_info('2')
print_key_request(key_request)
@@ -120,14 +121,14 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
pass
# Test 3: List requests
- print "Now listing some requests"
+ print("Now listing some requests")
keyrequests = keyclient.list_requests('complete', 'securityDataRecovery')
- print keyrequests.key_requests
+ print(keyrequests.key_requests)
for request in keyrequests.key_requests:
print_key_request(request)
# Test 4: generate symkey -- same as barbican_encode()
- print "Now generating symkey on KRA"
+ print("Now generating symkey on KRA")
client_key_id = "Vek #1" + time.strftime('%c')
algorithm = "AES"
key_size = 128
@@ -138,11 +139,11 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
size=key_size,
usages=usages)
print_key_request(response.request_info)
- print "Request ID is " + response.request_info.get_request_id()
+ print("Request ID is " + response.request_info.get_request_id())
key_id = response.get_key_id()
# Test 5: Confirm the key_id matches
- print "Now getting key ID for clientKeyID=\"" + client_key_id + "\""
+ print("Now getting key ID for clientKeyID=\"" + client_key_id + "\"")
key_infos = keyclient.list_keys(client_key_id=client_key_id,
status=keyclient.KEY_STATUS_ACTIVE)
key_id2 = None
@@ -150,16 +151,16 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
print_key_info(key_info)
key_id2 = key_info.get_key_id()
if key_id == key_id2:
- print "Success! The keys from generation and search match."
+ print("Success! The keys from generation and search match.")
else:
- print "Failure - key_ids for generation do not match!"
+ print("Failure - key_ids for generation do not match!")
# Test 6: Barbican_decode() - Retrieve while providing
# trans_wrapped_session_key
session_key = crypto.generate_session_key()
wrapped_session_key = crypto.asymmetric_wrap(session_key,
keyclient.transport_cert)
- print "My key id is " + str(key_id)
+ print("My key id is " + str(key_id))
key_data = keyclient.retrieve_key(
key_id, trans_wrapped_session_key=wrapped_session_key)
print_key_data(key_data)
@@ -175,70 +176,70 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
# Test 8 - Confirm that keys returned are the same
if key1 == key2:
- print "Success: The keys returned match! Key = " + str(key1)
+ print("Success: The keys returned match! Key = " + str(key1))
else:
- print "Failure: The returned keys do not match!"
- print "key1: " + key1
- print "key2: " + key2
+ print("Failure: The returned keys do not match!")
+ print("key1: " + key1)
+ print("key2: " + key2)
# Test 10 = test BadRequestException on create()
- print "Trying to generate a new symkey with the same client ID"
+ print("Trying to generate a new symkey with the same client ID")
try:
keyclient.generate_symmetric_key(client_key_id,
algorithm=algorithm,
size=key_size,
usages=usages)
except pki.BadRequestException as exc:
- print "BadRequestException thrown - Code:" + exc.code +\
- " Message: " + exc.message
+ print("BadRequestException thrown - Code:" + exc.code +
+ " Message: " + exc.message)
# Test 11 - Test RequestNotFoundException on get_request_info
- print "Try to list a nonexistent request"
+ print("Try to list a nonexistent request")
try:
keyclient.get_request_info('200000034')
except pki.RequestNotFoundException as exc:
- print "RequestNotFoundException thrown - Code:" + exc.code +\
- " Message: " + exc.message
+ print("RequestNotFoundException thrown - Code:" + exc.code +
+ " Message: " + exc.message)
# Test 12 - Test exception on retrieve_key.
- print "Try to retrieve an invalid key"
+ print("Try to retrieve an invalid key")
try:
keyclient.retrieve_key('2000003434')
except pki.KeyNotFoundException as exc:
- print "KeyNotFoundException thrown - Code:" + exc.code + \
- " Message: " + exc.message
+ print("KeyNotFoundException thrown - Code:" + exc.code +
+ " Message: " + exc.message)
# Test 13 = getKeyInfo
- print "Get key info for existing key"
+ print("Get key info for existing key")
key_info = keyclient.get_key_info(key_id)
print_key_info(key_info)
# Test 14: get the active key
- print "Get the active key for client id: " + client_key_id
+ print("Get the active key for client id: " + client_key_id)
key_info = keyclient.get_active_key_info(client_key_id)
print_key_info(key_info)
# Test 15: change the key status
- print "Change the key status"
+ print("Change the key status")
keyclient.modify_key_status(key_id, keyclient.KEY_STATUS_INACTIVE)
print_key_info(keyclient.get_key_info(key_id))
# Test 16: Get key info for non-existent key
- print "Get key info for non-existent key"
+ print("Get key info for non-existent key")
try:
keyclient.get_key_info('200004556')
except pki.KeyNotFoundException as exc:
- print "KeyNotFoundException thrown - Code:" + exc.code +\
- " Message: " + exc.message
+ print("KeyNotFoundException thrown - Code:" + exc.code +
+ " Message: " + exc.message)
# Test 17: Get key info for non-existent active key
- print "Get non-existent active key"
+ print("Get non-existent active key")
try:
key_info = keyclient.get_active_key_info(client_key_id)
print_key_info(key_info)
except pki.ResourceNotFoundException as exc:
- print "ResourceNotFoundException thrown - Code: " + exc.code +\
- "Message: " + exc.message
+ print("ResourceNotFoundException thrown - Code: " + exc.code +
+ "Message: " + exc.message)
# Test 18: Generate a symmetric key with default parameters
client_key_id = "Vek #3" + time.strftime('%c')
@@ -246,8 +247,8 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
print_key_request(response.request_info)
# Test 19: Try to archive key
- print "try to archive key"
- print "key to archive: " + key1
+ print("try to archive key")
+ print("key to archive: " + key1)
client_key_id = "Vek #4" + time.strftime('%c')
response = keyclient.archive_key(client_key_id,
@@ -266,13 +267,13 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
key2 = base64.encodestring(key_data.data)
if key1 == key2:
- print "Success: archived and recovered keys match"
+ print("Success: archived and recovered keys match")
else:
- print "Error: archived and recovered keys do not match"
- print
+ print("Error: archived and recovered keys do not match")
+ print()
# Test 20: Generating asymmetric keys
- print "Generating asymmetric keys"
+ print("Generating asymmetric keys")
try:
response = keyclient.generate_asymmetric_key(
"Vek #5" + time.strftime('%c'),
@@ -282,24 +283,24 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir,
)
print_key_request(response.request_info)
except pki.BadRequestException as exc:
- print "BadRequestException thrown - Code:" + exc.code +\
- " Message: " + exc.message
+ print("BadRequestException thrown - Code:" + exc.code +
+ " Message: " + exc.message)
# Test 21: Get key information of the newly generated asymmetric keys
- print "Retrieving key information"
+ print("Retrieving key information")
key_info = keyclient.get_key_info(response.request_info.get_key_id())
print_key_info(key_info)
def usage():
- print 'Usage: drmtest.py [OPTIONS]'
- print
- print ' -P <protocol> KRA server protocol (default: https).'
- print ' -h <hostname> KRA server hostname (default: localhost).'
- print ' -p <port> KRA server port (default: 8443).'
- print ' -n <path> KRA agent certificate and private key (default: kraagent.pem).' # nopep8
- print
- print ' --help Show this help message.'
+ print('Usage: drmtest.py [OPTIONS]')
+ print()
+ print(' -P <protocol> KRA server protocol (default: https).')
+ print(' -h <hostname> KRA server hostname (default: localhost).')
+ print(' -p <port> KRA server port (default: 8443).')
+ print(' -n <path> KRA agent certificate and private key (default: kraagent.pem).') # nopep8
+ print()
+ print(' --help Show this help message.')
def main(argv):
@@ -307,7 +308,7 @@ def main(argv):
opts, _ = getopt.getopt(argv[1:], 'h:P:p:n:d:c:', ['help'])
except getopt.GetoptError as e:
- print 'ERROR: ' + str(e)
+ print('ERROR: ' + str(e))
usage()
sys.exit(1)
@@ -334,18 +335,18 @@ def main(argv):
sys.exit()
else:
- print 'ERROR: unknown option ' + o
+ print('ERROR: unknown option ' + o)
usage()
sys.exit(1)
certdb_dir = tempfile.mkdtemp(prefix='pki-kra-test-')
- print "NSS database dir: %s" % certdb_dir
+ print("NSS database dir: %s" % certdb_dir)
certdb_password = ''.join(
random.choice(
string.ascii_letters +
string.digits) for i in range(8))
- print "NSS database password: %s" % certdb_password
+ print("NSS database password: %s" % certdb_password)
try:
run_test(