Commit d2375d50 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud&slap_tool: Get user from its Certificate Login

  Now we dont rely on the document reference anymore.
  Invoke generateCertificate on tests else the user isnt valid.
  Note:  Login name returns the Certificate Login reference, to keep
    backward compatibility with the API (and current usage) it user
    the actual user reference, so it is easier to identify which document
    set the access status.
parent dcb154ea
...@@ -109,8 +109,8 @@ class SlapOSCacheMixin: ...@@ -109,8 +109,8 @@ class SlapOSCacheMixin:
return self._setAccessStatus("%s %s" % (BUILDING, text), state, reindex) return self._setAccessStatus("%s %s" % (BUILDING, text), state, reindex)
def _setAccessStatus(self, text, state="", reindex=0): def _setAccessStatus(self, text, state="", reindex=0):
user_reference = self.getPortalObject().portal_membership.getAuthenticatedMember()\ user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName() .getUserValue()
previous = self._getCachedAccessInfo() previous = self._getCachedAccessInfo()
created_at = rfc1123_date(DateTime()) created_at = rfc1123_date(DateTime())
...@@ -125,6 +125,11 @@ class SlapOSCacheMixin: ...@@ -125,6 +125,11 @@ class SlapOSCacheMixin:
if state == "": if state == "":
state = previous_json.get("state", "") state = previous_json.get("state", "")
if user is not None:
user_reference = user.getReference()
else:
user_reference = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
value = json.dumps({ value = json.dumps({
'user': '%s' % user_reference, 'user': '%s' % user_reference,
'created_at': '%s' % created_at, 'created_at': '%s' % created_at,
......
...@@ -157,8 +157,14 @@ class SlapOSComputeNodeMixin(object): ...@@ -157,8 +157,14 @@ class SlapOSComputeNodeMixin(object):
def _getComputeNodeInformation(self, user, refresh_etag): def _getComputeNodeInformation(self, user, refresh_etag):
portal = self.getPortalObject() portal = self.getPortalObject()
user_document = _assertACI(portal.portal_catalog.unrestrictedGetResultValue( login = portal.portal_catalog.unrestrictedGetResultValue(
reference=user, portal_type=['Person', 'Compute Node', 'Software Instance'])) reference=user, portal_type="Certificate Login",
parent_portal_type=['Person', 'Compute Node', 'Software Instance'])
if not login:
raise Unauthorized('User %s not found!' % user)
user_document = _assertACI(login.getParentValue())
user_type = user_document.getPortalType() user_type = user_document.getPortalType()
if user_type in ('Compute Node', 'Person'): if user_type in ('Compute Node', 'Person'):
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
############################################################################## ##############################################################################
from erp5.component.test.SlapOSTestCaseDefaultScenarioMixin import DefaultScenarioMixin from erp5.component.test.SlapOSTestCaseDefaultScenarioMixin import DefaultScenarioMixin
from DateTime import DateTime from DateTime import DateTime
import re import re
...@@ -48,6 +49,7 @@ class TestSlapOSDefaultScenario(DefaultScenarioMixin): ...@@ -48,6 +49,7 @@ class TestSlapOSDefaultScenario(DefaultScenarioMixin):
self.setAccessToMemcached(public_server) self.setAccessToMemcached(public_server)
self.assertNotEqual(None, public_server) self.assertNotEqual(None, public_server)
self.setServerOpenPublic(public_server) self.setServerOpenPublic(public_server)
public_server.generateCertificate()
personal_server_title = 'Personal Server for %s' % owner_reference personal_server_title = 'Personal Server for %s' % owner_reference
personal_server_id = self.requestComputeNode(personal_server_title) personal_server_id = self.requestComputeNode(personal_server_title)
...@@ -56,6 +58,7 @@ class TestSlapOSDefaultScenario(DefaultScenarioMixin): ...@@ -56,6 +58,7 @@ class TestSlapOSDefaultScenario(DefaultScenarioMixin):
self.setAccessToMemcached(personal_server) self.setAccessToMemcached(personal_server)
self.assertNotEqual(None, personal_server) self.assertNotEqual(None, personal_server)
self.setServerOpenPersonal(personal_server) self.setServerOpenPersonal(personal_server)
personal_server.generateCertificate()
# and install some software on them # and install some software on them
public_server_software = self.generateNewSoftwareReleaseUrl() public_server_software = self.generateNewSoftwareReleaseUrl()
......
...@@ -173,9 +173,9 @@ class SlapTool(BaseTool): ...@@ -173,9 +173,9 @@ class SlapTool(BaseTool):
Reuses slap library for easy marshalling. Reuses slap library for easy marshalling.
""" """
portal = self.getPortalObject() portal = self.getPortalObject()
user = portal.portal_membership.getAuthenticatedMember().getUserName() user_value = portal.portal_membership.getAuthenticatedMember().getUserValue()
if str(user) == computer_id: if user_value is not None and user_value.getReference() == computer_id:
compute_node = portal.portal_membership.getAuthenticatedMember().getUserValue() compute_node = user_value
compute_node.setAccessStatus(computer_id) compute_node.setAccessStatus(computer_id)
else: else:
# Don't use getDocument because we don't want use _assertACI here, but # Don't use getDocument because we don't want use _assertACI here, but
...@@ -186,11 +186,18 @@ class SlapTool(BaseTool): ...@@ -186,11 +186,18 @@ class SlapTool(BaseTool):
refresh_etag = compute_node._calculateRefreshEtag() refresh_etag = compute_node._calculateRefreshEtag()
user = portal.portal_membership.getAuthenticatedMember().getUserName()
# Keep compatibility with older clients that relies on marshalling. # Keep compatibility with older clients that relies on marshalling.
# This code is an adaptation of SlapOSComputeNodeMixin._getComputeNodeInformation # This code is an adaptation of SlapOSComputeNodeMixin._getComputeNodeInformation
# To comply with cache capability. # To comply with cache capability.
user_document = _assertACI(portal.portal_catalog.unrestrictedGetResultValue( login = portal.portal_catalog.unrestrictedGetResultValue(
reference=user, portal_type=['Person', 'Compute Node', 'Software Instance'])) reference=user, portal_type="Certificate Login",
parent_portal_type=['Person', 'Compute Node', 'Software Instance'])
if not login:
raise Unauthorized('User %s not found!' % user)
user_document = _assertACI(login.getParentValue())
user_type = user_document.getPortalType() user_type = user_document.getPortalType()
if user_type in ('Compute Node', 'Person'): if user_type in ('Compute Node', 'Person'):
if not compute_node._isTestRun(): if not compute_node._isTestRun():
......
...@@ -1186,6 +1186,9 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans ...@@ -1186,6 +1186,9 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
# format the compute_nodes # format the compute_nodes
self.formatComputeNode(subscription_server) self.formatComputeNode(subscription_server)
# Without certificate computer isnt a user yet.
subscription_server.generateCertificate()
self.tic() self.tic()
self.logout() self.logout()
return subscription_server return subscription_server
......
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