Commit cf57decd authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Person dont directly revoke

   revoke occur directly on the Certificate Login
parent f5dd3045
......@@ -3,12 +3,6 @@ import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
# Revoke user certificate
try:
person.revokeCertificate()
except ValueError:
pass
web_site = context.getWebSiteValue()
request_url = "%s/%s" % (
web_site.getLayoutProperty(
......
......@@ -11,7 +11,7 @@ if person is None:
return {}
try:
return json.dumps(person.getCertificate())
return json.dumps(person.generateCertificate())
# Certificate is Created
except ValueError:
# Certificate was already requested, please revoke existing one.
......
""" This script is required due the ValueError, should be more HTTP friendly.
"""
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
request = context.REQUEST
response = request.RESPONSE
import json
if person is None:
response.setStatus(403)
else:
try:
person.revokeCertificate()
return json.dumps(True)
except ValueError:
return json.dumps(False)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_revokeCertificate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -727,7 +727,7 @@ class TestPerson_newLogin(TestSlapOSHalJsonStyleMixin):
self.assertEqual(self.portal.REQUEST.RESPONSE.getStatus(), 200)
self.assertIn(person.getRelativeUrl(), result)
class TestPerson_get_revoke_Certificate(TestSlapOSHalJsonStyleMixin):
class TestPerson_get_Certificate(TestSlapOSHalJsonStyleMixin):
def test_Person_getCertificate_unauthorized(self):
person = self._makePerson(user=1)
self.assertEqual(1 , len(person.objectValues( portal_type="ERP5 Login")))
......@@ -735,38 +735,43 @@ class TestPerson_get_revoke_Certificate(TestSlapOSHalJsonStyleMixin):
self.assertEqual(person.Person_getCertificate(), {})
self.assertEqual(self.portal.REQUEST.RESPONSE.getStatus(), 403)
def test_Person_revokeCertificate_unauthorized(self):
def test_Person_get_Certificate(self):
person = self._makePerson(user=1)
self.assertEqual(1 , len(person.objectValues( portal_type="ERP5 Login")))
self.assertEqual(person.Person_revokeCertificate(), None)
self.assertEqual(self.portal.REQUEST.RESPONSE.getStatus(), 403)
def test_Person_get_revoke_Certificate(self):
person = self._makePerson(user=1)
self.assertEqual(1 , len(person.objectValues( portal_type="ERP5 Login")))
self.assertEqual(1 , len(person.objectValues(portal_type="ERP5 Login")))
self.login(person.getUserId())
response_dict = json.loads(person.Person_getCertificate())
self.assertEqual(1 , len(person.objectValues(portal_type="Certificate Login")))
login = person.objectValues(portal_type="Certificate Login")[0]
self.assertEqual("validated" , login.getValidationState())
self.assertSameSet(response_dict.keys(), ["common_name", "certificate", "id", "key"])
self.assertEqual(response_dict["common_name"], person.getUserId())
self.assertEqual(response_dict["id"], login.getDestinationReference())
self.assertEqual(response_dict["common_name"], login.getReference())
self.assertEqual(self.portal.REQUEST.RESPONSE.getStatus(), 200)
response_false = json.loads(person.Person_getCertificate())
self.assertFalse(response_false)
new_response_dict = json.loads(person.Person_getCertificate())
self.assertTrue(new_response_dict)
response_true = json.loads(person.Person_revokeCertificate())
self.assertTrue(response_true)
self.assertEqual(2 , len(person.objectValues(portal_type="Certificate Login")))
new_login = [i for i in person.objectValues(portal_type="Certificate Login")
if i.getUid() != login.getUid()][0]
response_false = json.loads(person.Person_revokeCertificate())
self.assertFalse(response_false)
self.assertEqual("validated" , login.getValidationState())
self.assertEqual("validated" , new_login.getValidationState())
self.assertNotEqual(login.getReference(), new_login.getReference())
self.assertNotEqual(login.getDestinationReference(), new_login.getDestinationReference())
response_dict = json.loads(person.Person_getCertificate())
self.assertSameSet(new_response_dict.keys(), ["common_name", "certificate", "id", "key"])
self.assertEqual(new_response_dict["common_name"], new_login.getReference())
self.assertEqual(new_response_dict["id"], new_login.getDestinationReference())
self.assertNotEqual(new_response_dict["common_name"], response_dict["common_name"])
self.assertNotEqual(new_response_dict["id"], response_dict["id"])
self.assertNotEqual(new_response_dict["key"], response_dict["key"])
self.assertNotEqual(new_response_dict["certificate"], response_dict["certificate"])
self.assertSameSet(response_dict.keys(), ["common_name", "certificate", "id", "key"])
self.assertEqual(response_dict["common_name"], person.getUserId())
self.assertEqual(self.portal.REQUEST.RESPONSE.getStatus(), 200)
class TestPerson_testLoginExistence(TestSlapOSHalJsonStyleMixin):
......
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