]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/transaction_handlers_test.go
patch: v0.2.3
[rbdr/mobius] / hotline / transaction_handlers_test.go
index ec947c9feeb2ded12de6fb71c4309b2febdaf93d..e1dc8cbe9336baa4d7e141169a31e87bc6dfa28c 100644 (file)
@@ -1,11 +1,13 @@
 package hotline
 
 import (
 package hotline
 
 import (
+       "errors"
+       "fmt"
        "github.com/stretchr/testify/assert"
        "io/fs"
        "math/rand"
        "os"
        "github.com/stretchr/testify/assert"
        "io/fs"
        "math/rand"
        "os"
-       "reflect"
+       "strings"
        "testing"
 )
 
        "testing"
 )
 
@@ -227,6 +229,21 @@ func TestHandleGetUserNameList(t *testing.T) {
                                                                Icon:     &[]byte{0, 2},
                                                                Flags:    &[]byte{0, 3},
                                                                UserName: []byte{0, 4},
                                                                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},
+                                                               UserName: []byte{0, 4},
+                                                               Agreed:   true,
+                                                       },
+                                                       uint16(3): {
+                                                               ID:       &[]byte{0, 3},
+                                                               Icon:     &[]byte{0, 2},
+                                                               Flags:    &[]byte{0, 3},
+                                                               UserName: []byte{0, 4},
+                                                               Agreed:   false,
                                                        },
                                                },
                                        },
                                                        },
                                                },
                                        },
@@ -249,6 +266,10 @@ func TestHandleGetUserNameList(t *testing.T) {
                                                        fieldUsernameWithInfo,
                                                        []byte{00, 01, 00, 02, 00, 03, 00, 02, 00, 04},
                                                ),
                                                        fieldUsernameWithInfo,
                                                        []byte{00, 01, 00, 02, 00, 03, 00, 02, 00, 04},
                                                ),
+                                               NewField(
+                                                       fieldUsernameWithInfo,
+                                                       []byte{00, 02, 00, 02, 00, 03, 00, 02, 00, 04},
+                                               ),
                                        },
                                },
                        },
                                        },
                                },
                        },
@@ -262,9 +283,7 @@ func TestHandleGetUserNameList(t *testing.T) {
                                t.Errorf("HandleGetUserNameList() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
                                t.Errorf("HandleGetUserNameList() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
-                       if !reflect.DeepEqual(got, tt.want) {
-                               t.Errorf("HandleGetUserNameList() got = %v, want %v", got, tt.want)
-                       }
+                       assert.Equal(t, tt.want, got)
                })
        }
 }
                })
        }
 }
