mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-17 10:20:13 +00:00
SFTP: add tests for more combinations of open flags.
This commit is contained in:
parent
f0945526ce
commit
a62733ed08
@ -876,10 +876,9 @@ class SFTPUserHandler(ConchUser, PrefixingLogMixin):
|
|||||||
raise SFTPError(FX_BAD_MESSAGE,
|
raise SFTPError(FX_BAD_MESSAGE,
|
||||||
"invalid file open flags: at least one of FXF_READ and FXF_WRITE must be set")
|
"invalid file open flags: at least one of FXF_READ and FXF_WRITE must be set")
|
||||||
|
|
||||||
if not (flags & FXF_CREAT):
|
if (flags & FXF_EXCL) and not (flags & FXF_CREAT):
|
||||||
if flags & FXF_EXCL:
|
raise SFTPError(FX_BAD_MESSAGE,
|
||||||
raise SFTPError(FX_BAD_MESSAGE,
|
"invalid file open flags: FXF_EXCL cannot be set without FXF_CREAT")
|
||||||
"invalid file open flags: FXF_EXCL cannot be set without FXF_CREAT")
|
|
||||||
|
|
||||||
path = self._path_from_string(pathstring)
|
path = self._path_from_string(pathstring)
|
||||||
if not path:
|
if not path:
|
||||||
@ -993,7 +992,7 @@ class SFTPUserHandler(ConchUser, PrefixingLogMixin):
|
|||||||
|
|
||||||
metadata['readonly'] = _is_readonly(parent_readonly, filenode)
|
metadata['readonly'] = _is_readonly(parent_readonly, filenode)
|
||||||
return _make_sftp_file(self.check_abort, flags, self._convergence, parent=parent,
|
return _make_sftp_file(self.check_abort, flags, self._convergence, parent=parent,
|
||||||
childname=childname, filenode=filenode, metadata=metadata)
|
childname=childname, filenode=filenode, metadata=metadata)
|
||||||
def _no_child(f):
|
def _no_child(f):
|
||||||
if noisy: self.log("_no_child(%r)" % (f,), level=NOISY)
|
if noisy: self.log("_no_child(%r)" % (f,), level=NOISY)
|
||||||
f.trap(NoSuchChildError)
|
f.trap(NoSuchChildError)
|
||||||
@ -1006,7 +1005,7 @@ class SFTPUserHandler(ConchUser, PrefixingLogMixin):
|
|||||||
"cannot create a file when the parent directory is read-only")
|
"cannot create a file when the parent directory is read-only")
|
||||||
|
|
||||||
return _make_sftp_file(self.check_abort, flags, self._convergence, parent=parent,
|
return _make_sftp_file(self.check_abort, flags, self._convergence, parent=parent,
|
||||||
childname=childname)
|
childname=childname)
|
||||||
d3.addCallbacks(_got_child, _no_child)
|
d3.addCallbacks(_got_child, _no_child)
|
||||||
return d3
|
return d3
|
||||||
|
|
||||||
|
@ -747,18 +747,57 @@ class Handler(GridTestMixin, ShouldFailMixin, unittest.TestCase):
|
|||||||
d.addCallback(lambda node: download_to_data(node))
|
d.addCallback(lambda node: download_to_data(node))
|
||||||
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "012345678901234"))
|
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "012345678901234"))
|
||||||
|
|
||||||
# test WRITE | CREAT without TRUNC
|
# test WRITE | CREAT | APPEND when the file does not already exist
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.handler.openFile("creatappend", sftp.FXF_WRITE | sftp.FXF_CREAT |
|
||||||
|
sftp.FXF_APPEND, {}))
|
||||||
|
def _write_creat_append_new(wf):
|
||||||
|
d2 = wf.writeChunk(10, "0123456789")
|
||||||
|
d2.addCallback(lambda ign: wf.writeChunk(5, "01234"))
|
||||||
|
d2.addCallback(lambda ign: wf.close())
|
||||||
|
return d2
|
||||||
|
d.addCallback(_write_creat_append_new)
|
||||||
|
d.addCallback(lambda ign: self.root.get(u"creatappend"))
|
||||||
|
d.addCallback(lambda node: download_to_data(node))
|
||||||
|
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "012345678901234"))
|
||||||
|
|
||||||
|
# ... and when it does exist
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.handler.openFile("creatappend", sftp.FXF_WRITE | sftp.FXF_CREAT |
|
||||||
|
sftp.FXF_APPEND, {}))
|
||||||
|
def _write_creat_append_existing(wf):
|
||||||
|
d2 = wf.writeChunk(5, "01234")
|
||||||
|
d2.addCallback(lambda ign: wf.close())
|
||||||
|
return d2
|
||||||
|
d.addCallback(_write_creat_append_existing)
|
||||||
|
d.addCallback(lambda ign: self.root.get(u"creatappend"))
|
||||||
|
d.addCallback(lambda node: download_to_data(node))
|
||||||
|
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "01234567890123401234"))
|
||||||
|
|
||||||
|
# test WRITE | CREAT without TRUNC, when the file does not already exist
|
||||||
d.addCallback(lambda ign:
|
d.addCallback(lambda ign:
|
||||||
self.handler.openFile("newfile2", sftp.FXF_WRITE | sftp.FXF_CREAT, {}))
|
self.handler.openFile("newfile2", sftp.FXF_WRITE | sftp.FXF_CREAT, {}))
|
||||||
def _write_notrunc(wf):
|
def _write_creat_new(wf):
|
||||||
d2 = wf.writeChunk(0, "0123456789")
|
d2 = wf.writeChunk(0, "0123456789")
|
||||||
d2.addCallback(lambda ign: wf.close())
|
d2.addCallback(lambda ign: wf.close())
|
||||||
return d2
|
return d2
|
||||||
d.addCallback(_write_notrunc)
|
d.addCallback(_write_creat_new)
|
||||||
d.addCallback(lambda ign: self.root.get(u"newfile2"))
|
d.addCallback(lambda ign: self.root.get(u"newfile2"))
|
||||||
d.addCallback(lambda node: download_to_data(node))
|
d.addCallback(lambda node: download_to_data(node))
|
||||||
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "0123456789"))
|
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "0123456789"))
|
||||||
|
|
||||||
|
# ... and when it does exist
|
||||||
|
d.addCallback(lambda ign:
|
||||||
|
self.handler.openFile("newfile2", sftp.FXF_WRITE | sftp.FXF_CREAT, {}))
|
||||||
|
def _write_creat_existing(wf):
|
||||||
|
d2 = wf.writeChunk(0, "abcde")
|
||||||
|
d2.addCallback(lambda ign: wf.close())
|
||||||
|
return d2
|
||||||
|
d.addCallback(_write_creat_existing)
|
||||||
|
d.addCallback(lambda ign: self.root.get(u"newfile2"))
|
||||||
|
d.addCallback(lambda node: download_to_data(node))
|
||||||
|
d.addCallback(lambda data: self.failUnlessReallyEqual(data, "abcde56789"))
|
||||||
|
|
||||||
# test writing to a mutable file
|
# test writing to a mutable file
|
||||||
d.addCallback(lambda ign:
|
d.addCallback(lambda ign:
|
||||||
self.handler.openFile("mutable", sftp.FXF_WRITE, {}))
|
self.handler.openFile("mutable", sftp.FXF_WRITE, {}))
|
||||||
|
Loading…
Reference in New Issue
Block a user