X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/c1c44744fdbd3ddeec509efffba91011a4d49990..32d7bb7e1d8c96f93c0d24884fe038c477c4df02:/hotline/transaction_handlers_test.go diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index cb9e21f..bc40254 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -1613,6 +1613,48 @@ func TestHandleNewUser(t *testing.T) { }, wantErr: assert.NoError, }, + { + name: "when user attempts to create account with greater access", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() accessBitmap { + var bits accessBitmap + bits.Set(accessCreateUser) + return bits + }(), + }, + Server: &Server{ + Accounts: map[string]*Account{}, + }, + }, + t: NewTransaction( + tranNewUser, &[]byte{0, 1}, + NewField(fieldUserLogin, []byte("userB")), + NewField( + fieldUserAccess, + func() []byte { + var bits accessBitmap + bits.Set(accessDisconUser) + return bits[:] + }(), + ), + ), + }, + wantRes: []Transaction{ + { + Flags: 0x00, + IsReply: 0x01, + Type: []byte{0, 0x00}, + ID: []byte{0x9a, 0xcb, 0x04, 0x42}, + ErrorCode: []byte{0, 0, 0, 1}, + Fields: []Field{ + NewField(fieldError, []byte("Cannot create account with more access than yourself.")), + }, + }, + }, + wantErr: assert.NoError, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -2302,6 +2344,7 @@ func TestHandleSendInstantMsg(t *testing.T) { Clients: map[uint16]*ClientConn{ uint16(2): { AutoReply: []byte(nil), + Flags: []byte{0, 0}, }, }, }, @@ -2350,6 +2393,7 @@ func TestHandleSendInstantMsg(t *testing.T) { Server: &Server{ Clients: map[uint16]*ClientConn{ uint16(2): { + Flags: []byte{0, 0}, ID: &[]byte{0, 2}, UserName: []byte("User2"), AutoReply: []byte("autohai"), @@ -2393,6 +2437,57 @@ func TestHandleSendInstantMsg(t *testing.T) { }, wantErr: assert.NoError, }, + { + name: "when client 2 has refuse private messages enabled", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() accessBitmap { + var bits accessBitmap + bits.Set(accessSendPrivMsg) + return bits + }(), + }, + ID: &[]byte{0, 1}, + UserName: []byte("User1"), + Server: &Server{ + Clients: map[uint16]*ClientConn{ + uint16(2): { + Flags: []byte{255, 255}, + ID: &[]byte{0, 2}, + UserName: []byte("User2"), + }, + }, + }, + }, + t: NewTransaction( + tranSendInstantMsg, + &[]byte{0, 1}, + NewField(fieldData, []byte("hai")), + NewField(fieldUserID, []byte{0, 2}), + ), + }, + wantRes: []Transaction{ + *NewTransaction( + tranServerMsg, + &[]byte{0, 1}, + NewField(fieldData, []byte("User2 does not accept private messages.")), + NewField(fieldUserName, []byte("User2")), + NewField(fieldUserID, []byte{0, 2}), + NewField(fieldOptions, []byte{0, 2}), + ), + { + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x01, + Type: []byte{0x0, 0x6c}, + ID: []byte{0, 0, 0, 0}, + ErrorCode: []byte{0, 0, 0, 0}, + Fields: []Field(nil), + }, + }, + wantErr: assert.NoError, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -3429,7 +3524,7 @@ func TestHandleInviteNewChat(t *testing.T) { ID: []byte{0, 0, 0, 0}, ErrorCode: []byte{0, 0, 0, 0}, Fields: []Field{ - NewField(fieldData, []byte("UserB does not accept private messages.")), + NewField(fieldData, []byte("UserB does not accept private chats.")), NewField(fieldUserName, []byte("UserB")), NewField(fieldUserID, []byte{0, 2}), NewField(fieldOptions, []byte{0, 2}),