@@ -284,6 +303,14 @@ func TestHandleChatSend(t *testing.T) {
                        name: "sends chat msg transaction to all clients",
                        args: args{
                                cc: &ClientConn{
                        name: "sends chat msg transaction to all clients",
                        args: args{
                                cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendChat)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
                                        UserName: []byte{0x00, 0x01},
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                        UserName: []byte{0x00, 0x01},
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
@@ -334,10 +361,52 @@ func TestHandleChatSend(t *testing.T) {
                        },
                        wantErr: false,
                },
                        },
                        wantErr: false,
                },
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranChatSend, &[]byte{0, 1},
+                                       NewField(fieldData, []byte("hai")),
+                               ),
+                       },
+                       want: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to participate in chat.")),
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
                {
                        name: "sends chat msg as emote if fieldChatOptions is set",
                        args: args{
                                cc: &ClientConn{
                {
                        name: "sends chat msg as emote if fieldChatOptions is set",
                        args: args{
                                cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendChat)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
                                        UserName: []byte("Testy McTest"),
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                        UserName: []byte("Testy McTest"),
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
@@ -393,6 +462,14 @@ func TestHandleChatSend(t *testing.T) {
                        name: "only sends chat msg to clients with accessReadChat permission",
                        args: args{
                                cc: &ClientConn{
                        name: "only sends chat msg to clients with accessReadChat permission",
                        args: args{
                                cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessSendChat)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
                                        UserName: []byte{0x00, 0x01},
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
                                        UserName: []byte{0x00, 0x01},
                                        Server: &Server{
                                                Clients: map[uint16]*ClientConn{
@@ -434,7 +511,6 @@ func TestHandleChatSend(t *testing.T) {
                },
        }
        for _, tt := range tests {
                },
        }
        for _, tt := range tests {
-               rand.Seed(1) // reset seed between tests to make transaction IDs predictable
                t.Run(tt.name, func(t *testing.T) {
                        got, err := HandleChatSend(tt.args.cc, tt.args.t)
 
                t.Run(tt.name, func(t *testing.T) {
                        got, err := HandleChatSend(tt.args.cc, tt.args.t)
 
@@ -442,9 +518,7 @@ func TestHandleChatSend(t *testing.T) {
                                t.Errorf("HandleChatSend() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
                                t.Errorf("HandleChatSend() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
-                       if !assert.Equal(t, tt.want, got) {
-                               t.Errorf("HandleChatSend() got = %v, want %v", got, tt.want)
-                       }
+                       tranAssertEqual(t, tt.want, got)
                })
        }
 }
                })
        }
 }
@@ -469,7 +543,10 @@ func TestHandleGetFileInfo(t *testing.T) {
                                        ID: &[]byte{0x00, 0x01},
                                        Server: &Server{
                                                Config: &Config{
                                        ID: &[]byte{0x00, 0x01},
                                        Server: &Server{
                                                Config: &Config{
-                                                       FileRoot: "./test/config/Files/",
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return path + "/test/config/Files"
+                                                       }(),
                                                },
                                        },
                                },
                                                },
                                        },
                                },
@@ -477,19 +554,6 @@ func TestHandleGetFileInfo(t *testing.T) {
                                        tranGetFileInfo, nil,
                                        NewField(fieldFileName, []byte("testfile.txt")),
                                        NewField(fieldFilePath, []byte{0x00, 0x00}),
                                        tranGetFileInfo, nil,
                                        NewField(fieldFileName, []byte("testfile.txt")),
                                        NewField(fieldFilePath, []byte{0x00, 0x00}),
-                                       //NewField(fieldFilePath, []byte{
-                                       //      0x00, 0x03,
-                                       //      0x00, 0x00,
-                                       //      0x04,
-                                       //      0x74, 0x65, 0x73, 0x74,
-                                       //      0x00, 0x00,
-                                       //      0x06,
-                                       //      0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
-                                       //
-                                       //      0x00, 0x00,
-                                       //      0x05,
-                                       //      0x46, 0x69, 0x6c, 0x65, 73},
-                                       //),
                                ),
                        },
                        wantRes: []Transaction{
                                ),
                        },
                        wantRes: []Transaction{
@@ -503,11 +567,11 @@ func TestHandleGetFileInfo(t *testing.T) {
                                        Fields: []Field{
                                                NewField(fieldFileName, []byte("testfile.txt")),
                                                NewField(fieldFileTypeString, []byte("TEXT")),
                                        Fields: []Field{
                                                NewField(fieldFileName, []byte("testfile.txt")),
                                                NewField(fieldFileTypeString, []byte("TEXT")),
-                                               NewField(fieldFileCreatorString, []byte("TTXT")),
-                                               NewField(fieldFileComment, []byte("TODO")),
+                                               NewField(fieldFileCreatorString, []byte("ttxt")),
+                                               NewField(fieldFileComment, []byte{}),
                                                NewField(fieldFileType, []byte("TEXT")),
                                                NewField(fieldFileType, []byte("TEXT")),
-                                               NewField(fieldFileCreateDate, []byte{0x07, 0x70, 0x00, 0x00, 0xba, 0x74, 0x24, 0x73}),
-                                               NewField(fieldFileModifyDate, []byte{0x07, 0x70, 0x00, 0x00, 0xba, 0x74, 0x24, 0x73}),
+                                               NewField(fieldFileCreateDate, make([]byte, 8)),
+                                               NewField(fieldFileModifyDate, make([]byte, 8)),
                                                NewField(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
                                        },
                                },
                                                NewField(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
                                        },
                                },
@@ -524,6 +588,11 @@ func TestHandleGetFileInfo(t *testing.T) {
                                t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
                                t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr)
                                return
                        }
+
+                       // Clear the file timestamp fields to work around problems running the tests in multiple timezones
+                       // TODO: revisit how to test this by mocking the stat calls
+                       gotRes[0].Fields[5].Data = make([]byte, 8)
+                       gotRes[0].Fields[6].Data = make([]byte, 8)
                        if !assert.Equal(t, tt.wantRes, gotRes) {
                                t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
                        }
                        if !assert.Equal(t, tt.wantRes, gotRes) {
                                t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
                        }
@@ -566,7 +635,7 @@ func TestHandleNewFolder(t *testing.T) {
                                ),
                        },
                        setup: func() {
                                ),
                        },
                        setup: func() {
-                               mfs := MockFileStore{}
+                               mfs := &MockFileStore{}
                                mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
                                mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
@@ -600,7 +669,7 @@ func TestHandleNewFolder(t *testing.T) {
                                ),
                        },
                        setup: func() {
                                ),
                        },
                        setup: func() {
-                               mfs := MockFileStore{}
+                               mfs := &MockFileStore{}
                                mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
                                mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
@@ -637,7 +706,7 @@ func TestHandleNewFolder(t *testing.T) {
                                ),
                        },
                        setup: func() {
                                ),
                        },
                        setup: func() {
-                               mfs := MockFileStore{}
+                               mfs := &MockFileStore{}
                                mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
                                mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
@@ -659,11 +728,10 @@ func TestHandleNewFolder(t *testing.T) {
                                t: NewTransaction(
                                        tranNewFolder, &[]byte{0, 1},
                                        NewField(fieldFileName, []byte("../../testFolder")),
                                t: NewTransaction(
                                        tranNewFolder, &[]byte{0, 1},
                                        NewField(fieldFileName, []byte("../../testFolder")),
-
                                ),
                        },
                        setup: func() {
                                ),
                        },
                        setup: func() {
-                               mfs := MockFileStore{}
+                               mfs := &MockFileStore{}
                                mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
                                mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
@@ -677,7 +745,7 @@ func TestHandleNewFolder(t *testing.T) {
                                        ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
                                        ErrorCode: []byte{0, 0, 0, 0},
                                },
                                        ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
                                        ErrorCode: []byte{0, 0, 0, 0},
                                },
-                       },                      wantErr: false,
+                       }, wantErr: false,
                },
                {
                        name: "fieldFilePath does not allow directory traversal",
                },
                {
                        name: "fieldFilePath does not allow directory traversal",
@@ -705,7 +773,7 @@ func TestHandleNewFolder(t *testing.T) {
                                ),
                        },
                        setup: func() {
                                ),
                        },
                        setup: func() {
-                               mfs := MockFileStore{}
+                               mfs := &MockFileStore{}
                                mfs.On("Mkdir", "/Files/foo/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/foo/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
                                mfs.On("Mkdir", "/Files/foo/testFolder", fs.FileMode(0777)).Return(nil)
                                mfs.On("Stat", "/Files/foo/testFolder").Return(nil, os.ErrNotExist)
                                FS = mfs
@@ -719,7 +787,7 @@ func TestHandleNewFolder(t *testing.T) {
                                        ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
                                        ErrorCode: []byte{0, 0, 0, 0},
                                },
                                        ID:        []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
                                        ErrorCode: []byte{0, 0, 0, 0},
                                },
-                       },                      wantErr: false,
+                       }, wantErr: false,
                },
        }
        for _, tt := range tests {
                },
        }
        for _, tt := range tests {
@@ -738,3 +806,539 @@ func TestHandleNewFolder(t *testing.T) {
        }
 }
 
        }
 }
 
