summaryrefslogtreecommitdiffstats
path: root/base/kra/functional
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2014-05-23 10:30:18 -0400
committerAde Lee <alee@redhat.com>2014-05-29 11:29:28 -0400
commita353e5f81341830ea8a151e88ffc2be35aa40451 (patch)
tree6019e2ce4ffff2abb1674fcfed23a10ad286653d /base/kra/functional
parent7a50009c96d3592240e1b75a95593e9db403c062 (diff)
downloadpki-a353e5f81341830ea8a151e88ffc2be35aa40451.tar.gz
pki-a353e5f81341830ea8a151e88ffc2be35aa40451.tar.xz
pki-a353e5f81341830ea8a151e88ffc2be35aa40451.zip
latest changes for code review
Diffstat (limited to 'base/kra/functional')
-rw-r--r--base/kra/functional/drmtest.py77
1 files changed, 41 insertions, 36 deletions
diff --git a/base/kra/functional/drmtest.py b/base/kra/functional/drmtest.py
index b6fa18dcb..0fff95c2e 100644
--- a/base/kra/functional/drmtest.py
+++ b/base/kra/functional/drmtest.py
@@ -17,9 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-'''
+"""
=========================================================================
-Python test code for interacting with the DRM using the RESTful interface
+Python test code for interacting with the DRM using the REST interface
=========================================================================
This code is to be viewed as example code on how to interact with the DRM
@@ -27,7 +27,7 @@ for Key and KeyRequest resources using the Python REST client framework.
Some setup is required to run the tests here successfully.
See drmtest.readme.txt.
-'''
+"""
import base64
import pki
@@ -38,35 +38,39 @@ import time
from pki.client import PKIConnection
from pki.kraclient import KRAClient
+
def print_key_request(request):
- ''' Prints the relevant fields of a KeyRequestInfo object '''
- print "RequestURL: " + str(request.requestURL)
- print "RequestType: " + str(request.requestType)
- print "RequestStatus: " + str(request.requestStatus)
+ """ 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.keyURL)
+
def print_key_info(key_info):
- ''' Prints the relevant fields of a KeyInfo object '''
- print "Key URL: " + str(key_info.keyURL)
- print "Client Key ID: " + str(key_info.clientKeyID)
+ """ 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.ownerName)
+ print "Owner Name: " + str(key_info.owner_name)
print "Size: " + str(key_info.size)
-def print_key_data(key):
- ''' Prints the relevant fields of a KeyData object '''
- print "Key Algorithm: " + str(key.algorithm)
- print "Key Size: " + str(key.size)
- print "Nonce Data: " + base64.encodestring(key.nonce_data)
- print "Wrapped Private Data: " + base64.encodestring(key.encrypted_data)
- if key.data is not None:
- print "Private Data: " + base64.encodestring(key.data)
+
+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)
+ if key_data.data is not None:
+ print "Private Data: " + base64.encodestring(key_data.data)
+
def main():
- ''' test code execution '''
+ """ test code execution """
- # set up the connectoon to the DRM, including authentication credentials
+ # set up the connection to the DRM, including authentication credentials
connection = PKIConnection('https', 'localhost', '8443', 'kra')
connection.set_authentication_cert('/tmp/temp4.pem')
@@ -83,7 +87,7 @@ def main():
# Get transport cert and insert in the certdb
transport_nick = "kra transport cert"
transport_cert = kraclient.system_certs.get_transport_cert()
- tcert = transport_cert[len(pki.CERT_HEADER):len(transport_cert) -len(pki.CERT_FOOTER)]
+ tcert = transport_cert[len(pki.CERT_HEADER):len(transport_cert) - len(pki.CERT_FOOTER)]
crypto.import_cert(transport_nick, base64.decodestring(tcert), "u,u,u")
# initialize the certdb for crypto operations
@@ -96,8 +100,8 @@ def main():
# Test 2: Get key request info
print "Now getting key request"
try:
- keyrequest = keyclient.get_request_info('2')
- print_key_request(keyrequest)
+ key_request = keyclient.get_request_info('2')
+ print_key_request(key_request)
except pki.RequestNotFoundException:
pass
@@ -125,6 +129,7 @@ def main():
# Test 5: Confirm the key_id matches
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
for key_info in key_infos.key_infos:
print_key_info(key_info)
key_id2 = key_info.get_key_id()
@@ -160,24 +165,24 @@ def main():
# Test 10 = test BadRequestException on create()
print "Trying to generate a new symkey with the same client ID"
try:
- response = keyclient.generate_symmetric_key(client_key_id,
- algorithm=algorithm,
- size=key_size,
- usages=usages)
+ 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
# Test 11 - Test RequestNotFoundException on get_request_info
print "Try to list a nonexistent request"
try:
- keyrequest = keyclient.get_request_info('200000034')
+ keyclient.get_request_info('200000034')
except pki.RequestNotFoundException as exc:
print "RequestNotFoundException thrown - Code:" + exc.code + " Message: " + exc.message
# Test 12 - Test exception on retrieve_key.
print "Try to retrieve an invalid key"
try:
- key_data = keyclient.retrieve_key('2000003434')
+ keyclient.retrieve_key('2000003434')
except pki.KeyNotFoundException as exc:
print "KeyNotFoundException thrown - Code:" + exc.code + " Message: " + exc.message
@@ -199,7 +204,7 @@ def main():
# Test 16: Get key info for non-existent key
print "Get key info for non-existent key"
try:
- key_info = keyclient.get_key_info('200004556')
+ keyclient.get_key_info('200004556')
except pki.KeyNotFoundException as exc:
print "KeyNotFoundException thrown - Code:" + exc.code + " Message: " + exc.message
@@ -214,7 +219,7 @@ def main():
#Test 18: Generate a symmetric key with default parameters
client_key_id = "Vek #3" + time.strftime('%c')
response = keyclient.generate_symmetric_key(client_key_id)
- print_key_request(response.requestInfo)
+ print_key_request(response.request_info)
# Test 19: Try to archive key
print "try to archive key"
@@ -222,10 +227,10 @@ def main():
client_key_id = "Vek #4" + time.strftime('%c')
response = keyclient.archive_key(client_key_id, keyclient.SYMMETRIC_KEY_TYPE,
- base64.decodestring(key1),
- key_algorithm=keyclient.AES_ALGORITHM,
- key_size=128)
- print_key_request(response.requestInfo)
+ base64.decodestring(key1),
+ key_algorithm=keyclient.AES_ALGORITHM,
+ key_size=128)
+ print_key_request(response.request_info)
# Test 20: Lets get it back
key_info = keyclient.get_active_key_info(client_key_id)