Commit Graph

87 Commits

Author SHA1 Message Date
greatroar d3695c2587 Fix Glob handling of backslashes
\m\a\t\c\h\.\g\o would be interpreted as a literal path, because the
backslash was missing in the check.
2021-03-15 18:11:02 +01:00
Nicola Murino e1e59da6e3 add readAtSequential: used if concurrent reads are disabled ...
... and the requested buffer is bigger than maxPacket
2021-03-05 15:04:17 +01:00
Nicola Murino 5f2c008b8e add an option to disable concurrent reads
Fixs #345
2021-02-23 19:13:26 +01:00
Cassondra Foesch 29c556e3a6 WriteTo benchmarks 2021-02-22 12:04:43 +00:00
Cassondra Foesch 59de31242c more robust tests, fix typos 2021-02-22 12:04:43 +00:00
Cassondra Foesch d178e4730e avoid panic if double call to Close 2021-02-22 12:04:43 +00:00
Cassondra Foesch 27538347e7 defers in a for loop don't execute until the end of the function 2021-02-22 12:04:43 +00:00
Cassondra Foesch 4f2503d286 using sftp-server these tests hang without this close 2021-02-22 12:04:43 +00:00
Nicola Murino f5fd2fb058 normalise permission denied error as file not found error 2020-12-08 12:14:21 +01:00
greatroar 06d60c4c06 Test disconnect handling in open files 2020-11-04 10:17:06 +01:00
greatroar 7f43671909 Rename remaining temps in client integration test 2020-10-31 14:34:16 +01:00
greatroar 360f7af3e6 {assert,require}.Nil(t, err) => NoError, NotNil => Error 2020-10-29 16:02:25 +01:00
greatroar 4c4fa330bb First check for uid 0, then lookup daemon's uid 2020-10-29 16:00:27 +01:00
greatroar 7c0f7eea70 Comment out path matching test that breaks on Go tip 2020-10-29 14:47:28 +01:00
greatroar eb20cfe9bc Clean up temporary files in client tests 2020-10-23 22:14:32 +02:00
greatroar 83e0eb8f30 Fix typos in clients tests 2020-10-23 22:14:05 +02:00
greatroar d352a1d176 Add Client.Sync method
This uses the fsync@openssh.com extension:
https://github.com/openssh/openssh-portable/blob/master/PROTOCOL, §3.6.
2020-10-23 13:09:54 +02:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
Tommie Gannert 2c24eaad1c Implement the hardlink@openssh.com extension.
Both client and server. This is documented in

  https://github.com/openssh/openssh-portable/blob/master/PROTOCOL

Draft 7 of SFTP added support for SSH_FXP_LINK which supports both
symlinks and hardlinks, but unfortunately OpenSSH doesn't support
that:

  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-07#section-7.7

Adding support for this as an option would be a nice extension to
this.
2019-08-25 20:16:37 -07:00
Daniel Theophanes d8ec5de5ee sftp: update tests to finish and not panic on windows
Many Unix assuptions have been made when testing.
Previously running tests on windows threw a panic
part way through the tests. After these changes
many more tests pass when the fix was isolated
to the test itself, and none panic.

Some tests are skipped because they do make sense
on windows (chmod, chown), while others are skipped
just to how the test was implemented.

Lastly, some of the external executables were hard coded.
Change these to look paths in TestMain first. This is done
to better support windows, where openssh may be installed and
sftp and sftp-server may both be in the PATH.
2019-01-18 16:29:07 -08:00
Urjit Singh Bhatia 831654e4aa Client.MkdirAll - mimic os.MkdirAll code for consistency & perf 2018-04-25 08:13:19 -07:00
Urjit Singh Bhatia a03704e892 Add mkdirall implementation 2018-04-24 23:58:10 -07:00
John Eikenberry 49488377fa fix client deadlock on server death during writes
Fixes #234

Similar to #181 (which was about read methods), the client deadlocks on
server drop on write methods (Write/ReadFrom). This is another case of
broadcastErr() and dispatchRequest() deadlocking.

The fix is to bump up the channel used to communicate about inflight
packets to maxConcurrentRequests+1 (+1 is new). It seems that it can
have the full set of packets going and hit the error (triggering
broadcastErr) yet it still tries to call dispatchRequest again. More
details in that ticket.

I'm also bumping up the chan buffer in the read methods to keep them
consistent. I can't reproduce the problem, but it looks like it should
have it. So it might just be a much harder race to trigger.

