X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/67d1f7231b807771b57c8f0e63dd796a03130eaf..48ecb30da4babac9955891063f658207a31480ba:/hotline/transaction_handlers_test.go diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 751590e..9c0359f 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "io" "io/fs" "math/rand" "os" @@ -768,7 +769,6 @@ func TestHandleGetFileInfo(t *testing.T) { 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)), @@ -791,8 +791,8 @@ 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) { t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes) } @@ -1056,7 +1056,6 @@ func TestHandleNewFolder(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotRes, err := HandleNewFolder(tt.args.cc, tt.args.t) if (err != nil) != tt.wantErr { t.Errorf("HandleNewFolder() error = %v, wantErr %v", err, tt.wantErr) @@ -1175,7 +1174,6 @@ func TestHandleUploadFile(t *testing.T) { } tranAssertEqual(t, tt.wantRes, gotRes) - }) } } @@ -1407,7 +1405,7 @@ func TestHandleGetUser(t *testing.T) { ErrorCode: []byte{0, 0, 0, 0}, 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}), }, @@ -1535,7 +1533,7 @@ func TestHandleDeleteUser(t *testing.T) { }, t: NewTransaction( TranDeleteUser, &[]byte{0, 1}, - NewField(FieldUserLogin, negateString([]byte("testuser"))), + NewField(FieldUserLogin, encodeString([]byte("testuser"))), ), }, wantRes: []Transaction{ @@ -1566,7 +1564,7 @@ func TestHandleDeleteUser(t *testing.T) { }, t: NewTransaction( TranDeleteUser, &[]byte{0, 1}, - NewField(FieldUserLogin, negateString([]byte("testuser"))), + NewField(FieldUserLogin, encodeString([]byte("testuser"))), ), }, wantRes: []Transaction{ @@ -2440,7 +2438,7 @@ func TestHandleSendInstantMsg(t *testing.T) { }, }, }, - wantErr: assert.NoError, + wantErr: assert.Error, }, { name: "when client 1 sends a message to client 2", @@ -2860,9 +2858,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 }(), ), @@ -2982,7 +2980,7 @@ func TestHandleGetClientInfoText(t *testing.T) { ErrorCode: []byte{0, 0, 0, 0}, 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 @@ -3007,7 +3005,7 @@ None. None. -`, "\n", "\r", -1)), +`, "\n", "\r")), ), NewField(FieldUserName, []byte("Testy McTest")), }, @@ -3193,10 +3191,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", }, }}, }, @@ -3239,10 +3235,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", }, }}, }, @@ -3295,10 +3289,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", }, }}, }, @@ -3340,72 +3332,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 @@ -3781,7 +3707,6 @@ func TestHandleGetNewsArtNameList(t *testing.T) { return } tranAssertEqual(t, tt.wantRes, gotRes) - }) } } @@ -3850,11 +3775,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), }, }}, }, @@ -3886,7 +3809,7 @@ func TestHandleNewNewsFldr(t *testing.T) { 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{ @@ -3942,7 +3865,7 @@ func TestHandleNewNewsFldr(t *testing.T) { // }, // }, // wantErr: assert.Error, - //}, + // }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -3954,3 +3877,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) + }) + } +}