def setUp(self): # Do this on a per-test basis so we have a clean ghidcache for the # restoration test clear_ghidcache('/ghidcache_test') self.percore = PersistenceCore() self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.bookie = Bookie() self.librarian = DiskLibrarian(cache_dir='/ghidcache_test') self.postman = MrPostman() self.undertaker = Undertaker() self.salmonator = Salmonator() self.rolodex = RolodexMock() self.golcore = GCoreMock(TEST_AGENT1) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) self.lawyer.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.salmonator.assemble(self.percore, self.percore, self.doorman, self.postman, self.librarian)
def setUp(self): self.percore = PersistenceCore() self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.bookie = Bookie() self.librarian = MemoryLibrarian() self.postman = MrPostman() self.undertaker = Undertaker() self.salmonator = Salmonator() self.rolodex = RolodexMock() self.golcore = GCoreMock(TEST_AGENT1) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) self.lawyer.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.salmonator.assemble(self.percore, self.percore, self.doorman, self.postman, self.librarian)
def setUp(self): # These are directly required by the oracle self.golcore = GolixCore() self.ghidproxy = GhidProxier() self.privateer = Privateer() self.percore = PersistenceCore() self.bookie = Bookie() self.librarian = MemoryLibrarian() self.oracle = Oracle() self.postman = MrPostman() self.salmonator = SalmonatorNoop() # These are here, for lack of fixturing of the above. self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.undertaker = Undertaker() self.rolodex = MockRolodex() # These are a mix of "necessary" and "unnecessary if well-fixtured" self.golcore.assemble(self.librarian) self.ghidproxy.assemble(self.librarian, self.salmonator) self.oracle.assemble(self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian, self.postman, self.salmonator) self.privateer.assemble(self.golcore, self.ghidproxy, self.oracle) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.lawyer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) # These are both "who-knows-if-necessary-when-fixtured" credential = MockCredential(self.privateer, TEST_AGENT1) self.golcore.bootstrap(credential) self.privateer.prep_bootstrap() # Just do this manually. self.privateer._credential = credential # self.privateer.bootstrap( # persistent_secrets = {}, # staged_secrets = {}, # chains = {} # ) self.percore.ingest(TEST_AGENT1.second_party.packed)
def test_restoration(self): self.test_trash() percore = PersistenceCore() doorman = Doorman() enforcer = Enforcer() lawyer = Lawyer() bookie = Bookie() librarian = DiskLibrarian(cache_dir='/ghidcache_test') postman = MrPostman() undertaker = Undertaker() salmonator = Salmonator() rolodex = RolodexMock() golcore = GCoreMock(TEST_AGENT1) percore.assemble(doorman, enforcer, lawyer, bookie, librarian, postman, undertaker, salmonator) doorman.assemble(librarian) postman.assemble(golcore, librarian, bookie, rolodex) undertaker.assemble(librarian, bookie, postman) lawyer.assemble(librarian) enforcer.assemble(librarian) bookie.assemble(librarian, lawyer, undertaker) librarian.assemble(percore) salmonator.assemble(percore, percore, doorman, postman, librarian) # And now reload errything librarian.restore() # And make sure the two librarians are equivalent self.assertEqual(self.librarian._catalog, librarian._catalog) all_debound = self.bookie._debound_by_ghid.combine( self.bookie._debound_by_ghid_staged) all_debound2 = bookie._debound_by_ghid.combine( bookie._debound_by_ghid_staged) self.assertEqual(all_debound, all_debound2)
class DiskLibrarianTrashtest(unittest.TestCase, _GenericPersistenceTest): def setUp(self): # Do this on a per-test basis so we have a clean ghidcache for the # restoration test clear_ghidcache('/ghidcache_test') self.percore = PersistenceCore() self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.bookie = Bookie() self.librarian = DiskLibrarian(cache_dir='/ghidcache_test') self.postman = MrPostman() self.undertaker = Undertaker() self.salmonator = Salmonator() self.rolodex = RolodexMock() self.golcore = GCoreMock(TEST_AGENT1) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) self.lawyer.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.salmonator.assemble(self.percore, self.percore, self.doorman, self.postman, self.librarian) def test_restoration(self): self.test_trash() percore = PersistenceCore() doorman = Doorman() enforcer = Enforcer() lawyer = Lawyer() bookie = Bookie() librarian = DiskLibrarian(cache_dir='/ghidcache_test') postman = MrPostman() undertaker = Undertaker() salmonator = Salmonator() rolodex = RolodexMock() golcore = GCoreMock(TEST_AGENT1) percore.assemble(doorman, enforcer, lawyer, bookie, librarian, postman, undertaker, salmonator) doorman.assemble(librarian) postman.assemble(golcore, librarian, bookie, rolodex) undertaker.assemble(librarian, bookie, postman) lawyer.assemble(librarian) enforcer.assemble(librarian) bookie.assemble(librarian, lawyer, undertaker) librarian.assemble(percore) salmonator.assemble(percore, percore, doorman, postman, librarian) # And now reload errything librarian.restore() # And make sure the two librarians are equivalent self.assertEqual(self.librarian._catalog, librarian._catalog) all_debound = self.bookie._debound_by_ghid.combine( self.bookie._debound_by_ghid_staged) all_debound2 = bookie._debound_by_ghid.combine( bookie._debound_by_ghid_staged) self.assertEqual(all_debound, all_debound2)
class OracleTest(unittest.TestCase): def setUp(self): # These are directly required by the oracle self.golcore = GolixCore() self.ghidproxy = GhidProxier() self.privateer = Privateer() self.percore = PersistenceCore() self.bookie = Bookie() self.librarian = MemoryLibrarian() self.oracle = Oracle() self.postman = MrPostman() self.salmonator = SalmonatorNoop() # These are here, for lack of fixturing of the above. self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.undertaker = Undertaker() self.rolodex = MockRolodex() # These are a mix of "necessary" and "unnecessary if well-fixtured" self.golcore.assemble(self.librarian) self.ghidproxy.assemble(self.librarian, self.salmonator) self.oracle.assemble(self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian, self.postman, self.salmonator) self.privateer.assemble(self.golcore, self.ghidproxy, self.oracle) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.lawyer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) # These are both "who-knows-if-necessary-when-fixtured" credential = MockCredential(self.privateer, TEST_AGENT1) self.golcore.bootstrap(credential) self.privateer.prep_bootstrap() # Just do this manually. self.privateer._credential = credential # self.privateer.bootstrap( # persistent_secrets = {}, # staged_secrets = {}, # chains = {} # ) self.percore.ingest(TEST_AGENT1.second_party.packed) def test_load(self): # First let's try simple retrieval from _fixtures.remote_exchanges import pt1 from _fixtures.remote_exchanges import cont1_1 from _fixtures.remote_exchanges import secret1_1 geoc1_1 = _GeocLite(cont1_1.ghid, cont1_1.author) from _fixtures.remote_exchanges import pt2 from _fixtures.remote_exchanges import cont1_2 from _fixtures.remote_exchanges import secret1_2 geoc1_2 = _GeocLite(cont1_2.ghid, cont1_2.author) from _fixtures.remote_exchanges import dyn1_1a gobd1_a = _GobdLite( dyn1_1a.ghid_dynamic, dyn1_1a.binder, dyn1_1a.target, dyn1_1a.ghid, dyn1_1a.history) from _fixtures.remote_exchanges import dyn1_1b gobd1_b = _GobdLite( dyn1_1b.ghid_dynamic, dyn1_1b.binder, dyn1_1b.target, dyn1_1b.ghid, dyn1_1b.history) self.percore.ingest(dyn1_1a.packed) self.percore.ingest(cont1_1.packed) self.privateer.stage(cont1_1.ghid, secret1_1) # Manually call this before next update, to prevent later keyerrors # from attempting to deliver a "posthumous" notification for the above # ingestion. self.postman.do_mail_run() # Okay, now we should be able to get that. obj = self.oracle.get_object(_GAO, dyn1_1a.ghid_dynamic) self.assertEqual(obj.extract_state(), pt1) # Make sure we loaded it into memory self.assertIn(dyn1_1a.ghid_dynamic, self.oracle._lookup) # Test loading it again to get the other code path obj = self.oracle.get_object(_GAO, dyn1_1a.ghid_dynamic) # Now, that should have registered with the postman, so let's make sure # it did, by updating the object. self.percore.ingest(dyn1_1b.packed) self.percore.ingest(cont1_2.packed) self.privateer.stage(cont1_2.ghid, secret1_2) # Do the mail run and then verify the state has updated self.postman.do_mail_run() # Ew. Gross. time.sleep(.1) self.assertEqual(obj.extract_state(), pt2) # TODO: also verify that the object has been registered with the # salmonator. def test_new(self): state = b'\x00' obj = self.oracle.new_object(_GAO, state, dynamic=True) # Make sure we called push and therefore have a ghid self.assertTrue(obj.ghid) self.assertEqual(obj.extract_state(), state) # Make sure we loaded it into memory self.assertIn(obj.ghid, self.oracle._lookup)
class GAOTest(unittest.TestCase): def setUp(self): # These are directly required by the GAO self.golcore = GolixCore() self.ghidproxy = GhidProxier() self.privateer = Privateer() self.percore = PersistenceCore() self.bookie = Bookie() self.librarian = MemoryLibrarian() # These are here, for lack of fixturing of the above. self.oracle = Oracle() self.doorman = Doorman() self.enforcer = Enforcer() self.lawyer = Lawyer() self.postman = MrPostman() self.undertaker = Undertaker() self.salmonator = SalmonatorNoop() self.rolodex = MockRolodex() # These are a mix of "necessary" and "unnecessary if well-fixtured" self.golcore.assemble(self.librarian) self.ghidproxy.assemble(self.librarian, self.salmonator) self.oracle.assemble(self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian, self.postman, self.salmonator) self.privateer.assemble(self.golcore, self.ghidproxy, self.oracle) self.percore.assemble(self.doorman, self.enforcer, self.lawyer, self.bookie, self.librarian, self.postman, self.undertaker, self.salmonator) self.doorman.assemble(self.librarian) self.enforcer.assemble(self.librarian) self.lawyer.assemble(self.librarian) self.bookie.assemble(self.librarian, self.lawyer, self.undertaker) self.librarian.assemble(self.percore) self.postman.assemble(self.golcore, self.librarian, self.bookie, self.rolodex) self.undertaker.assemble(self.librarian, self.bookie, self.postman) # These are both "who-knows-if-necessary-when-fixtured" credential = MockCredential(self.privateer, TEST_AGENT1) self.golcore.bootstrap(credential) self.privateer.prep_bootstrap() # Just do this manually. self.privateer._credential = credential # self.privateer.bootstrap( # persistent_secrets = {}, # staged_secrets = {}, # chains = {} # ) self.percore.ingest(TEST_AGENT1.second_party.packed) def test_source(self): ''' These tests are alone-ish and can definitely be wholly fixtured ''' # Test a static object being created obj_static = _GAO(self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian, False) msg1 = b'hello stagnant world' obj_static.apply_state(msg1) obj_static.push() self.assertTrue(obj_static.ghid) self.assertEqual(obj_static.extract_state(), msg1) self.assertIn(obj_static.ghid, self.privateer) self.assertIn(obj_static.ghid, self.librarian) # Now test a dynamic object being created obj_dyn = _GAO(self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian, True) msg2 = b'hello mutable world' obj_dyn.apply_state(msg2) obj_dyn.push() self.assertTrue(obj_dyn.ghid) # Speaking of inadequate fixturing... self.oracle._lookup[obj_dyn.ghid] = obj_dyn # Back to business as usual now. self.assertEqual(obj_dyn.extract_state(), msg2) # We should NOT see the dynamic ghid in privateer. self.assertNotIn(obj_dyn.ghid, self.privateer) # But we should see the most recent target self.assertIn(obj_dyn._history_targets[0], self.privateer) self.assertIn(obj_dyn.ghid, self.librarian) # And let's test mutation thereof. 0000001000000110000011100001111 msg3 = b'AFFIRMATIVE' obj_dyn.apply_state(msg3) obj_dyn.push() self.assertTrue(obj_dyn.ghid) self.assertEqual(obj_dyn.extract_state(), msg3) # We should NOT see the dynamic ghid in privateer. self.assertNotIn(obj_dyn.ghid, self.privateer) # But we should see the most recent target self.assertIn(obj_dyn._history_targets[0], self.privateer) self.assertIn(obj_dyn.ghid, self.librarian) # Now let's try freezing it frozen_ghid = obj_dyn.freeze() self.assertEqual(frozen_ghid, obj_dyn._history_targets[0]) # And then delete the original obj_dyn.delete() # TODO: assess that this has actually deleted anything... def test_sink(self): ''' Test retrieval from known ghids, pulls, etc ''' # "Remote" frame 1 from _fixtures.remote_exchanges import pt1 from _fixtures.remote_exchanges import secret1_1 from _fixtures.remote_exchanges import cont1_1 from _fixtures.remote_exchanges import dyn1_1a # "Remote" frame 2 from _fixtures.remote_exchanges import pt2 from _fixtures.remote_exchanges import secret1_2 from _fixtures.remote_exchanges import cont1_2 from _fixtures.remote_exchanges import dyn1_1b self.percore.ingest(dyn1_1a.packed) self.percore.ingest(cont1_1.packed) self.privateer.stage(cont1_1.ghid, secret1_1) obj_dyn = _GAO.from_ghid(dyn1_1a.ghid_dynamic, self.golcore, self.ghidproxy, self.privateer, self.percore, self.bookie, self.librarian) self.assertEqual(obj_dyn.extract_state(), pt1) # NOTE! These are not ratcheted. self.percore.ingest(dyn1_1b.packed) self.percore.ingest(cont1_2.packed) self.privateer.stage(cont1_2.ghid, secret1_2) obj_dyn.pull() self.assertEqual(obj_dyn.extract_state(), pt2)