]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/transaction_handlers_test.go
Implement "Refuse private messages" client preference
[rbdr/mobius] / hotline / transaction_handlers_test.go
index 0e2c9499c62fcddac2a8ce4ae31dd98be25823e1..fd66feae5af7a240ac947c6d9039fed939d6d046 100644 (file)
@@ -4,6 +4,7 @@ import (
        "errors"
        "fmt"
        "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/mock"
        "io/fs"
        "math/rand"
        "os"
@@ -36,13 +37,13 @@ func TestHandleSetChatSubject(t *testing.T) {
                                                                ClientConn: map[uint16]*ClientConn{
                                                                        uint16(1): {
                                                                                Account: &Account{
-                                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                                },
                                                                                ID: &[]byte{0, 1},
                                                                        },
                                                                        uint16(2): {
                                                                                Account: &Account{
-                                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                                },
                                                                                ID: &[]byte{0, 2},
                                                                        },
@@ -52,13 +53,13 @@ func TestHandleSetChatSubject(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
@@ -144,13 +145,13 @@ func TestHandleLeaveChat(t *testing.T) {
                                                                ClientConn: map[uint16]*ClientConn{
                                                                        uint16(1): {
                                                                                Account: &Account{
-                                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                                },
                                                                                ID: &[]byte{0, 1},
                                                                        },
                                                                        uint16(2): {
                                                                                Account: &Account{
-                                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                                },
                                                                                ID: &[]byte{0, 2},
                                                                        },
@@ -160,13 +161,13 @@ func TestHandleLeaveChat(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
@@ -228,22 +229,22 @@ func TestHandleGetUserNameList(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                ID:       &[]byte{0, 1},
-                                                               Icon:     &[]byte{0, 2},
-                                                               Flags:    &[]byte{0, 3},
+                                                               Icon:     []byte{0, 2},
+                                                               Flags:    []byte{0, 3},
                                                                UserName: []byte{0, 4},
                                                                Agreed:   true,
                                                        },
                                                        uint16(2): {
                                                                ID:       &[]byte{0, 2},
-                                                               Icon:     &[]byte{0, 2},
-                                                               Flags:    &[]byte{0, 3},
+                                                               Icon:     []byte{0, 2},
+                                                               Flags:    []byte{0, 3},
                                                                UserName: []byte{0, 4},
                                                                Agreed:   true,
                                                        },
                                                        uint16(3): {
                                                                ID:       &[]byte{0, 3},
-                                                               Icon:     &[]byte{0, 2},
-                                                               Flags:    &[]byte{0, 3},
+                                                               Icon:     []byte{0, 2},
+                                                               Flags:    []byte{0, 3},
                                                                UserName: []byte{0, 4},
                                                                Agreed:   false,
                                                        },
@@ -306,11 +307,10 @@ func TestHandleChatSend(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessSendChat)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        UserName: []byte{0x00, 0x01},
@@ -318,13 +318,13 @@ func TestHandleChatSend(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
@@ -368,10 +368,9 @@ func TestHandleChatSend(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -402,11 +401,10 @@ func TestHandleChatSend(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessSendChat)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        UserName: []byte("Testy McTest"),
@@ -414,13 +412,13 @@ func TestHandleChatSend(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
@@ -465,11 +463,10 @@ func TestHandleChatSend(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessSendChat)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        UserName: []byte{0x00, 0x01},
@@ -477,13 +474,16 @@ func TestHandleChatSend(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
-                                                               },
+                                                                       Access: func() accessBitmap {
+                                                                               var bits accessBitmap
+                                                                               bits.Set(accessReadChat)
+                                                                               return bits
+                                                                       }()},
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{0, 0, 0, 0, 0, 0, 0, 0},
+                                                                       Access: accessBitmap{0, 0, 0, 0, 0, 0, 0, 0},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
@@ -516,11 +516,10 @@ func TestHandleChatSend(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessSendChat)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        UserName: []byte{0x00, 0x01},
@@ -540,19 +539,19 @@ func TestHandleChatSend(t *testing.T) {
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(1): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+                                                                       Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255},
                                                                },
                                                                ID: &[]byte{0, 1},
                                                        },
                                                        uint16(2): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{0, 0, 0, 0, 0, 0, 0, 0},
+                                                                       Access: accessBitmap{0, 0, 0, 0, 0, 0, 0, 0},
                                                                },
                                                                ID: &[]byte{0, 2},
                                                        },
                                                        uint16(3): {
                                                                Account: &Account{
-                                                                       Access: &[]byte{0, 0, 0, 0, 0, 0, 0, 0},
+                                                                       Access: accessBitmap{0, 0, 0, 0, 0, 0, 0, 0},
                                                                },
                                                                ID: &[]byte{0, 3},
                                                        },
@@ -702,10 +701,9 @@ func TestHandleNewFolder(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -733,11 +731,10 @@ func TestHandleNewFolder(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessCreateFolder)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        ID: &[]byte{0, 1},
@@ -781,11 +778,10 @@ func TestHandleNewFolder(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessCreateFolder)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        ID: &[]byte{0, 1},
@@ -819,15 +815,14 @@ func TestHandleNewFolder(t *testing.T) {
                        wantErr: false,
                },
                {
-                       name: "when UnmarshalBinary returns an err",
+                       name: "when Write returns an err",
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessCreateFolder)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        ID: &[]byte{0, 1},
@@ -859,11 +854,10 @@ func TestHandleNewFolder(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessCreateFolder)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        ID: &[]byte{0, 1},
@@ -900,11 +894,10 @@ func TestHandleNewFolder(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessCreateFolder)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        ID: &[]byte{0, 1},
@@ -978,15 +971,20 @@ func TestHandleUploadFile(t *testing.T) {
                        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 {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessUploadFile)
                                                        bits.Set(accessUploadAnywhere)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -1020,15 +1018,11 @@ func TestHandleUploadFile(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
-                                       Server: &Server{
-                                               FileTransfers: map[uint32]*FileTransfer{},
-                                       },
                                },
                                t: NewTransaction(
                                        tranUploadFile, &[]byte{0, 1},
@@ -1086,12 +1080,12 @@ func TestHandleMakeAlias(t *testing.T) {
                        name: "with valid input and required permissions",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessMakeAlias)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1137,12 +1131,12 @@ func TestHandleMakeAlias(t *testing.T) {
                        name: "when symlink returns an error",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessMakeAlias)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1190,11 +1184,11 @@ func TestHandleMakeAlias(t *testing.T) {
                        name: "when user does not have required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1267,11 +1261,10 @@ func TestHandleGetUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessOpenUser)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1280,7 +1273,7 @@ func TestHandleGetUser(t *testing.T) {
                                                                Login:    "guest",
                                                                Name:     "Guest",
                                                                Password: "password",
-                                                               Access:   &[]byte{1},
+                                                               Access:   accessBitmap{},
                                                        },
                                                },
                                        },
@@ -1301,7 +1294,7 @@ func TestHandleGetUser(t *testing.T) {
                                                NewField(fieldUserName, []byte("Guest")),
                                                NewField(fieldUserLogin, negateString([]byte("guest"))),
                                                NewField(fieldUserPassword, []byte("password")),
-                                               NewField(fieldUserAccess, []byte{1}),
+                                               NewField(fieldUserAccess, []byte{0, 0, 0, 0, 0, 0, 0, 0}),
                                        },
                                },
                        },
@@ -1312,10 +1305,9 @@ func TestHandleGetUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1346,11 +1338,10 @@ func TestHandleGetUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessOpenUser)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1405,11 +1396,10 @@ func TestHandleDeleteUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessDeleteUser)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1418,7 +1408,7 @@ func TestHandleDeleteUser(t *testing.T) {
                                                                Login:    "testuser",
                                                                Name:     "Testy McTest",
                                                                Password: "password",
-                                                               Access:   &[]byte{1},
+                                                               Access:   accessBitmap{},
                                                        },
                                                },
                                                FS: func() *MockFileStore {
@@ -1450,10 +1440,9 @@ func TestHandleDeleteUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1508,11 +1497,10 @@ func TestHandleGetMsgs(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessNewsReadArt)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1542,10 +1530,9 @@ func TestHandleGetMsgs(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1599,10 +1586,9 @@ func TestHandleNewUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1656,10 +1642,9 @@ func TestHandleListUsers(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -1684,6 +1669,51 @@ func TestHandleListUsers(t *testing.T) {
                        },
                        wantErr: assert.NoError,
                },
+               {
+                       name: "when user has required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenUser)
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{
+                                                       "guest": {
+                                                               Name:     "guest",
+                                                               Login:    "guest",
+                                                               Password: "zz",
+                                                               Access:   accessBitmap{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) {
@@ -1713,10 +1743,9 @@ func TestHandleDownloadFile(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{},
@@ -1741,18 +1770,19 @@ func TestHandleDownloadFile(t *testing.T) {
                        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 {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessDownloadFile)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
                                                FS:            &OSFileStore{},
-                                               FileTransfers: make(map[uint32]*FileTransfer),
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
                                                Config: &Config{
                                                        FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
                                                },
@@ -1787,17 +1817,18 @@ func TestHandleDownloadFile(t *testing.T) {
                        name: "when client requests to resume 1k test file at offset 256",
                        args: args{
                                cc: &ClientConn{
-                                       Transfers: make(map[int][]*FileTransfer),
-                                       Account: &Account{
-                                               Access: func() *[]byte {
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               FileDownload: {},
+                                       }, Account: &Account{
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessDownloadFile)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
                                                FS: &OSFileStore{},
+
                                                // FS: func() *MockFileStore {
                                                //      path, _ := os.Getwd()
                                                //      testFile, err := os.Open(path + "/test/config/Files/testfile-1k")
@@ -1815,7 +1846,7 @@ func TestHandleDownloadFile(t *testing.T) {
                                                //
                                                //      return mfs
                                                // }(),
-                                               FileTransfers: make(map[uint32]*FileTransfer),
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
                                                Config: &Config{
                                                        FileRoot: func() string { path, _ := os.Getwd(); return path + "/test/config/Files" }(),
                                                },
@@ -1901,14 +1932,14 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is create user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                        },
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -1954,6 +1985,7 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is modify user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
                                                Logger: NewTestLogger(),
                                                Accounts: map[string]*Account{
@@ -1961,10 +1993,9 @@ func TestHandleUpdateUser(t *testing.T) {
                                                },
                                        },
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -2010,17 +2041,16 @@ func TestHandleUpdateUser(t *testing.T) {
                        name: "when action is delete user without required permission",
                        args: args{
                                cc: &ClientConn{
+                                       logger: NewTestLogger(),
                                        Server: &Server{
-                                               Logger: NewTestLogger(),
                                                Accounts: map[string]*Account{
                                                        "bbb": {},
                                                },
                                        },
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -2078,10 +2108,9 @@ func TestHandleDelNewsArt(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -2132,10 +2161,9 @@ func TestHandleDisconnectUser(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -2167,22 +2195,20 @@ func TestHandleDisconnectUser(t *testing.T) {
                                                        uint16(1): {
                                                                Account: &Account{
                                                                        Login: "unnamed",
-                                                                       Access: func() *[]byte {
+                                                                       Access: func() accessBitmap {
                                                                                var bits accessBitmap
                                                                                bits.Set(accessCannotBeDiscon)
-                                                                               access := bits[:]
-                                                                               return &access
+                                                                               return bits
                                                                        }(),
                                                                },
                                                        },
                                                },
                                        },
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessDisconUser)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                },
@@ -2229,16 +2255,54 @@ func TestHandleSendInstantMsg(t *testing.T) {
                wantRes []Transaction
                wantErr assert.ErrorAssertionFunc
        }{
+               {
+                       name: "without required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDelNewsArt,
+                                       &[]byte{0, 0},
+                               ),
+                       },
+                       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 send private messages.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
                {
                        name: "when client 1 sends a message to client 2",
                        args: args{
                                cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendPrivMsg)
+                                                       return bits
+                                               }(),
+                                       },
                                        ID:       &[]byte{0, 1},
                                        UserName: []byte("User1"),
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(2): {
                                                                AutoReply: []byte(nil),
+                                                               Flags:     []byte{0, 0},
                                                        },
                                                },
                                        },
@@ -2275,11 +2339,19 @@ func TestHandleSendInstantMsg(t *testing.T) {
                        name: "when client 2 has autoreply enabled",
                        args: args{
                                cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendPrivMsg)
+                                                       return bits
+                                               }(),
+                                       },
                                        ID:       &[]byte{0, 1},
                                        UserName: []byte("User1"),
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                                        uint16(2): {
+                                                               Flags:     []byte{0, 0},
                                                                ID:        &[]byte{0, 2},
                                                                UserName:  []byte("User2"),
                                                                AutoReply: []byte("autohai"),
@@ -2323,6 +2395,57 @@ func TestHandleSendInstantMsg(t *testing.T) {
                        },
                        wantErr: assert.NoError,
                },
+               {
+                       name: "when client 2 has refuse private messages enabled",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendPrivMsg)
+                                                       return bits
+                                               }(),
+                                       },
+                                       ID:       &[]byte{0, 1},
+                                       UserName: []byte("User1"),
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(2): {
+                                                               Flags:    []byte{255, 255},
+                                                               ID:       &[]byte{0, 2},
+                                                               UserName: []byte("User2"),
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranSendInstantMsg,
+                                       &[]byte{0, 1},
+                                       NewField(fieldData, []byte("hai")),
+                                       NewField(fieldUserID, []byte{0, 2}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               *NewTransaction(
+                                       tranServerMsg,
+                                       &[]byte{0, 1},
+                                       NewField(fieldData, []byte("User2 does not accept private messages.")),
+                                       NewField(fieldUserName, []byte("User2")),
+                                       NewField(fieldUserID, []byte{0, 2}),
+                                       NewField(fieldOptions, []byte{0, 2}),
+                               ),
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x0, 0x6c},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields:    []Field(nil),
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
@@ -2352,10 +2475,9 @@ func TestHandleDeleteFile(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -2412,11 +2534,10 @@ func TestHandleDeleteFile(t *testing.T) {
                        args: args{
                                cc: &ClientConn{
                                        Account: &Account{
-                                               Access: func() *[]byte {
+                                               Access: func() accessBitmap {
                                                        var bits accessBitmap
                                                        bits.Set(accessDeleteFile)
-                                                       access := bits[:]
-                                                       return &access
+                                                       return bits
                                                }(),
                                        },
                                        Server: &Server{
@@ -2485,3 +2606,915 @@ func TestHandleDeleteFile(t *testing.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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessGetClientInfo)
+                                                       return bits
+                                               }(),
+                                               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() accessBitmap {
+                                                                               var bits accessBitmap
+                                                                               bits.Set(accessGetClientInfo)
+                                                                               return bits
+                                                                       }(),
+                                                                       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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDisconUser)
+                                                       bits.Set(accessAnyName)
+                                                       return bits
+                                               }()},
+                                       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)
+               })
+       }
+}
+
+func TestHandleSetClientUserInfo(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when client does not have accessAnyName",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                                       ID:       &[]byte{0, 1},
+                                       UserName: []byte("Guest"),
+                                       Flags:    []byte{0, 1},
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(1): {
+                                                               ID: &[]byte{0, 1},
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranSetClientUserInfo, nil,
+                                       NewField(fieldUserIconID, []byte{0, 1}),
+                                       NewField(fieldUserName, []byte("NOPE")),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0x01, 0x2d},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldUserID, []byte{0, 1}),
+                                               NewField(fieldUserIconID, []byte{0, 1}),
+                                               NewField(fieldUserFlags, []byte{0, 1}),
+                                               NewField(fieldUserName, []byte("Guest"))},
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleSetClientUserInfo(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleSetClientUserInfo(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleDelNewsItem(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 permission to delete a news category",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: accessBitmap{},
+                                       },
+                                       ID: &[]byte{0, 1},
+                                       Server: &Server{
+                                               ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+                                                       "test": {
+                                                               Type:     []byte{0, 3},
+                                                               Count:    nil,
+                                                               NameSize: 0,
+                                                               Name:     "zz",
+                                                       },
+                                               }},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDelNewsItem, nil,
+                                       NewField(fieldNewsPath,
+                                               []byte{
+                                                       0, 1,
+                                                       0, 0,
+                                                       4,
+                                                       0x74, 0x65, 0x73, 0x74,
+                                               },
+                                       ),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       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 delete news categories.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user does not have permission to delete a news folder",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: accessBitmap{},
+                                       },
+                                       ID: &[]byte{0, 1},
+                                       Server: &Server{
+                                               ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+                                                       "testcat": {
+                                                               Type:     []byte{0, 2},
+                                                               Count:    nil,
+                                                               NameSize: 0,
+                                                               Name:     "test",
+                                                       },
+                                               }},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDelNewsItem, nil,
+                                       NewField(fieldNewsPath,
+                                               []byte{
+                                                       0, 1,
+                                                       0, 0,
+                                                       4,
+                                                       0x74, 0x65, 0x73, 0x74,
+                                               },
+                                       ),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       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 delete news folders.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user deletes a news folder",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessNewsDeleteFldr)
+                                                       return bits
+                                               }(),
+                                       },
+                                       ID: &[]byte{0, 1},
+                                       Server: &Server{
+                                               ConfigDir: "/fakeConfigRoot",
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("WriteFile", "/fakeConfigRoot/ThreadedNews.yaml", mock.Anything, mock.Anything).Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
+                                               ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+                                                       "testcat": {
+                                                               Type:     []byte{0, 2},
+                                                               Count:    nil,
+                                                               NameSize: 0,
+                                                               Name:     "test",
+                                                       },
+                                               }},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDelNewsItem, nil,
+                                       NewField(fieldNewsPath,
+                                               []byte{
+                                                       0, 1,
+                                                       0, 0,
+                                                       4,
+                                                       0x74, 0x65, 0x73, 0x74,
+                                               },
+                                       ),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x01, 0x7c},
+                                       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 := HandleDelNewsItem(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDelNewsItem(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleDownloadBanner(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "returns expected response",
+                       args: args{
+                               cc: &ClientConn{
+                                       ID: &[]byte{0, 1},
+                                       transfers: map[int]map[[4]byte]*FileTransfer{
+                                               bannerDownload: {},
+                                       },
+                                       Server: &Server{
+                                               ConfigDir: "/config",
+                                               Config: &Config{
+                                                       BannerFile: "banner.jpg",
+                                               },
+                                               fileTransfers: map[[4]byte]*FileTransfer{},
+                                               FS: func() *MockFileStore {
+                                                       mfi := &MockFileInfo{}
+                                                       mfi.On("Size").Return(int64(100))
+
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("Stat", "/config/banner.jpg").Return(mfi, nil)
+                                                       return mfs
+                                               }(),
+                                       },
+                               },
+                               t: NewTransaction(tranDownloadBanner, nil),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x00, 0xd4},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldRefNum, []byte{1, 2, 3, 4}),
+                                               NewField(fieldTransferSize, []byte{0, 0, 0, 0x64}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleDownloadBanner(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleTranOldPostNews(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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranOldPostNews, &[]byte{0, 1},
+                                       NewField(fieldData, []byte("hai")),
+                               ),
+                       },
+                       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 post news.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user posts news update",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessNewsPostArt)
+                                                       return bits
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               FS: func() *MockFileStore {
+                                                       mfs := &MockFileStore{}
+                                                       mfs.On("WriteFile", "/fakeConfigRoot/MessageBoard.txt", mock.Anything, mock.Anything).Return(nil, os.ErrNotExist)
+                                                       return mfs
+                                               }(),
+                                               ConfigDir: "/fakeConfigRoot",
+                                               Config:    &Config{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranOldPostNews, &[]byte{0, 1},
+                                       NewField(fieldData, []byte("hai")),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x67},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleTranOldPostNews(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleTranOldPostNews(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleInviteNewChat(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() accessBitmap {
+                                                       var bits accessBitmap
+                                                       return bits
+                                               }(),
+                                       },
+                               },
+                               t: NewTransaction(tranInviteNewChat, &[]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 request private chat.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when userA invites userB to new private chat",
+                       args: args{
+                               cc: &ClientConn{
+                                       ID: &[]byte{0, 1},
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenChat)
+                                                       return bits
+                                               }(),
+                                       },
+                                       UserName: []byte("UserA"),
+                                       Icon:     []byte{0, 1},
+                                       Flags:    []byte{0, 0},
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(2): {
+                                                               ID:       &[]byte{0, 2},
+                                                               UserName: []byte("UserB"),
+                                                               Flags:    []byte{0, 0},
+                                                       },
+                                               },
+                                               PrivateChats: make(map[uint32]*PrivateChat),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranInviteNewChat, &[]byte{0, 1},
+                                       NewField(fieldUserID, []byte{0, 2}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 2},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0, 0x71},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(fieldUserName, []byte("UserA")),
+                                               NewField(fieldUserID, []byte{0, 1}),
+                                       },
+                               },
+
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x70},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(fieldUserName, []byte("UserA")),
+                                               NewField(fieldUserID, []byte{0, 1}),
+                                               NewField(fieldUserIconID, []byte{0, 1}),
+                                               NewField(fieldUserFlags, []byte{0, 0}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when userA invites userB to new private chat, but UserB has refuse private chat enabled",
+                       args: args{
+                               cc: &ClientConn{
+                                       ID: &[]byte{0, 1},
+                                       Account: &Account{
+                                               Access: func() accessBitmap {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenChat)
+                                                       return bits
+                                               }(),
+                                       },
+                                       UserName: []byte("UserA"),
+                                       Icon:     []byte{0, 1},
+                                       Flags:    []byte{0, 0},
+                                       Server: &Server{
+                                               Clients: map[uint16]*ClientConn{
+                                                       uint16(2): {
+                                                               ID:       &[]byte{0, 2},
+                                                               UserName: []byte("UserB"),
+                                                               Flags:    []byte{255, 255},
+                                                       },
+                                               },
+                                               PrivateChats: make(map[uint32]*PrivateChat),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranInviteNewChat, &[]byte{0, 1},
+                                       NewField(fieldUserID, []byte{0, 2}),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x00,
+                                       Type:      []byte{0, 0x68},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldData, []byte("UserB does not accept private chats.")),
+                                               NewField(fieldUserName, []byte("UserB")),
+                                               NewField(fieldUserID, []byte{0, 2}),
+                                               NewField(fieldOptions, []byte{0, 2}),
+                                       },
+                               },
+                               {
+                                       clientID:  &[]byte{0, 1},
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x70},
+                                       ID:        []byte{0, 0, 0, 0},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+                                               NewField(fieldUserName, []byte("UserA")),
+                                               NewField(fieldUserID, []byte{0, 1}),
+                                               NewField(fieldUserIconID, []byte{0, 1}),
+                                               NewField(fieldUserFlags, []byte{0, 0}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       rand.Seed(1)
+                       gotRes, err := HandleInviteNewChat(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleInviteNewChat(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}