| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- package handler
- import (
- "bytes"
- "log/slog"
- "testing"
- "github.com/mk6i/retro-aim-server/wire"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/mock"
- )
- func TestLocateHandler_GetDirInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateGetDirInfo,
- },
- Body: wire.SNAC_0x02_0x0B_LocateGetDirInfo{
- ScreenName: "screen-name",
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateGetDirReply,
- },
- Body: wire.SNAC_0x02_0x0C_LocateGetDirReply{
- Status: 1,
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- DirInfo(mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.GetDirInfo(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_RightsQuery(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateRightsQuery,
- },
- Body: struct{}{},
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateRightsReply,
- },
- Body: wire.SNAC_0x02_0x03_LocateRightsReply{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- wire.NewTLVBE(0x01, uint16(1000)),
- },
- },
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- RightsQuery(mock.Anything, input.Frame).
- Return(output)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.RightsQuery(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_SetDirInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateSetDirInfo,
- },
- Body: wire.SNAC_0x02_0x09_LocateSetDirInfo{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- {
- Tag: 0x01,
- Value: []byte{1, 2, 3, 4},
- },
- },
- },
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateSetDirReply,
- },
- Body: wire.SNAC_0x02_0x0A_LocateSetDirReply{
- Result: 1,
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- SetDirInfo(mock.Anything, mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.SetDirInfo(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_SetInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateSetInfo,
- },
- Body: wire.SNAC_0x02_0x04_LocateSetInfo{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- {
- Tag: 0x01,
- Value: []byte{1, 2, 3, 4},
- },
- },
- },
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- SetInfo(mock.Anything, mock.Anything, input.Body).
- Return(nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.SetInfo(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_SetKeywordInfo(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateSetKeywordInfo,
- },
- Body: wire.SNAC_0x02_0x0F_LocateSetKeywordInfo{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- {
- Tag: 0x01,
- Value: []byte{1, 2, 3, 4},
- },
- },
- },
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateSetKeywordReply,
- },
- Body: wire.SNAC_0x02_0x10_LocateSetKeywordReply{
- Unknown: 1,
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- SetKeywordInfo(mock.Anything, mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.SetKeywordInfo(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_UserInfoQuery(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateUserInfoQuery,
- },
- Body: wire.SNAC_0x02_0x05_LocateUserInfoQuery{
- Type: 1,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateUserInfoReply,
- },
- Body: wire.SNAC_0x02_0x06_LocateUserInfoReply{
- TLVUserInfo: wire.TLVUserInfo{
- ScreenName: "screen-name",
- },
- LocateInfo: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- {
- Tag: 0x01,
- Value: []byte{1, 2, 3, 4},
- },
- },
- },
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- UserInfoQuery(mock.Anything, mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.UserInfoQuery(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestLocateHandler_UserInfoQuery2(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateUserInfoQuery2,
- },
- Body: wire.SNAC_0x02_0x15_LocateUserInfoQuery2{
- Type2: 1,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.Locate,
- SubGroup: wire.LocateUserInfoReply,
- },
- Body: wire.SNAC_0x02_0x06_LocateUserInfoReply{
- TLVUserInfo: wire.TLVUserInfo{
- ScreenName: "screen-name",
- },
- LocateInfo: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- {
- Tag: 0x01,
- Value: []byte{1, 2, 3, 4},
- },
- },
- },
- },
- }
- svc := newMockLocateService(t)
- svc.EXPECT().
- UserInfoQuery(mock.Anything, mock.Anything, input.Frame, wire.SNAC_0x02_0x05_LocateUserInfoQuery{Type: 1}).
- Return(output, nil)
- h := NewLocateHandler(svc, slog.Default())
- responseWriter := newMockResponseWriter(t)
- responseWriter.EXPECT().
- SendSNAC(output.Frame, output.Body).
- Return(nil)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.UserInfoQuery2(nil, nil, input.Frame, buf, responseWriter))
- }
|