summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/soledad/server/_incoming.py9
-rw-r--r--testing/tests/server/test_incoming_server.py5
2 files changed, 14 insertions, 0 deletions
diff --git a/src/leap/soledad/server/_incoming.py b/src/leap/soledad/server/_incoming.py
index 187b6973..1d34f4f3 100644
--- a/src/leap/soledad/server/_incoming.py
+++ b/src/leap/soledad/server/_incoming.py
@@ -17,13 +17,16 @@
"""
A twisted resource that saves externally delivered documents into user's db.
"""
+import json
from twisted.web.server import NOT_DONE_YET
from twisted.web.resource import Resource
+from twisted.web.test.test_web import DummyRequest
from ._config import get_config
from io import BytesIO
from leap.soledad.server._blobs import BlobsServerState
from leap.soledad.common.couch.state import CouchServerState
from leap.soledad.common.document import ServerDocument
+from leap.soledad.common.blobs import Flags
from leap.soledad.common.crypto import ENC_JSON_KEY
from leap.soledad.common.crypto import ENC_SCHEME_KEY
from leap.soledad.common.crypto import EncryptionSchemes
@@ -65,6 +68,12 @@ class IncomingResource(Resource):
preamble = self.formatter.preamble(raw_content, doc_id)
request.content = BytesIO(preamble + raw_content)
d = db.write_blob(uuid, doc_id, request, namespace='MX')
+ # FIXME: We really need to decouple request handling from the
+ # backend! This is very ugly, but will change when this refactor
+ # is done.
+ flagsReq = DummyRequest([''])
+ flagsReq.content = BytesIO(json.dumps([Flags.PENDING]))
+ d.addCallback(lambda _: db.set_flags(uuid, doc_id, flagsReq, 'MX'))
d.addCallback(lambda _: self._finish(request))
return NOT_DONE_YET
diff --git a/testing/tests/server/test_incoming_server.py b/testing/tests/server/test_incoming_server.py
index 8886a721..55eb8931 100644
--- a/testing/tests/server/test_incoming_server.py
+++ b/testing/tests/server/test_incoming_server.py
@@ -18,6 +18,7 @@
Integration tests for incoming API
"""
import pytest
+import json
from io import BytesIO
from uuid import uuid4
from twisted.web.test.test_web import DummyRequest
@@ -30,6 +31,7 @@ from leap.soledad.server._incoming import IncomingResource
from leap.soledad.server._blobs import BlobsServerState
from leap.soledad.server._incoming import IncomingFormatter
from leap.soledad.common.crypto import EncryptionSchemes
+from leap.soledad.common.blobs import Flags
from test_soledad.util import CouchServerStateForTests
from test_soledad.util import CouchDBTestCase
@@ -83,5 +85,8 @@ class IncomingOnCouchServerTestCase(CouchDBTestCase):
db = self.state.open_database(user_id)
request = DummyRequest([user_id, doc_id])
yield db.read_blob(user_id, doc_id, request, 'MX')
+ flags = db.get_flags(user_id, doc_id, request, 'MX')
+ flags = json.loads(flags)
expected = formatter.preamble(content, doc_id) + content
self.assertEquals(expected, request.written[0])
+ self.assertIn(Flags.PENDING, flags)