+func TestHandleUploadFile(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr bool
+       }{
+               {
+                       name: "when request is valid and user has Upload Anywhere permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Server: &Server{
+                                               FileTransfers: map[uint32]*FileTransfer{},
+                                       },
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessUploadFile)
+                                                       bits.Set(accessUploadAnywhere)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranUploadFile, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testFile")),
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x2e, 0x2e, 0x2f,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0xcb},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), // rand.Seed(1)
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
+               {
+                       name: "when user does not have required access",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               FileTransfers: map[uint32]*FileTransfer{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranUploadFile, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testFile")),
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x2e, 0x2e, 0x2f,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to upload files.")), // rand.Seed(1)
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       rand.Seed(1)
+                       gotRes, err := HandleUploadFile(tt.args.cc, tt.args.t)
+                       if (err != nil) != tt.wantErr {
+                               t.Errorf("HandleUploadFile() error = %v, wantErr %v", err, tt.wantErr)
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+
+               })
+       }
+}
+
+func TestHandleMakeAlias(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               setup   func()
+               args    args
+               wantRes []Transaction
+               wantErr bool
+       }{
+               {
+                       name: "with valid input and required permissions",
+                       setup: func() {
+                               mfs := &MockFileStore{}
+                               path, _ := os.Getwd()
+                               mfs.On(
+                                       "Symlink",
+                                       path+"/test/config/Files/foo/testFile",
+                                       path+"/test/config/Files/bar/testFile",
+                               ).Return(nil)
+                               FS = mfs
+                       },
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessMakeAlias)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return path + "/test/config/Files"
+                                                       }(),
+                                               },
+                                               Logger: NewTestLogger(),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testFile")),
+                                       NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
+                                       NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0xd1},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields:    []Field(nil),
+                               },
+                       },
+                       wantErr: false,
+               },
+               {
+                       name: "when symlink returns an error",
+                       setup: func() {
+                               mfs := &MockFileStore{}
+                               path, _ := os.Getwd()
+                               mfs.On(
+                                       "Symlink",
+                                       path+"/test/config/Files/foo/testFile",
+                                       path+"/test/config/Files/bar/testFile",
+                               ).Return(errors.New("ohno"))
+                               FS = mfs
+                       },
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessMakeAlias)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return path + "/test/config/Files"
+                                                       }(),
+                                               },
+                                               Logger: NewTestLogger(),
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testFile")),
+                                       NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
+                                       NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("Error creating alias")),
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
+               {
+                       name:  "when user does not have required permission",
+                       setup: func() {},
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Config: &Config{
+                                                       FileRoot: func() string {
+                                                               path, _ := os.Getwd()
+                                                               return path + "/test/config/Files"
+                                                       }(),
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranMakeFileAlias, &[]byte{0, 1},
+                                       NewField(fieldFileName, []byte("testFile")),
+                                       NewField(fieldFilePath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x2e, 0x2e, 0x2e,
+                                       }),
+                                       NewField(fieldFileNewPath, []byte{
+                                               0x00, 0x01,
+                                               0x00, 0x00,
+                                               0x03,
+                                               0x2e, 0x2e, 0x2e,
+                                       }),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to make aliases.")),
+                                       },
+                               },
+                       },
+                       wantErr: false,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.setup()
+
+                       gotRes, err := HandleMakeAlias(tt.args.cc, tt.args.t)
+                       if (err != nil) != tt.wantErr {
+                               t.Errorf("HandleMakeAlias(%v, %v)", tt.args.cc, tt.args.t)
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleGetUser(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when account is valid",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenUser)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{
+                                                       "guest": {
+                                                               Login:    "guest",
+                                                               Name:     "Guest",
+                                                               Password: "password",
+                                                               Access:   &[]byte{1},
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetUser, &[]byte{0, 1},
+                                       NewField(fieldUserLogin, []byte("guest")),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x01, 0x60},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields: []Field{
+                                               NewField(fieldUserName, []byte("Guest")),
+                                               NewField(fieldUserLogin, negateString([]byte("guest"))),
+                                               NewField(fieldUserPassword, []byte("password")),
+                                               NewField(fieldUserAccess, []byte{1}),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when user does not have required permission",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetUser, &[]byte{0, 1},
+                                       NewField(fieldUserLogin, []byte("nonExistentUser")),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to view accounts.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name: "when account does not exist",
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessOpenUser)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranGetUser, &[]byte{0, 1},
+                                       NewField(fieldUserLogin, []byte("nonExistentUser")),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("Account does not exist.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       gotRes, err := HandleGetUser(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleGetUser(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}
+
+func TestHandleDeleteUser(t *testing.T) {
+       type args struct {
+               cc *ClientConn
+               t  *Transaction
+       }
+       tests := []struct {
+               name    string
+               setup   func()
+               args    args
+               wantRes []Transaction
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "when user exists",
+                       setup: func() {
+                               mfs := &MockFileStore{}
+                               mfs.On("Remove", "Users/testuser.yaml").Return(nil)
+                               FS = mfs
+                       },
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       bits.Set(accessDeleteUser)
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{
+                                                       "testuser": {
+                                                               Login:    "testuser",
+                                                               Name:     "Testy McTest",
+                                                               Password: "password",
+                                                               Access:   &[]byte{1},
+                                                       },
+                                               },
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDeleteUser, &[]byte{0, 1},
+                                       NewField(fieldUserLogin, negateString([]byte("testuser"))),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0x1, 0x5f},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 0},
+                                       Fields:    []Field(nil),
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+               {
+                       name:  "when user does not have required permission",
+                       setup: func() {},
+                       args: args{
+                               cc: &ClientConn{
+                                       Account: &Account{
+                                               Access: func() *[]byte {
+                                                       var bits accessBitmap
+                                                       access := bits[:]
+                                                       return &access
+                                               }(),
+                                       },
+                                       Server: &Server{
+                                               Accounts: map[string]*Account{},
+                                       },
+                               },
+                               t: NewTransaction(
+                                       tranDeleteUser, &[]byte{0, 1},
+                                       NewField(fieldUserLogin, negateString([]byte("testuser"))),
+                               ),
+                       },
+                       wantRes: []Transaction{
+                               {
+                                       Flags:     0x00,
+                                       IsReply:   0x01,
+                                       Type:      []byte{0, 0x00},
+                                       ID:        []byte{0x9a, 0xcb, 0x04, 0x42},
+                                       ErrorCode: []byte{0, 0, 0, 1},
+                                       Fields: []Field{
+                                               NewField(fieldError, []byte("You are not allowed to delete accounts.")),
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.setup()
+                       gotRes, err := HandleDeleteUser(tt.args.cc, tt.args.t)
+                       if !tt.wantErr(t, err, fmt.Sprintf("HandleDeleteUser(%v, %v)", tt.args.cc, tt.args.t)) {
+                               return
+                       }
+
+                       tranAssertEqual(t, tt.wantRes, gotRes)
+               })
+       }
+}