Пример #1
0
  def setUp(self):
    # Need to initialize the JeevesLib environment.
    JeevesLib.init()

    # Define some locations.
    self.countryUSA = Country("USA")
    self.cityCambridge = City("Cambridge", self.countryUSA)
    self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge) 

    # Define some users with their locations.
    # Alice's location is restricted to Alice and her friends.
    aliceLabel = JeevesLib.mkLabel()
    JeevesLib.restrict(aliceLabel
      , lambda oc: owner == oc or owner.isFriends(oc))
    self.alice = User(0
      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
    
    # Bob's location has no policies.
    self.bob = User(1, self.cityCambridge)

    
    self.carol = User(2, self.countryUSA)

    self.alice.addFriend(self.bob)
    self.bob.addFriend(self.alice)
Пример #2
0
    def setUp(self):
        def canSee(owner, ctxt):
            return owner == ctxt or owner.isFriends(ctxt)

        # Need to initialize the JeevesLib environment.
        JeevesLib.init()

        # Define some locations.
        self.countryUSA = Country("USA")
        self.cityCambridge = City("Cambridge", self.countryUSA)
        self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge)

        # Define some users.
        self.alice = User(0)
        #      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
        self.bob = User(1)  #, self.cityCambridge)
        self.carol = User(2)  #, self.countryUSA)

        self.alice.addFriend(self.bob)
        self.bob.addFriend(self.alice)

        aliceLabel = JeevesLib.mkLabel()
        JeevesLib.restrict(
            aliceLabel,
            lambda oc: oc == self.alice or self.alice.isFriends(oc))
        self.aliceLoc = JeevesLib.mkSensitive(aliceLabel, self.gpsMIT,
                                              self.cityCambridge)
Пример #3
0
  def setUp(self):
    def canSee(owner, ctxt):
      return owner == ctxt or owner.isFriends(ctxt)

    # Need to initialize the JeevesLib environment.
    JeevesLib.init()

    # Define some locations.
    self.countryUSA = Country("USA")
    self.cityCambridge = City("Cambridge", self.countryUSA)
    self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge) 

    # Define some users.
    self.alice = User(0)
#      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
    self.bob = User(1) #, self.cityCambridge)
    self.carol = User(2) #, self.countryUSA)

    self.alice.addFriend(self.bob)
    self.bob.addFriend(self.alice)

    aliceLabel = JeevesLib.mkLabel()
    JeevesLib.restrict(aliceLabel, lambda oc: oc == self.alice or self.alice.isFriends(oc))
    self.aliceLoc = JeevesLib.mkSensitive(aliceLabel, self.gpsMIT
                      , self.cityCambridge)
Пример #4
0
    def setUp(self):
        # Need to initialize the JeevesLib environment.
        JeevesLib.init()

        # Define some locations.
        self.countryUSA = Country("USA")
        self.cityCambridge = City("Cambridge", self.countryUSA)
        self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge)

        # Define some users with their locations.
        # Alice's location is restricted to Alice and her friends.
        aliceLabel = JeevesLib.mkLabel()
        JeevesLib.restrict(aliceLabel,
                           lambda oc: owner == oc or owner.isFriends(oc))
        self.alice = User(
            0,
            JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))

        # Bob's location has no policies.
        self.bob = User(1, self.cityCambridge)

        self.carol = User(2, self.countryUSA)

        self.alice.addFriend(self.bob)
        self.bob.addFriend(self.alice)
Пример #5
0
class TestLocationFlow(unittest.TestCase):
    def setUp(self):
        def canSee(owner, ctxt):
            return owner == ctxt or owner.isFriends(ctxt)

        # Need to initialize the JeevesLib environment.
        JeevesLib.init()

        # Define some locations.
        self.countryUSA = Country("USA")
        self.cityCambridge = City("Cambridge", self.countryUSA)
        self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge)

        # Define some users.
        self.alice = User(0)
        #      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
        self.bob = User(1)  #, self.cityCambridge)
        self.carol = User(2)  #, self.countryUSA)

        self.alice.addFriend(self.bob)
        self.bob.addFriend(self.alice)

        aliceLabel = JeevesLib.mkLabel()
        JeevesLib.restrict(
            aliceLabel,
            lambda oc: oc == self.alice or self.alice.isFriends(oc))
        self.aliceLoc = JeevesLib.mkSensitive(aliceLabel, self.gpsMIT,
                                              self.cityCambridge)

    @jeeves
    def testUpdates(self):
        # Bob cannot update Alice's location.
        self.assertEqual(
            self.alice.location.update(self.bob, self.bob, self.aliceLoc),
            UpdateResult.Unknown)

        # Alice updates her location.
        self.assertEqual(
            self.alice.location.update(self.alice, self.alice, self.aliceLoc),
            UpdateResult.Unknown)
        # Only Alice and her friends can see the high-confidentiality version of
        # her location.
        self.assertEqual(
            JeevesLib.concretize(self.alice, self.alice.location.v),
            self.gpsMIT)
        self.assertEqual(JeevesLib.concretize(self.bob, self.alice.location.v),
                         self.gpsMIT)
        # TODO: This doesn't work yet because we don't have a rank-ordering of
        # labels associated with write policies so that we can prioritize assigning
        # certain labels to high over others.
        self.assertEqual(
            JeevesLib.concretize(self.carol, self.alice.location.v),
            self.cityCambridge)

    def testCountUsersInLocation(self):
        self.assertEqual(
            self.alice.location.update(self.alice, self.alice, self.aliceLoc),
            UpdateResult.Unknown)
        self.assertEqual(
            self.bob.location.update(self.bob, self.bob, self.cityCambridge),
            UpdateResult.Unknown)
        self.assertEqual(
            self.carol.location.update(self.carol, self.carol,
                                       self.countryUSA), UpdateResult.Unknown)

        # Only Alice and Bob can see Alice's "high" location of S
        locNetwork = LocationNetwork([self.alice, self.bob, self.carol])
        usersInStata = locNetwork.countUsersInLocation(self.gpsMIT)
        self.assertEqual(JeevesLib.concretize(self.alice, usersInStata), 1)
        self.assertEqual(JeevesLib.concretize(self.bob, usersInStata), 1)
        self.assertEqual(JeevesLib.concretize(self.carol, usersInStata), 0)
