| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- package handler
- import (
- "bytes"
- "context"
- "log/slog"
- "testing"
- "github.com/mk6i/retro-aim-server/server/oscar/middleware"
- "github.com/mk6i/retro-aim-server/state"
- "github.com/mk6i/retro-aim-server/wire"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/mock"
- )
- func TestOServiceBOSHandler_ClientOnline(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceClientOnline,
- },
- Body: wire.SNAC_0x01_0x02_OServiceClientOnline{
- GroupVersions: []struct {
- FoodGroup uint16
- Version uint16
- ToolID uint16
- ToolVersion uint16
- }{
- {
- FoodGroup: 10,
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ClientOnline(mock.Anything, input.Body, mock.Anything).
- Return(nil)
- h := NewOServiceHandler(slog.Default(), svc)
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.ClientOnline(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceBOSHandler_ServiceRequest(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceServiceRequest,
- },
- Body: wire.SNAC_0x01_0x04_OServiceServiceRequest{
- FoodGroup: wire.Chat,
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceServiceResponse,
- },
- Body: wire.SNAC_0x01_0x05_OServiceServiceResponse{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- wire.NewTLVBE(0x01, uint16(1000)),
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ServiceRequest(mock.Anything, mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := NewOServiceHandler(slog.Default(), svc)
- 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.ServiceRequest(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceChatHandler_ClientOnline(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceClientOnline,
- },
- Body: wire.SNAC_0x01_0x02_OServiceClientOnline{
- GroupVersions: []struct {
- FoodGroup uint16
- Version uint16
- ToolID uint16
- ToolVersion uint16
- }{
- {
- FoodGroup: 10,
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ClientOnline(mock.Anything, mock.Anything, mock.Anything).
- Return(nil)
- h := NewOServiceHandler(slog.Default(), svc)
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.ClientOnline(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_IdleNotification(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceIdleNotification,
- },
- Body: wire.SNAC_0x01_0x11_OServiceIdleNotification{
- IdleTime: 10,
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- IdleNotification(mock.Anything, mock.Anything, input.Body).
- Return(nil)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: slog.Default(),
- },
- }
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.IdleNotification(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_ClientVersions(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceClientVersions,
- },
- Body: wire.SNAC_0x01_0x17_OServiceClientVersions{
- Versions: []uint16{
- 10,
- },
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceHostVersions,
- },
- Body: wire.SNAC_0x01_0x18_OServiceHostVersions{
- Versions: []uint16{
- 10,
- },
- },
- }
- sess := state.NewSession()
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ClientVersions(mock.Anything, sess, input.Frame, input.Body).
- Return(output)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: 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.ClientVersions(context.Background(), sess, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_RateParamsQuery(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceRateParamsQuery,
- },
- Body: struct{}{},
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceRateParamsReply,
- },
- Body: wire.SNAC_0x01_0x07_OServiceRateParamsReply{
- RateGroups: []struct {
- ID uint16
- Pairs []struct {
- FoodGroup uint16
- SubGroup uint16
- } `oscar:"count_prefix=uint16"`
- }{
- {
- ID: 1,
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- RateParamsQuery(mock.Anything, mock.Anything, input.Frame).
- Return(output)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: 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.RateParamsQuery(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_RateParamsSubAdd(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceRateParamsSubAdd,
- },
- Body: wire.SNAC_0x01_0x08_OServiceRateParamsSubAdd{
- ClassIDs: []uint16{1, 2, 3, 4},
- },
- }
- sess := state.NewSession()
- svc := newMockOServiceService(t)
- svc.EXPECT().
- RateParamsSubAdd(mock.Anything, sess, input.Body)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: slog.Default(),
- },
- }
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.RateParamsSubAdd(context.Background(), sess, input.Frame, buf, nil))
- }
- func TestOServiceHandler_SetUserInfoFields(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceSetUserInfoFields,
- },
- Body: wire.SNAC_0x01_0x1E_OServiceSetUserInfoFields{
- TLVRestBlock: wire.TLVRestBlock{
- TLVList: wire.TLVList{
- wire.NewTLVBE(0x01, []byte{1, 2, 3, 4}),
- },
- },
- },
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceUserInfoUpdate,
- },
- Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
- UserInfo: []wire.TLVUserInfo{
- {ScreenName: "screen-name"},
- {ScreenName: "screen-name"},
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- SetUserInfoFields(mock.Anything, mock.Anything, input.Frame, input.Body).
- Return(output, nil)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: 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.SetUserInfoFields(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_UserInfoQuery(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceUserInfoQuery,
- },
- Body: struct{}{},
- }
- output := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceUserInfoUpdate,
- },
- Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
- UserInfo: []wire.TLVUserInfo{
- {ScreenName: "screen-name"},
- {ScreenName: "screen-name"},
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- UserInfoQuery(mock.Anything, mock.Anything, input.Frame).
- Return(output)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: 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 TestOServiceHandler_Noop(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceNoop,
- },
- Body: struct{}{},
- }
- h := OServiceHandler{
- RouteLogger: middleware.RouteLogger{
- Logger: slog.Default(),
- },
- }
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.Noop(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceHandler_SetPrivacyFlags(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceSetPrivacyFlags,
- },
- Body: wire.SNAC_0x01_0x14_OServiceSetPrivacyFlags{
- PrivacyFlags: wire.OServicePrivacyFlagMember,
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- SetPrivacyFlags(mock.Anything, input.Body)
- h := OServiceHandler{
- OServiceService: svc,
- RouteLogger: middleware.RouteLogger{
- Logger: slog.Default(),
- },
- }
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.SetPrivacyFlags(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceChatNavHandler_ClientOnline(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceClientOnline,
- },
- Body: wire.SNAC_0x01_0x02_OServiceClientOnline{
- GroupVersions: []struct {
- FoodGroup uint16
- Version uint16
- ToolID uint16
- ToolVersion uint16
- }{
- {
- FoodGroup: 10,
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ClientOnline(mock.Anything, input.Body, mock.Anything).
- Return(nil)
- h := NewOServiceHandler(slog.Default(), svc)
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.ClientOnline(nil, nil, input.Frame, buf, responseWriter))
- }
- func TestOServiceAlertHandler_ClientOnline(t *testing.T) {
- input := wire.SNACMessage{
- Frame: wire.SNACFrame{
- FoodGroup: wire.OService,
- SubGroup: wire.OServiceClientOnline,
- },
- Body: wire.SNAC_0x01_0x02_OServiceClientOnline{
- GroupVersions: []struct {
- FoodGroup uint16
- Version uint16
- ToolID uint16
- ToolVersion uint16
- }{
- {
- FoodGroup: 10,
- },
- },
- },
- }
- svc := newMockOServiceService(t)
- svc.EXPECT().
- ClientOnline(mock.Anything, input.Body, mock.Anything).
- Return(nil)
- h := NewOServiceHandler(slog.Default(), svc)
- responseWriter := newMockResponseWriter(t)
- buf := &bytes.Buffer{}
- assert.NoError(t, wire.MarshalBE(input.Body, buf))
- assert.NoError(t, h.ClientOnline(nil, nil, input.Frame, buf, responseWriter))
- }
|