6 "github.com/stretchr/testify/assert"
14 func TestHandleSetChatSubject(t *testing.T) {
26 name: "sends chat subject to private chat members",
29 UserName: []byte{0x00, 0x01},
31 PrivateChats: map[uint32]*PrivateChat{
34 ClientConn: map[uint16]*ClientConn{
37 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
43 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
50 Clients: map[uint16]*ClientConn{
53 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
59 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
69 Type: []byte{0, 0x6a},
70 ID: []byte{0, 0, 0, 1},
71 ErrorCode: []byte{0, 0, 0, 0},
73 NewField(fieldChatID, []byte{0, 0, 0, 1}),
74 NewField(fieldChatSubject, []byte("Test Subject")),
80 clientID: &[]byte{0, 1},
83 Type: []byte{0, 0x77},
84 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
85 ErrorCode: []byte{0, 0, 0, 0},
87 NewField(fieldChatID, []byte{0, 0, 0, 1}),
88 NewField(fieldChatSubject, []byte("Test Subject")),
92 clientID: &[]byte{0, 2},
95 Type: []byte{0, 0x77},
96 ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1)
97 ErrorCode: []byte{0, 0, 0, 0},
99 NewField(fieldChatID, []byte{0, 0, 0, 1}),
100 NewField(fieldChatSubject, []byte("Test Subject")),
107 for _, tt := range tests {
108 rand.Seed(1) // reset seed between tests to make transaction IDs predictable
110 t.Run(tt.name, func(t *testing.T) {
111 got, err := HandleSetChatSubject(tt.args.cc, tt.args.t)
112 if (err != nil) != tt.wantErr {
113 t.Errorf("HandleSetChatSubject() error = %v, wantErr %v", err, tt.wantErr)
116 if !assert.Equal(t, tt.want, got) {
117 t.Errorf("HandleSetChatSubject() got = %v, want %v", got, tt.want)
123 func TestHandleLeaveChat(t *testing.T) {
135 name: "returns expected transactions",
140 PrivateChats: map[uint32]*PrivateChat{
142 ClientConn: map[uint16]*ClientConn{
145 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
151 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
158 Clients: map[uint16]*ClientConn{
161 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
167 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
174 t: NewTransaction(tranDeleteUser, nil, NewField(fieldChatID, []byte{0, 0, 0, 1})),
178 clientID: &[]byte{0, 1},
181 Type: []byte{0, 0x76},
182 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
183 ErrorCode: []byte{0, 0, 0, 0},
185 NewField(fieldChatID, []byte{0, 0, 0, 1}),
186 NewField(fieldUserID, []byte{0, 2}),
193 for _, tt := range tests {
195 t.Run(tt.name, func(t *testing.T) {
196 got, err := HandleLeaveChat(tt.args.cc, tt.args.t)
197 if (err != nil) != tt.wantErr {
198 t.Errorf("HandleLeaveChat() error = %v, wantErr %v", err, tt.wantErr)
201 if !assert.Equal(t, tt.want, got) {
202 t.Errorf("HandleLeaveChat() got = %v, want %v", got, tt.want)
208 func TestHandleGetUserNameList(t *testing.T) {
220 name: "replies with userlist transaction",
226 Clients: map[uint16]*ClientConn{
230 Flags: &[]byte{0, 3},
231 UserName: []byte{0, 4},
237 Flags: &[]byte{0, 3},
238 UserName: []byte{0, 4},
244 Flags: &[]byte{0, 3},
245 UserName: []byte{0, 4},
252 ID: []byte{0, 0, 0, 1},
258 clientID: &[]byte{1, 1},
262 ID: []byte{0, 0, 0, 1},
263 ErrorCode: []byte{0, 0, 0, 0},
266 fieldUsernameWithInfo,
267 []byte{00, 01, 00, 02, 00, 03, 00, 02, 00, 04},
270 fieldUsernameWithInfo,
271 []byte{00, 02, 00, 02, 00, 03, 00, 02, 00, 04},
279 for _, tt := range tests {
280 t.Run(tt.name, func(t *testing.T) {
281 got, err := HandleGetUserNameList(tt.args.cc, tt.args.t)
282 if (err != nil) != tt.wantErr {
283 t.Errorf("HandleGetUserNameList() error = %v, wantErr %v", err, tt.wantErr)
286 assert.Equal(t, tt.want, got)
291 func TestHandleChatSend(t *testing.T) {
303 name: "sends chat msg transaction to all clients",
307 Access: func() *[]byte {
308 var bits accessBitmap
309 bits.Set(accessSendChat)
314 UserName: []byte{0x00, 0x01},
316 Clients: map[uint16]*ClientConn{
319 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
325 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
334 NewField(fieldData, []byte("hai")),
340 clientID: &[]byte{0, 1},
343 Type: []byte{0, 0x6a},
344 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
345 ErrorCode: []byte{0, 0, 0, 0},
347 NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
351 clientID: &[]byte{0, 2},
354 Type: []byte{0, 0x6a},
355 ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1)
356 ErrorCode: []byte{0, 0, 0, 0},
358 NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
365 name: "when user does not have required permission",
369 Access: func() *[]byte {
370 var bits accessBitmap
376 Accounts: map[string]*Account{},
380 tranChatSend, &[]byte{0, 1},
381 NewField(fieldData, []byte("hai")),
388 Type: []byte{0, 0x00},
389 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
390 ErrorCode: []byte{0, 0, 0, 1},
392 NewField(fieldError, []byte("You are not allowed to participate in chat.")),
399 name: "sends chat msg as emote if fieldChatOptions is set",
403 Access: func() *[]byte {
404 var bits accessBitmap
405 bits.Set(accessSendChat)
410 UserName: []byte("Testy McTest"),
412 Clients: map[uint16]*ClientConn{
415 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
421 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
430 NewField(fieldData, []byte("performed action")),
431 NewField(fieldChatOptions, []byte{0x00, 0x01}),
437 clientID: &[]byte{0, 1},
440 Type: []byte{0, 0x6a},
441 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
442 ErrorCode: []byte{0, 0, 0, 0},
444 NewField(fieldData, []byte("\r*** Testy McTest performed action")),
448 clientID: &[]byte{0, 2},
451 Type: []byte{0, 0x6a},
452 ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1)
453 ErrorCode: []byte{0, 0, 0, 0},
455 NewField(fieldData, []byte("\r*** Testy McTest performed action")),
462 name: "only sends chat msg to clients with accessReadChat permission",
466 Access: func() *[]byte {
467 var bits accessBitmap
468 bits.Set(accessSendChat)
473 UserName: []byte{0x00, 0x01},
475 Clients: map[uint16]*ClientConn{
478 Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
484 Access: &[]byte{0, 0, 0, 0, 0, 0, 0, 0},
493 NewField(fieldData, []byte("hai")),
499 clientID: &[]byte{0, 1},
502 Type: []byte{0, 0x6a},
503 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
504 ErrorCode: []byte{0, 0, 0, 0},
506 NewField(fieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}),
513 for _, tt := range tests {
514 t.Run(tt.name, func(t *testing.T) {
515 got, err := HandleChatSend(tt.args.cc, tt.args.t)
517 if (err != nil) != tt.wantErr {
518 t.Errorf("HandleChatSend() error = %v, wantErr %v", err, tt.wantErr)
521 tranAssertEqual(t, tt.want, got)
526 func TestHandleGetFileInfo(t *testing.T) {
527 rand.Seed(1) // reset seed between tests to make transaction IDs predictable
536 wantRes []Transaction
540 name: "returns expected fields when a valid file is requested",
543 ID: &[]byte{0x00, 0x01},
546 FileRoot: func() string {
547 path, _ := os.Getwd()
548 return path + "/test/config/Files"
554 tranGetFileInfo, nil,
555 NewField(fieldFileName, []byte("testfile.txt")),
556 NewField(fieldFilePath, []byte{0x00, 0x00}),
559 wantRes: []Transaction{
561 clientID: &[]byte{0, 1},
564 Type: []byte{0, 0xce},
565 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
566 ErrorCode: []byte{0, 0, 0, 0},
568 NewField(fieldFileName, []byte("testfile.txt")),
569 NewField(fieldFileTypeString, []byte("TEXT")),
570 NewField(fieldFileCreatorString, []byte("ttxt")),
571 NewField(fieldFileComment, []byte{}),
572 NewField(fieldFileType, []byte("TEXT")),
573 NewField(fieldFileCreateDate, make([]byte, 8)),
574 NewField(fieldFileModifyDate, make([]byte, 8)),
575 NewField(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
582 for _, tt := range tests {
583 t.Run(tt.name, func(t *testing.T) {
584 rand.Seed(1) // reset seed between tests to make transaction IDs predictable
586 gotRes, err := HandleGetFileInfo(tt.args.cc, tt.args.t)
587 if (err != nil) != tt.wantErr {
588 t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr)
592 // Clear the file timestamp fields to work around problems running the tests in multiple timezones
593 // TODO: revisit how to test this by mocking the stat calls
594 gotRes[0].Fields[5].Data = make([]byte, 8)
595 gotRes[0].Fields[6].Data = make([]byte, 8)
596 if !assert.Equal(t, tt.wantRes, gotRes) {
597 t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
603 func TestHandleNewFolder(t *testing.T) {
612 wantRes []Transaction
616 name: "when path is nested",
627 tranNewFolder, &[]byte{0, 1},
628 NewField(fieldFileName, []byte("testFolder")),
629 NewField(fieldFilePath, []byte{
638 mfs := &MockFileStore{}
639 mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
640 mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
643 wantRes: []Transaction{
645 clientID: &[]byte{0, 1},
648 Type: []byte{0, 0xcd},
649 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
650 ErrorCode: []byte{0, 0, 0, 0},
656 name: "when path is not nested",
667 tranNewFolder, &[]byte{0, 1},
668 NewField(fieldFileName, []byte("testFolder")),
672 mfs := &MockFileStore{}
673 mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
674 mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
677 wantRes: []Transaction{
679 clientID: &[]byte{0, 1},
682 Type: []byte{0, 0xcd},
683 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
684 ErrorCode: []byte{0, 0, 0, 0},
690 name: "when UnmarshalBinary returns an err",
701 tranNewFolder, &[]byte{0, 1},
702 NewField(fieldFileName, []byte("testFolder")),
703 NewField(fieldFilePath, []byte{
709 mfs := &MockFileStore{}
710 mfs.On("Mkdir", "/Files/aaa/testFolder", fs.FileMode(0777)).Return(nil)
711 mfs.On("Stat", "/Files/aaa/testFolder").Return(nil, os.ErrNotExist)
714 wantRes: []Transaction{},
718 name: "fieldFileName does not allow directory traversal",
729 tranNewFolder, &[]byte{0, 1},
730 NewField(fieldFileName, []byte("../../testFolder")),
734 mfs := &MockFileStore{}
735 mfs.On("Mkdir", "/Files/testFolder", fs.FileMode(0777)).Return(nil)
736 mfs.On("Stat", "/Files/testFolder").Return(nil, os.ErrNotExist)
739 wantRes: []Transaction{
741 clientID: &[]byte{0, 1},
744 Type: []byte{0, 0xcd},
745 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
746 ErrorCode: []byte{0, 0, 0, 0},
751 name: "fieldFilePath does not allow directory traversal",
762 tranNewFolder, &[]byte{0, 1},
763 NewField(fieldFileName, []byte("testFolder")),
764 NewField(fieldFilePath, []byte{
776 mfs := &MockFileStore{}
777 mfs.On("Mkdir", "/Files/foo/testFolder", fs.FileMode(0777)).Return(nil)
778 mfs.On("Stat", "/Files/foo/testFolder").Return(nil, os.ErrNotExist)
781 wantRes: []Transaction{
783 clientID: &[]byte{0, 1},
786 Type: []byte{0, 0xcd},
787 ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
788 ErrorCode: []byte{0, 0, 0, 0},
793 for _, tt := range tests {
794 t.Run(tt.name, func(t *testing.T) {
797 gotRes, err := HandleNewFolder(tt.args.cc, tt.args.t)
798 if (err != nil) != tt.wantErr {
799 t.Errorf("HandleNewFolder() error = %v, wantErr %v", err, tt.wantErr)
802 if !tranAssertEqual(t, tt.wantRes, gotRes) {
803 t.Errorf("HandleNewFolder() gotRes = %v, want %v", gotRes, tt.wantRes)
809 func TestHandleUploadFile(t *testing.T) {
817 wantRes []Transaction
821 name: "when request is valid and user has Upload Anywhere permission",
825 FileTransfers: map[uint32]*FileTransfer{},
828 Access: func() *[]byte {
829 var bits accessBitmap
830 bits.Set(accessUploadFile)
831 bits.Set(accessUploadAnywhere)
838 tranUploadFile, &[]byte{0, 1},
839 NewField(fieldFileName, []byte("testFile")),
840 NewField(fieldFilePath, []byte{
848 wantRes: []Transaction{
852 Type: []byte{0, 0xcb},
853 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
854 ErrorCode: []byte{0, 0, 0, 0},
856 NewField(fieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), // rand.Seed(1)
863 name: "when user does not have required access",
867 Access: func() *[]byte {
868 var bits accessBitmap
874 FileTransfers: map[uint32]*FileTransfer{},
878 tranUploadFile, &[]byte{0, 1},
879 NewField(fieldFileName, []byte("testFile")),
880 NewField(fieldFilePath, []byte{
888 wantRes: []Transaction{
892 Type: []byte{0, 0x00},
893 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
894 ErrorCode: []byte{0, 0, 0, 1},
896 NewField(fieldError, []byte("You are not allowed to upload files.")), // rand.Seed(1)
903 for _, tt := range tests {
904 t.Run(tt.name, func(t *testing.T) {
906 gotRes, err := HandleUploadFile(tt.args.cc, tt.args.t)
907 if (err != nil) != tt.wantErr {
908 t.Errorf("HandleUploadFile() error = %v, wantErr %v", err, tt.wantErr)
912 tranAssertEqual(t, tt.wantRes, gotRes)
918 func TestHandleMakeAlias(t *testing.T) {
927 wantRes []Transaction
931 name: "with valid input and required permissions",
933 mfs := &MockFileStore{}
934 path, _ := os.Getwd()
937 path+"/test/config/Files/foo/testFile",
938 path+"/test/config/Files/bar/testFile",
945 Access: func() *[]byte {
946 var bits accessBitmap
947 bits.Set(accessMakeAlias)
954 FileRoot: func() string {
955 path, _ := os.Getwd()
956 return path + "/test/config/Files"
959 Logger: NewTestLogger(),
963 tranMakeFileAlias, &[]byte{0, 1},
964 NewField(fieldFileName, []byte("testFile")),
965 NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
966 NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
969 wantRes: []Transaction{
973 Type: []byte{0, 0xd1},
974 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
975 ErrorCode: []byte{0, 0, 0, 0},
976 Fields: []Field(nil),
982 name: "when symlink returns an error",
984 mfs := &MockFileStore{}
985 path, _ := os.Getwd()
988 path+"/test/config/Files/foo/testFile",
989 path+"/test/config/Files/bar/testFile",
990 ).Return(errors.New("ohno"))
996 Access: func() *[]byte {
997 var bits accessBitmap
998 bits.Set(accessMakeAlias)
1005 FileRoot: func() string {
1006 path, _ := os.Getwd()
1007 return path + "/test/config/Files"
1010 Logger: NewTestLogger(),
1014 tranMakeFileAlias, &[]byte{0, 1},
1015 NewField(fieldFileName, []byte("testFile")),
1016 NewField(fieldFilePath, EncodeFilePath(strings.Join([]string{"foo"}, "/"))),
1017 NewField(fieldFileNewPath, EncodeFilePath(strings.Join([]string{"bar"}, "/"))),
1020 wantRes: []Transaction{
1024 Type: []byte{0, 0x00},
1025 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1026 ErrorCode: []byte{0, 0, 0, 1},
1028 NewField(fieldError, []byte("Error creating alias")),
1035 name: "when user does not have required permission",
1040 Access: func() *[]byte {
1041 var bits accessBitmap
1048 FileRoot: func() string {
1049 path, _ := os.Getwd()
1050 return path + "/test/config/Files"
1056 tranMakeFileAlias, &[]byte{0, 1},
1057 NewField(fieldFileName, []byte("testFile")),
1058 NewField(fieldFilePath, []byte{
1064 NewField(fieldFileNewPath, []byte{
1072 wantRes: []Transaction{
1076 Type: []byte{0, 0x00},
1077 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1078 ErrorCode: []byte{0, 0, 0, 1},
1080 NewField(fieldError, []byte("You are not allowed to make aliases.")),
1087 for _, tt := range tests {
1088 t.Run(tt.name, func(t *testing.T) {
1091 gotRes, err := HandleMakeAlias(tt.args.cc, tt.args.t)
1092 if (err != nil) != tt.wantErr {
1093 t.Errorf("HandleMakeAlias(%v, %v)", tt.args.cc, tt.args.t)
1097 tranAssertEqual(t, tt.wantRes, gotRes)
1102 func TestHandleGetUser(t *testing.T) {
1110 wantRes []Transaction
1111 wantErr assert.ErrorAssertionFunc
1114 name: "when account is valid",
1118 Access: func() *[]byte {
1119 var bits accessBitmap
1120 bits.Set(accessOpenUser)
1126 Accounts: map[string]*Account{
1130 Password: "password",
1137 tranGetUser, &[]byte{0, 1},
1138 NewField(fieldUserLogin, []byte("guest")),
1141 wantRes: []Transaction{
1145 Type: []byte{0x01, 0x60},
1146 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1147 ErrorCode: []byte{0, 0, 0, 0},
1149 NewField(fieldUserName, []byte("Guest")),
1150 NewField(fieldUserLogin, negateString([]byte("guest"))),
1151 NewField(fieldUserPassword, []byte("password")),
1152 NewField(fieldUserAccess, []byte{1}),
1156 wantErr: assert.NoError,
1159 name: "when user does not have required permission",
1163 Access: func() *[]byte {
1164 var bits accessBitmap
1170 Accounts: map[string]*Account{},
1174 tranGetUser, &[]byte{0, 1},
1175 NewField(fieldUserLogin, []byte("nonExistentUser")),
1178 wantRes: []Transaction{
1182 Type: []byte{0, 0x00},
1183 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1184 ErrorCode: []byte{0, 0, 0, 1},
1186 NewField(fieldError, []byte("You are not allowed to view accounts.")),
1190 wantErr: assert.NoError,
1193 name: "when account does not exist",
1197 Access: func() *[]byte {
1198 var bits accessBitmap
1199 bits.Set(accessOpenUser)
1205 Accounts: map[string]*Account{},
1209 tranGetUser, &[]byte{0, 1},
1210 NewField(fieldUserLogin, []byte("nonExistentUser")),
1213 wantRes: []Transaction{
1217 Type: []byte{0, 0x00},
1218 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1219 ErrorCode: []byte{0, 0, 0, 1},
1221 NewField(fieldError, []byte("Account does not exist.")),
1225 wantErr: assert.NoError,
1228 for _, tt := range tests {
1229 t.Run(tt.name, func(t *testing.T) {
1230 gotRes, err := HandleGetUser(tt.args.cc, tt.args.t)
1231 if !tt.wantErr(t, err, fmt.Sprintf("HandleGetUser(%v, %v)", tt.args.cc, tt.args.t)) {
1235 tranAssertEqual(t, tt.wantRes, gotRes)
1240 func TestHandleDeleteUser(t *testing.T) {
1249 wantRes []Transaction
1250 wantErr assert.ErrorAssertionFunc
1253 name: "when user exists",
1255 mfs := &MockFileStore{}
1256 mfs.On("Remove", "Users/testuser.yaml").Return(nil)
1262 Access: func() *[]byte {
1263 var bits accessBitmap
1264 bits.Set(accessDeleteUser)
1270 Accounts: map[string]*Account{
1273 Name: "Testy McTest",
1274 Password: "password",
1281 tranDeleteUser, &[]byte{0, 1},
1282 NewField(fieldUserLogin, negateString([]byte("testuser"))),
1285 wantRes: []Transaction{
1289 Type: []byte{0x1, 0x5f},
1290 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1291 ErrorCode: []byte{0, 0, 0, 0},
1292 Fields: []Field(nil),
1295 wantErr: assert.NoError,
1298 name: "when user does not have required permission",
1303 Access: func() *[]byte {
1304 var bits accessBitmap
1310 Accounts: map[string]*Account{},
1314 tranDeleteUser, &[]byte{0, 1},
1315 NewField(fieldUserLogin, negateString([]byte("testuser"))),
1318 wantRes: []Transaction{
1322 Type: []byte{0, 0x00},
1323 ID: []byte{0x9a, 0xcb, 0x04, 0x42},
1324 ErrorCode: []byte{0, 0, 0, 1},
1326 NewField(fieldError, []byte("You are not allowed to delete accounts.")),
1330 wantErr: assert.NoError,
1333 for _, tt := range tests {
1334 t.Run(tt.name, func(t *testing.T) {
1336 gotRes, err := HandleDeleteUser(tt.args.cc, tt.args.t)
1337 if !tt.wantErr(t, err, fmt.Sprintf("HandleDeleteUser(%v, %v)", tt.args.cc, tt.args.t)) {
1341 tranAssertEqual(t, tt.wantRes, gotRes)