forked from mirror/afero
* Cleanup and add some todos
This commit is contained in:
parent
7d5dacc912
commit
acdc8aab04
20
sftp_test.go
20
sftp_test.go
|
@ -81,7 +81,8 @@ func (ctx *SftpFsContext) Disconnect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunSftpServer() {
|
// TODO for such a weird reason rootpath is "." when writing "file1" with afero sftp backend
|
||||||
|
func RunSftpServer(rootpath string) {
|
||||||
var (
|
var (
|
||||||
readOnly bool
|
readOnly bool
|
||||||
debugLevelStr string
|
debugLevelStr string
|
||||||
|
@ -91,15 +92,15 @@ func RunSftpServer() {
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.BoolVar(&readOnly, "R", false, "read-only server")
|
flag.BoolVar(&readOnly, "R", false, "read-only server")
|
||||||
flag.BoolVar(&debugStderr, "e", false, "debug to stderr")
|
flag.BoolVar(&debugStderr, "e", true, "debug to stderr")
|
||||||
flag.StringVar(&debugLevelStr, "l", "none", "debug level")
|
flag.StringVar(&debugLevelStr, "l", "none", "debug level")
|
||||||
flag.StringVar(&rootDir, "root", ".", "root directory")
|
flag.StringVar(&rootDir, "root", rootpath, "root directory")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
debugStream := ioutil.Discard
|
debugStream := ioutil.Discard
|
||||||
if debugStderr {
|
if debugStderr {
|
||||||
debugStream = os.Stderr
|
debugStream = os.Stderr
|
||||||
debugLevel = 1
|
debugLevel = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
// An SSH server is represented by a ServerConfig, which holds
|
// An SSH server is represented by a ServerConfig, which holds
|
||||||
|
@ -188,7 +189,7 @@ func RunSftpServer() {
|
||||||
}
|
}
|
||||||
}(requests)
|
}(requests)
|
||||||
|
|
||||||
server, err := sftp.NewServer(channel, channel, debugStream, debugLevel, readOnly, rootDir)
|
server, err := sftp.NewServer(channel, channel, debugStream, debugLevel, readOnly, rootpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +199,6 @@ func RunSftpServer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MakeSSHKeyPair make a pair of public and private keys for SSH access.
|
// MakeSSHKeyPair make a pair of public and private keys for SSH access.
|
||||||
// Public key is encoded in the format for inclusion in an OpenSSH authorized_keys file.
|
// Public key is encoded in the format for inclusion in an OpenSSH authorized_keys file.
|
||||||
// Private Key generated is PEM encoded
|
// Private Key generated is PEM encoded
|
||||||
|
@ -233,7 +233,7 @@ func TestSftpCreate(t *testing.T) {
|
||||||
os.Mkdir("./test", 0777)
|
os.Mkdir("./test", 0777)
|
||||||
MakeSSHKeyPair(1024, "./test/id_rsa.pub", "./test/id_rsa")
|
MakeSSHKeyPair(1024, "./test/id_rsa.pub", "./test/id_rsa")
|
||||||
|
|
||||||
go RunSftpServer()
|
go RunSftpServer("./test/")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
ctx, err := SftpConnect("test", "test", "localhost:2022")
|
ctx, err := SftpConnect("test", "test", "localhost:2022")
|
||||||
|
@ -256,8 +256,8 @@ func TestSftpCreate(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
file.Write([]byte("whohoo\n"))
|
file.Write([]byte("hello\t"))
|
||||||
file.WriteString("sdsdsdsdsddssdsd")
|
file.WriteString("world!\n")
|
||||||
|
|
||||||
f1, err := AppFs.Open("file1")
|
f1, err := AppFs.Open("file1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -270,5 +270,5 @@ func TestSftpCreate(t *testing.T) {
|
||||||
_, err = f1.Read(b)
|
_, err = f1.Read(b)
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
|
|
||||||
AppFs.Remove("test")
|
// TODO check here if "hello\tworld\n" is in buffer b
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue