X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/3a3f91b2ccced90fcc2492ce54546d493f66db5e..1632959187e9c7d8946126914af99270fc14d40a:/hotline/transaction_handlers_test.go?ds=sidebyside diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 5136c7d..c504bbe 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -228,22 +228,22 @@ func TestHandleGetUserNameList(t *testing.T) { Clients: map[uint16]*ClientConn{ uint16(1): { ID: &[]byte{0, 1}, - Icon: &[]byte{0, 2}, - Flags: &[]byte{0, 3}, + 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}, + 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}, + Icon: []byte{0, 2}, + Flags: []byte{0, 3}, UserName: []byte{0, 4}, Agreed: false, }, @@ -2287,10 +2287,49 @@ func TestHandleSendInstantMsg(t *testing.T) { wantRes []Transaction wantErr assert.ErrorAssertionFunc }{ + { + name: "without required permission", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + access := bits[:] + return &access + }(), + }, + }, + t: NewTransaction( + tranDelNewsArt, + &[]byte{0, 0}, + ), + }, + wantRes: []Transaction{ + { + Flags: 0x00, + IsReply: 0x01, + Type: []byte{0, 0x00}, + ID: []byte{0, 0, 0, 0}, + ErrorCode: []byte{0, 0, 0, 1}, + Fields: []Field{ + NewField(fieldError, []byte("You are not allowed to send private messages.")), + }, + }, + }, + wantErr: assert.NoError, + }, { name: "when client 1 sends a message to client 2", args: args{ cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + bits.Set(accessSendPrivMsg) + access := bits[:] + return &access + }(), + }, ID: &[]byte{0, 1}, UserName: []byte("User1"), Server: &Server{ @@ -2333,6 +2372,14 @@ func TestHandleSendInstantMsg(t *testing.T) { name: "when client 2 has autoreply enabled", args: args{ cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + bits.Set(accessSendPrivMsg) + access := bits[:] + return &access + }(), + }, ID: &[]byte{0, 1}, UserName: []byte("User1"), Server: &Server{ @@ -2834,9 +2881,9 @@ func TestHandleTranAgreed(t *testing.T) { access := bits[:] return &access }()}, - Icon: &[]byte{0, 1}, - Flags: &[]byte{0, 1}, - Version: &[]byte{0, 1}, + Icon: []byte{0, 1}, + Flags: []byte{0, 1}, + Version: []byte{0, 1}, ID: &[]byte{0, 1}, logger: NewTestLogger(), Server: &Server{ @@ -2887,3 +2934,72 @@ func TestHandleTranAgreed(t *testing.T) { }) } } + +func TestHandleSetClientUserInfo(t *testing.T) { + type args struct { + cc *ClientConn + t *Transaction + } + tests := []struct { + name string + args args + wantRes []Transaction + wantErr assert.ErrorAssertionFunc + }{ + { + name: "when client does not have accessAnyName", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + access := bits[:] + return &access + }(), + }, + ID: &[]byte{0, 1}, + UserName: []byte("Guest"), + Flags: []byte{0, 1}, + Server: &Server{ + Clients: map[uint16]*ClientConn{ + uint16(1): { + ID: &[]byte{0, 1}, + }, + }, + }, + }, + t: NewTransaction( + tranSetClientUserInfo, nil, + NewField(fieldUserIconID, []byte{0, 1}), + NewField(fieldUserName, []byte("NOPE")), + ), + }, + 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}, + Fields: []Field{ + NewField(fieldUserID, []byte{0, 1}), + NewField(fieldUserIconID, []byte{0, 1}), + NewField(fieldUserFlags, []byte{0, 1}), + NewField(fieldUserName, []byte("Guest"))}, + }, + }, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotRes, err := HandleSetClientUserInfo(tt.args.cc, tt.args.t) + if !tt.wantErr(t, err, fmt.Sprintf("HandleSetClientUserInfo(%v, %v)", tt.args.cc, tt.args.t)) { + return + } + + tranAssertEqual(t, tt.wantRes, gotRes) + }) + } +}