github.com/pkg/sftp@v1.13.6/internal/encoding/ssh/filexfer/fxp_test.go (about) 1 package sshfx 2 3 import ( 4 "bufio" 5 "regexp" 6 "strconv" 7 "strings" 8 "testing" 9 ) 10 11 // This string data is copied verbatim from https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-13.txt 12 // except where commented that it was taken from a different source. 13 var fxpStandardsText = ` 14 SSH_FXP_INIT 1 15 SSH_FXP_VERSION 2 16 SSH_FXP_OPEN 3 17 SSH_FXP_CLOSE 4 18 SSH_FXP_READ 5 19 SSH_FXP_WRITE 6 20 SSH_FXP_LSTAT 7 21 SSH_FXP_FSTAT 8 22 SSH_FXP_SETSTAT 9 23 SSH_FXP_FSETSTAT 10 24 SSH_FXP_OPENDIR 11 25 SSH_FXP_READDIR 12 26 SSH_FXP_REMOVE 13 27 SSH_FXP_MKDIR 14 28 SSH_FXP_RMDIR 15 29 SSH_FXP_REALPATH 16 30 SSH_FXP_STAT 17 31 SSH_FXP_RENAME 18 32 SSH_FXP_READLINK 19 33 SSH_FXP_SYMLINK 20 // Deprecated in filexfer-13 added from filexfer-02 34 SSH_FXP_LINK 21 35 SSH_FXP_BLOCK 22 36 SSH_FXP_UNBLOCK 23 37 38 SSH_FXP_STATUS 101 39 SSH_FXP_HANDLE 102 40 SSH_FXP_DATA 103 41 SSH_FXP_NAME 104 42 SSH_FXP_ATTRS 105 43 44 SSH_FXP_EXTENDED 200 45 SSH_FXP_EXTENDED_REPLY 201 46 ` 47 48 func TestFxpNames(t *testing.T) { 49 whitespace := regexp.MustCompile(`[[:space:]]+`) 50 51 scan := bufio.NewScanner(strings.NewReader(fxpStandardsText)) 52 53 for scan.Scan() { 54 line := scan.Text() 55 if i := strings.Index(line, "//"); i >= 0 { 56 line = line[:i] 57 } 58 59 line = strings.TrimSpace(line) 60 if line == "" { 61 continue 62 } 63 64 fields := whitespace.Split(line, 2) 65 if len(fields) < 2 { 66 t.Fatalf("unexpected standards text line: %q", line) 67 } 68 69 name, value := fields[0], fields[1] 70 n, err := strconv.Atoi(value) 71 if err != nil { 72 t.Fatal("unexpected error:", err) 73 } 74 75 fxp := PacketType(n) 76 77 if got := fxp.String(); got != name { 78 t.Errorf("fxp name mismatch for %d: got %q, but want %q", n, got, name) 79 } 80 } 81 82 if err := scan.Err(); err != nil { 83 t.Fatal("unexpected error:", err) 84 } 85 }