Пример #6
0
class TestLocation(unittest.TestCase):
  def setUp(self):
    # Need to initialize the JeevesLib environment.
    JeevesLib.init()

    # Define some locations.
    self.countryUSA = Country("USA")
    self.cityCambridge = City("Cambridge", self.countryUSA)
    self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge) 

    # Define some users with their locations.
    # Alice's location is restricted to Alice and her friends.
    aliceLabel = JeevesLib.mkLabel()
    JeevesLib.restrict(aliceLabel
      , lambda oc: owner == oc or owner.isFriends(oc))
    self.alice = User(0
      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
    
    # Bob's location has no policies.
    self.bob = User(1, self.cityCambridge)

    
    self.carol = User(2, self.countryUSA)

    self.alice.addFriend(self.bob)
    self.bob.addFriend(self.alice)

  # This makes sure the isIn function works properly.
  def testIsin(self):
    self.assertTrue(self.cityCambridge.isIn(self.cityCambridge))
    self.assertTrue(self.cityCambridge.isIn(self.countryUSA))
    self.assertTrue(self.gpsMIT.isIn(self.gpsMIT))
    self.assertTrue(self.gpsMIT.isIn(self.countryUSA))
    self.assertFalse(self.cityCambridge.isIn(self.gpsMIT))
    self.assertFalse(self.countryUSA.isIn(self.gpsMIT))
    self.assertFalse(self.countryUSA.isIn(self.cityCambridge))

  # This makes sure the isFriends function works properly.
  def testIsFriends(self):
    self.assertTrue(
      JeevesLib.concretize(self.alice, self.alice.isFriends(self.bob)))
    self.assertTrue(
      JeevesLib.concretize(self.alice, self.bob.isFriends(self.alice)))
    self.assertFalse(
      JeevesLib.concretize(self.alice, self.alice.isFriends(self.carol)))
    self.assertFalse(
      JeevesLib.concretize(self.alice, self.carol.isFriends(self.alice)))

  # This makes sure locations can only be viewed if they are supposed to be
  # viewed.
  def testViewLocation(self):
    # Alice and Bob can see the high-confidentiality version of Alice's
    # location, but Carol cannot.
    self.assertEqual(JeevesLib.concretize(self.alice, self.alice.location)
      , self.gpsMIT)
    self.assertEqual(JeevesLib.concretize(self.bob, self.alice.location)
      , self.gpsMIT)
    self.assertEqual(JeevesLib.concretize(self.carol, self.alice.location)
      , self.cityCambridge)

  def testCountUsersInLocation(self):
    # Only Alice and Bob can see Alice's "high" location of S
    locNetwork = LocationNetwork([self.alice, self.bob, self.carol])
    usersInStata = locNetwork.countUsersInLocation(self.gpsMIT)
    self.assertEqual(JeevesLib.concretize(self.alice, usersInStata), 1)
    self.assertEqual(JeevesLib.concretize(self.bob, usersInStata), 1)
    self.assertEqual(JeevesLib.concretize(self.carol, usersInStata), 0)
Пример #7
0
class TestLocation(unittest.TestCase):
    def setUp(self):
        # Need to initialize the JeevesLib environment.
        JeevesLib.init()

        # Define some locations.
        self.countryUSA = Country("USA")
        self.cityCambridge = City("Cambridge", self.countryUSA)
        self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge)

        # Define some users with their locations.
        # Alice's location is restricted to Alice and her friends.
        aliceLabel = JeevesLib.mkLabel()
        JeevesLib.restrict(aliceLabel,
                           lambda oc: owner == oc or owner.isFriends(oc))
        self.alice = User(
            0,
            JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))

        # Bob's location has no policies.
        self.bob = User(1, self.cityCambridge)

        self.carol = User(2, self.countryUSA)

        self.alice.addFriend(self.bob)
        self.bob.addFriend(self.alice)

    # This makes sure the isIn function works properly.
    def testIsin(self):
        self.assertTrue(self.cityCambridge.isIn(self.cityCambridge))
        self.assertTrue(self.cityCambridge.isIn(self.countryUSA))
        self.assertTrue(self.gpsMIT.isIn(self.gpsMIT))
        self.assertTrue(self.gpsMIT.isIn(self.countryUSA))
        self.assertFalse(self.cityCambridge.isIn(self.gpsMIT))
        self.assertFalse(self.countryUSA.isIn(self.gpsMIT))
        self.assertFalse(self.countryUSA.isIn(self.cityCambridge))

    # This makes sure the isFriends function works properly.
    def testIsFriends(self):
        self.assertTrue(
            JeevesLib.concretize(self.alice, self.alice.isFriends(self.bob)))
        self.assertTrue(
            JeevesLib.concretize(self.alice, self.bob.isFriends(self.alice)))
        self.assertFalse(
            JeevesLib.concretize(self.alice, self.alice.isFriends(self.carol)))
        self.assertFalse(
            JeevesLib.concretize(self.alice, self.carol.isFriends(self.alice)))

    # This makes sure locations can only be viewed if they are supposed to be
    # viewed.
    def testViewLocation(self):
        # Alice and Bob can see the high-confidentiality version of Alice's
        # location, but Carol cannot.
        self.assertEqual(JeevesLib.concretize(self.alice, self.alice.location),
                         self.gpsMIT)
        self.assertEqual(JeevesLib.concretize(self.bob, self.alice.location),
                         self.gpsMIT)
        self.assertEqual(JeevesLib.concretize(self.carol, self.alice.location),
                         self.cityCambridge)

    def testCountUsersInLocation(self):
        # Only Alice and Bob can see Alice's "high" location of S
        locNetwork = LocationNetwork([self.alice, self.bob, self.carol])
        usersInStata = locNetwork.countUsersInLocation(self.gpsMIT)
        self.assertEqual(JeevesLib.concretize(self.alice, usersInStata), 1)
        self.assertEqual(JeevesLib.concretize(self.bob, usersInStata), 1)
        self.assertEqual(JeevesLib.concretize(self.carol, usersInStata), 0)
