def test_regenerate_user_key(self):
    
    pubkey = "1 2"
    privkey = "3 4 5"
    donor_key = "6 7"
    
    # Create a user who will be doing the acquiring.
    user = maindb.create_user("testuser", "password", "*****@*****.**", "affiliation", 
                              pubkey, privkey, donor_key)
    userport = user.usable_vessel_port

    vesselcount = 4
    
    # Have every vessel acquisition to the backend request succeed.
    calls_results = [True] * vesselcount
    mocklib.mock_backend_acquire_vessel(calls_results)
    
    testutil.create_nodes_on_different_subnets(vesselcount, [userport])

    # Acquire all vessels on behalf of this user.
    all_vessels_list = interface.acquire_vessels(user, vesselcount, 'rand')

    # Release 2 vessels.
    released_vessels_list = all_vessels_list[:2]
    kept_vessels_list = all_vessels_list[2:]
    interface.release_vessels(user, released_vessels_list)
    
    # Ensure all of the vessels are marked as having user keys in sync.
    for vessel in all_vessels_list:
      # Get a fresh vessel from the db.
      vessel = maindb.get_vessel(vessel.node.node_identifier, vessel.name)
      self.assertTrue(vessel.user_keys_in_sync)

    # We expect a single key to be generated through the keygen api (the new
    # user public key).
    mocklib.mock_keygen_generate_keypair([("55 66", "77 88 99")])
    
    interface.change_user_keys(user, pubkey=None)
    
    # Get a new user object from the database.
    user = maindb.get_user(user.username)
    
    # Make sure the user's key changed.
    self.assertEqual(user.user_pubkey, "55 66")
    self.assertEqual(user.user_privkey, "77 88 99")
    
    # Make sure that all of the vessels the user has access to (and no other
    # vessels) are marked as needing user keys to be sync'd.
    # Ensure all of the vessels are marked as having user keys in sync.
    for vessel in kept_vessels_list:
      # Get a fresh vessel from the db.
      vessel = maindb.get_vessel(vessel.node.node_identifier, vessel.name)
      self.assertFalse(vessel.user_keys_in_sync)

    for vessel in released_vessels_list:
      # Get a fresh vessel from the db.
      vessel = maindb.get_vessel(vessel.node.node_identifier, vessel.name)
      self.assertTrue(vessel.user_keys_in_sync)
