diff options
author | drebs <drebs@leap.se> | 2013-04-30 12:13:07 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-04-30 12:13:07 -0300 |
commit | f1cf6a4b262f202c141d0e7cdd90f0f8403f9f5d (patch) | |
tree | 3573874ba28e76715fcdeb6d0e49c4d0af333a8b /src/leap/soledad/backends/leap_backend.py | |
parent | c5cebeb1e730e4c1e72445870374c13b9ffeb892 (diff) |
Fix shared db auth and add tests.
Diffstat (limited to 'src/leap/soledad/backends/leap_backend.py')
-rw-r--r-- | src/leap/soledad/backends/leap_backend.py | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/leap/soledad/backends/leap_backend.py b/src/leap/soledad/backends/leap_backend.py index 9750ffad..81f6c211 100644 --- a/src/leap/soledad/backends/leap_backend.py +++ b/src/leap/soledad/backends/leap_backend.py @@ -30,33 +30,22 @@ except ImportError: from u1db import Document from u1db.remote import utils -from u1db.remote.http_target import HTTPSyncTarget -from u1db.remote.http_database import HTTPDatabase from u1db.errors import BrokenSyncStream +from u1db.remote.http_target import HTTPSyncTarget from leap.common.keymanager import KeyManager from leap.common.check import leap_assert +from leap.soledad.auth import ( + set_token_credentials, + _sign_request, +) # # Exceptions # -class NoDefaultKey(Exception): - """ - Exception to signal that there's no default OpenPGP key configured. - """ - pass - - -class NoSoledadCryptoInstance(Exception): - """ - Exception to signal that no Soledad instance was found. - """ - pass - - class DocumentNotEncrypted(Exception): """ Raised for failures in document encryption. @@ -267,6 +256,18 @@ class LeapSyncTarget(HTTPSyncTarget): receiving. """ + # + # Token auth methods. + # + + set_token_credentials = set_token_credentials + + _sign_request = _sign_request + + # + # Modified HTTPSyncTarget methods. + # + @staticmethod def connect(url, crypto=None): return LeapSyncTarget(url, crypto=crypto) @@ -403,15 +404,3 @@ class LeapSyncTarget(HTTPSyncTarget): res = self._parse_sync_stream(data, return_doc_cb, ensure_callback) data = None return res['new_generation'], res['new_transaction_id'] - - def set_token_credentials(self, address, token): - self._creds = {'token': (address, token)} - - def _sign_request(self, method, url_query, params): - if 'token' in self._creds: - address, token = self._creds['token'] - auth = '%s:%s' % (address, token) - return [('Authorization', 'Token %s' % auth.encode('base64'))] - else: - return HTTPSyncTarget._sign_request( - self, method, url_query, params) |