This also includes 2 tests which reprocuded the issue for ReadFrom and
Write.
2018-03-15 13:53:30 -07:00
John Eikenberry 161bbaf9a8 a few code simplifications
ran gosimple over the code and made suggested adjustments
2018-02-15 11:17:19 -08:00
John Eikenberry 9fa3832aa2 update seek constants 2018-02-15 10:27:33 -08:00
Iain Wade 9b6cdb8fab Add PosixRename method which uses the posix-rename@openssh.com extension
to support actual rename() operations rather than the link() call
effectively mandated by the sftp v3/draft-2 requirement that targets
not be overwritten.
2017-09-05 04:46:03 -07:00
John Eikenberry 4f3e725e88 Fixes #188; eliminates duplicated core code
match contained lots of cut-n-pasted code from filepath/match.go in the
core libraries. Particularly Match() and Join() were changed in such a
way that made them functionally equivalent to the versions in
path/match.go. This removes the duplicate code and just calls the path
versions.
2017-07-20 15:28:11 -07:00
John Eikenberry 8e0c78ade5 fix spelling error in comment 2017-07-03 13:14:51 -07:00
John Eikenberry 737aa1dc61 Fixes #181: client deadlock on server death
The client was deadlocking if you killed the server when a file transfer
was occuring. The problem occured when you had many requests sent and
were waiting on responses when the server dies. The errors for all those
pending requests get sent along the response channel which is also used
for the errors reported by the new requests being made. The new request
channel send is in the same loop as the channel reading, so when it
blocked due to all other errors filling the channel it deadlocked the
program.

There were 2 possible fixes, changing the new request error channel
usage to be in a separate goroutine to keep it from blocking the loop or
to increase the size of the buffer to handle all the errors. This
implements the latter.

Included is a test that reproduces the problem most of the time. Due to
the required timing of the issue, it was impossible to reproduce 100% of
the time.
2017-06-29 11:27:52 -07:00
John Eikenberry ca043ca452 add ReadFrom benchmark 2017-06-25 19:21:59 -07:00
John Eikenberry 8f9da7f630 quick fix to get benchmarks running
benchmarks were broken due to double closing of a channel in some tests.
I just commented out the problematic closes which probably means it's
leaking in the tests but at least they run now. Should probably try to
figure out what happened here at some point.
2017-03-14 12:27:51 -07:00
Catalin Tanasescu 43d52d4faa ported Glob method from filepath - https://golang.org/pkg/path/filepath/#Glob 2017-02-18 14:26:32 -08:00
John Eikenberry cfb6d5c5b2 Add tests for deadlocks in Read and WriteTo
Just like issues reported in #145
2017-02-13 17:20:40 -08:00
John Eikenberry 14f0a222dd Tests to replicate deadlock bug in Write/ReadFrom
github issue #145

A deadlock will occur in cases when using client.Write or client.ReadFrom,
it has 2 network issues in a row, and it is starting a new loop to send
more concurrent packets.
2017-02-13 00:32:33 -08:00
John Eikenberry bc4cce8bc3 basic ReadFrom test 2017-02-12 19:37:13 -08:00
Dave Cheney c5050bbe83 removed unused code 2016-06-15 11:33:39 +10:00
Dave Cheney 982656642c Introduce netpipe (#105)
netPipe provides a pair of io.ReadWriteClosers connected to each other.
The functions is identical to os.Pipe with the exception that netPipe
provides the Read/Close guarentees that os.File derrived pipes do not.
2016-05-29 17:22:48 +10:00
Dave Cheney f3fc26f1c3 General server cleanups (#103)
- no need to initalise mutexes, their zero value is valid
- make NewServer simpler, 90% of use cases already had an
  io.ReadWriteCloser, in the single case that it it is easy to provide a
  simple wrapper.
2016-05-29 16:32:05 +10:00
Mark Sheahan 7e2e721fdf use ssh_FXP_STAT for Stat(); previously Stat() and Lstat() were both Lstat() 2016-04-26 12:07:21 -07:00
Matt Layher 8e47c759f5 server: remote rootDir parameter, as it does nothing 2016-01-16 12:41:01 -05:00
Matt Layher 403657b31e server: use functional options for NewServer 2016-01-11 11:52:51 -05:00
Matt Layher 051287be6d *: remove all named and naked returns 2016-01-07 15:56:04 -05:00
Matt Layher b348482b1a *: golint (part 1) 2016-01-07 12:10:24 -05:00
Dave Cheney 9e66bf3ae2 Merge pull request #72 from mdlayher/master
client: make Client.{Lstat,Open,Stat} satisfy os.IsNotExist
2016-01-04 12:14:20 +01:00
Matt Layher 3fa7dab0f1 client: add normaliseError, make Client.{Lstat,Open,Stat} satisfy os.IsNotExist 2016-01-03 16:10:58 -05:00
Dave Cheney 94fb4ddd0c Add -testserver permutation
Fixes #69

io.Pipe is unbuffered and provides a poor replacement for a net.Conn, use an os.Pipe instead.

Also skip some tests which don't work under the Go server as it runs in process.
2016-01-02 10:28:56 +01:00
Dave Cheney 53002ca6c0 Check that writing to a read only file returns an error
Fixes #28
2015-12-25 18:46:07 +01:00
Matthew Sykes f5afc8315a Add Getwd to client 2015-12-22 09:04:46 -05:00
Dave Cheney 167ae32ca7 Handle osx returning EPERM not ENOTDIR
Fixes #57

Also fix the integration tests to run on darwin by default.
2015-12-22 13:34:21 +09:00
DrJosh9000 f76972fd8d rm extra f.Name in test 2015-09-25 18:17:46 +10:00