Пример #2
0
    def test_renew_vessels_dont_belong_to_user(self):

        # Create a user who will be doing the acquiring.
        user = maindb.create_user("testuser", "password",
                                  "*****@*****.**", "affiliation", "1 2",
                                  "2 2 2", "3 4")
        userport = user.usable_vessel_port

        # Create a second user.
        user2 = maindb.create_user("user2", "password", "*****@*****.**",
                                   "affiliation", "1 2", "2 2 2", "3 4")

        vesselcount = 4

        # Have every vessel acquisition to the backend request succeed.
        calls_results = [True] * vesselcount
        mocklib.mock_backend_acquire_vessel(calls_results)

        testutil.create_nodes_on_different_subnets(vesselcount, [userport])

        # Acquire all of the vessels the user can acquire.
        vessel_list = interface.acquire_vessels(user, vesselcount, 'rand')

        release_vessel = vessel_list[0]
        interface.release_vessels(user, [release_vessel])

        # Manually fiddle with one of the vessels to make it owned by user2.
        user2_vessel = vessel_list[1]
        user2_vessel.acquired_by_user = user2
        user2_vessel.save()

        # Try to renew all of the originally acquired vessels, including the ones
        # that were released. We expect these to just be ignored.
        interface.renew_vessels(user, vessel_list)

        # Get fresh vessel objects that reflect the renewal.
        remaining_vessels = interface.get_acquired_vessels(user)
        release_vessel = maindb.get_vessel(release_vessel.node.node_identifier,
                                           release_vessel.name)
        user2_vessel = maindb.get_vessel(user2_vessel.node.node_identifier,
                                         user2_vessel.name)

        now = datetime.datetime.now()
        timedelta_oneday = datetime.timedelta(days=1)

        # Ensure that the vessels the user still has were renewed but that the ones
        # the user released were ignored (not renewed).
        for vessel in remaining_vessels:
            self.assertTrue(vessel.date_expires - now > timedelta_oneday)

        self.assertTrue(user2_vessel.date_expires - now < timedelta_oneday)

        self.assertEqual(release_vessel.date_expires, None)
  def test_renew_vessels_dont_belong_to_user(self):
    
    # Create a user who will be doing the acquiring.
    user = maindb.create_user("testuser", "password", "*****@*****.**", "affiliation", "1 2", "2 2 2", "3 4")
    userport = user.usable_vessel_port
    
    # Create a second user.
    user2 = maindb.create_user("user2", "password", "*****@*****.**", "affiliation", "1 2", "2 2 2", "3 4")
    
    vesselcount = 4
    
    # Have every vessel acquisition to the backend request succeed.
    calls_results = [True] * vesselcount
    mocklib.mock_backend_acquire_vessel(calls_results)
    
    testutil.create_nodes_on_different_subnets(vesselcount, [userport])
    
    # Acquire all of the vessels the user can acquire.
    vessel_list = interface.acquire_vessels(user, vesselcount, 'rand')
    
    release_vessel = vessel_list[0]
    interface.release_vessels(user, [release_vessel])
    
    # Manually fiddle with one of the vessels to make it owned by user2.
    user2_vessel = vessel_list[1]
    user2_vessel.acquired_by_user = user2
    user2_vessel.save()
    
    # Try to renew all of the originally acquired vessels, including the ones
    # that were released. We expect these to just be ignored.
    interface.renew_vessels(user, vessel_list)
  
    # Get fresh vessel objects that reflect the renewal.
    remaining_vessels = interface.get_acquired_vessels(user)
    release_vessel = maindb.get_vessel(release_vessel.node.node_identifier, release_vessel.name)
    user2_vessel = maindb.get_vessel(user2_vessel.node.node_identifier, user2_vessel.name)
   
    now = datetime.datetime.now()
    timedelta_oneday = datetime.timedelta(days=1)
  
    # Ensure that the vessels the user still has were renewed but that the ones
    # the user released were ignored (not renewed).
    for vessel in remaining_vessels:
      self.assertTrue(vessel.date_expires - now > timedelta_oneday)

    self.assertTrue(user2_vessel.date_expires - now < timedelta_oneday)
    
    self.assertEqual(release_vessel.date_expires, None)
    def test_set_user_key(self):

        pubkey = "1 2"
        privkey = "3 4 5"
        donor_key = "6 7"

        # Create a user who will be doing the acquiring.
        user = maindb.create_user("testuser", "password",
                                  "*****@*****.**", "affiliation", pubkey,
                                  privkey, donor_key)
        userport = user.usable_vessel_port

        vesselcount = 4

        # Have every vessel acquisition to the backend request succeed.
        calls_results = [True] * vesselcount
        mocklib.mock_backend_acquire_vessel(calls_results)

        testutil.create_nodes_on_different_subnets(vesselcount, [userport])

        # Acquire all vessels on behalf of this user.
        all_vessels_list = interface.acquire_vessels(user, vesselcount, 'rand')

        # Release 2 vessels.
        released_vessels_list = all_vessels_list[:2]
        kept_vessels_list = all_vessels_list[2:]
        interface.release_vessels(user, released_vessels_list)

        # Ensure all of the vessels are marked as having user keys in sync.
        for vessel in all_vessels_list:
            # Get a fresh vessel from the db.
            vessel = maindb.get_vessel(vessel.node.node_identifier,
                                       vessel.name)
            self.assertTrue(vessel.user_keys_in_sync)

        # We expect no keys to be generated through the keygen api.
        mocklib.mock_keygen_generate_keypair([])

        interface.change_user_keys(user, pubkey="55 66")

        # Get a new user object from the database.
        user = maindb.get_user(user.username)

        # Make sure the user's key changed.
        self.assertEqual(user.user_pubkey, "55 66")
        self.assertEqual(user.user_privkey, None)

        # Make sure that all of the vessels the user has access to (and no other
        # vessels) are marked as needing user keys to be sync'd.
        # Ensure all of the vessels are marked as having user keys in sync.
        for vessel in kept_vessels_list:
            # Get a fresh vessel from the db.
            vessel = maindb.get_vessel(vessel.node.node_identifier,
                                       vessel.name)
            self.assertFalse(vessel.user_keys_in_sync)

        for vessel in released_vessels_list:
            # Get a fresh vessel from the db.
            vessel = maindb.get_vessel(vessel.node.node_identifier,
                                       vessel.name)
            self.assertTrue(vessel.user_keys_in_sync)
