Beispiel #1
0
 def test_multiple_ops_in_id_with_version1(self):
     test_oven = macaroonbakery.Oven()
     ops = [macaroonbakery.Op('one', 'read'),
            macaroonbakery.Op('one', 'write'),
            macaroonbakery.Op('two', 'read')]
     m = test_oven.macaroon(macaroonbakery.BAKERY_V1, AGES, None, ops)
     got_ops, conds = test_oven.macaroon_ops([m.macaroon])
     self.assertEquals(len(conds), 1)  # time-before caveat.
     self.assertEquals(macaroonbakery.canonical_ops(got_ops), ops)
Beispiel #2
0
 def test_multiple_ops(self):
     test_oven = macaroonbakery.Oven(
         ops_store=macaroonbakery.MemoryOpsStore())
     ops = [macaroonbakery.Op('one', 'read'),
            macaroonbakery.Op('one', 'write'),
            macaroonbakery.Op('two', 'read')]
     m = test_oven.macaroon(macaroonbakery.LATEST_BAKERY_VERSION, AGES,
                            None, ops)
     got_ops, conds = test_oven.macaroon_ops([m.macaroon])
     self.assertEquals(len(conds), 1)  # time-before caveat.
     self.assertEquals(macaroonbakery.canonical_ops(got_ops), ops)
Beispiel #3
0
 def test_multiple_ops_in_id(self):
     test_oven = bakery.Oven()
     ops = [
         bakery.Op('one', 'read'),
         bakery.Op('one', 'write'),
         bakery.Op('two', 'read')
     ]
     m = test_oven.macaroon(bakery.LATEST_VERSION, AGES, None, ops)
     got_ops, conds = test_oven.macaroon_ops([m.macaroon])
     self.assertEquals(len(conds), 1)  # time-before caveat.
     self.assertEquals(bakery.canonical_ops(got_ops), ops)
Beispiel #4
0
    def test_huge_number_of_ops_gives_small_macaroon(self):
        test_oven = bakery.Oven(ops_store=bakery.MemoryOpsStore())
        ops = []
        for i in range(30000):
            ops.append(
                bakery.Op(entity='entity' + str(i), action='action' + str(i)))

        m = test_oven.macaroon(bakery.LATEST_VERSION, AGES, None, ops)
        got_ops, conds = test_oven.macaroon_ops([m.macaroon])
        self.assertEquals(len(conds), 1)  # time-before caveat.
        self.assertEquals(bakery.canonical_ops(got_ops),
                          bakery.canonical_ops(ops))

        data = m.serialize_json()
        self.assertLess(len(data), 300)
Beispiel #5
0
    def test_ops_stored_only_once(self):
        st = macaroonbakery.MemoryOpsStore()
        test_oven = macaroonbakery.Oven(ops_store=st)

        ops = [macaroonbakery.Op('one', 'read'),
               macaroonbakery.Op('one', 'write'),
               macaroonbakery.Op('two', 'read')]

        m = test_oven.macaroon(macaroonbakery.LATEST_BAKERY_VERSION, AGES,
                               None, ops)
        got_ops, conds = test_oven.macaroon_ops([m.macaroon])
        self.assertEquals(macaroonbakery.canonical_ops(got_ops),
                          macaroonbakery.canonical_ops(ops))

        # Make another macaroon containing the same ops in a different order.
        ops = [macaroonbakery.Op('one', 'write'),
               macaroonbakery.Op('one', 'read'),
               macaroonbakery.Op('one', 'read'),
               macaroonbakery.Op('two', 'read')]
        test_oven.macaroon(macaroonbakery.LATEST_BAKERY_VERSION, AGES, None,
                           ops)
        self.assertEquals(len(st._store), 1)