-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_test.go
101 lines (87 loc) · 1.97 KB
/
session_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2018 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ftp
import (
"net"
"testing"
"time"
)
func TestConnBuildPath(t *testing.T) {
c := &Session{
curDir: "",
}
pathtests := []struct {
in string
out string
}{
{"/", "/"},
{"one.txt", "/one.txt"},
{"/files/two.txt", "/files/two.txt"},
{"files/two.txt", "/files/two.txt"},
{"/../../../../etc/passwd", "/etc/passwd"},
{"rclone-test-roxarey8facabob5tuwetet4/hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠/z.txt", "/rclone-test-roxarey8facabob5tuwetet4/hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠/z.txt"},
}
for _, tt := range pathtests {
t.Run(tt.in, func(t *testing.T) {
s := c.buildPath(tt.in)
if s != tt.out {
t.Errorf("got %q, want %q", s, tt.out)
}
})
}
}
type mockConn struct {
ip net.IP
port int
}
func (m mockConn) Read(b []byte) (n int, err error) {
return 0, nil
}
func (m mockConn) Write(b []byte) (n int, err error) {
return 0, nil
}
func (m mockConn) Close() error {
return nil
}
func (m mockConn) LocalAddr() net.Addr {
return &net.TCPAddr{
IP: m.ip,
Port: m.port,
}
}
func (m mockConn) RemoteAddr() net.Addr {
return nil
}
func (m mockConn) SetDeadline(t time.Time) error {
return nil
}
func (m mockConn) SetReadDeadline(t time.Time) error {
return nil
}
func (m mockConn) SetWriteDeadline(t time.Time) error {
return nil
}
func TestPassiveListenIP(t *testing.T) {
c := &Session{
server: &Server{
Options: &Options{
PublicIP: "1.1.1.1",
},
},
}
if c.passiveListenIP() != "1.1.1.1" {
t.Fatalf("Expected passive listen IP to be 1.1.1.1 but got %s", c.passiveListenIP())
}
c = &Session{
Conn: mockConn{
ip: net.IPv4(1, 1, 1, 1),
},
server: &Server{
Options: &Options{},
},
}
if c.passiveListenIP() != "1.1.1.1" {
t.Fatalf("Expected passive listen IP to be 1.1.1.1 but got %s", c.passiveListenIP())
}
}