Пример #5
0
  # vessel_handle needs to be a list (even though we only add one handle), 
  # since get_vessel_list expects a list.
  vessel_handle = []
  vessel_handle.append(request.POST['handle'])
  remove_summary = ""
  
  try:
    # convert handle to vessel
    vessel_to_release = interface.get_vessel_list(vessel_handle)
  except DoesNotExistError:
    remove_summary = "Unable to remove vessel. The vessel you are trying to remove does not exist."
  except InvalidRequestError, err:
    remove_summary = "Unable to remove vessel. " + str(err)
  else:
    try:
      interface.release_vessels(user, vessel_to_release)
    except InvalidRequestError, err:
      remove_summary = "Unable to remove vessel. The vessel does not belong"
      remove_summary += " to you any more (maybe it expired?). " + str(err)
  
  return myvessels(request, remove_summary=remove_summary)






@login_required
def del_all_resources(request):
  try:
    user = _validate_and_get_geniuser(request)
Пример #6
0
  # vessel_handle needs to be a list (even though we only add one handle), 
  # since get_vessel_list expects a list.
  vessel_handle = []
  vessel_handle.append(request.POST['handle'])
  remove_summary = ""
  
  try:
    # convert handle to vessel
    vessel_to_release = interface.get_vessel_list(vessel_handle)
  except DoesNotExistError:
    remove_summary = "Unable to remove vessel. The vessel you are trying to remove does not exist."
  except InvalidRequestError, err:
    remove_summary = "Unable to remove vessel. " + str(err)
  else:
    try:
      interface.release_vessels(user, vessel_to_release)
    except InvalidRequestError, err:
      remove_summary = "Unable to remove vessel. The vessel does not belong"
      remove_summary += " to you any more (maybe it expired?). " + str(err)
  
  return myvessels(request, remove_summary=remove_summary)






@login_required
def del_all_resources(request):
  try:
    user = _validate_and_get_geniuser(request)
Пример #7
0
    if not isinstance(vesselhandle_list, list):
      raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, "Invalid data type for handle list.")
    
    # since we're given a list of vessel 'handles', we need to convert them to a 
    # list of actual Vessel objects; as release_vessels_of_user expects Vessel objs.
    try:
      list_of_vessel_objs = interface.get_vessel_list(vesselhandle_list)
    except DoesNotExistError, err:
      # given handle refers to a non-existant vessel
      raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))
    except InvalidRequestError, err:
      # A handle is of an invalid format or the list of vessels is empty.
      raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))
    
    try:
      interface.release_vessels(geni_user, list_of_vessel_objs)
    except InvalidRequestError, err:
      # vessel exists but isn't valid for you to use.
      raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))
    
    return 0



  @staticmethod
  @log_function_call
  def renew_resources(auth, vesselhandle_list):
    """
    <Purpose>
      Renew resources for a user over XMLRPC. Renewal changes the expiration
      time to the maximum allowed.
Пример #8
0
            raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST,
                                  "Invalid data type for handle list.")

        # since we're given a list of vessel 'handles', we need to convert them to a
        # list of actual Vessel objects; as release_vessels_of_user expects Vessel objs.
        try:
            list_of_vessel_objs = interface.get_vessel_list(vesselhandle_list)
        except DoesNotExistError, err:
            # given handle refers to a non-existant vessel
            raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))
        except InvalidRequestError, err:
            # A handle is of an invalid format or the list of vessels is empty.
            raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))

        try:
            interface.release_vessels(geni_user, list_of_vessel_objs)
        except InvalidRequestError, err:
            # vessel exists but isn't valid for you to use.
            raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, str(err))

        return 0

    @staticmethod
    @log_function_call
    def renew_resources(auth, vesselhandle_list):
        """
    <Purpose>
      Renew resources for a user over XMLRPC. Renewal changes the expiration
      time to the maximum allowed.
    <Arguments>
      auth