-
Notifications
You must be signed in to change notification settings - Fork 1
/
sftp_test.go
75 lines (65 loc) · 2.1 KB
/
sftp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sftp
import (
"errors"
"io"
"syscall"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrFxCode(t *testing.T) {
table := []struct {
err error
fx fxerr
}{
{err: errors.New("random error"), fx: ErrSSHFxFailure},
{err: EBADF, fx: ErrSSHFxFailure},
{err: syscall.ENOENT, fx: ErrSSHFxNoSuchFile},
{err: syscall.EPERM, fx: ErrSSHFxPermissionDenied},
{err: io.EOF, fx: ErrSSHFxEOF},
}
for _, tt := range table {
statusErr := statusFromError(1, tt.err).StatusError
assert.Equal(t, statusErr.FxCode(), tt.fx)
}
}
func TestSupportedExtensions(t *testing.T) {
for _, supportedExtension := range supportedSFTPExtensions {
_, err := getSupportedExtensionByName(supportedExtension.Name)
assert.NoError(t, err)
}
_, err := getSupportedExtensionByName("invalid@example.com")
assert.Error(t, err)
}
func TestExtensions(t *testing.T) {
var supportedExtensions []string
for _, supportedExtension := range supportedSFTPExtensions {
supportedExtensions = append(supportedExtensions, supportedExtension.Name)
}
testSFTPExtensions := []string{"hardlink@openssh.com"}
expectedSFTPExtensions := []sshExtensionPair{
{"hardlink@openssh.com", "1"},
}
err := SetSFTPExtensions(testSFTPExtensions...)
assert.NoError(t, err)
assert.Equal(t, expectedSFTPExtensions, sftpExtensions)
invalidSFTPExtensions := []string{"invalid@example.com"}
err = SetSFTPExtensions(invalidSFTPExtensions...)
assert.Error(t, err)
assert.Equal(t, expectedSFTPExtensions, sftpExtensions)
emptySFTPExtensions := []string{}
expectedSFTPExtensions = []sshExtensionPair{}
err = SetSFTPExtensions(emptySFTPExtensions...)
assert.NoError(t, err)
assert.Equal(t, expectedSFTPExtensions, sftpExtensions)
// if we only have an invalid extension nothing will be modified.
invalidSFTPExtensions = []string{
"hardlink@openssh.com",
"invalid@example.com",
}
err = SetSFTPExtensions(invalidSFTPExtensions...)
assert.Error(t, err)
assert.Equal(t, expectedSFTPExtensions, sftpExtensions)
err = SetSFTPExtensions(supportedExtensions...)
assert.NoError(t, err)
assert.Equal(t, supportedSFTPExtensions, sftpExtensions)
}