X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/aeb97482e923b5c441dd59e3ca4a7e275ac2b4c2..153e2eac3b51a6a426556752fa2c532cfe53f026:/hotline/transaction_handlers_test.go diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index ff1a53c..9ea4a0a 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "io" "io/fs" - "math/rand" "os" "path/filepath" "strings" @@ -67,11 +67,8 @@ func TestHandleSetChatSubject(t *testing.T) { }, }, t: &Transaction{ - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0, 0, 0, 1}, - ErrorCode: []byte{0, 0, 0, 0}, + Type: [2]byte{0, 0x6a}, + ID: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldChatSubject, []byte("Test Subject")), @@ -80,24 +77,16 @@ func TestHandleSetChatSubject(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x77}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x77}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldChatSubject, []byte("Test Subject")), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x77}, - ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Type: [2]byte{0, 0x77}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldChatSubject, []byte("Test Subject")), @@ -108,15 +97,13 @@ func TestHandleSetChatSubject(t *testing.T) { }, } 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 := HandleSetChatSubject(tt.args.cc, tt.args.t) if (err != nil) != tt.wantErr { t.Errorf("HandleSetChatSubject() error = %v, wantErr %v", err, tt.wantErr) return } - if !assert.Equal(t, tt.want, got) { + if !tranAssertEqual(t, tt.want, got) { t.Errorf("HandleSetChatSubject() got = %v, want %v", got, tt.want) } }) @@ -178,12 +165,10 @@ func TestHandleLeaveChat(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x76}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x00, + Type: [2]byte{0, 0x76}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldUserID, []byte{0, 2}), @@ -194,14 +179,13 @@ func TestHandleLeaveChat(t *testing.T) { }, } for _, tt := range tests { - rand.Seed(1) t.Run(tt.name, func(t *testing.T) { got, err := HandleLeaveChat(tt.args.cc, tt.args.t) if (err != nil) != tt.wantErr { t.Errorf("HandleLeaveChat() error = %v, wantErr %v", err, tt.wantErr) return } - if !assert.Equal(t, tt.want, got) { + if !tranAssertEqual(t, tt.want, got) { t.Errorf("HandleLeaveChat() got = %v, want %v", got, tt.want) } }) @@ -242,19 +226,12 @@ func TestHandleGetUserNameList(t *testing.T) { }, }, }, - t: &Transaction{ - ID: []byte{0, 0, 0, 1}, - Type: []byte{0, 1}, - }, + t: &Transaction{}, }, want: []Transaction{ { - clientID: &[]byte{1, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 1}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{1, 1}, + IsReply: 0x01, Fields: []Field{ NewField( FieldUsernameWithInfo, @@ -330,23 +307,19 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x00, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Flags: 0x00, + IsReply: 0x00, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, @@ -392,23 +365,15 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, @@ -437,11 +402,8 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to participate in chat.")), }, @@ -487,23 +449,19 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x00, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte("\r*** Testy McTest performed action")), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Flags: 0x00, + IsReply: 0x00, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte("\r*** Testy McTest performed action")), }, @@ -549,23 +507,15 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte("\r Testy McTest: hello")), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0xf0, 0xc5, 0x34, 0x1e}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte("\r Testy McTest: hello")), }, @@ -613,12 +563,8 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, @@ -682,24 +628,16 @@ func TestHandleChatSend(t *testing.T) { }, want: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), }, }, { - clientID: &[]byte{0, 2}, - Flags: 0x00, - IsReply: 0x00, - Type: []byte{0, 0x6a}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 2}, + Type: [2]byte{0, 0x6a}, Fields: []Field{ NewField(FieldChatID, []byte{0, 0, 0, 1}), NewField(FieldData, []byte{0x0d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x01, 0x3a, 0x20, 0x20, 0x68, 0x61, 0x69}), @@ -723,8 +661,6 @@ func TestHandleChatSend(t *testing.T) { } func TestHandleGetFileInfo(t *testing.T) { - rand.Seed(1) // reset seed between tests to make transaction IDs predictable - type args struct { cc *ClientConn t *Transaction @@ -758,17 +694,13 @@ func TestHandleGetFileInfo(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Type: [2]byte{0, 0}, Fields: []Field{ NewField(FieldFileName, []byte("testfile.txt")), NewField(FieldFileTypeString, []byte("Text File")), NewField(FieldFileCreatorString, []byte("ttxt")), - NewField(FieldFileComment, []byte{}), NewField(FieldFileType, []byte("TEXT")), NewField(FieldFileCreateDate, make([]byte, 8)), NewField(FieldFileModifyDate, make([]byte, 8)), @@ -781,8 +713,6 @@ func TestHandleGetFileInfo(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - rand.Seed(1) // reset seed between tests to make transaction IDs predictable - gotRes, err := HandleGetFileInfo(tt.args.cc, tt.args.t) if (err != nil) != tt.wantErr { t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr) @@ -791,9 +721,10 @@ func TestHandleGetFileInfo(t *testing.T) { // Clear the fileWrapper timestamp fields to work around problems running the tests in multiple timezones // TODO: revisit how to test this by mocking the stat calls + gotRes[0].Fields[4].Data = make([]byte, 8) gotRes[0].Fields[5].Data = make([]byte, 8) - gotRes[0].Fields[6].Data = make([]byte, 8) - if !assert.Equal(t, tt.wantRes, gotRes) { + + if !tranAssertEqual(t, tt.wantRes, gotRes) { t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes) } }) @@ -829,11 +760,8 @@ func TestHandleNewFolder(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to create folders.")), }, @@ -878,12 +806,8 @@ func TestHandleNewFolder(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, }, }, wantErr: false, @@ -919,12 +843,8 @@ func TestHandleNewFolder(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, }, }, wantErr: false, @@ -995,12 +915,8 @@ func TestHandleNewFolder(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, }, }, wantErr: false, }, @@ -1044,12 +960,8 @@ func TestHandleNewFolder(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1) - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, }, }, wantErr: false, }, @@ -1115,11 +1027,7 @@ func TestHandleUploadFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), // rand.Seed(1) }, @@ -1151,11 +1059,8 @@ func TestHandleUploadFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to upload files.")), // rand.Seed(1) }, @@ -1166,7 +1071,6 @@ func TestHandleUploadFile(t *testing.T) { } 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) @@ -1230,12 +1134,8 @@ func TestHandleMakeAlias(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + IsReply: 0x01, + Fields: []Field(nil), }, }, wantErr: false, @@ -1281,11 +1181,8 @@ func TestHandleMakeAlias(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("Error creating alias")), }, @@ -1332,11 +1229,8 @@ func TestHandleMakeAlias(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to make aliases.")), }, @@ -1398,14 +1292,10 @@ func TestHandleGetUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldUserName, []byte("Guest")), - NewField(FieldUserLogin, negateString([]byte("guest"))), + NewField(FieldUserLogin, encodeString([]byte("guest"))), NewField(FieldUserPassword, []byte("password")), NewField(FieldUserAccess, []byte{0, 0, 0, 0, 0, 0, 0, 0}), }, @@ -1434,11 +1324,8 @@ func TestHandleGetUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to view accounts.")), }, @@ -1470,9 +1357,8 @@ func TestHandleGetUser(t *testing.T) { { Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + Type: [2]byte{0, 0}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("Account does not exist.")), }, @@ -1533,17 +1419,15 @@ func TestHandleDeleteUser(t *testing.T) { }, t: NewTransaction( TranDeleteUser, &[]byte{0, 1}, - NewField(FieldUserLogin, negateString([]byte("testuser"))), + NewField(FieldUserLogin, encodeString([]byte("testuser"))), ), }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + Flags: 0x00, + IsReply: 0x01, + Type: [2]byte{0, 0}, + Fields: []Field(nil), }, }, wantErr: assert.NoError, @@ -1564,16 +1448,13 @@ func TestHandleDeleteUser(t *testing.T) { }, t: NewTransaction( TranDeleteUser, &[]byte{0, 1}, - NewField(FieldUserLogin, negateString([]byte("testuser"))), + NewField(FieldUserLogin, encodeString([]byte("testuser"))), ), }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete accounts.")), }, @@ -1626,11 +1507,7 @@ func TestHandleGetMsgs(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldData, []byte("TEST")), }, @@ -1658,11 +1535,8 @@ func TestHandleGetMsgs(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to read news.")), }, @@ -1714,11 +1588,8 @@ func TestHandleNewUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to create new accounts.")), }, @@ -1756,11 +1627,8 @@ func TestHandleNewUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("Cannot create account with more access than yourself.")), }, @@ -1812,11 +1680,8 @@ func TestHandleListUsers(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to view accounts.")), }, @@ -1853,11 +1718,7 @@ func TestHandleListUsers(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldData, []byte{ 0x00, 0x04, 0x00, 0x66, 0x00, 0x05, 0x67, 0x75, 0x65, 0x73, 0x74, 0x00, 0x69, 0x00, 0x05, 0x98, @@ -1909,11 +1770,8 @@ func TestHandleDownloadFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to download files.")), }, @@ -1953,11 +1811,7 @@ func TestHandleDownloadFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), NewField(FieldWaitingCount, []byte{0x00, 0x00}), @@ -2044,11 +1898,7 @@ func TestHandleDownloadFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldRefNum, []byte{0x52, 0xfd, 0xfc, 0x07}), NewField(FieldWaitingCount, []byte{0x00, 0x00}), @@ -2124,11 +1974,8 @@ func TestHandleUpdateUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to create new accounts.")), }, @@ -2180,11 +2027,8 @@ func TestHandleUpdateUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to modify accounts.")), }, @@ -2222,11 +2066,8 @@ func TestHandleUpdateUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete accounts.")), }, @@ -2276,11 +2117,8 @@ func TestHandleDelNewsArt(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete news articles.")), }, @@ -2329,11 +2167,8 @@ func TestHandleDisconnectUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to disconnect users.")), }, @@ -2375,11 +2210,8 @@ func TestHandleDisconnectUser(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("unnamed is not allowed to be disconnected.")), }, @@ -2428,17 +2260,14 @@ func TestHandleSendInstantMsg(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to send private messages.")), }, }, }, - wantErr: assert.NoError, + wantErr: assert.Error, }, { name: "when client 1 sends a message to client 2", @@ -2479,13 +2308,9 @@ func TestHandleSendInstantMsg(t *testing.T) { NewField(FieldOptions, []byte{0, 1}), ), { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field(nil), }, }, wantErr: assert.NoError, @@ -2539,13 +2364,9 @@ func TestHandleSendInstantMsg(t *testing.T) { NewField(FieldOptions, []byte{0, 1}), ), { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field(nil), }, }, wantErr: assert.NoError, @@ -2590,13 +2411,9 @@ func TestHandleSendInstantMsg(t *testing.T) { NewField(FieldOptions, []byte{0, 2}), ), { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field(nil), }, }, wantErr: assert.NoError, @@ -2672,11 +2489,8 @@ func TestHandleDeleteFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete files.")), }, @@ -2737,12 +2551,8 @@ func TestHandleDeleteFile(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x0, 0x0, 0x0, 0x0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field(nil), + IsReply: 0x01, + Fields: []Field(nil), }, }, wantErr: assert.NoError, @@ -2805,11 +2615,8 @@ func TestHandleGetFileNameList(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to view drop boxes.")), }, @@ -2840,11 +2647,7 @@ func TestHandleGetFileNameList(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField( FieldFileNameWithInfo, @@ -2858,9 +2661,9 @@ func TestHandleGetFileNameList(t *testing.T) { NameScript: [2]byte{}, NameSize: [2]byte{0, 0x0b}, }, - name: []byte("testfile-1k"), + Name: []byte("testfile-1k"), } - b, _ := fnwi.MarshalBinary() + b, _ := io.ReadAll(&fnwi) return b }(), ), @@ -2914,11 +2717,8 @@ func TestHandleGetClientInfoText(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to get client info.")), }, @@ -2973,14 +2773,10 @@ func TestHandleGetClientInfoText(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, Fields: []Field{ NewField(FieldData, []byte( - strings.Replace(`Nickname: Testy McTest + strings.ReplaceAll(`Nickname: Testy McTest Name: test Account: test Address: 1.2.3.4:12345 @@ -3005,7 +2801,7 @@ None. None. -`, "\n", "\r", -1)), +`, "\n", "\r")), ), NewField(FieldUserName, []byte("Testy McTest")), }, @@ -3067,24 +2863,16 @@ func TestHandleTranAgreed(t *testing.T) { }, 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}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x7a}, Fields: []Field{ NewField(FieldBannerType, []byte("JPEG")), }, }, { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field{}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field{}, }, }, wantErr: assert.NoError, @@ -3141,12 +2929,8 @@ func TestHandleSetClientUserInfo(t *testing.T) { }, 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}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0x01, 0x2d}, Fields: []Field{ NewField(FieldUserID, []byte{0, 1}), NewField(FieldUserIconID, []byte{0, 1}), @@ -3191,10 +2975,8 @@ func TestHandleDelNewsItem(t *testing.T) { Server: &Server{ ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "test": { - Type: []byte{0, 3}, - Count: nil, - NameSize: 0, - Name: "zz", + Type: [2]byte{0, 3}, + Name: "zz", }, }}, }, @@ -3214,11 +2996,8 @@ func TestHandleDelNewsItem(t *testing.T) { wantRes: []Transaction{ { clientID: &[]byte{0, 1}, - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete news categories.")), }, @@ -3237,10 +3016,8 @@ func TestHandleDelNewsItem(t *testing.T) { Server: &Server{ ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "testcat": { - Type: []byte{0, 2}, - Count: nil, - NameSize: 0, - Name: "test", + Type: [2]byte{0, 2}, + Name: "test", }, }}, }, @@ -3260,11 +3037,8 @@ func TestHandleDelNewsItem(t *testing.T) { wantRes: []Transaction{ { clientID: &[]byte{0, 1}, - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to delete news folders.")), }, @@ -3293,10 +3067,8 @@ func TestHandleDelNewsItem(t *testing.T) { }(), ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "testcat": { - Type: []byte{0, 2}, - Count: nil, - NameSize: 0, - Name: "test", + Type: [2]byte{0, 2}, + Name: "test", }, }}, }, @@ -3315,13 +3087,9 @@ func TestHandleDelNewsItem(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field{}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field{}, }, }, wantErr: assert.NoError, @@ -3338,72 +3106,6 @@ func TestHandleDelNewsItem(t *testing.T) { } } -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{0, 0}, - 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 @@ -3433,11 +3135,8 @@ func TestHandleTranOldPostNews(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to post news.")), }, @@ -3473,11 +3172,7 @@ func TestHandleTranOldPostNews(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + IsReply: 0x01, }, }, wantErr: assert.NoError, @@ -3521,11 +3216,8 @@ func TestHandleInviteNewChat(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to request private chat.")), }, @@ -3566,12 +3258,8 @@ func TestHandleInviteNewChat(t *testing.T) { }, 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}, + clientID: &[]byte{0, 2}, + Type: [2]byte{0, 0x71}, Fields: []Field{ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}), NewField(FieldUserName, []byte("UserA")), @@ -3580,12 +3268,8 @@ func TestHandleInviteNewChat(t *testing.T) { }, { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, Fields: []Field{ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}), NewField(FieldUserName, []byte("UserA")), @@ -3630,12 +3314,8 @@ func TestHandleInviteNewChat(t *testing.T) { }, 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}, + clientID: &[]byte{0, 1}, + Type: [2]byte{0, 0x68}, Fields: []Field{ NewField(FieldData, []byte("UserB does not accept private chats.")), NewField(FieldUserName, []byte("UserB")), @@ -3644,12 +3324,8 @@ func TestHandleInviteNewChat(t *testing.T) { }, }, { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, Fields: []Field{ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}), NewField(FieldUserName, []byte("UserA")), @@ -3664,7 +3340,6 @@ func TestHandleInviteNewChat(t *testing.T) { } 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 @@ -3705,11 +3380,8 @@ func TestHandleGetNewsArtData(t *testing.T) { }, wantRes: []Transaction{ { - Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0x9a, 0xcb, 0x04, 0x42}, - ErrorCode: []byte{0, 0, 0, 1}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to read news.")), }, @@ -3762,8 +3434,8 @@ func TestHandleGetNewsArtNameList(t *testing.T) { { Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + Type: [2]byte{0, 0}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to read news.")), }, @@ -3771,6 +3443,75 @@ func TestHandleGetNewsArtNameList(t *testing.T) { }, wantErr: assert.NoError, }, + { + name: "when user has required access", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() accessBitmap { + var bits accessBitmap + bits.Set(accessNewsReadArt) + return bits + }(), + }, + Server: &Server{ + ThreadedNews: &ThreadedNews{ + Categories: map[string]NewsCategoryListData15{ + "Example Category": { + Type: [2]byte{0, 2}, + Name: "", + Articles: map[uint32]*NewsArtData{ + uint32(1): { + Title: "testTitle", + Poster: "testPoster", + Data: "testBody", + }, + }, + SubCats: nil, + GUID: [16]byte{}, + AddSN: [4]byte{}, + DeleteSN: [4]byte{}, + }, + }, + }, + + //Accounts: map[string]*Account{ + // "guest": { + // Name: "guest", + // Login: "guest", + // Password: "zz", + // Access: accessBitmap{255, 255, 255, 255, 255, 255, 255, 255}, + // }, + //}, + }, + }, + t: NewTransaction( + TranGetNewsArtNameList, + &[]byte{0, 1}, + // 00000000 00 01 00 00 10 45 78 61 6d 70 6c 65 20 43 61 74 |.....Example Cat| + // 00000010 65 67 6f 72 79 |egory| + NewField(FieldNewsPath, []byte{ + 0x00, 0x01, 0x00, 0x00, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, + }), + ), + }, + wantRes: []Transaction{ + { + IsReply: 0x01, + Fields: []Field{ + NewField(FieldNewsArtListData, []byte{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x09, 0x74, 0x65, 0x73, 0x74, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x50, + 0x6f, 0x73, 0x74, 0x65, 0x72, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, 0x61, 0x69, 0x6e, + 0x00, 0x08, + }, + ), + }, + }, + }, + wantErr: assert.NoError, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -3816,8 +3557,8 @@ func TestHandleNewNewsFldr(t *testing.T) { { Flags: 0x00, IsReply: 0x01, - Type: []byte{0, 0}, - ErrorCode: []byte{0, 0, 0, 1}, + Type: [2]byte{0, 0}, + ErrorCode: [4]byte{0, 0, 0, 1}, Fields: []Field{ NewField(FieldError, []byte("You are not allowed to create news folders.")), }, @@ -3847,11 +3588,9 @@ func TestHandleNewNewsFldr(t *testing.T) { }(), ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "test": { - Type: []byte{0, 2}, - Count: nil, - NameSize: 0, - Name: "test", - SubCats: make(map[string]NewsCategoryListData15), + Type: [2]byte{0, 2}, + Name: "test", + SubCats: make(map[string]NewsCategoryListData15), }, }}, }, @@ -3871,19 +3610,15 @@ func TestHandleNewNewsFldr(t *testing.T) { }, wantRes: []Transaction{ { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field{}, + clientID: &[]byte{0, 1}, + IsReply: 0x01, + Fields: []Field{}, }, }, wantErr: assert.NoError, }, //{ - // name: "when there is an error writing the threaded news file", + // Name: "when there is an error writing the threaded news file", // args: args{ // cc: &ClientConn{ // Account: &Account{ @@ -3931,8 +3666,8 @@ func TestHandleNewNewsFldr(t *testing.T) { // clientID: &[]byte{0, 1}, // Flags: 0x00, // IsReply: 0x01, - // Type: []byte{0, 0}, - // ErrorCode: []byte{0, 0, 0, 1}, + // Type: [2]byte{0, 0}, + // ErrorCode: [4]byte{0, 0, 0, 1}, // Fields: []Field{ // NewField(FieldError, []byte("Error creating news folder.")), // }, @@ -3951,3 +3686,27 @@ func TestHandleNewNewsFldr(t *testing.T) { }) } } + +func TestHandleDownloadBanner(t *testing.T) { + type args struct { + cc *ClientConn + t *Transaction + } + tests := []struct { + name string + args args + wantRes []Transaction + wantErr assert.ErrorAssertionFunc + }{ + // TODO: Add test cases. + } + 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 + } + assert.Equalf(t, tt.wantRes, gotRes, "HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t) + }) + } +}