Commit 46bfbe41 authored by Gabriel Monnerat's avatar Gabriel Monnerat

reorganize steps, rename tests to Slave Instance to follow one pattern in...

reorganize steps, rename tests to Slave Instance to follow one pattern in names and implemented tests to check that the customer B can not access a Slave Instance created by customer A
parent bb546aab
...@@ -28,10 +28,13 @@ ...@@ -28,10 +28,13 @@
# #
############################################################################## ##############################################################################
from DateTime import DateTime from DateTime import DateTime
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.Errors import UnsupportedWorkflowMethod from Products.ERP5Type.Errors import UnsupportedWorkflowMethod
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.backportUnittest import expectedFailure from Products.ERP5Type.tests.backportUnittest import expectedFailure
from Products.ERP5Type.tests.backportUnittest import skip from Products.ERP5Type.tests.backportUnittest import skip
from Products.ERP5Type.tests.SecurityTestCase import AssertNoPermissionMethod
from Products.ERP5Type import Permissions
from VifibMixin import testVifibMixin from VifibMixin import testVifibMixin
from random import random from random import random
from slapos import slap from slapos import slap
...@@ -101,6 +104,9 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -101,6 +104,9 @@ class TestVifibSlapWebService(testVifibMixin):
minimal_correct_xml = '<?xml version="1.0" encoding="utf-8"?><instance/>' minimal_correct_xml = '<?xml version="1.0" encoding="utf-8"?><instance/>'
computer_partition_amount = 1 computer_partition_amount = 1
failIfUserCanViewDocument = AssertNoPermissionMethod(Permissions.View)
failIfUserCanAccessDocument = AssertNoPermissionMethod(
Permissions.AccessContentsInformation)
def afterSetUp(self): def afterSetUp(self):
fakeSlapAuth() fakeSlapAuth()
...@@ -111,6 +117,13 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -111,6 +117,13 @@ class TestVifibSlapWebService(testVifibMixin):
unfakeSlapAuth() unfakeSlapAuth()
super(testVifibMixin, self).beforeTearDown() super(testVifibMixin, self).beforeTearDown()
def _loginAsUser(self, username):
"""Login as a given username. The user must exist."""
uf = self.getPortal().acl_users
user = uf.getUserById(username)
self.assertNotEquals(user, None, 'No user %s' % username)
newSecurityManager(None, user.__of__(uf))
######################################## ########################################
# Assertions # Assertions
######################################## ########################################
...@@ -371,11 +384,11 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -371,11 +384,11 @@ class TestVifibSlapWebService(testVifibMixin):
self.assertEqual(1, len(software_instance_list)) self.assertEqual(1, len(software_instance_list))
software_instance = software_instance_list[0] software_instance = software_instance_list[0]
sequence.edit( sequence.edit(
software_instance_uid=software_instance.getUid(), software_instance_uid=software_instance.getUid(),
software_instance_reference=software_instance.getReference(), software_instance_reference=software_instance.getReference(),
hosting_subscription_uid=software_instance.getAggregateRelatedValue( hosting_subscription_uid=software_instance.getAggregateRelatedValue(
portal_type='Sale Order Line').getAggregateValue( portal_type='Sale Order Line').getAggregateValue(
portal_type='Hosting Subscription').getUid()) portal_type='Hosting Subscription').getUid())
def stepSetSelectedComputerPartition(self, sequence, **kw): def stepSetSelectedComputerPartition(self, sequence, **kw):
"""Sets in sequence computer partition parameters related to current software instance""" """Sets in sequence computer partition parameters related to current software instance"""
...@@ -4461,55 +4474,6 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4461,55 +4474,6 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def stepCheckEmptySlaveInstanceListFromOneComputerPartition(self, sequence):
computer_guid = sequence["computer_reference"]
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
computer = self.slap.registerComputer(computer_guid)
computer_partition = computer.getComputerPartitionList()[0]
self.assertEquals([],
computer_partition.getInstanceParameterDict()["slave_instance_list"])
def stepCheckSlaveInstanceListFromOneComputerPartition(self, sequence):
computer_guid = sequence["computer_reference"]
partition_id = sequence["computer_partition_reference"]
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(computer_guid,
partition_id)
parameter_dict = computer_partition.getInstanceParameterDict()
self.assertEquals("RootSoftwareInstance",
parameter_dict["slap_software_type"])
slave_instance_list = parameter_dict["slave_instance_list"]
self.assertEquals(1, len(slave_instance_list))
slave_instance = slave_instance_list[0]
self.assertEquals("SlaveInstance", slave_instance["slap_software_type"])
def test_ComputerPartition_SlaveInstance_ParameterList(self):
"""
Check that Computer Partition of user A is reinstanciated with new
parameters provided by user B. User B and Aget the right connection
parameter
"""
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """
SlapLoginCurrentComputer
CheckEmptySlaveInstanceListFromOneComputerPartition
Tic
SlapLogout
Tic
LoginAsCustomerA
PersonRequestSlaveInstance
SlapLogout
LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense
Tic
SlapLoginCurrentComputer
CheckSlaveInstanceListFromOneComputerPartition
SlapLogout
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
######################################### #########################################
# SlaveInstance.request # SlaveInstance.request
...@@ -4520,7 +4484,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4520,7 +4484,7 @@ class TestVifibSlapWebService(testVifibMixin):
REMOTE_USER = "test_vifib_customer_a" REMOTE_USER = "test_vifib_customer_a"
self.login("test_vifib_customer_a") self.login("test_vifib_customer_a")
def test_Person_request_SlaveInstance_with_Different_User(self): def test_Slaveinstance_Person_request_with_Different_User(self):
""" """
Check that user B can declare a slot of slave instance in computer Check that user B can declare a slot of slave instance in computer
partition used by user A partition used by user A
...@@ -4545,7 +4509,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4545,7 +4509,7 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_Person_request_SlaveInstance(self): def test_SlaveInstance_Person_request_SlaveInstance(self):
""" """
Check that one Slave Instance is created correctly Check that one Slave Instance is created correctly
""" """
...@@ -4571,7 +4535,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4571,7 +4535,7 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_Person_request_SlaveInstance_without_SoftwareInstance(self): def test_SlaveInstance_Person_request_without_SoftwareInstance(self):
""" """
Check that one Slave Instance will wait allocation correctly when no Check that one Slave Instance will wait allocation correctly when no
exists Software Instance installed exists Software Instance installed
...@@ -4591,7 +4555,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4591,7 +4555,7 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_Person_request_SlaveInstance_Two_Different_SoftwareInstance(self): def test_SlaveInstance_Person_request_with_Two_Different_SoftwareInstance(self):
""" """
Check that one Slave Instance is allocated correctly when exists two different Check that one Slave Instance is allocated correctly when exists two different
Software Instances and Computer Partition. The slave instance must be Software Instances and Computer Partition. The slave instance must be
...@@ -4616,7 +4580,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4616,7 +4580,7 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_Person_request_SlaveInstance_twice(self): def test_SlaveInstance_Person_request_twice(self):
""" """
Check that request a Slave Instance twice, the instances are created Check that request a Slave Instance twice, the instances are created
correctly correctly
...@@ -4624,21 +4588,21 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4624,21 +4588,21 @@ class TestVifibSlapWebService(testVifibMixin):
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """ sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """
Tic Tic
LoginAsCustomerA
PersonRequestSlaveInstance PersonRequestSlaveInstance
Tic Tic
Logout SlapLogout
LoginTestVifibCustomer LoginTestVifibCustomer
PersonRequestSlaveInstance PersonRequestSlaveInstance
Tic Tic
Logout SlapLogout
LoginDefaultUser LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense ConfirmOrderedSaleOrderActiveSense
Tic Tic
CheckTwoSlaveInstanceRequest CheckTwoSlaveInstanceRequest
Logout SlapLogout
""" """
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
...@@ -4650,10 +4614,89 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -4650,10 +4614,89 @@ class TestVifibSlapWebService(testVifibMixin):
available slot available slot
""" """
@skip("Not Implemented yet") @skip("Not Finished yet")
def test_ComputerPartition_getInstanceParameterDict_withSlaveInstance(self): def test_request_destroy_SlaveInstance(self):
"""
Check that the Slave Instance will be destroyed correctly
"""
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """
LoginTestVifibCustomer
PersonRequestSlaveInstance
SlapLogout
LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense
Tic
LoginTestVifibCustomer
RequestSoftwareInstanceDestroy
Tic
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckSlaveInstanceSecurityWithDifferentCustomer(self, sequence):
software_instance_uid = sequence["software_instance_uid"]
username = str(self.portal.portal_membership.getAuthenticatedMember())
self.login()
software_instance = self.portal.portal_catalog.getResultValue(
uid=software_instance_uid)
self.failIfUserCanViewDocument(username, software_instance)
self.login(username)
def test_SlaveInstance_Customer_Permission(self):
"""
Check that one Customer A can not view the Slave Instance of a Customer B
""" """
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """
LoginTestVifibCustomer
PersonRequestSlaveInstance
Tic
SlapLogout
LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense
Tic
SlapLogout
LoginAsCustomerA
CheckSlaveInstanceSecurityWithDifferentCustomer
PersonRequestSlaveInstance
Tic
SlapLogout
LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense
SlapLogout
LoginTestVifibCustomer
CheckSlaveInstanceSecurityWithDifferentCustomer
SlapLogout
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_SlaveInstance_Information_in_getInstanceParameterDict(self):
"""
Check that Computer Partition of user A is reinstanciated with new
parameters provided by user B. User B and Aget the right connection
parameter
"""
sequence_list = SequenceList()
sequence_string = self.prepare_install_requested_computer_partition_sequence_string + """
SlapLoginCurrentComputer
CheckEmptySlaveInstanceListFromOneComputerPartition
Tic
SlapLogout
Tic
LoginAsCustomerA
PersonRequestSlaveInstance
SlapLogout
LoginDefaultUser
ConfirmOrderedSaleOrderActiveSense
Tic
SlapLoginCurrentComputer
CheckSlaveInstanceListFromOneComputerPartition
SlapLogout
""" """
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
######################################## ########################################
# ComputerPartition.request - shared # ComputerPartition.request - shared
...@@ -5690,6 +5733,30 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -5690,6 +5733,30 @@ class TestVifibSlapWebService(testVifibMixin):
portal_type=self.sale_packing_list_line_portal_type) portal_type=self.sale_packing_list_line_portal_type)
self.assertEquals(sale_packing_list_line, None) self.assertEquals(sale_packing_list_line, None)
def stepCheckEmptySlaveInstanceListFromOneComputerPartition(self, sequence):
computer_guid = sequence["computer_reference"]
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
computer = self.slap.registerComputer(computer_guid)
computer_partition = computer.getComputerPartitionList()[0]
self.assertEquals([],
computer_partition.getInstanceParameterDict()["slave_instance_list"])
def stepCheckSlaveInstanceListFromOneComputerPartition(self, sequence):
computer_guid = sequence["computer_reference"]
partition_id = sequence["computer_partition_reference"]
self.slap = slap.slap()
self.slap.initializeConnection(self.server_url)
computer_partition = self.slap.registerComputerPartition(computer_guid,
partition_id)
parameter_dict = computer_partition.getInstanceParameterDict()
self.assertEquals("RootSoftwareInstance",
parameter_dict["slap_software_type"])
slave_instance_list = parameter_dict["slave_instance_list"]
self.assertEquals(1, len(slave_instance_list))
slave_instance = slave_instance_list[0]
self.assertEquals("SlaveInstance", slave_instance["slap_software_type"])
prepare_two_purchase_packing_list = \ prepare_two_purchase_packing_list = \
prepare_software_release_purchase_packing_list + '\ prepare_software_release_purchase_packing_list + '\
LoginDefaultUser \ LoginDefaultUser \
......
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