]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/transaction_handlers_test.go
Fix panic on v1.2.3 login
[rbdr/mobius] / hotline / transaction_handlers_test.go
index c174822723ad435073dc9f08e96f273a314be518..5136c7d314934701bce8cb10938fab9ebb6b1434 100644 (file)
@@ -7,8 +7,10 @@ import (
        "io/fs"
        "math/rand"
        "os"
        "io/fs"
        "math/rand"
        "os"
+       "path/filepath"
        "strings"
        "testing"
        "strings"
        "testing"
+       "time"
 )
 
 func TestHandleSetChatSubject(t *testing.T) {
 )
 
 func TestHandleSetChatSubject(t *testing.T) {
@@ -625,10 +627,11 @@ func TestHandleGetFileInfo(t *testing.T) {
                                cc: &ClientConn{
                                        ID: &[]byte{0x00, 0x01},
                                        Server: &Server{
                                cc: &ClientConn{
                                        ID: &[]byte{0x00, 0x01},
                                        Server: &Server{
+                                               FS: &OSFileStore{},
                                                Config: &Config{
                                                        FileRoot: func() string {
                                                                path, _ := os.Getwd()
                                                Config: &Config{
                                                        FileRoot: func() string {
                                                                path, _ := os.Getwd()
-                                                               return path + "/test/config/Files"
+                                                               return filepath.Join(path, "/test/config/Files")
                                                        }(),
                                                },
                                        },
                                                        }(),
                                                },
                                        },
@@ -672,7 +675,7 @@ func TestHandleGetFileInfo(t *testing.T) {
                                return
                        }
 
                                return
                        }
 
-                       // Clear the file timestamp fields to work around problems running the tests in multiple timezones
+                       // Clear the fileWrapper timestamp fields to work around problems running the tests in multiple timezones
                        // TODO: revisit how to test this by mocking the stat calls
                        gotRes[0].Fields[5].Data = make([]byte, 8)
                        gotRes[0].Fields[6].Data = make([]byte, 8)
                        // TODO: revisit how to test this by mocking the stat calls
                        gotRes[0].Fields[5].Data = make([]byte, 8)
                        gotRes[0].Fields[6].Data = make([]byte, 8)
@@ -689,15 +692,13 @@ func TestHandleNewFolder(t *testing.T) {
                t  *Transaction
        }
        tests := []struct {
                t  *Transaction
        }
        tests := []struct {
-               setup   func()
                name    string
                args    args
                wantRes []Transaction
                wantErr bool
        }{
                {
                name    string
                args    args
                wantRes []Transaction
                wantErr bool
        }{
                {
-                       name:  "without required permission",
-                       setup: func() {},
+                       name: "without required permission",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -744,6 +745,12 @@ func TestHandleNewFolder(t *testing.T) {
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
+                                                       mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -757,12 +764,6 @@ func TestHandleNewFolder(t *testing.T) {
                                        }),
                                ),
                        },
                                        }),
                                ),
                        },
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
-                               mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
-                               FS = mfs
-                       },
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
@@ -792,6 +793,12 @@ func TestHandleNewFolder(t *testing.T) {
                                                Config: &Config{
                                                        FileRoot: "/Files",
                                                },
                                                Config: &Config{
                                                        FileRoot: "/Files",
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
+                                                       mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -799,12 +806,6 @@ func TestHandleNewFolder(t *testing.T) {
                                        NewField(fieldFileName, []byte("testFolder")),
                                ),
                        },
                                        NewField(fieldFileName, []byte("testFolder")),
                                ),
                        },
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
-                               mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
-                               FS = mfs
-                       },
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
@@ -834,6 +835,12 @@ func TestHandleNewFolder(t *testing.T) {
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
+                                                       mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -844,12 +851,6 @@ func TestHandleNewFolder(t *testing.T) {
                                        }),
                                ),
                        },
                                        }),
                                ),
                        },
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
-                               mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
-                               FS = mfs
-                       },
                        wantRes: []Transaction{},
                        wantErr: true,
                },
                        wantRes: []Transaction{},
                        wantErr: true,
                },