Пример #8
0
class TestLocationFlow(unittest.TestCase):
  def setUp(self):
    def canSee(owner, ctxt):
      return owner == ctxt or owner.isFriends(ctxt)

    # Need to initialize the JeevesLib environment.
    JeevesLib.init()

    # Define some locations.
    self.countryUSA = Country("USA")
    self.cityCambridge = City("Cambridge", self.countryUSA)
    self.gpsMIT = GPS(40.589063, -74.159178, self.cityCambridge) 

    # Define some users.
    self.alice = User(0)
#      , JeevesLib.mkSensitive(aliceLabel, self.gpsMIT, self.cityCambridge))
    self.bob = User(1) #, self.cityCambridge)
    self.carol = User(2) #, self.countryUSA)

    self.alice.addFriend(self.bob)
    self.bob.addFriend(self.alice)

    aliceLabel = JeevesLib.mkLabel()
    JeevesLib.restrict(aliceLabel, lambda oc: oc == self.alice or self.alice.isFriends(oc))
    self.aliceLoc = JeevesLib.mkSensitive(aliceLabel, self.gpsMIT
                      , self.cityCambridge)

  @jeeves
  def testUpdates(self):
    # Bob cannot update Alice's location.
    self.assertEqual(
      self.alice.location.update(self.bob, self.bob, self.aliceLoc)
      , UpdateResult.Unknown)

    # Alice updates her location.
    self.assertEqual(self.alice.location.update(self.alice, self.alice
      , self.aliceLoc), UpdateResult.Unknown)
    # Only Alice and her friends can see the high-confidentiality version of
    # her location.
    self.assertEqual(JeevesLib.concretize(self.alice, self.alice.location.v)
      , self.gpsMIT)
    self.assertEqual(JeevesLib.concretize(self.bob, self.alice.location.v)
      , self.gpsMIT)
    # TODO: This doesn't work yet because we don't have a rank-ordering of
    # labels associated with write policies so that we can prioritize assigning
    # certain labels to high over others.
    self.assertEqual(JeevesLib.concretize(self.carol, self.alice.location.v)
      , self.cityCambridge)

  def testCountUsersInLocation(self):
    self.assertEqual(self.alice.location.update(self.alice, self.alice
      , self.aliceLoc), UpdateResult.Unknown)
    self.assertEqual(self.bob.location.update(self.bob, self.bob, self.cityCambridge), UpdateResult.Unknown)
    self.assertEqual(self.carol.location.update(self.carol, self.carol, self.countryUSA), UpdateResult.Unknown)

    # Only Alice and Bob can see Alice's "high" location of S
    locNetwork = LocationNetwork([self.alice, self.bob, self.carol])
    usersInStata = locNetwork.countUsersInLocation(self.gpsMIT)
    self.assertEqual(JeevesLib.concretize(self.alice, usersInStata), 1)
    self.assertEqual(JeevesLib.concretize(self.bob, usersInStata), 1)
    self.assertEqual(JeevesLib.concretize(self.carol, usersInStata), 0)