def test_forbidden_edit(self): """ A user may lost its rights to edit a file (or even access to the document). In that case, a notification is shown and the Direct Edit is stopped early. """ filename = "secret-file.txt" doc_id = self.remote.make_file_with_blob("/", filename, b"Initial content.") def forbidden_signal(self, *args, **kwargs): nonlocal received received = True received = False self.direct_edit.directEditForbidden.connect(forbidden_signal) bad_remote = self.get_bad_remote() bad_remote.make_server_call_raise(Forbidden(message="Mock")) with patch.object(self.manager_1, "open_local_file", new=open_local_file), patch.object(self.engine_1, "remote", new=bad_remote): self.direct_edit._prepare_edit(self.nuxeo_url, doc_id) assert received
def test_forbidden_upload(self): """ A user may lost its rights to edit a file (or even access to the document). In that case, a notification is shown and the document is remove dfrom the upload queue. """ filename = "secret-file2.txt" doc_id = self.remote.make_file_with_blob("/", filename, b"Initial content.") local_path = f"/{doc_id}_file-content/{filename}" with patch.object(self.manager_1, "open_local_file", new=open_local_file): self.direct_edit._prepare_edit(self.nuxeo_url, doc_id) self.wait_sync(timeout=2, fail_if_timeout=False) # Simulate server error bad_remote = self.get_bad_remote() bad_remote.make_upload_raise(Forbidden(message="Mock")) with patch.object(self.engine_1, "remote", new=bad_remote): # Update file content self.local.update_content(local_path, b"Updated") time.sleep(5) # The file should _not_ be updated on the server assert (self.remote.get_blob( self.remote.get_info(doc_id)) == b"Initial content.")
def lock(_): msg = ( "(Mock'ed) Failed to invoke operation: Document.Lock, Failed " "to invoke operation Document.Lock, Privilege 'WriteProperties' " "is not granted to 'USER'") raise Forbidden(message=msg)
def test_crafted_forbidden(): exc = Forbidden() assert exc.status == 403