aboutsummaryrefslogtreecommitdiff
path: root/hotline/transaction_handlers_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-10 18:52:46 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-10 13:52:46 -0700
commit72dd37f1abb2b550aaaac48eac677403d5664797 (patch)
tree5c431679475647f2f932f2934e6acd65090d2499 /hotline/transaction_handlers_test.go
parent9d41bcdf29778eab3253f8e31670baf64ad389bf (diff)
Add tests and clean up
Diffstat (limited to 'hotline/transaction_handlers_test.go')
-rw-r--r--hotline/transaction_handlers_test.go145
1 files changed, 141 insertions, 4 deletions
diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go
index cf05a99..e62cce2 100644
--- a/hotline/transaction_handlers_test.go
+++ b/hotline/transaction_handlers_test.go
@@ -22,7 +22,7 @@ func TestHandleSetChatSubject(t *testing.T) {
name: "sends chat subject to private chat members",
args: args{
cc: &ClientConn{
- UserName: &[]byte{0x00, 0x01},
+ UserName: []byte{0x00, 0x01},
Server: &Server{
PrivateChats: map[uint32]*PrivateChat{
uint32(1): {
@@ -224,7 +224,7 @@ func TestHandleGetUserNameList(t *testing.T) {
ID: &[]byte{0, 1},
Icon: &[]byte{0, 2},
Flags: &[]byte{0, 3},
- UserName: &[]byte{0, 4},
+ UserName: []byte{0, 4},
},
},
},
@@ -282,7 +282,7 @@ func TestHandleChatSend(t *testing.T) {
name: "sends chat msg transaction to all clients",
args: args{
cc: &ClientConn{
- UserName: &[]byte{0x00, 0x01},
+ UserName: []byte{0x00, 0x01},
Server: &Server{
Clients: map[uint16]*ClientConn{
uint16(1): {
@@ -333,10 +333,65 @@ func TestHandleChatSend(t *testing.T) {
wantErr: false,
},
{
+ name: "sends chat msg as emote if fieldChatOptions is set",
+ args: args{
+ cc: &ClientConn{
+ UserName: []byte("Testy McTest"),
+ Server: &Server{
+ Clients: map[uint16]*ClientConn{
+ uint16(1): {
+ Account: &Account{
+ Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+ },
+ ID: &[]byte{0, 1},
+ },
+ uint16(2): {
+ Account: &Account{
+ Access: &[]byte{255, 255, 255, 255, 255, 255, 255, 255},
+ },
+ ID: &[]byte{0, 2},
+ },
+ },
+ },
+ },
+ t: &Transaction{
+ Fields: []Field{
+ NewField(fieldData, []byte("performed action")),
+ NewField(fieldChatOptions, []byte{0x00, 0x01}),
+ },
+ },
+ },
+ 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},
+ 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}, // Random ID from rand.Seed(1)
+ ErrorCode: []byte{0, 0, 0, 0},
+ Fields: []Field{
+ NewField(fieldData, []byte("\r*** Testy McTest performed action")),
+ },
+ },
+ },
+ wantErr: false,
+ },
+ {
name: "only sends chat msg to clients with accessReadChat permission",
args: args{
cc: &ClientConn{
- UserName: &[]byte{0x00, 0x01},
+ UserName: []byte{0x00, 0x01},
Server: &Server{
Clients: map[uint16]*ClientConn{
uint16(1): {
@@ -391,3 +446,85 @@ 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
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ wantErr bool
+ }{
+ {
+ name: "returns expected fields when a valid file is requested",
+ args: args{
+ cc: &ClientConn{
+ ID: &[]byte{0x00, 0x01},
+ Server: &Server{
+ Config: &Config{
+ FileRoot: "./test/config/Files/",
+ },
+ },
+ },
+ t: NewTransaction(
+ 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{
+ {
+ clientID: &[]byte{0, 1},
+ Flags: 0x00,
+ IsReply: 0x01,
+ Type: []byte{0, 0xce},
+ ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
+ ErrorCode: []byte{0, 0, 0, 0},
+ Fields: []Field{
+ NewField(fieldFileName, []byte("testfile.txt")),
+ NewField(fieldFileTypeString, []byte("TEXT")),
+ NewField(fieldFileCreatorString, []byte("TTXT")),
+ NewField(fieldFileComment, []byte("TODO")),
+ 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(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
+ },
+ },
+ },
+ wantErr: false,
+ },
+ }
+ 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)
+ return
+ }
+ if !assert.Equal(t, tt.wantRes, gotRes) {
+ t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
+ }
+ })
+ }
+}