def test_get_signature(self): gref = Gref(self.repo, "testchannel", "test_get_signature") root = self.create_root_object(gref) oid = self.repo.create_blob(root.as_object()) signature = (17 ** 23,) gref.write_tip(oid, signature) self.assertEqual(signature, gref.get_signature(oid))
def test_get_signature(self): gref = Gref(self.repo, "testchannel", "test_get_signature") root = self.create_root_object(gref) oid = self.repo.create_blob(root.as_object()) signature = (17**23, ) gref.write_tip(oid, signature) self.assertEqual(signature, gref.get_signature(oid))
def test_remove_tip(self): gref = Gref(self.repo, "testchannel", "test_write_tip") gref.write_tip("foobarbaz", "") gref.write_tip("lulzbutts", "") gref.write_tip("buttslols", "") gref.remove_tip("lulzbutts") self.assertTrue("foobarbaz" in list(gref)) self.assertTrue("buttslols" in list(gref)) self.assertFalse("lulzbutts" in list(gref))
def test_marshalls_untrusted_signatures(self): gref = Gref(self.repo, "testchannel", "test_untrusted_signature") adaptor = RSAAdaptor({"valid": crypto_fixture.passphrase_pubkey}) private_adaptor = RSAPrivateAdaptor(crypto_fixture.valid_key) root = root_object("test", "test_channel", "test") root_oid = self.repo.create_blob(root.as_object()) update = update_object("test object", [root_oid]) update_oid = self.repo.create_blob(update.as_object()) gref.write_tip(update_oid, private_adaptor.sign(update_oid)) marshalled = gref.marshall(crypto_adaptor=adaptor) self.assertFalse(marshalled["signatures"][update_oid])
def test_parents(self): gref = Gref(self.repo, "testchannel", "test_write_tip") root = self.create_root_object(gref) current = root parents = [] for i in xrange(10): oid = self.repo.create_blob(current.as_object()) parents.append(oid) current = self.create_update_object([oid], "lol data") else: oid = self.repo.create_blob(current.as_object()) gref.write_tip(oid, "") our_parents = gref.parents() for parent in our_parents: self.assertIn(parent, parents)
def test_marshalls_tips(self): gref = Gref(self.repo, "testchannel", "test_write_tip") objects = [] root = root_object("test", "test_channel", "test") root_oid = self.repo.create_blob(root.as_object()) for i in xrange(5): update = update_object("test %i" % i, [root_oid]) update_oid = self.repo.create_blob(update.as_object()) objects.append(update_oid) gref.write_tip(update_oid, "") marshalled = gref.marshall() for i in objects: self.assertIn(i, marshalled["tips"])
def test_direct_parents(self): gref = Gref(self.repo, "testchannel", "test_write_tip") root = self.create_root_object(gref) root_oid = self.repo.create_blob(root.as_object()) first_tier = [] for i in xrange(5): obj = self.create_update_object([root_oid], "test_%i") oid = self.repo.create_blob(obj.as_object()) first_tier.append(oid) final = self.create_update_object(first_tier, "final object") final_oid = self.repo.create_blob(final.as_object()) gref.write_tip(final_oid, "") self.assertEqual(gref.direct_parents(final_oid), first_tier)
def test_marshalls_untrusted_signatures(self): gref = Gref(self.repo, "testchannel", "test_untrusted_signature") adaptor = RSAAdaptor({ "valid": crypto_fixture.passphrase_pubkey }) private_adaptor = RSAPrivateAdaptor(crypto_fixture.valid_key) root = root_object("test", "test_channel", "test") root_oid = self.repo.create_blob(root.as_object()) update = update_object("test object", [root_oid]) update_oid = self.repo.create_blob(update.as_object()) gref.write_tip(update_oid, private_adaptor.sign(update_oid)) marshalled = gref.marshall(crypto_adaptor=adaptor) self.assertFalse(marshalled["signatures"][update_oid])
def test_marshalls_roots(self): gref = Gref(self.repo, "testchannel", "test_write_root") roots = [] for i in xrange(5): root = root_object("test", "test_channel", "test%i" % i) root_oid = self.repo.create_blob(root.as_object()) root.sha1 = root_oid roots.append(root_oid) # Create an update object for valid tip update = update_object("test %i" % i, roots) update_oid = self.repo.create_blob(update.as_object()) gref.write_tip(update_oid, "") marshalled = gref.marshall() root_hashes = [i.sha1 for i in marshalled["roots"]] for i in roots: self.assertIn(i, root_hashes)
def test_write_tip(self): gref = Gref(self.repo, "testchannel", "test_write_tip") gref.write_tip("foobarbaz", "") self.assertEqual(list(gref), ["foobarbaz"])
# Creates a thread in the current groundstation context import uuid import stricken from groundstation.node import Node from groundstation.station import Station from groundstation.objects.root_object import RootObject from groundstation.objects.update_object import UpdateObject from groundstation.gref import Gref node = Node() station = Station.from_env(node) CHANNEL = "messages" thread_id = str(uuid.uuid1()) gref = Gref(station.store, CHANNEL, thread_id) root = RootObject(thread_id, CHANNEL, stricken.PROTOCOL) oid = station.write(root.as_object()) print("Root id: %s" % (oid)) update = UpdateObject([oid], "Post content") oid = station.write(update.as_object()) print("Update id: %s" % (oid)) gref.write_tip(oid, "")