Example #1
0
 def setup():
     client = soledad_client()
     pool = SyncEncrypterPool(client._crypto, client._sync_db)
     pool.start()
     request.addfinalizer(pool.stop)
     docs = [
         SoledadDocument(doc_id=uuid4().hex,
                         rev='rev',
                         json=json.dumps(DOC_CONTENT))
         for _ in xrange(amount)
     ]
     return pool, docs
Example #2
0
class TestSyncEncrypterPool(BaseSoledadTest):
    def setUp(self):
        BaseSoledadTest.setUp(self)
        crypto = self._soledad._crypto
        sync_db = self._soledad._sync_db
        self._pool = SyncEncrypterPool(crypto, sync_db)
        self._pool.start()

    def tearDown(self):
        self._pool.stop()
        BaseSoledadTest.tearDown(self)

    @inlineCallbacks
    def test_get_encrypted_doc_returns_none(self):
        """
        Test that trying to get an encrypted doc from the pool returns None if
        the document was never added for encryption.
        """
        doc = yield self._pool.get_encrypted_doc(DOC_ID, DOC_REV)
        self.assertIsNone(doc)

    @inlineCallbacks
    def test_encrypt_doc_and_get_it_back(self):
        """
        Test that the pool actually encrypts a document added to the queue.
        """
        doc = SoledadDocument(doc_id=DOC_ID,
                              rev=DOC_REV,
                              json=json.dumps(DOC_CONTENT))

        yield self._pool.encrypt_doc(doc)
        encrypted = yield self._pool.get_encrypted_doc(DOC_ID, DOC_REV)

        self.assertIsNotNone(encrypted)
Example #3
0
class TestSyncEncrypterPool(BaseSoledadTest):

    def setUp(self):
        BaseSoledadTest.setUp(self)
        crypto = self._soledad._crypto
        sync_db = self._soledad._sync_db
        self._pool = SyncEncrypterPool(crypto, sync_db)
        self._pool.start()

    def tearDown(self):
        self._pool.stop()
        BaseSoledadTest.tearDown(self)

    @inlineCallbacks
    def test_get_encrypted_doc_returns_none(self):
        """
        Test that trying to get an encrypted doc from the pool returns None if
        the document was never added for encryption.
        """
        doc = yield self._pool.get_encrypted_doc(DOC_ID, DOC_REV)
        self.assertIsNone(doc)

    @inlineCallbacks
    def test_encrypt_doc_and_get_it_back(self):
        """
        Test that the pool actually encrypts a document added to the queue.
        """
        doc = SoledadDocument(
            doc_id=DOC_ID, rev=DOC_REV, json=json.dumps(DOC_CONTENT))
        self._pool.encrypt_doc(doc)

        # exhaustivelly attempt to get the encrypted document
        encrypted = None
        attempts = 0
        while encrypted is None and attempts < 10:
            encrypted = yield self._pool.get_encrypted_doc(DOC_ID, DOC_REV)
            attempts += 1

        self.assertIsNotNone(encrypted)
        self.assertTrue(attempts < 10)
Example #4
0
 def setUp(self):
     BaseSoledadTest.setUp(self)
     crypto = self._soledad._crypto
     sync_db = self._soledad._sync_db
     self._pool = SyncEncrypterPool(crypto, sync_db)
     self._pool.start()
Example #5
0
 def setUp(self):
     BaseSoledadTest.setUp(self)
     crypto = self._soledad._crypto
     sync_db = self._soledad._sync_db
     self._pool = SyncEncrypterPool(crypto, sync_db)
     self._pool.start()