def test_perform_undelete(app, alice_identity, file): vlob = {'id': '2345', 'read_trust_seed': '42', 'write_trust_seed': '43'} blob = [{ 'blocks': [{ 'block': '4567', 'digest': digest(b''), 'size': 0 }], 'key': to_jsonb64(b'<dummy-key-00000000000000000001>') }] blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_delete(EDelete('/foo')) sequence = [ (EIdentityGet(), const(alice_identity)), (EVlobRead(vlob['id'], vlob['read_trust_seed']), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EVlobList(), const([])), (EVlobRead(vlob['id'], vlob['read_trust_seed'], 1), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EBlockDelete('4567'), conste(BlockNotFound('Block not found.'))), (EVlobDelete('2345'), conste(VlobNotFound('Vlob not found.'))) ] ret = perform_sequence(sequence, eff) eff = app.perform_undelete(EUndelete('2345')) sequence = [(EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) assert ret is None
def test_perform_file_history(app, file, alice_identity): vlob = {'id': '2345', 'read_trust_seed': '42', 'write_trust_seed': '43'} blob = [{ 'blocks': [{ 'block': '4567', 'digest': digest(b''), 'size': 0 }], 'key': to_jsonb64(b'<dummy-key-00000000000000000001>') }] blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_file_history(EFileHistory('/foo', 1, 1)) sequence = [ (EIdentityGet(), const(alice_identity)), (EIdentityGet(), const(alice_identity)), (EVlobRead(vlob['id'], vlob['read_trust_seed']), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EVlobList(), const([])), ] perform_sequence(sequence, eff)
def test_perform_delete(app, alice_identity): eff = app.perform_folder_create(EFolderCreate('/dir')) sequence = [(EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) eff = app.perform_delete(EDelete('/dir')) sequence = [(EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) assert ret is None
def test_perform_stat(app, alice_identity, file): eff = app.perform_folder_create(EFolderCreate('/dir')) sequence = [(EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) eff = app.perform_stat(EStat('/dir')) sequence = [(EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) assert ret == {'children': [], 'type': 'folder'}
def test_api_identity_info(): # Not loaded eff = execute_cmd('identity_info', {}) sequence = [ (EIdentityGet(), conste(IdentityNotLoadedError())), ] resp = perform_sequence(sequence, eff) assert resp == {'status': 'ok', 'loaded': False, 'id': None} # Loaded eff = execute_cmd('identity_info', {}) sequence = [ (EIdentityGet(), const(Identity('JohnDoe', Mock(), Mock()))), ] resp = perform_sequence(sequence, eff) assert resp == {'status': 'ok', 'loaded': True, 'id': 'JohnDoe'}
def api_identity_info(msg): UnknownCheckedSchema().load(msg) try: identity = yield Effect(EIdentityGet()) return {'status': 'ok', 'loaded': True, 'id': identity.id} except IdentityNotLoadedError: return {'status': 'ok', 'loaded': False, 'id': None}
def app(mock_crypto_passthrough, alice_identity): # app = FSComponent() # identity_component = IdentityComponent() fs_component = FSComponent() # synchronizer_component = SynchronizerComponent() # identity_component = IdentityComponent() # app = app_factory( # fs_component.get_dispatcher(), # synchronizer_component.get_dispatcher(), # identity_component.get_dispatcher() # ) blob = { 'dustbin': [], 'entries': { '/': None }, 'groups': {}, 'versions': {} } blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) sequence = [(EIdentityGet(), const(alice_identity)), (EUserVlobRead(), const({ 'blob': '', 'version': 0 })), (EUserVlobUpdate(1, blob), noop)] perform_sequence(sequence, fs_component._get_manifest()) return fs_component
def test_perform_file_create(app, alice_identity, file): vlob = {'id': '2345', 'read_trust_seed': '42', 'write_trust_seed': '43'} block_id = '4567' # Already exist blob = [{ 'blocks': [{ 'block': block_id, 'digest': digest(b''), 'size': 0 }], 'key': to_jsonb64(b'<dummy-key-00000000000000000003>') }] blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_file_create(EFileCreate('/foo')) sequence = [ (EBlockCreate(''), const(block_id)), (EVlobCreate(blob), const(vlob)), (EIdentityGet(), const(alice_identity)), (EVlobRead(vlob['id'], vlob['read_trust_seed'], 1), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EBlockDelete(block_id), noop), (EVlobDelete(vlob['id']), noop), ] with pytest.raises(ManifestError): perform_sequence(sequence, eff)
def test_perform_dustbin_show(app, alice_identity, file): with freeze_time('2012-01-01') as frozen_datetime: vlob = { 'id': '2345', 'read_trust_seed': '42', 'write_trust_seed': '43' } blob = [{ 'blocks': [{ 'block': '4567', 'digest': digest(b''), 'size': 0 }], 'key': to_jsonb64(b'<dummy-key-00000000000000000001>') }] blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_delete(EDelete('/foo')) sequence = [ (EIdentityGet(), const(alice_identity)), (EVlobRead(vlob['id'], vlob['read_trust_seed']), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EVlobList(), const([])), (EVlobRead(vlob['id'], vlob['read_trust_seed'], 1), const({ 'id': vlob['id'], 'blob': blob, 'version': 1 })), (EBlockDelete('4567'), conste(BlockNotFound('Block not found.'))), (EVlobDelete('2345'), conste(VlobNotFound('Vlob not found.'))), ] perform_sequence(sequence, eff) eff = app.perform_dustbin_show(EDustbinShow()) sequence = [(EIdentityGet(), const(alice_identity))] dustbin = perform_sequence(sequence, eff) vlob['path'] = '/foo' vlob['removed_date'] = frozen_datetime().isoformat() vlob['key'] = to_jsonb64(b'<dummy-key-00000000000000000002>') assert dustbin == [vlob]
def test_perform_group_create(app, alice_identity): blob = {'dustbin': [], 'entries': {'/': None}, 'versions': {}} blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_group_create(EGroupCreate('share')) sequence = [(EIdentityGet(), const(alice_identity)), (EVlobCreate(), const({ 'id': '1234', 'read_trust_seed': '42', 'write_trust_seed': '43' })), (EVlobUpdate('1234', '43', 1, blob), noop)] ret = perform_sequence(sequence, eff) assert ret is None
def _get_manifest(self, group=None): identity = yield Effect(EIdentityGet()) if (not self.user_manifest or self.user_manifest.encryptor._hazmat_private_key != identity.private_key._hazmat_private_key): if not identity: raise IdentityNotLoadedError('Identity not loaded.') manifest = yield UserManifest.load( identity.private_key._hazmat_private_key) self.user_manifest = manifest else: manifest = self.user_manifest if group: return manifest.get_group_manifest(group) else: return manifest
def test_perform_synchronize(app, alice_identity): blob = { 'dustbin': [], 'entries': { '/': None }, 'groups': {}, 'versions': {} } blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_synchronize(ESynchronize()) sequence = [(EIdentityGet(), const(alice_identity)), (EVlobList(), const([])), (EUserVlobUpdate(1, blob), noop), (EUserVlobSynchronize(), noop)] ret = perform_sequence(sequence, eff) assert ret is None
def file(app, alice_identity, mock_crypto_passthrough): vlob = {'id': '2345', 'read_trust_seed': '42', 'write_trust_seed': '43'} block_id = '4567' blob = [{ 'blocks': [{ 'block': block_id, 'digest': digest(b''), 'size': 0 }], 'key': to_jsonb64(b'<dummy-key-00000000000000000001>') }] blob = ejson_dumps(blob).encode() blob = to_jsonb64(blob) eff = app.perform_file_create(EFileCreate('/foo')) sequence = [(EBlockCreate(''), const(block_id)), (EVlobCreate(blob), const(vlob)), (EIdentityGet(), const(alice_identity))] ret = perform_sequence(sequence, eff) assert ret is None File.files = {}
def performer_with_connection(intent): try: if self.connection: # Reuse already opened connection try: return (yield AsyncFunc(async_performer(intent))) except BackendConnectionError: # The connection has been closed, try to reconnect # and rerun the performer yield AsyncFunc(self.connection.close_connection()) self.connection = None return (yield performer_with_connection(intent)) else: # Open new connection and run command identity = yield Effect(EIdentityGet()) connection = BackendConnection(self.url, self.watchdog) yield AsyncFunc(connection.open_connection(identity)) self.connection = connection return (yield AsyncFunc(async_performer(intent))) except BackendConnectionError: if self.connection: yield AsyncFunc(self.connection.close_connection()) self.connection = None raise
def test_perform_manifest_restore(app, alice_identity): eff = app.perform_manifest_restore(EManifestRestore()) with pytest.raises(ManifestError): sequence = [(EIdentityGet(), const(alice_identity))] perform_sequence(sequence, eff)
def test_perform_manifest_history(app, alice_identity): eff = app.perform_manifest_history(EManifestHistory()) sequence = [(EIdentityGet(), const(alice_identity))] history = perform_sequence(sequence, eff) assert history == {'detailed_history': []}