@@ -870,6 +871,12 @@ func TestHandleNewFolder(t *testing.T) {
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
+                                                       mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -877,12 +884,6 @@ func TestHandleNewFolder(t *testing.T) {
                                        NewField(fieldFileName, []byte("../../testFolder")),
                                ),
                        },
                                        NewField(fieldFileName, []byte("../../testFolder")),
                                ),
                        },
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
-                               mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
-                               FS = mfs
-                       },
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
@@ -911,6 +912,12 @@ func TestHandleNewFolder(t *testing.T) {
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
                                                Config: &Config{
                                                        FileRoot: "/Files/",
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Mkdir", "/Files/foo/testFolder", fs.FileMode(0777)).Return(nil)
+                                                       mfs.On("Stat", "/Files/foo/testFolder").Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -927,12 +934,6 @@ func TestHandleNewFolder(t *testing.T) {
                                        }),
                                ),
                        },
                                        }),
                                ),
                        },
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Mkdir", "/Files/foo/testFolder", fs.FileMode(0777)).Return(nil)
-                               mfs.On("Stat", "/Files/foo/testFolder").Return(nil, os.ErrNotExist)
-                               FS = mfs
-                       },
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
                        wantRes: []Transaction{
                                {
                                        clientID:  &[]byte{0, 1},
@@ -947,7 +948,6 @@ func TestHandleNewFolder(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       tt.setup()
 
                        gotRes, err := HandleNewFolder(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
 
                        gotRes, err := HandleNewFolder(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
@@ -978,7 +978,13 @@ func TestHandleUploadFile(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Server: &Server{
                        args: args{
                                cc: &ClientConn{
                                        Server: &Server{
-                                               FileTransfers: map[uint32]*FileTransfer{},
+                                               FS:            &OSFileStore{},
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
+                                               Config: &Config{
+                                                       FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
+                                               }},
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               FileUpload: {},
                                        },
                                        Account: &Account{
                                                Access: func() *[]byte {
                                        },
                                        Account: &Account{
                                                Access: func() *[]byte {
@@ -1026,9 +1032,6 @@ func TestHandleUploadFile(t *testing.T) {
                                                        return &access
                                                }(),
                                        },
                                                        return &access
                                                }(),
                                        },
-                                       Server: &Server{
-                                               FileTransfers: map[uint32]*FileTransfer{},
-                                       },
                                },
                                t: NewTransaction(
                                        tranUploadFile, &[]byte{0, 1},
                                },
                                t: NewTransaction(
                                        tranUploadFile, &[]byte{0, 1},
@@ -1078,25 +1081,15 @@ func TestHandleMakeAlias(t *testing.T) {
        }
        tests := []struct {
                name    string
        }
        tests := []struct {
                name    string
-               setup   func()
                args    args
                wantRes []Transaction
                wantErr bool
        }{
                {
                        name: "with valid input and required permissions",
                args    args
                wantRes []Transaction
                wantErr bool
        }{
                {
                        name: "with valid input and required permissions",
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               path, _ := os.Getwd()
-                               mfs.On(
-                                       "Symlink",
-                                       path+"/test/config/Files/foo/testFile",
-                                       path+"/test/config/Files/bar/testFile",
-                               ).Return(nil)
-                               FS = mfs
-                       },
                        args: args{
                                cc: &ClientConn{
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
@@ -1113,6 +1106,16 @@ func TestHandleMakeAlias(t *testing.T) {
                                                        }(),
                                                },
                                                Logger: NewTestLogger(),
                                                        }(),
                                                },
                                                Logger: NewTestLogger(),
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       path, _ := os.Getwd()
+                                                       mfs.On(
+                                                               "Symlink",
+                                                               path+"/test/config/Files/foo/testFile",
+                                                               path+"/test/config/Files/bar/testFile",
+                                                       ).Return(nil)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -1136,18 +1139,9 @@ func TestHandleMakeAlias(t *testing.T) {
                },
                {
                        name: "when symlink returns an error",
                },
                {
                        name: "when symlink returns an error",
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               path, _ := os.Getwd()
-                               mfs.On(
-                                       "Symlink",
-                                       path+"/test/config/Files/foo/testFile",
-                                       path+"/test/config/Files/bar/testFile",
-                               ).Return(errors.New("ohno"))
-                               FS = mfs
-                       },
                        args: args{
                                cc: &ClientConn{
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
@@ -1164,6 +1158,16 @@ func TestHandleMakeAlias(t *testing.T) {
                                                        }(),
                                                },
                                                Logger: NewTestLogger(),
                                                        }(),
                                                },
                                                Logger: NewTestLogger(),
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       path, _ := os.Getwd()
+                                                       mfs.On(
+                                                               "Symlink",
+                                                               path+"/test/config/Files/foo/testFile",
+                                                               path+"/test/config/Files/bar/testFile",
+                                                       ).Return(errors.New("ohno"))
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -1188,10 +1192,10 @@ func TestHandleMakeAlias(t *testing.T) {
                        wantErr: false,
                },
                {
                        wantErr: false,
                },
                {
-                       name:  "when user does not have required permission",
-                       setup: func() {},
+                       name: "when user does not have required permission",
                        args: args{
                                cc: &ClientConn{
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
@@ -1242,8 +1246,6 @@ func TestHandleMakeAlias(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       tt.setup()
-
                        gotRes, err := HandleMakeAlias(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleMakeAlias(%v, %v)", tt.args.cc, tt.args.t)
                        gotRes, err := HandleMakeAlias(tt.args.cc, tt.args.t)
                        if (err != nil) != tt.wantErr {
                                t.Errorf("HandleMakeAlias(%v, %v)", tt.args.cc, tt.args.t)
@@ -1400,18 +1402,12 @@ func TestHandleDeleteUser(t *testing.T) {
        }
        tests := []struct {
                name    string
        }
        tests := []struct {
                name    string
-               setup   func()
                args    args
                wantRes []Transaction
                wantErr assert.ErrorAssertionFunc
        }{
                {
                args    args
                wantRes []Transaction
                wantErr assert.ErrorAssertionFunc
        }{
                {
-                       name: "when user exists",
-                       setup: func() {
-                               mfs := &MockFileStore{}
-                               mfs.On("Remove", "Users/testuser.yaml").Return(nil)
-                               FS = mfs
-                       },
+                       name: "when user dataFile",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -1431,6 +1427,11 @@ func TestHandleDeleteUser(t *testing.T) {
                                                                Access:   &[]byte{1},
                                                        },
                                                },
                                                                Access:   &[]byte{1},
                                                        },
                                                },
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Remove", "Users/testuser.yaml").Return(nil)
+                                                       return mfs
+                                               }(),
                                        },
                                },
                                t: NewTransaction(
                                        },
                                },
                                t: NewTransaction(
@@ -1451,8 +1452,7 @@ func TestHandleDeleteUser(t *testing.T) {
                        wantErr: assert.NoError,
                },
                {
                        wantErr: assert.NoError,
                },
                {
-                       name:  "when user does not have required permission",
-                       setup: func() {},
+                       name: "when user does not have required permission",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
@@ -1488,7 +1488,6 @@ func TestHandleDeleteUser(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       tt.setup()
                        gotRes, err := HandleDeleteUser(tt.args.cc, tt.args.t)
                        if !tt.wantErr(t, err, fmt.Sprintf("HandleDeleteUser(%v, %v)", tt.args.cc, tt.args.t)) {
                                return
                        gotRes, err := HandleDeleteUser(tt.args.cc, tt.args.t)
                        if !tt.wantErr(t, err, fmt.Sprintf("HandleDeleteUser(%v, %v)", tt.args.cc, tt.args.t)) {
                                return
@@ -1691,6 +1690,52 @@ func TestHandleListUsers(t *testing.T) {
                        },
                        wantErr: assert.NoError,
                },
                        },
                        wantErr: assert.NoError,
                },
+               {
+                       name: "when user has required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenUser)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{
+                                                       "guest": {
+                                                               Name:     "guest",
+                                                               Login:    "guest",
+                                                               Password: "zz",
+                                                               Access:   &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(fieldUserID, []byte{0, 1}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x01, 0x2f},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte{
+                                                       0x00, 0x04, 0x00, 0x66, 0x00, 0x05, 0x67, 0x75, 0x65, 0x73, 0x74, 0x00, 0x69, 0x00, 0x05, 0x98,
+                                                       0x8a, 0x9a, 0x8c, 0x8b, 0x00, 0x6e, 0x00, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                       0x00, 0x6a, 0x00, 0x01, 0x78,
+                                               }),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
@@ -1748,7 +1793,9 @@ func TestHandleDownloadFile(t *testing.T) {
                        name: "with a valid file",
                        args: args{
                                cc: &ClientConn{
                        name: "with a valid file",
                        args: args{
                                cc: &ClientConn{
-                                       Transfers: make(map[int][]*FileTransfer),
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               FileDownload: {},
+                                       },
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
                                        Account: &Account{
                                                Access: func() *[]byte {
                                                        var bits accessBitmap
@@ -1758,7 +1805,8 @@ func TestHandleDownloadFile(t *testing.T) {
                                                }(),
                                        },
                                        Server: &Server{
                                                }(),
                                        },
                                        Server: &Server{
-                                               FileTransfers: make(map[uint32]*FileTransfer),
+                                               FS:            &OSFileStore{},
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
                                                Config: &Config{
                                                        FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
                                                },
                                                Config: &Config{
                                                        FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
                                                },
@@ -1789,12 +1837,101 @@ func TestHandleDownloadFile(t *testing.T) {
                        },
                        wantErr: assert.NoError,
                },
                        },
                        wantErr: assert.NoError,
                },
+               {
+                       name: "when client requests to resume 1k test file at offset 256",
+                       args: args{
+                               cc: &ClientConn{
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               FileDownload: {},
+                                       }, Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDownloadFile)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               FS: &OSFileStore{},
+
+                                               // FS: func() *MockFileStore {
+                                               //      path, _ := os.Getwd()
+                                               //      testFile, err := os.Open(path + "/test/config/Files/testfile-1k")
+                                               //      if err != nil {
+                                               //              panic(err)
+                                               //      }
+                                               //
+                                               //      mfi := &MockFileInfo{}
+                                               //      mfi.On("Mode").Return(fs.FileMode(0))
+                                               //      mfs := &MockFileStore{}
+                                               //      mfs.On("Stat", "/fakeRoot/Files/testfile.txt").Return(mfi, nil)
+                                               //      mfs.On("Open", "/fakeRoot/Files/testfile.txt").Return(testFile, nil)
+                                               //      mfs.On("Stat", "/fakeRoot/Files/.info_testfile.txt").Return(nil, errors.New("no"))
+                                               //      mfs.On("Stat", "/fakeRoot/Files/.rsrc_testfile.txt").Return(nil, errors.New("no"))
+                                               //
+                                               //      return mfs
+                                               // }(),
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
+                                               Config: &Config{
+                                                       FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
+                                               },
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       accessDownloadFile,
+                                       &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testfile-1k")),
+                                       NewField(fieldFilePath, []byte{0x00, 0x00}),
+                                       NewField(
+                                               fieldFileResumeData,
+                                               func() []byte {
+                                                       frd := FileResumeData{
+                                                               Format:    [4]byte{},
+                                                               Version:   [2]byte{},
+                                                               RSVD:      [34]byte{},
+                                                               ForkCount: [2]byte{0, 2},
+                                                               ForkInfoList: []ForkInfoList{
+                                                                       {
+                                                                               Fork:     [4]byte{0x44, 0x41, 0x54, 0x41}, // "DATA"
+                                                                               DataSize: [4]byte{0, 0, 0x01, 0x00},       // request offset 256
+                                                                               RSVDA:    [4]byte{},
+                                                                               RSVDB:    [4]byte{},
+                                                                       },
+                                                                       {
+                                                                               Fork:     [4]byte{0x4d, 0x41, 0x43, 0x52}, // "MACR"
+                                                                               DataSize: [4]byte{0, 0, 0, 0},
+                                                                               RSVDA:    [4]byte{},
+                                                                               RSVDB:    [4]byte{},
+                                                                       },
+                                                               },
+                                                       }
+                                                       b, _ := frd.BinaryMarshal()
+                                                       return b
+                                               }(),
+                                       ),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x2},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(fieldWaitingCount, []byte{0x00, 0x00}),
+                                               NewField(fieldTransferSize, []byte{0x00, 0x00, 0x03, 0x8d}),
+                                               NewField(fieldFileSize, []byte{0x00, 0x00, 0x03, 0x00}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
-                       // reset the rand seed so that the random fieldRefNum will be deterministic
-                       rand.Seed(1)
-
                        gotRes, err := HandleDownloadFile(tt.args.cc, tt.args.t)
                        if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadFile(%v, %v)", tt.args.cc, tt.args.t)) {
                                return
                        gotRes, err := HandleDownloadFile(tt.args.cc, tt.args.t)
                        if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadFile(%v, %v)", tt.args.cc, tt.args.t)) {
                                return
@@ -1820,6 +1957,7 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is create user without required permission",
                        args: args{
                                cc: &ClientConn{
                        name: "when action is create user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                        },
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                        },
@@ -1873,6 +2011,7 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is modify user without required permission",
                        args: args{
                                cc: &ClientConn{
                        name: "when action is modify user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                                Accounts: map[string]*Account{
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                                Accounts: map[string]*Account{
@@ -1929,8 +2068,8 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is delete user without required permission",
                        args: args{
                                cc: &ClientConn{
                        name: "when action is delete user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
                                        Server: &Server{
-                                               Logger: NewTestLogger(),
                                                Accounts: map[string]*Account{
                                                        "bbb": {},
                                                },
                                                Accounts: map[string]*Account{
                                                        "bbb": {},
                                                },
@@ -2254,3 +2393,497 @@ func TestHandleSendInstantMsg(t *testing.T) {
                })
        }
 }
                })
        }
 }
+
+func TestHandleDeleteFile(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user does not have required permission to delete a folder",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               return "/fakeRoot/Files"
+                                                       }(),
+                                               },
+                                               FS: func() *MockFileStore {
+                                                       mfi := &MockFileInfo{}
+                                                       mfi.On("Mode").Return(fs.FileMode(0))
+                                                       mfi.On("Size").Return(int64(100))
+                                                       mfi.On("ModTime").Return(time.Parse(time.Layout, time.Layout))
+                                                       mfi.On("IsDir").Return(false)
+                                                       mfi.On("Name").Return("testfile")
+
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/testfile").Return(mfi, nil)
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/.info_testfile").Return(nil, errors.New("err"))
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/.rsrc_testfile").Return(nil, errors.New("err"))
+
+                                                       return mfs
+                                               }(),
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDeleteFile, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testfile")),
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x61, 0x61, 0x61,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to delete files.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "deletes all associated metadata files",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDeleteFile)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               return "/fakeRoot/Files"
+                                                       }(),
+                                               },
+                                               FS: func() *MockFileStore {
+                                                       mfi := &MockFileInfo{}
+                                                       mfi.On("Mode").Return(fs.FileMode(0))
+                                                       mfi.On("Size").Return(int64(100))
+                                                       mfi.On("ModTime").Return(time.Parse(time.Layout, time.Layout))
+                                                       mfi.On("IsDir").Return(false)
+                                                       mfi.On("Name").Return("testfile")
+
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/testfile").Return(mfi, nil)
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/.info_testfile").Return(nil, errors.New("err"))
+                                                       mfs.On("Stat", "/fakeRoot/Files/aaa/.rsrc_testfile").Return(nil, errors.New("err"))
+
+                                                       mfs.On("RemoveAll", "/fakeRoot/Files/aaa/testfile").Return(nil)
+                                                       mfs.On("Remove", "/fakeRoot/Files/aaa/testfile.incomplete").Return(nil)
+                                                       mfs.On("Remove", "/fakeRoot/Files/aaa/.rsrc_testfile").Return(nil)
+                                                       mfs.On("Remove", "/fakeRoot/Files/aaa/.info_testfile").Return(nil)
+
+                                                       return mfs
+                                               }(),
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDeleteFile, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testfile")),
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x61, 0x61, 0x61,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x0, 0xcc},
+                                       ID:        []byte{0x0, 0x0, 0x0, 0x0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields:    []Field(nil),
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleDeleteFile(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDeleteFile(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+
+                       tt.args.cc.Server.FS.(*MockFileStore).AssertExpectations(t)
+               })
+       }
+}
+
+func TestHandleGetFileNameList(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when fieldFilePath is a drop box, but user does not have accessViewDropBoxes ",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return filepath.Join(path, "/test/config/Files/getFileNameListTestDir")
+                                                       }(),
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetFileNameList, &[]byte{0, 1},
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x08,
+                                               0x64, 0x72, 0x6f, 0x70, 0x20, 0x62, 0x6f, 0x78, // "drop box"
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to view drop boxes.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "with file root",
+                       args: args{
+                               cc: &ClientConn{
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return filepath.Join(path, "/test/config/Files/getFileNameListTestDir")
+                                                       }(),
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetFileNameList, &[]byte{0, 1},
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x00,
+                                               0x00, 0x00,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0xc8},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(
+                                                       fieldFileNameWithInfo,
+                                                       func() []byte {
+                                                               fnwi := FileNameWithInfo{
+                                                                       fileNameWithInfoHeader: fileNameWithInfoHeader{
+                                                                               Type:       [4]byte{0x54, 0x45, 0x58, 0x54},
+                                                                               Creator:    [4]byte{0x54, 0x54, 0x58, 0x54},
+                                                                               FileSize:   [4]byte{0, 0, 0x04, 0},
+                                                                               RSVD:       [4]byte{},
+                                                                               NameScript: [2]byte{},
+                                                                               NameSize:   [2]byte{0, 0x0b},
+                                                                       },
+                                                                       name: []byte("testfile-1k"),
+                                                               }
+                                                               b, _ := fnwi.MarshalBinary()
+                                                               return b
+                                                       }(),
+                                               ),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleGetFileNameList(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleGetFileNameList(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleGetClientInfoText(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(fieldUserID, []byte{0, 1}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to get client info.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "with a valid user",
+                       args: args{
+                               cc: &ClientConn{
+                                       UserName:   []byte("Testy McTest"),
+                                       RemoteAddr: "1.2.3.4:12345",
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessGetClientInfo)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                               Name:  "test",
+                                               Login: "test",
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(1): {
+                                                               UserName:   []byte("Testy McTest"),
+                                                               RemoteAddr: "1.2.3.4:12345",
+                                                               Account: &Account{
+                                                                       Access: func() *[]byte {
+                                                                               var bits accessBitmap
+                                                                               bits.Set(accessGetClientInfo)
+                                                                               access := bits[:]
+                                                                               return &access
+                                                                       }(),
+                                                                       Name:  "test",
+                                                                       Login: "test",
+                                                               },
+                                                       },
+                                               },
+                                       },
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               FileDownload:   {},
+                                               FileUpload:     {},
+                                               FolderDownload: {},
+                                               FolderUpload:   {},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetClientInfoText, &[]byte{0, 1},
+                                       NewField(fieldUserID, []byte{0, 1}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x1, 0x2f},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte(
+                                                       strings.Replace(`Nickname:   Testy McTest
+Name:       test
+Account:    test
+Address:    1.2.3.4:12345
+
+-------- File Downloads ---------
+
+None.
+
+------- Folder Downloads --------
+
+None.
+
+--------- File Uploads ----------
+
+None.
+
+-------- Folder Uploads ---------
+
+None.
+
+------- Waiting Downloads -------
+
+None.
+
+`, "\n", "\r", -1)),
+                                               ),
+                                               NewField(fieldUserName, []byte("Testy McTest")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleGetClientInfoText(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleGetClientInfoText(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleTranAgreed(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "normal request flow",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDisconUser)
+                                                       bits.Set(accessAnyName)
+                                                       access := bits[:]
+                                                       return &access
+                                               }()},
+                                       Icon:    &[]byte{0, 1},
+                                       Flags:   &[]byte{0, 1},
+                                       Version: &[]byte{0, 1},
+                                       ID:      &[]byte{0, 1},
+                                       logger:  NewTestLogger(),
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       BannerFile: "banner.jpg",
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranAgreed, nil,
+                                       NewField(fieldUserName, []byte("username")),
+                                       NewField(fieldUserIconID, []byte{0, 1}),
+                                       NewField(fieldOptions, []byte{0, 0}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0, 0x7a},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldBannerType, []byte("JPEG")),
+                                       },
+                               },
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x79},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields:    []Field{},
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleTranAgreed(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleTranAgreed(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}