mutable: parameterize Publish/Retrieve classes in MutableFileNode, for tests
authorBrian Warner <warner@allmydata.com>
Tue, 6 Nov 2007 22:18:09 +0000 (15:18 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 6 Nov 2007 22:18:09 +0000 (15:18 -0700)
src/allmydata/mutable.py
src/allmydata/test/test_mutable.py

index e2bd556a8d8cd5d98e4c28602d5ae882f840627a..ce9e081bee361fa995532c6d49f46f014684c08d 100644 (file)
@@ -163,6 +163,8 @@ def pack_offsets(verification_key_length, signature_length,
 
 class MutableFileNode:
     implements(IMutableFileNode)
+    publish_class = Publish
+    retrieve_class = Retrieve
 
     def __init__(self, client):
         self._client = client
@@ -195,28 +197,33 @@ class MutableFileNode:
         """
         self._required_shares = 3
         self._total_shares = 10
-        self._pubkey, self._privkey = self._generate_pubprivkeys()
-        pubkey_s = self._pubkey.serialize()
-        privkey_s = self._privkey.serialize()
-        self._writekey = hashutil.ssk_writekey_hash(privkey_s)
-        self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
-        self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
-        self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint)
-        self._readkey = self._uri.readkey
-        self._storage_index = self._uri.storage_index
-        self._current_seqnum = 0 # TODO: really we mean "doesn't matter
-        # since nobody knows about us yet"
-        self._current_roothash = "\x00"*32
-        return self._publish(initial_contents)
+        d = defer.maybeDeferred(self._generate_pubprivkeys)
+        def _generated( (pubkey, privkey) ):
+            self._pubkey, self._privkey = pubkey, privkey
+            pubkey_s = self._pubkey.serialize()
+            privkey_s = self._privkey.serialize()
+            self._writekey = hashutil.ssk_writekey_hash(privkey_s)
+            self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
+            self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
+            self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint)
+            self._readkey = self._uri.readkey
+            self._storage_index = self._uri.storage_index
+            # TODO: seqnum/roothash: really we mean "doesn't matter since
+            # nobody knows about us yet"
+            self._current_seqnum = 0
+            self._current_roothash = "\x00"*32
+            return self._publish(initial_contents)
+        d.addCallback(_generated)
+        return d
 
     def _generate_pubprivkeys(self):
+        # TODO: wire these up to pycryptopp
         privkey = "very private"
         pubkey = "public"
         return pubkey, privkey
 
     def _publish(self, initial_contents):
-        # TODO: actually do all that stuff
-        p = Publish(self)
+        p = self.publish_class(self)
         d = p.publish(initial_contents)
         d.addCallback(lambda res: self)
         return d
index 4176b813f30a61e3cbd68ad939b6c6f3b9657c36..fdb5083b4670df33d8016e2988bc6d8105233e48 100644 (file)
@@ -82,6 +82,20 @@ class FakePublish(mutable.Publish):
         answer = (True, readv)
         return defer.succeed(answer)
 
+class FakeRetrieve(mutable.Retrieve):
+    def _do_query(self, args):
+        pass
+    def _deserialize_pubkey(self, pubkey_s):
+        return FakePubKey(134)
+
+class LessFakeFilenode(mutable.MutableFileNode):
+    publish_class = FakePublish
+    retrieve_class = FakeRetrieve
+
+    def _generate_pubprivkeys(self):
+        count = self.counter.next()
+        return FakePubKey(count), FakePrivKey(count)
+
 
 class FakeNewDirectoryNode(dirnode2.NewDirectoryNode):
     filenode_class = FakeFilenode
@@ -392,6 +406,9 @@ class FakePubKey:
         self.count = count
     def serialize(self):
         return "PUBKEY-%d" % self.count
+    def verify(self, msg, signature):
+        return True
+
 class FakePrivKey:
     def __init__(self, count):
         self.count = count