Commit 5fce544a authored by Łukasz Nowak's avatar Łukasz Nowak

Check computer request and cert manipulation.

parent aafb86eb
from Products.ERP5Type.tests.Sequence import SequenceList
import transaction
import unittest
from testVifibSlapWebService import TestVifibSlapWebServiceMixin
class TestVifibSlapComputer(TestVifibSlapWebServiceMixin):
def stepCheckRequestedComputerCertificate(self, sequence, **kw):
computer = sequence['requested_computer']
sequence['computer_reference'] = computer._computer_id
certificate_dict = computer.getCertificateDict()
self.assertTrue('certificate' in certificate_dict)
self.assertTrue('key' in certificate_dict)
self.assertNotEqual(None, certificate_dict['certificate'])
self.assertNotEqual(None, certificate_dict['key'])
self.assertTrue(certificate_dict['key'].startswith(
'-----BEGIN PRIVATE KEY-----'))
self.assertTrue('-----BEGIN CERTIFICATE-----' in \
certificate_dict['certificate'])
computer = self.portal.portal_catalog.getResultValue(
reference=sequence['computer_reference'], portal_type='Computer')
self.assertNotEqual(None, computer.getDestinationReference())
sequence['certificate_reference'] = computer.getDestinationReference()
def test_request(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckSecondRequestComputer(self, sequence, **kw):
computer = sequence['requested_computer']
self.assertEqual(computer._computer_id, sequence['computer_reference'])
certificate_dict = computer.getCertificateDict()
self.assertTrue('certificate' in certificate_dict)
self.assertTrue('key' in certificate_dict)
self.assertEqual(None, certificate_dict['certificate'])
self.assertEqual(None, certificate_dict['key'])
computer_document = self.portal.portal_catalog.getResultValue(
reference=sequence['computer_reference'], portal_type='Computer')
self.assertEqual(sequence['certificate_reference'],
computer_document.getDestinationReference())
def test_request_twice(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
RequestComputer \
CleanTic \
CheckSecondRequestComputer \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckDoubleRequestRaisesNotImplementedError(self, sequence, **kw):
person = self.portal.ERP5Site_getAuthenticatedMemberPersonValue()
person.requestComputer(computer_title=sequence['computer_title'])
transaction.commit()
self.assertRaises(NotImplementedError, person.requestComputer,
computer_title=sequence['computer_title'])
def test_request_twice_activity(self):
sequence_list = SequenceList()
sequence_string = '\
LoginTestVifibAdmin \
SetComputerTitle \
CheckDoubleRequestRaisesNotImplementedError \
Logout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckComputerNoCertificate(self, sequence, **kw):
computer = self.portal.portal_catalog.getResultValue(
reference=sequence['computer_reference'], portal_type='Computer')
self.assertEqual(None, computer.getDestinationReference())
def test_revokeCertificate(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
RevokeComputerCertificate \
CheckComputerNoCertificate \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckRevokeComputerCertificateRaisesValueError(self, sequence, **kw):
computer = self.portal.portal_catalog.getResultValue(
reference=sequence['computer_reference'], portal_type='Computer')
self.assertRaises(ValueError, computer.revokeCertificate)
def test_revokeCertificateRevoked(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
RevokeComputerCertificate \
CheckComputerNoCertificate \
SlapLogout \
LoginTestVifibAdmin \
CheckRevokeComputerCertificateRaisesValueError \
Logout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_getCertificate(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
RevokeComputerCertificate \
CheckComputerNoCertificate \
GetComputerCertificate \
CleanTic \
CheckRequestedComputerCertificate \
SlapLogout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckGetComputerCertificateRaisesValueError(self, sequence, **kw):
computer = self.portal.portal_catalog.getResultValue(
reference=sequence['computer_reference'], portal_type='Computer')
self.assertRaises(ValueError, computer.getCertificate)
def test_getCertificateNotRevoked(self):
sequence_list = SequenceList()
sequence_string = '\
SlapLoginTestVifibAdmin \
SetComputerTitle \
RequestComputer \
CleanTic \
CheckRequestedComputerCertificate \
SlapLogout \
LoginTestVifibAdmin \
CheckGetComputerCertificateRaisesValueError \
Logout \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestVifibSlapComputer))
return suite
......@@ -672,6 +672,26 @@ class TestVifibSlapWebServiceMixin(testVifibMixin):
sequence['computer_title'] = str(random())
self.slap.requestComputer(sequence['computer_title'])
def stepSetComputerTitle(self, sequence, **kw):
sequence['computer_title'] = str(random())
def stepRequestComputer(self, sequence, **kw):
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url, timeout=None)
sequence['requested_computer'] = self.slap.requestComputer(
sequence['computer_title'])
def stepRevokeComputerCertificate(self, sequence, **kw):
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url, timeout=None)
self.slap.revokeComputerCertificate(sequence['computer_reference'])
def stepGetComputerCertificate(self, sequence, **kw):
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url, timeout=None)
sequence['requested_computer'] = self.slap.getComputerCertificate(
sequence['computer_reference'])
def stepSetComputerCoordinatesFromComputerTitle(self, sequence, **kw):
computer = self.portal.portal_catalog.getResultValue(
title=sequence['computer_title'], portal_type='Computer')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment