handler_test.go 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331
  1. package oscar
  2. import (
  3. "bytes"
  4. "context"
  5. "log/slog"
  6. "math"
  7. "testing"
  8. "github.com/mk6i/retro-aim-server/config"
  9. "github.com/mk6i/retro-aim-server/server/oscar/middleware"
  10. "github.com/mk6i/retro-aim-server/state"
  11. "github.com/mk6i/retro-aim-server/wire"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/mock"
  14. )
  15. func TestHandler_AdminConfirmRequest(t *testing.T) {
  16. tests := []struct {
  17. name string
  18. inputBody wire.SNAC_0x07_0x06_AdminConfirmRequest
  19. serviceError error
  20. responseError error
  21. expectedError error
  22. }{
  23. {
  24. name: "success",
  25. inputBody: wire.SNAC_0x07_0x06_AdminConfirmRequest{},
  26. },
  27. {
  28. name: "service error",
  29. inputBody: wire.SNAC_0x07_0x06_AdminConfirmRequest{},
  30. serviceError: assert.AnError,
  31. expectedError: assert.AnError,
  32. },
  33. {
  34. name: "response writer error",
  35. inputBody: wire.SNAC_0x07_0x06_AdminConfirmRequest{},
  36. responseError: assert.AnError,
  37. expectedError: assert.AnError,
  38. },
  39. }
  40. for _, tt := range tests {
  41. t.Run(tt.name, func(t *testing.T) {
  42. input := wire.SNACMessage{
  43. Frame: wire.SNACFrame{
  44. FoodGroup: wire.Admin,
  45. SubGroup: wire.AdminAcctConfirmRequest,
  46. },
  47. Body: tt.inputBody,
  48. }
  49. output := wire.SNACMessage{
  50. Frame: wire.SNACFrame{
  51. FoodGroup: wire.Admin,
  52. SubGroup: wire.AdminAcctConfirmReply,
  53. },
  54. Body: wire.SNAC_0x07_0x07_AdminConfirmReply{
  55. Status: wire.AdminAcctConfirmStatusEmailSent,
  56. },
  57. }
  58. svc := newMockAdminService(t)
  59. svc.EXPECT().
  60. ConfirmRequest(mock.Anything, mock.Anything, input.Frame).
  61. Return(output, tt.serviceError)
  62. h := Handler{
  63. AdminService: svc,
  64. RouteLogger: middleware.RouteLogger{
  65. Logger: slog.Default(),
  66. },
  67. }
  68. responseWriter := newMockResponseWriter(t)
  69. if tt.serviceError == nil {
  70. responseWriter.EXPECT().
  71. SendSNAC(output.Frame, output.Body).
  72. Return(tt.responseError)
  73. }
  74. buf := &bytes.Buffer{}
  75. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  76. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  77. if tt.expectedError != nil {
  78. assert.ErrorIs(t, err, tt.expectedError)
  79. } else {
  80. assert.NoError(t, err)
  81. }
  82. })
  83. }
  84. }
  85. func TestHandler_AdminInfoQuery_RegistrationStatus(t *testing.T) {
  86. tests := []struct {
  87. name string
  88. inputBody wire.SNAC_0x07_0x02_AdminInfoQuery
  89. serviceError error
  90. responseError error
  91. expectedError error
  92. }{
  93. {
  94. name: "success",
  95. inputBody: wire.SNAC_0x07_0x02_AdminInfoQuery{
  96. TLVRestBlock: wire.TLVRestBlock{
  97. TLVList: wire.TLVList{
  98. wire.NewTLVBE(wire.AdminTLVRegistrationStatus, uint16(0x00)),
  99. },
  100. },
  101. },
  102. },
  103. {
  104. name: "service error",
  105. inputBody: wire.SNAC_0x07_0x02_AdminInfoQuery{
  106. TLVRestBlock: wire.TLVRestBlock{
  107. TLVList: wire.TLVList{
  108. wire.NewTLVBE(wire.AdminTLVRegistrationStatus, uint16(0x00)),
  109. },
  110. },
  111. },
  112. serviceError: assert.AnError,
  113. expectedError: assert.AnError,
  114. },
  115. {
  116. name: "response writer error",
  117. inputBody: wire.SNAC_0x07_0x02_AdminInfoQuery{
  118. TLVRestBlock: wire.TLVRestBlock{
  119. TLVList: wire.TLVList{
  120. wire.NewTLVBE(wire.AdminTLVRegistrationStatus, uint16(0x00)),
  121. },
  122. },
  123. },
  124. responseError: assert.AnError,
  125. expectedError: assert.AnError,
  126. },
  127. }
  128. for _, tt := range tests {
  129. t.Run(tt.name, func(t *testing.T) {
  130. input := wire.SNACMessage{
  131. Frame: wire.SNACFrame{
  132. FoodGroup: wire.Admin,
  133. SubGroup: wire.AdminInfoQuery,
  134. },
  135. Body: tt.inputBody,
  136. }
  137. output := wire.SNACMessage{
  138. Frame: wire.SNACFrame{
  139. FoodGroup: wire.Admin,
  140. SubGroup: wire.AdminInfoReply,
  141. },
  142. Body: wire.SNAC_0x07_0x03_AdminInfoReply{
  143. Permissions: wire.AdminInfoPermissionsReadWrite,
  144. TLVBlock: wire.TLVBlock{
  145. TLVList: wire.TLVList{
  146. wire.NewTLVBE(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusFullDisclosure),
  147. },
  148. },
  149. },
  150. }
  151. svc := newMockAdminService(t)
  152. svc.EXPECT().
  153. InfoQuery(mock.Anything, mock.Anything, input.Frame, input.Body).
  154. Return(output, tt.serviceError)
  155. h := Handler{
  156. AdminService: svc,
  157. RouteLogger: middleware.RouteLogger{
  158. Logger: slog.Default(),
  159. },
  160. }
  161. responseWriter := newMockResponseWriter(t)
  162. if tt.serviceError == nil {
  163. responseWriter.EXPECT().
  164. SendSNAC(output.Frame, output.Body).
  165. Return(tt.responseError)
  166. }
  167. buf := &bytes.Buffer{}
  168. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  169. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  170. if tt.expectedError != nil {
  171. assert.ErrorIs(t, err, tt.expectedError)
  172. } else {
  173. assert.NoError(t, err)
  174. }
  175. })
  176. }
  177. }
  178. func TestHandler_AdminInfoChangeRequest_ScreenNameFormatted(t *testing.T) {
  179. tests := []struct {
  180. name string
  181. inputBody wire.SNAC_0x07_0x04_AdminInfoChangeRequest
  182. serviceError error
  183. responseError error
  184. expectedError error
  185. }{
  186. {
  187. name: "success",
  188. inputBody: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
  189. TLVRestBlock: wire.TLVRestBlock{
  190. TLVList: wire.TLVList{
  191. wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
  192. },
  193. },
  194. },
  195. },
  196. {
  197. name: "service error",
  198. inputBody: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
  199. TLVRestBlock: wire.TLVRestBlock{
  200. TLVList: wire.TLVList{
  201. wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
  202. },
  203. },
  204. },
  205. serviceError: assert.AnError,
  206. expectedError: assert.AnError,
  207. },
  208. {
  209. name: "response writer error",
  210. inputBody: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
  211. TLVRestBlock: wire.TLVRestBlock{
  212. TLVList: wire.TLVList{
  213. wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
  214. },
  215. },
  216. },
  217. responseError: assert.AnError,
  218. expectedError: assert.AnError,
  219. },
  220. }
  221. for _, tt := range tests {
  222. t.Run(tt.name, func(t *testing.T) {
  223. input := wire.SNACMessage{
  224. Frame: wire.SNACFrame{
  225. FoodGroup: wire.Admin,
  226. SubGroup: wire.AdminInfoChangeRequest,
  227. },
  228. Body: tt.inputBody,
  229. }
  230. output := wire.SNACMessage{
  231. Frame: wire.SNACFrame{
  232. FoodGroup: wire.Admin,
  233. SubGroup: wire.AdminInfoChangeReply,
  234. },
  235. Body: wire.SNAC_0x07_0x05_AdminChangeReply{
  236. Permissions: wire.AdminInfoPermissionsReadWrite,
  237. TLVBlock: wire.TLVBlock{
  238. TLVList: wire.TLVList{
  239. wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
  240. },
  241. },
  242. },
  243. }
  244. svc := newMockAdminService(t)
  245. svc.EXPECT().
  246. InfoChangeRequest(mock.Anything, mock.Anything, input.Frame, input.Body).
  247. Return(output, tt.serviceError)
  248. h := Handler{
  249. AdminService: svc,
  250. RouteLogger: middleware.RouteLogger{
  251. Logger: slog.Default(),
  252. },
  253. }
  254. responseWriter := newMockResponseWriter(t)
  255. if tt.serviceError == nil {
  256. responseWriter.EXPECT().
  257. SendSNAC(output.Frame, output.Body).
  258. Return(tt.responseError)
  259. }
  260. buf := &bytes.Buffer{}
  261. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  262. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  263. if tt.expectedError != nil {
  264. assert.ErrorIs(t, err, tt.expectedError)
  265. } else {
  266. assert.NoError(t, err)
  267. }
  268. })
  269. }
  270. }
  271. func TestHandler_AlertNotifyCapabilities(t *testing.T) {
  272. tests := []struct {
  273. name string
  274. inputBody wire.SNACFrame
  275. expectedError error
  276. }{
  277. {
  278. name: "success",
  279. inputBody: wire.SNACFrame{},
  280. },
  281. {
  282. name: "empty body",
  283. inputBody: wire.SNACFrame{},
  284. },
  285. }
  286. for _, tt := range tests {
  287. t.Run(tt.name, func(t *testing.T) {
  288. input := wire.SNACMessage{
  289. Frame: wire.SNACFrame{
  290. FoodGroup: wire.Alert,
  291. SubGroup: wire.AlertNotifyCapabilities,
  292. },
  293. Body: tt.inputBody,
  294. }
  295. h := Handler{
  296. RouteLogger: middleware.RouteLogger{
  297. Logger: slog.Default(),
  298. },
  299. }
  300. buf := &bytes.Buffer{}
  301. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  302. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, nil, config.Listener{})
  303. if tt.expectedError != nil {
  304. assert.ErrorIs(t, err, tt.expectedError)
  305. } else {
  306. assert.NoError(t, err)
  307. }
  308. })
  309. }
  310. }
  311. func TestHandler_AlertNotifyDisplayCapabilities(t *testing.T) {
  312. tests := []struct {
  313. name string
  314. inputBody wire.SNACFrame
  315. expectedError error
  316. }{
  317. {
  318. name: "success",
  319. inputBody: wire.SNACFrame{},
  320. },
  321. {
  322. name: "empty body",
  323. inputBody: wire.SNACFrame{},
  324. },
  325. }
  326. for _, tt := range tests {
  327. t.Run(tt.name, func(t *testing.T) {
  328. input := wire.SNACMessage{
  329. Frame: wire.SNACFrame{
  330. FoodGroup: wire.Alert,
  331. SubGroup: wire.AlertNotifyDisplayCapabilities,
  332. },
  333. Body: tt.inputBody,
  334. }
  335. h := Handler{
  336. RouteLogger: middleware.RouteLogger{
  337. Logger: slog.Default(),
  338. },
  339. }
  340. buf := &bytes.Buffer{}
  341. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  342. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, nil, config.Listener{})
  343. if tt.expectedError != nil {
  344. assert.ErrorIs(t, err, tt.expectedError)
  345. } else {
  346. assert.NoError(t, err)
  347. }
  348. })
  349. }
  350. }
  351. func TestHandler_BARTDownloadQuery(t *testing.T) {
  352. tests := []struct {
  353. name string
  354. inputBody wire.SNAC_0x10_0x04_BARTDownloadQuery
  355. serviceError error
  356. responseError error
  357. expectedError error
  358. }{
  359. {
  360. name: "success",
  361. inputBody: wire.SNAC_0x10_0x04_BARTDownloadQuery{},
  362. },
  363. {
  364. name: "service error",
  365. inputBody: wire.SNAC_0x10_0x04_BARTDownloadQuery{},
  366. serviceError: assert.AnError,
  367. expectedError: assert.AnError,
  368. },
  369. {
  370. name: "response writer error",
  371. inputBody: wire.SNAC_0x10_0x04_BARTDownloadQuery{},
  372. responseError: assert.AnError,
  373. expectedError: assert.AnError,
  374. },
  375. }
  376. for _, tt := range tests {
  377. t.Run(tt.name, func(t *testing.T) {
  378. input := wire.SNACMessage{
  379. Frame: wire.SNACFrame{
  380. FoodGroup: wire.BART,
  381. SubGroup: wire.BARTDownloadQuery,
  382. },
  383. Body: tt.inputBody,
  384. }
  385. output := wire.SNACMessage{
  386. Frame: wire.SNACFrame{
  387. FoodGroup: wire.BART,
  388. SubGroup: wire.BARTDownloadReply,
  389. },
  390. Body: wire.SNAC_0x10_0x05_BARTDownloadReply{
  391. ScreenName: "the-screen-name",
  392. },
  393. }
  394. svc := newMockBARTService(t)
  395. svc.EXPECT().
  396. RetrieveItem(mock.Anything, mock.Anything, input.Frame, input.Body).
  397. Return(output, tt.serviceError)
  398. h := Handler{
  399. BARTService: svc,
  400. RouteLogger: middleware.RouteLogger{
  401. Logger: slog.Default(),
  402. },
  403. }
  404. responseWriter := newMockResponseWriter(t)
  405. if tt.serviceError == nil {
  406. responseWriter.EXPECT().
  407. SendSNAC(output.Frame, output.Body).
  408. Return(tt.responseError)
  409. }
  410. buf := &bytes.Buffer{}
  411. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  412. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  413. if tt.expectedError != nil {
  414. assert.ErrorIs(t, err, tt.expectedError)
  415. } else {
  416. assert.NoError(t, err)
  417. }
  418. })
  419. }
  420. }
  421. func TestHandler_BARTUploadQuery(t *testing.T) {
  422. tests := []struct {
  423. name string
  424. inputBody wire.SNAC_0x10_0x02_BARTUploadQuery
  425. serviceError error
  426. responseError error
  427. expectedError error
  428. }{
  429. {
  430. name: "success",
  431. inputBody: wire.SNAC_0x10_0x02_BARTUploadQuery{
  432. Type: 1,
  433. },
  434. },
  435. {
  436. name: "service error",
  437. inputBody: wire.SNAC_0x10_0x02_BARTUploadQuery{
  438. Type: 1,
  439. },
  440. serviceError: assert.AnError,
  441. expectedError: assert.AnError,
  442. },
  443. {
  444. name: "response writer error",
  445. inputBody: wire.SNAC_0x10_0x02_BARTUploadQuery{
  446. Type: 1,
  447. },
  448. responseError: assert.AnError,
  449. expectedError: assert.AnError,
  450. },
  451. }
  452. for _, tt := range tests {
  453. t.Run(tt.name, func(t *testing.T) {
  454. input := wire.SNACMessage{
  455. Frame: wire.SNACFrame{
  456. FoodGroup: wire.BART,
  457. SubGroup: wire.BARTUploadQuery,
  458. },
  459. Body: tt.inputBody,
  460. }
  461. output := wire.SNACMessage{
  462. Frame: wire.SNACFrame{
  463. FoodGroup: wire.BART,
  464. SubGroup: wire.BARTUploadReply,
  465. },
  466. Body: wire.SNAC_0x10_0x03_BARTUploadReply{
  467. Code: wire.BARTReplyCodesSuccess,
  468. },
  469. }
  470. svc := newMockBARTService(t)
  471. svc.EXPECT().
  472. UpsertItem(mock.Anything, mock.Anything, input.Frame, input.Body).
  473. Return(output, tt.serviceError)
  474. h := Handler{
  475. BARTService: svc,
  476. RouteLogger: middleware.RouteLogger{
  477. Logger: slog.Default(),
  478. },
  479. }
  480. responseWriter := newMockResponseWriter(t)
  481. if tt.serviceError == nil {
  482. responseWriter.EXPECT().
  483. SendSNAC(output.Frame, output.Body).
  484. Return(tt.responseError)
  485. }
  486. buf := &bytes.Buffer{}
  487. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  488. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  489. if tt.expectedError != nil {
  490. assert.ErrorIs(t, err, tt.expectedError)
  491. } else {
  492. assert.NoError(t, err)
  493. }
  494. })
  495. }
  496. }
  497. func TestHandler_BuddyRightsQuery(t *testing.T) {
  498. tests := []struct {
  499. name string
  500. inputBody wire.SNAC_0x03_0x02_BuddyRightsQuery
  501. responseError error
  502. expectedError error
  503. }{
  504. {
  505. name: "success",
  506. inputBody: wire.SNAC_0x03_0x02_BuddyRightsQuery{
  507. TLVRestBlock: wire.TLVRestBlock{
  508. TLVList: wire.TLVList{
  509. wire.NewTLVBE(0x01, uint16(1000)),
  510. },
  511. },
  512. },
  513. },
  514. {
  515. name: "response writer error",
  516. inputBody: wire.SNAC_0x03_0x02_BuddyRightsQuery{
  517. TLVRestBlock: wire.TLVRestBlock{
  518. TLVList: wire.TLVList{
  519. wire.NewTLVBE(0x01, uint16(1000)),
  520. },
  521. },
  522. },
  523. responseError: assert.AnError,
  524. expectedError: assert.AnError,
  525. },
  526. }
  527. for _, tt := range tests {
  528. t.Run(tt.name, func(t *testing.T) {
  529. input := wire.SNACMessage{
  530. Frame: wire.SNACFrame{
  531. FoodGroup: wire.Buddy,
  532. SubGroup: wire.BuddyRightsQuery,
  533. },
  534. Body: tt.inputBody,
  535. }
  536. output := wire.SNACMessage{
  537. Frame: wire.SNACFrame{
  538. FoodGroup: wire.Buddy,
  539. SubGroup: wire.BuddyRightsReply,
  540. },
  541. Body: wire.SNAC_0x03_0x03_BuddyRightsReply{
  542. TLVRestBlock: wire.TLVRestBlock{
  543. TLVList: wire.TLVList{
  544. wire.NewTLVBE(0x01, uint16(1000)),
  545. },
  546. },
  547. },
  548. }
  549. svc := newMockBuddyService(t)
  550. svc.EXPECT().
  551. RightsQuery(mock.Anything, input.Frame).
  552. Return(output)
  553. h := Handler{
  554. BuddyService: svc,
  555. RouteLogger: middleware.RouteLogger{
  556. Logger: slog.Default(),
  557. },
  558. }
  559. responseWriter := newMockResponseWriter(t)
  560. responseWriter.EXPECT().
  561. SendSNAC(output.Frame, output.Body).
  562. Return(tt.responseError)
  563. buf := &bytes.Buffer{}
  564. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  565. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  566. if tt.expectedError != nil {
  567. assert.ErrorIs(t, err, tt.expectedError)
  568. } else {
  569. assert.NoError(t, err)
  570. }
  571. })
  572. }
  573. }
  574. func TestHandler_BuddyAddBuddies(t *testing.T) {
  575. tests := []struct {
  576. name string
  577. inputBody wire.SNAC_0x03_0x04_BuddyAddBuddies
  578. serviceError error
  579. expectedError error
  580. }{
  581. {
  582. name: "success",
  583. inputBody: wire.SNAC_0x03_0x04_BuddyAddBuddies{
  584. Buddies: []struct {
  585. ScreenName string `oscar:"len_prefix=uint8"`
  586. }{
  587. {
  588. ScreenName: "user1",
  589. },
  590. },
  591. },
  592. },
  593. {
  594. name: "service error",
  595. inputBody: wire.SNAC_0x03_0x04_BuddyAddBuddies{
  596. Buddies: []struct {
  597. ScreenName string `oscar:"len_prefix=uint8"`
  598. }{
  599. {
  600. ScreenName: "user1",
  601. },
  602. },
  603. },
  604. serviceError: assert.AnError,
  605. expectedError: assert.AnError,
  606. },
  607. }
  608. for _, tt := range tests {
  609. t.Run(tt.name, func(t *testing.T) {
  610. input := wire.SNACMessage{
  611. Frame: wire.SNACFrame{
  612. FoodGroup: wire.Buddy,
  613. SubGroup: wire.BuddyAddBuddies,
  614. },
  615. Body: tt.inputBody,
  616. }
  617. svc := newMockBuddyService(t)
  618. svc.EXPECT().
  619. AddBuddies(mock.Anything, mock.Anything, input.Body).
  620. Return(tt.serviceError)
  621. h := Handler{
  622. BuddyService: svc,
  623. RouteLogger: middleware.RouteLogger{
  624. Logger: slog.Default(),
  625. },
  626. }
  627. responseWriter := newMockResponseWriter(t)
  628. buf := &bytes.Buffer{}
  629. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  630. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  631. if tt.expectedError != nil {
  632. assert.ErrorIs(t, err, tt.expectedError)
  633. } else {
  634. assert.NoError(t, err)
  635. }
  636. })
  637. }
  638. }
  639. func TestHandler_BuddyDelBuddies(t *testing.T) {
  640. tests := []struct {
  641. name string
  642. inputBody wire.SNAC_0x03_0x05_BuddyDelBuddies
  643. serviceError error
  644. expectedError error
  645. }{
  646. {
  647. name: "success",
  648. inputBody: wire.SNAC_0x03_0x05_BuddyDelBuddies{
  649. Buddies: []struct {
  650. ScreenName string `oscar:"len_prefix=uint8"`
  651. }{
  652. {
  653. ScreenName: "user1",
  654. },
  655. },
  656. },
  657. },
  658. {
  659. name: "service error",
  660. inputBody: wire.SNAC_0x03_0x05_BuddyDelBuddies{
  661. Buddies: []struct {
  662. ScreenName string `oscar:"len_prefix=uint8"`
  663. }{
  664. {
  665. ScreenName: "user1",
  666. },
  667. },
  668. },
  669. serviceError: assert.AnError,
  670. expectedError: assert.AnError,
  671. },
  672. }
  673. for _, tt := range tests {
  674. t.Run(tt.name, func(t *testing.T) {
  675. input := wire.SNACMessage{
  676. Frame: wire.SNACFrame{
  677. FoodGroup: wire.Buddy,
  678. SubGroup: wire.BuddyDelBuddies,
  679. },
  680. Body: tt.inputBody,
  681. }
  682. svc := newMockBuddyService(t)
  683. svc.EXPECT().
  684. DelBuddies(mock.Anything, mock.Anything, input.Body).
  685. Return(tt.serviceError)
  686. h := Handler{
  687. BuddyService: svc,
  688. RouteLogger: middleware.RouteLogger{
  689. Logger: slog.Default(),
  690. },
  691. }
  692. responseWriter := newMockResponseWriter(t)
  693. buf := &bytes.Buffer{}
  694. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  695. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  696. if tt.expectedError != nil {
  697. assert.ErrorIs(t, err, tt.expectedError)
  698. } else {
  699. assert.NoError(t, err)
  700. }
  701. })
  702. }
  703. }
  704. func TestHandler_ChatNavCreateRoom(t *testing.T) {
  705. tests := []struct {
  706. name string
  707. inputBody wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate
  708. serviceError error
  709. responseError error
  710. expectedError error
  711. }{
  712. {
  713. name: "success",
  714. inputBody: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  715. Exchange: 1,
  716. },
  717. },
  718. {
  719. name: "service error",
  720. inputBody: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  721. Exchange: 1,
  722. },
  723. serviceError: assert.AnError,
  724. expectedError: assert.AnError,
  725. },
  726. {
  727. name: "response writer error",
  728. inputBody: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  729. Exchange: 1,
  730. },
  731. responseError: assert.AnError,
  732. expectedError: assert.AnError,
  733. },
  734. }
  735. for _, tt := range tests {
  736. t.Run(tt.name, func(t *testing.T) {
  737. input := wire.SNACMessage{
  738. Frame: wire.SNACFrame{
  739. FoodGroup: wire.ChatNav,
  740. SubGroup: wire.ChatNavCreateRoom,
  741. },
  742. Body: tt.inputBody,
  743. }
  744. output := wire.SNACMessage{
  745. Frame: wire.SNACFrame{
  746. FoodGroup: wire.ChatNav,
  747. SubGroup: wire.ChatNavNavInfo,
  748. },
  749. Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
  750. }
  751. sess := state.NewSession()
  752. svc := newMockChatNavService(t)
  753. svc.EXPECT().
  754. CreateRoom(mock.Anything, sess, input.Frame, input.Body).
  755. Return(output, tt.serviceError)
  756. h := Handler{
  757. ChatNavService: svc,
  758. RouteLogger: middleware.RouteLogger{
  759. Logger: slog.Default(),
  760. },
  761. }
  762. responseWriter := newMockResponseWriter(t)
  763. if tt.serviceError == nil {
  764. responseWriter.EXPECT().
  765. SendSNAC(output.Frame, output.Body).
  766. Return(tt.responseError)
  767. }
  768. buf := &bytes.Buffer{}
  769. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  770. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, responseWriter, config.Listener{})
  771. if tt.expectedError != nil {
  772. assert.ErrorIs(t, err, tt.expectedError)
  773. } else {
  774. assert.NoError(t, err)
  775. }
  776. })
  777. }
  778. }
  779. func TestHandler_ChatNavCreateRoom_ReadErr(t *testing.T) {
  780. input := wire.SNACMessage{
  781. Frame: wire.SNACFrame{
  782. FoodGroup: wire.ChatNav,
  783. SubGroup: wire.ChatNavCreateRoom,
  784. },
  785. Body: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
  786. Exchange: 1,
  787. },
  788. }
  789. output := wire.SNACMessage{
  790. Frame: wire.SNACFrame{
  791. FoodGroup: wire.ChatNav,
  792. SubGroup: wire.ChatNavNavInfo,
  793. },
  794. Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
  795. }
  796. sess := state.NewSession()
  797. svc := newMockChatNavService(t)
  798. svc.EXPECT().
  799. CreateRoom(mock.Anything, sess, input.Frame, input.Body).
  800. Return(output, nil)
  801. h := Handler{
  802. ChatNavService: svc,
  803. RouteLogger: middleware.RouteLogger{
  804. Logger: slog.Default(),
  805. },
  806. }
  807. ss := newMockResponseWriter(t)
  808. ss.EXPECT().
  809. SendSNAC(output.Frame, output.Body).
  810. Return(nil)
  811. buf := &bytes.Buffer{}
  812. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  813. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, ss, config.Listener{}))
  814. }
  815. func TestHandler_ChatNavRequestChatRights(t *testing.T) {
  816. tests := []struct {
  817. name string
  818. inputBody struct{}
  819. responseError error
  820. expectedError error
  821. }{
  822. {
  823. name: "success",
  824. inputBody: struct{}{},
  825. },
  826. {
  827. name: "response writer error",
  828. inputBody: struct{}{},
  829. responseError: assert.AnError,
  830. expectedError: assert.AnError,
  831. },
  832. }
  833. for _, tt := range tests {
  834. t.Run(tt.name, func(t *testing.T) {
  835. input := wire.SNACMessage{
  836. Frame: wire.SNACFrame{
  837. FoodGroup: wire.ChatNav,
  838. SubGroup: wire.ChatNavRequestChatRights,
  839. },
  840. Body: tt.inputBody,
  841. }
  842. output := wire.SNACMessage{
  843. Frame: wire.SNACFrame{
  844. FoodGroup: wire.ChatNav,
  845. SubGroup: wire.ChatNavNavInfo,
  846. },
  847. Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
  848. }
  849. svc := newMockChatNavService(t)
  850. svc.EXPECT().
  851. RequestChatRights(mock.Anything, input.Frame).
  852. Return(output)
  853. h := Handler{
  854. ChatNavService: svc,
  855. RouteLogger: middleware.RouteLogger{
  856. Logger: slog.Default(),
  857. },
  858. }
  859. responseWriter := newMockResponseWriter(t)
  860. responseWriter.EXPECT().
  861. SendSNAC(output.Frame, output.Body).
  862. Return(tt.responseError)
  863. buf := &bytes.Buffer{}
  864. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  865. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  866. if tt.expectedError != nil {
  867. assert.ErrorIs(t, err, tt.expectedError)
  868. } else {
  869. assert.NoError(t, err)
  870. }
  871. })
  872. }
  873. }
  874. func TestHandler_ChatNavRequestRoomInfo(t *testing.T) {
  875. tests := []struct {
  876. name string
  877. inputBody wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo
  878. serviceError error
  879. responseError error
  880. expectedError error
  881. }{
  882. {
  883. name: "success",
  884. inputBody: wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo{
  885. Exchange: 1,
  886. },
  887. },
  888. {
  889. name: "service error",
  890. inputBody: wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo{
  891. Exchange: 1,
  892. },
  893. serviceError: assert.AnError,
  894. expectedError: assert.AnError,
  895. },
  896. {
  897. name: "response writer error",
  898. inputBody: wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo{
  899. Exchange: 1,
  900. },
  901. responseError: assert.AnError,
  902. expectedError: assert.AnError,
  903. },
  904. }
  905. for _, tt := range tests {
  906. t.Run(tt.name, func(t *testing.T) {
  907. input := wire.SNACMessage{
  908. Frame: wire.SNACFrame{
  909. FoodGroup: wire.ChatNav,
  910. SubGroup: wire.ChatNavRequestRoomInfo,
  911. },
  912. Body: tt.inputBody,
  913. }
  914. output := wire.SNACMessage{
  915. Frame: wire.SNACFrame{
  916. FoodGroup: wire.ChatNav,
  917. SubGroup: wire.ChatNavNavInfo,
  918. },
  919. Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
  920. }
  921. svc := newMockChatNavService(t)
  922. svc.EXPECT().
  923. RequestRoomInfo(mock.Anything, input.Frame, input.Body).
  924. Return(output, tt.serviceError)
  925. h := Handler{
  926. ChatNavService: svc,
  927. RouteLogger: middleware.RouteLogger{
  928. Logger: slog.Default(),
  929. },
  930. }
  931. responseWriter := newMockResponseWriter(t)
  932. if tt.serviceError == nil {
  933. responseWriter.EXPECT().
  934. SendSNAC(output.Frame, output.Body).
  935. Return(tt.responseError)
  936. }
  937. buf := &bytes.Buffer{}
  938. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  939. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  940. if tt.expectedError != nil {
  941. assert.ErrorIs(t, err, tt.expectedError)
  942. } else {
  943. assert.NoError(t, err)
  944. }
  945. })
  946. }
  947. }
  948. func TestHandler_ChatNavRequestExchangeInfo(t *testing.T) {
  949. tests := []struct {
  950. name string
  951. inputBody wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo
  952. serviceError error
  953. responseError error
  954. expectedError error
  955. }{
  956. {
  957. name: "success",
  958. inputBody: wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo{
  959. Exchange: 4,
  960. },
  961. },
  962. {
  963. name: "service error",
  964. inputBody: wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo{
  965. Exchange: 4,
  966. },
  967. serviceError: assert.AnError,
  968. expectedError: assert.AnError,
  969. },
  970. {
  971. name: "response writer error",
  972. inputBody: wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo{
  973. Exchange: 4,
  974. },
  975. responseError: assert.AnError,
  976. expectedError: assert.AnError,
  977. },
  978. }
  979. for _, tt := range tests {
  980. t.Run(tt.name, func(t *testing.T) {
  981. input := wire.SNACMessage{
  982. Frame: wire.SNACFrame{
  983. FoodGroup: wire.ChatNav,
  984. SubGroup: wire.ChatNavRequestExchangeInfo,
  985. },
  986. Body: tt.inputBody,
  987. }
  988. output := wire.SNACMessage{
  989. Frame: wire.SNACFrame{
  990. FoodGroup: wire.ChatNav,
  991. SubGroup: wire.ChatNavNavInfo,
  992. },
  993. Body: wire.SNAC_0x0D_0x09_ChatNavNavInfo{},
  994. }
  995. svc := newMockChatNavService(t)
  996. svc.EXPECT().
  997. ExchangeInfo(mock.Anything, input.Frame, input.Body).
  998. Return(output, tt.serviceError)
  999. h := Handler{
  1000. ChatNavService: svc,
  1001. RouteLogger: middleware.RouteLogger{
  1002. Logger: slog.Default(),
  1003. },
  1004. }
  1005. responseWriter := newMockResponseWriter(t)
  1006. if tt.serviceError == nil {
  1007. responseWriter.EXPECT().
  1008. SendSNAC(output.Frame, output.Body).
  1009. Return(tt.responseError)
  1010. }
  1011. buf := &bytes.Buffer{}
  1012. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1013. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1014. if tt.expectedError != nil {
  1015. assert.ErrorIs(t, err, tt.expectedError)
  1016. } else {
  1017. assert.NoError(t, err)
  1018. }
  1019. })
  1020. }
  1021. }
  1022. func TestHandler_ChatChannelMsgToHost(t *testing.T) {
  1023. tests := []struct {
  1024. name string
  1025. inputBody wire.SNAC_0x0E_0x05_ChatChannelMsgToHost
  1026. serviceResponse *wire.SNACMessage
  1027. serviceError error
  1028. responseError error
  1029. expectedError error
  1030. }{
  1031. {
  1032. name: "success with reflected response",
  1033. inputBody: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
  1034. Channel: 4,
  1035. },
  1036. serviceResponse: &wire.SNACMessage{
  1037. Frame: wire.SNACFrame{
  1038. FoodGroup: wire.Chat,
  1039. SubGroup: wire.ChatChannelMsgToClient,
  1040. },
  1041. Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
  1042. Channel: 4,
  1043. },
  1044. },
  1045. },
  1046. {
  1047. name: "service error with reflected response",
  1048. inputBody: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
  1049. Channel: 4,
  1050. },
  1051. serviceResponse: &wire.SNACMessage{
  1052. Frame: wire.SNACFrame{
  1053. FoodGroup: wire.Chat,
  1054. SubGroup: wire.ChatChannelMsgToClient,
  1055. },
  1056. Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
  1057. Channel: 4,
  1058. },
  1059. },
  1060. serviceError: assert.AnError,
  1061. expectedError: assert.AnError,
  1062. },
  1063. {
  1064. name: "response writer error with reflected response",
  1065. inputBody: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
  1066. Channel: 4,
  1067. },
  1068. serviceResponse: &wire.SNACMessage{
  1069. Frame: wire.SNACFrame{
  1070. FoodGroup: wire.Chat,
  1071. SubGroup: wire.ChatChannelMsgToClient,
  1072. },
  1073. Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
  1074. Channel: 4,
  1075. },
  1076. },
  1077. responseError: assert.AnError,
  1078. expectedError: assert.AnError,
  1079. },
  1080. {
  1081. name: "success without reflected response",
  1082. inputBody: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
  1083. Channel: 4,
  1084. },
  1085. serviceResponse: nil, // nil response means no reflection back to caller
  1086. },
  1087. {
  1088. name: "service error without reflected response",
  1089. inputBody: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
  1090. Channel: 4,
  1091. },
  1092. serviceResponse: nil,
  1093. serviceError: assert.AnError,
  1094. expectedError: assert.AnError,
  1095. },
  1096. }
  1097. for _, tt := range tests {
  1098. t.Run(tt.name, func(t *testing.T) {
  1099. input := wire.SNACMessage{
  1100. Frame: wire.SNACFrame{
  1101. FoodGroup: wire.Chat,
  1102. SubGroup: wire.ChatChannelMsgToHost,
  1103. },
  1104. Body: tt.inputBody,
  1105. }
  1106. svc := newMockChatService(t)
  1107. svc.EXPECT().
  1108. ChannelMsgToHost(mock.Anything, mock.Anything, input.Frame, input.Body).
  1109. Return(tt.serviceResponse, tt.serviceError)
  1110. h := Handler{
  1111. ChatService: svc,
  1112. RouteLogger: middleware.RouteLogger{
  1113. Logger: slog.Default(),
  1114. },
  1115. }
  1116. responseWriter := newMockResponseWriter(t)
  1117. if tt.serviceError == nil && tt.serviceResponse != nil {
  1118. responseWriter.EXPECT().
  1119. SendSNAC(tt.serviceResponse.Frame, tt.serviceResponse.Body).
  1120. Return(tt.responseError)
  1121. }
  1122. buf := &bytes.Buffer{}
  1123. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1124. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1125. if tt.expectedError != nil {
  1126. assert.ErrorIs(t, err, tt.expectedError)
  1127. } else {
  1128. assert.NoError(t, err)
  1129. }
  1130. })
  1131. }
  1132. }
  1133. func TestHandler_FeedbagDeleteItem(t *testing.T) {
  1134. tests := []struct {
  1135. name string
  1136. inputBody wire.SNAC_0x13_0x0A_FeedbagDeleteItem
  1137. serviceError error
  1138. responseError error
  1139. expectedError error
  1140. }{
  1141. {
  1142. name: "success",
  1143. inputBody: wire.SNAC_0x13_0x0A_FeedbagDeleteItem{
  1144. Items: []wire.FeedbagItem{
  1145. {
  1146. Name: "my-item",
  1147. },
  1148. },
  1149. },
  1150. },
  1151. {
  1152. name: "service error",
  1153. inputBody: wire.SNAC_0x13_0x0A_FeedbagDeleteItem{
  1154. Items: []wire.FeedbagItem{
  1155. {
  1156. Name: "my-item",
  1157. },
  1158. },
  1159. },
  1160. serviceError: assert.AnError,
  1161. expectedError: assert.AnError,
  1162. },
  1163. {
  1164. name: "response writer error",
  1165. inputBody: wire.SNAC_0x13_0x0A_FeedbagDeleteItem{
  1166. Items: []wire.FeedbagItem{
  1167. {
  1168. Name: "my-item",
  1169. },
  1170. },
  1171. },
  1172. responseError: assert.AnError,
  1173. expectedError: assert.AnError,
  1174. },
  1175. }
  1176. for _, tt := range tests {
  1177. t.Run(tt.name, func(t *testing.T) {
  1178. input := wire.SNACMessage{
  1179. Frame: wire.SNACFrame{
  1180. FoodGroup: wire.Feedbag,
  1181. SubGroup: wire.FeedbagDeleteItem,
  1182. },
  1183. Body: tt.inputBody,
  1184. }
  1185. output := wire.SNACMessage{
  1186. Frame: wire.SNACFrame{
  1187. FoodGroup: wire.Feedbag,
  1188. SubGroup: wire.FeedbagStatus,
  1189. },
  1190. Body: wire.SNAC_0x13_0x0E_FeedbagStatus{
  1191. Results: []uint16{1234},
  1192. },
  1193. }
  1194. svc := newMockFeedbagService(t)
  1195. svc.EXPECT().
  1196. DeleteItem(mock.Anything, mock.Anything, input.Frame, input.Body).
  1197. Return(output, tt.serviceError)
  1198. h := Handler{
  1199. FeedbagService: svc,
  1200. RouteLogger: middleware.RouteLogger{
  1201. Logger: slog.Default(),
  1202. },
  1203. }
  1204. responseWriter := newMockResponseWriter(t)
  1205. if tt.serviceError == nil {
  1206. responseWriter.EXPECT().
  1207. SendSNAC(output.Frame, output.Body).
  1208. Return(tt.responseError)
  1209. }
  1210. buf := &bytes.Buffer{}
  1211. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1212. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1213. if tt.expectedError != nil {
  1214. assert.ErrorIs(t, err, tt.expectedError)
  1215. } else {
  1216. assert.NoError(t, err)
  1217. }
  1218. })
  1219. }
  1220. }
  1221. func TestHandler_FeedbagEndCluster(t *testing.T) {
  1222. tests := []struct {
  1223. name string
  1224. inputBody struct{}
  1225. expectedError error
  1226. }{
  1227. {
  1228. name: "success",
  1229. inputBody: struct{}{},
  1230. },
  1231. }
  1232. for _, tt := range tests {
  1233. t.Run(tt.name, func(t *testing.T) {
  1234. input := wire.SNACMessage{
  1235. Frame: wire.SNACFrame{
  1236. FoodGroup: wire.Feedbag,
  1237. SubGroup: wire.FeedbagEndCluster,
  1238. },
  1239. Body: tt.inputBody,
  1240. }
  1241. svc := newMockFeedbagService(t)
  1242. h := Handler{
  1243. FeedbagService: svc,
  1244. RouteLogger: middleware.RouteLogger{
  1245. Logger: slog.Default(),
  1246. },
  1247. }
  1248. responseWriter := newMockResponseWriter(t)
  1249. buf := &bytes.Buffer{}
  1250. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1251. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1252. if tt.expectedError != nil {
  1253. assert.ErrorIs(t, err, tt.expectedError)
  1254. } else {
  1255. assert.NoError(t, err)
  1256. }
  1257. })
  1258. }
  1259. }
  1260. func TestHandler_FeedbagInsertItem(t *testing.T) {
  1261. tests := []struct {
  1262. name string
  1263. inputBody wire.SNAC_0x13_0x08_FeedbagInsertItem
  1264. serviceError error
  1265. responseError error
  1266. expectedError error
  1267. }{
  1268. {
  1269. name: "success",
  1270. inputBody: wire.SNAC_0x13_0x08_FeedbagInsertItem{
  1271. Items: []wire.FeedbagItem{
  1272. {
  1273. Name: "my-item",
  1274. },
  1275. },
  1276. },
  1277. },
  1278. {
  1279. name: "service error",
  1280. inputBody: wire.SNAC_0x13_0x08_FeedbagInsertItem{
  1281. Items: []wire.FeedbagItem{
  1282. {
  1283. Name: "my-item",
  1284. },
  1285. },
  1286. },
  1287. serviceError: assert.AnError,
  1288. expectedError: assert.AnError,
  1289. },
  1290. {
  1291. name: "response writer error",
  1292. inputBody: wire.SNAC_0x13_0x08_FeedbagInsertItem{
  1293. Items: []wire.FeedbagItem{
  1294. {
  1295. Name: "my-item",
  1296. },
  1297. },
  1298. },
  1299. responseError: assert.AnError,
  1300. expectedError: assert.AnError,
  1301. },
  1302. }
  1303. for _, tt := range tests {
  1304. t.Run(tt.name, func(t *testing.T) {
  1305. input := wire.SNACMessage{
  1306. Frame: wire.SNACFrame{
  1307. FoodGroup: wire.Feedbag,
  1308. SubGroup: wire.FeedbagInsertItem,
  1309. },
  1310. Body: tt.inputBody,
  1311. }
  1312. output := wire.SNACMessage{
  1313. Frame: wire.SNACFrame{
  1314. FoodGroup: wire.Feedbag,
  1315. SubGroup: wire.FeedbagStatus,
  1316. },
  1317. Body: wire.SNAC_0x13_0x0E_FeedbagStatus{
  1318. Results: []uint16{1234},
  1319. },
  1320. }
  1321. svc := newMockFeedbagService(t)
  1322. svc.EXPECT().
  1323. UpsertItem(mock.Anything, mock.Anything, input.Frame, tt.inputBody.Items).
  1324. Return(output, tt.serviceError)
  1325. h := Handler{
  1326. FeedbagService: svc,
  1327. RouteLogger: middleware.RouteLogger{
  1328. Logger: slog.Default(),
  1329. },
  1330. }
  1331. responseWriter := newMockResponseWriter(t)
  1332. if tt.serviceError == nil {
  1333. responseWriter.EXPECT().
  1334. SendSNAC(output.Frame, output.Body).
  1335. Return(tt.responseError)
  1336. }
  1337. buf := &bytes.Buffer{}
  1338. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1339. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1340. if tt.expectedError != nil {
  1341. assert.ErrorIs(t, err, tt.expectedError)
  1342. } else {
  1343. assert.NoError(t, err)
  1344. }
  1345. })
  1346. }
  1347. }
  1348. func TestHandler_FeedbagQuery(t *testing.T) {
  1349. tests := []struct {
  1350. name string
  1351. inputBody wire.SNAC_0x13_0x02_FeedbagRightsQuery
  1352. serviceError error
  1353. responseError error
  1354. expectedError error
  1355. }{
  1356. {
  1357. name: "success",
  1358. inputBody: wire.SNAC_0x13_0x02_FeedbagRightsQuery{
  1359. TLVRestBlock: wire.TLVRestBlock{
  1360. TLVList: wire.TLVList{
  1361. {
  1362. Tag: 0x01,
  1363. Value: []byte{1, 2, 3, 4},
  1364. },
  1365. },
  1366. },
  1367. },
  1368. },
  1369. {
  1370. name: "service error",
  1371. inputBody: wire.SNAC_0x13_0x02_FeedbagRightsQuery{
  1372. TLVRestBlock: wire.TLVRestBlock{
  1373. TLVList: wire.TLVList{
  1374. {
  1375. Tag: 0x01,
  1376. Value: []byte{1, 2, 3, 4},
  1377. },
  1378. },
  1379. },
  1380. },
  1381. serviceError: assert.AnError,
  1382. expectedError: assert.AnError,
  1383. },
  1384. {
  1385. name: "response writer error",
  1386. inputBody: wire.SNAC_0x13_0x02_FeedbagRightsQuery{
  1387. TLVRestBlock: wire.TLVRestBlock{
  1388. TLVList: wire.TLVList{
  1389. {
  1390. Tag: 0x01,
  1391. Value: []byte{1, 2, 3, 4},
  1392. },
  1393. },
  1394. },
  1395. },
  1396. responseError: assert.AnError,
  1397. expectedError: assert.AnError,
  1398. },
  1399. }
  1400. for _, tt := range tests {
  1401. t.Run(tt.name, func(t *testing.T) {
  1402. input := wire.SNACMessage{
  1403. Frame: wire.SNACFrame{
  1404. FoodGroup: wire.Feedbag,
  1405. SubGroup: wire.FeedbagQuery,
  1406. },
  1407. Body: tt.inputBody,
  1408. }
  1409. output := wire.SNACMessage{
  1410. Frame: wire.SNACFrame{
  1411. FoodGroup: wire.Feedbag,
  1412. SubGroup: wire.FeedbagReply,
  1413. },
  1414. Body: wire.SNAC_0x13_0x06_FeedbagReply{
  1415. Version: 4,
  1416. },
  1417. }
  1418. svc := newMockFeedbagService(t)
  1419. svc.EXPECT().
  1420. Query(mock.Anything, mock.Anything, input.Frame).
  1421. Return(output, tt.serviceError)
  1422. h := Handler{
  1423. FeedbagService: svc,
  1424. RouteLogger: middleware.RouteLogger{
  1425. Logger: slog.Default(),
  1426. },
  1427. }
  1428. responseWriter := newMockResponseWriter(t)
  1429. if tt.serviceError == nil {
  1430. responseWriter.EXPECT().
  1431. SendSNAC(output.Frame, output.Body).
  1432. Return(tt.responseError)
  1433. }
  1434. buf := &bytes.Buffer{}
  1435. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1436. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1437. if tt.expectedError != nil {
  1438. assert.ErrorIs(t, err, tt.expectedError)
  1439. } else {
  1440. assert.NoError(t, err)
  1441. }
  1442. })
  1443. }
  1444. }
  1445. func TestHandler_FeedbagQueryIfModified(t *testing.T) {
  1446. tests := []struct {
  1447. name string
  1448. inputBody wire.SNAC_0x13_0x05_FeedbagQueryIfModified
  1449. serviceError error
  1450. responseError error
  1451. expectedError error
  1452. }{
  1453. {
  1454. name: "success",
  1455. inputBody: wire.SNAC_0x13_0x05_FeedbagQueryIfModified{
  1456. LastUpdate: 1234,
  1457. },
  1458. },
  1459. {
  1460. name: "service error",
  1461. inputBody: wire.SNAC_0x13_0x05_FeedbagQueryIfModified{
  1462. LastUpdate: 1234,
  1463. },
  1464. serviceError: assert.AnError,
  1465. expectedError: assert.AnError,
  1466. },
  1467. {
  1468. name: "response writer error",
  1469. inputBody: wire.SNAC_0x13_0x05_FeedbagQueryIfModified{
  1470. LastUpdate: 1234,
  1471. },
  1472. responseError: assert.AnError,
  1473. expectedError: assert.AnError,
  1474. },
  1475. }
  1476. for _, tt := range tests {
  1477. t.Run(tt.name, func(t *testing.T) {
  1478. input := wire.SNACMessage{
  1479. Frame: wire.SNACFrame{
  1480. FoodGroup: wire.Feedbag,
  1481. SubGroup: wire.FeedbagQueryIfModified,
  1482. },
  1483. Body: tt.inputBody,
  1484. }
  1485. output := wire.SNACMessage{
  1486. Frame: wire.SNACFrame{
  1487. FoodGroup: wire.Feedbag,
  1488. SubGroup: wire.FeedbagReply,
  1489. },
  1490. Body: wire.SNAC_0x13_0x06_FeedbagReply{
  1491. LastUpdate: 1234,
  1492. },
  1493. }
  1494. svc := newMockFeedbagService(t)
  1495. svc.EXPECT().
  1496. QueryIfModified(mock.Anything, mock.Anything, input.Frame, input.Body).
  1497. Return(output, tt.serviceError)
  1498. h := Handler{
  1499. FeedbagService: svc,
  1500. RouteLogger: middleware.RouteLogger{
  1501. Logger: slog.Default(),
  1502. },
  1503. }
  1504. responseWriter := newMockResponseWriter(t)
  1505. if tt.serviceError == nil {
  1506. responseWriter.EXPECT().
  1507. SendSNAC(output.Frame, output.Body).
  1508. Return(tt.responseError)
  1509. }
  1510. buf := &bytes.Buffer{}
  1511. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1512. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1513. if tt.expectedError != nil {
  1514. assert.ErrorIs(t, err, tt.expectedError)
  1515. } else {
  1516. assert.NoError(t, err)
  1517. }
  1518. })
  1519. }
  1520. }
  1521. func TestHandler_FeedbagRightsQuery(t *testing.T) {
  1522. tests := []struct {
  1523. name string
  1524. inputBody wire.SNAC_0x13_0x02_FeedbagRightsQuery
  1525. responseError error
  1526. expectedError error
  1527. }{
  1528. {
  1529. name: "success",
  1530. inputBody: wire.SNAC_0x13_0x02_FeedbagRightsQuery{
  1531. TLVRestBlock: wire.TLVRestBlock{
  1532. TLVList: wire.TLVList{
  1533. {
  1534. Tag: 0x01,
  1535. Value: []byte{1, 2, 3, 4},
  1536. },
  1537. },
  1538. },
  1539. },
  1540. },
  1541. {
  1542. name: "response writer error",
  1543. inputBody: wire.SNAC_0x13_0x02_FeedbagRightsQuery{
  1544. TLVRestBlock: wire.TLVRestBlock{
  1545. TLVList: wire.TLVList{
  1546. {
  1547. Tag: 0x01,
  1548. Value: []byte{1, 2, 3, 4},
  1549. },
  1550. },
  1551. },
  1552. },
  1553. responseError: assert.AnError,
  1554. expectedError: assert.AnError,
  1555. },
  1556. }
  1557. for _, tt := range tests {
  1558. t.Run(tt.name, func(t *testing.T) {
  1559. input := wire.SNACMessage{
  1560. Frame: wire.SNACFrame{
  1561. FoodGroup: wire.Feedbag,
  1562. SubGroup: wire.FeedbagRightsQuery,
  1563. },
  1564. Body: tt.inputBody,
  1565. }
  1566. output := wire.SNACMessage{
  1567. Frame: wire.SNACFrame{
  1568. FoodGroup: wire.Feedbag,
  1569. SubGroup: wire.FeedbagRightsReply,
  1570. },
  1571. Body: wire.SNAC_0x13_0x03_FeedbagRightsReply{
  1572. TLVRestBlock: wire.TLVRestBlock{
  1573. TLVList: wire.TLVList{
  1574. {
  1575. Tag: 0x01,
  1576. Value: []byte{1, 2, 3, 4},
  1577. },
  1578. },
  1579. },
  1580. },
  1581. }
  1582. svc := newMockFeedbagService(t)
  1583. svc.EXPECT().
  1584. RightsQuery(mock.Anything, input.Frame).
  1585. Return(output)
  1586. h := Handler{
  1587. FeedbagService: svc,
  1588. RouteLogger: middleware.RouteLogger{
  1589. Logger: slog.Default(),
  1590. },
  1591. }
  1592. responseWriter := newMockResponseWriter(t)
  1593. responseWriter.EXPECT().
  1594. SendSNAC(output.Frame, output.Body).
  1595. Return(tt.responseError)
  1596. buf := &bytes.Buffer{}
  1597. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1598. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1599. if tt.expectedError != nil {
  1600. assert.ErrorIs(t, err, tt.expectedError)
  1601. } else {
  1602. assert.NoError(t, err)
  1603. }
  1604. })
  1605. }
  1606. }
  1607. func TestHandler_FeedbagStartCluster(t *testing.T) {
  1608. tests := []struct {
  1609. name string
  1610. inputBody wire.SNAC_0x13_0x11_FeedbagStartCluster
  1611. expectedError error
  1612. }{
  1613. {
  1614. name: "success",
  1615. inputBody: wire.SNAC_0x13_0x11_FeedbagStartCluster{
  1616. TLVRestBlock: wire.TLVRestBlock{
  1617. TLVList: wire.TLVList{
  1618. {
  1619. Tag: 0x01,
  1620. Value: []byte{1, 2, 3, 4},
  1621. },
  1622. },
  1623. },
  1624. },
  1625. },
  1626. }
  1627. for _, tt := range tests {
  1628. t.Run(tt.name, func(t *testing.T) {
  1629. input := wire.SNACMessage{
  1630. Frame: wire.SNACFrame{
  1631. FoodGroup: wire.Feedbag,
  1632. SubGroup: wire.FeedbagStartCluster,
  1633. },
  1634. Body: tt.inputBody,
  1635. }
  1636. svc := newMockFeedbagService(t)
  1637. svc.EXPECT().
  1638. StartCluster(mock.Anything, input.Frame, input.Body)
  1639. h := Handler{
  1640. FeedbagService: svc,
  1641. RouteLogger: middleware.RouteLogger{
  1642. Logger: slog.Default(),
  1643. },
  1644. }
  1645. responseWriter := newMockResponseWriter(t)
  1646. buf := &bytes.Buffer{}
  1647. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1648. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1649. if tt.expectedError != nil {
  1650. assert.ErrorIs(t, err, tt.expectedError)
  1651. } else {
  1652. assert.NoError(t, err)
  1653. }
  1654. })
  1655. }
  1656. }
  1657. func TestHandler_FeedbagUpdateItem(t *testing.T) {
  1658. tests := []struct {
  1659. name string
  1660. inputBody wire.SNAC_0x13_0x09_FeedbagUpdateItem
  1661. serviceError error
  1662. responseError error
  1663. expectedError error
  1664. }{
  1665. {
  1666. name: "success",
  1667. inputBody: wire.SNAC_0x13_0x09_FeedbagUpdateItem{
  1668. Items: []wire.FeedbagItem{
  1669. {
  1670. Name: "my-item",
  1671. },
  1672. },
  1673. },
  1674. },
  1675. {
  1676. name: "service error",
  1677. inputBody: wire.SNAC_0x13_0x09_FeedbagUpdateItem{
  1678. Items: []wire.FeedbagItem{
  1679. {
  1680. Name: "my-item",
  1681. },
  1682. },
  1683. },
  1684. serviceError: assert.AnError,
  1685. expectedError: assert.AnError,
  1686. },
  1687. {
  1688. name: "response writer error",
  1689. inputBody: wire.SNAC_0x13_0x09_FeedbagUpdateItem{
  1690. Items: []wire.FeedbagItem{
  1691. {
  1692. Name: "my-item",
  1693. },
  1694. },
  1695. },
  1696. responseError: assert.AnError,
  1697. expectedError: assert.AnError,
  1698. },
  1699. }
  1700. for _, tt := range tests {
  1701. t.Run(tt.name, func(t *testing.T) {
  1702. input := wire.SNACMessage{
  1703. Frame: wire.SNACFrame{
  1704. FoodGroup: wire.Feedbag,
  1705. SubGroup: wire.FeedbagUpdateItem,
  1706. },
  1707. Body: tt.inputBody,
  1708. }
  1709. output := wire.SNACMessage{
  1710. Frame: wire.SNACFrame{
  1711. FoodGroup: wire.Feedbag,
  1712. SubGroup: wire.FeedbagStatus,
  1713. },
  1714. Body: wire.SNAC_0x13_0x0E_FeedbagStatus{
  1715. Results: []uint16{1234},
  1716. },
  1717. }
  1718. svc := newMockFeedbagService(t)
  1719. svc.EXPECT().
  1720. UpsertItem(mock.Anything, mock.Anything, input.Frame, tt.inputBody.Items).
  1721. Return(output, tt.serviceError)
  1722. h := Handler{
  1723. FeedbagService: svc,
  1724. RouteLogger: middleware.RouteLogger{
  1725. Logger: slog.Default(),
  1726. },
  1727. }
  1728. responseWriter := newMockResponseWriter(t)
  1729. if tt.serviceError == nil {
  1730. responseWriter.EXPECT().
  1731. SendSNAC(output.Frame, output.Body).
  1732. Return(tt.responseError)
  1733. }
  1734. buf := &bytes.Buffer{}
  1735. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1736. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1737. if tt.expectedError != nil {
  1738. assert.ErrorIs(t, err, tt.expectedError)
  1739. } else {
  1740. assert.NoError(t, err)
  1741. }
  1742. })
  1743. }
  1744. }
  1745. func TestHandler_FeedbagUse(t *testing.T) {
  1746. tests := []struct {
  1747. name string
  1748. inputBody struct{}
  1749. serviceError error
  1750. expectedError error
  1751. }{
  1752. {
  1753. name: "success",
  1754. inputBody: struct{}{},
  1755. },
  1756. {
  1757. name: "service error",
  1758. inputBody: struct{}{},
  1759. serviceError: assert.AnError,
  1760. expectedError: assert.AnError,
  1761. },
  1762. }
  1763. for _, tt := range tests {
  1764. t.Run(tt.name, func(t *testing.T) {
  1765. input := wire.SNACMessage{
  1766. Frame: wire.SNACFrame{
  1767. FoodGroup: wire.Feedbag,
  1768. SubGroup: wire.FeedbagUse,
  1769. },
  1770. Body: tt.inputBody,
  1771. }
  1772. svc := newMockFeedbagService(t)
  1773. svc.EXPECT().
  1774. Use(mock.Anything, mock.Anything).
  1775. Return(tt.serviceError)
  1776. h := Handler{
  1777. FeedbagService: svc,
  1778. RouteLogger: middleware.RouteLogger{
  1779. Logger: slog.Default(),
  1780. },
  1781. }
  1782. responseWriter := newMockResponseWriter(t)
  1783. buf := &bytes.Buffer{}
  1784. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1785. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1786. if tt.expectedError != nil {
  1787. assert.ErrorIs(t, err, tt.expectedError)
  1788. } else {
  1789. assert.NoError(t, err)
  1790. }
  1791. })
  1792. }
  1793. }
  1794. func TestHandler_FeedbagRespondAuthorizeToHost(t *testing.T) {
  1795. input := wire.SNACMessage{
  1796. Frame: wire.SNACFrame{
  1797. FoodGroup: wire.Feedbag,
  1798. SubGroup: wire.FeedbagRespondAuthorizeToHost,
  1799. },
  1800. Body: wire.SNAC_0x13_0x1A_FeedbagRespondAuthorizeToHost{
  1801. ScreenName: "theScreenName",
  1802. },
  1803. }
  1804. svc := newMockFeedbagService(t)
  1805. svc.EXPECT().
  1806. RespondAuthorizeToHost(mock.Anything, mock.Anything, input.Frame, input.Body).
  1807. Return(nil)
  1808. h := Handler{
  1809. FeedbagService: svc,
  1810. RouteLogger: middleware.RouteLogger{
  1811. Logger: slog.Default(),
  1812. },
  1813. }
  1814. responseWriter := newMockResponseWriter(t)
  1815. buf := &bytes.Buffer{}
  1816. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1817. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{}))
  1818. }
  1819. func TestHandler_ICBMAddParameters(t *testing.T) {
  1820. tests := []struct {
  1821. name string
  1822. inputBody wire.SNAC_0x04_0x02_ICBMAddParameters
  1823. expectedError error
  1824. }{
  1825. {
  1826. name: "success",
  1827. inputBody: wire.SNAC_0x04_0x02_ICBMAddParameters{
  1828. Channel: 1,
  1829. },
  1830. },
  1831. }
  1832. for _, tt := range tests {
  1833. t.Run(tt.name, func(t *testing.T) {
  1834. input := wire.SNACMessage{
  1835. Frame: wire.SNACFrame{
  1836. FoodGroup: wire.ICBM,
  1837. SubGroup: wire.ICBMAddParameters,
  1838. },
  1839. Body: tt.inputBody,
  1840. }
  1841. svc := newMockICBMService(t)
  1842. h := Handler{
  1843. ICBMService: svc,
  1844. RouteLogger: middleware.RouteLogger{
  1845. Logger: slog.Default(),
  1846. },
  1847. }
  1848. responseWriter := newMockResponseWriter(t)
  1849. buf := &bytes.Buffer{}
  1850. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1851. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1852. if tt.expectedError != nil {
  1853. assert.ErrorIs(t, err, tt.expectedError)
  1854. } else {
  1855. assert.NoError(t, err)
  1856. }
  1857. })
  1858. }
  1859. }
  1860. func TestHandler_ICBMChannelMsgToHost(t *testing.T) {
  1861. tests := []struct {
  1862. name string
  1863. inputBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost
  1864. serviceError error
  1865. responseError error
  1866. expectedError error
  1867. }{
  1868. {
  1869. name: "success",
  1870. inputBody: wire.SNAC_0x04_0x06_ICBMChannelMsgToHost{
  1871. ScreenName: "recipient-screen-name",
  1872. },
  1873. },
  1874. {
  1875. name: "service error",
  1876. inputBody: wire.SNAC_0x04_0x06_ICBMChannelMsgToHost{
  1877. ScreenName: "recipient-screen-name",
  1878. },
  1879. serviceError: assert.AnError,
  1880. expectedError: assert.AnError,
  1881. },
  1882. {
  1883. name: "response writer error",
  1884. inputBody: wire.SNAC_0x04_0x06_ICBMChannelMsgToHost{
  1885. ScreenName: "recipient-screen-name",
  1886. },
  1887. responseError: assert.AnError,
  1888. expectedError: assert.AnError,
  1889. },
  1890. }
  1891. for _, tt := range tests {
  1892. t.Run(tt.name, func(t *testing.T) {
  1893. input := wire.SNACMessage{
  1894. Frame: wire.SNACFrame{
  1895. FoodGroup: wire.ICBM,
  1896. SubGroup: wire.ICBMChannelMsgToHost,
  1897. },
  1898. Body: tt.inputBody,
  1899. }
  1900. output := wire.SNACMessage{
  1901. Frame: wire.SNACFrame{
  1902. FoodGroup: wire.ICBM,
  1903. SubGroup: wire.ICBMHostAck,
  1904. },
  1905. Body: wire.SNAC_0x04_0x0C_ICBMHostAck{
  1906. ChannelID: 4,
  1907. },
  1908. }
  1909. svc := newMockICBMService(t)
  1910. svc.EXPECT().
  1911. ChannelMsgToHost(mock.Anything, mock.Anything, input.Frame, input.Body).
  1912. Return(&output, tt.serviceError)
  1913. h := Handler{
  1914. ICBMService: svc,
  1915. RouteLogger: middleware.RouteLogger{
  1916. Logger: slog.Default(),
  1917. },
  1918. }
  1919. responseWriter := newMockResponseWriter(t)
  1920. if tt.serviceError == nil {
  1921. responseWriter.EXPECT().
  1922. SendSNAC(output.Frame, output.Body).
  1923. Return(tt.responseError)
  1924. }
  1925. buf := &bytes.Buffer{}
  1926. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1927. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1928. if tt.expectedError != nil {
  1929. assert.ErrorIs(t, err, tt.expectedError)
  1930. } else {
  1931. assert.NoError(t, err)
  1932. }
  1933. })
  1934. }
  1935. }
  1936. func TestHandler_ICBMClientErr(t *testing.T) {
  1937. tests := []struct {
  1938. name string
  1939. inputBody wire.SNAC_0x04_0x0B_ICBMClientErr
  1940. serviceError error
  1941. expectedError error
  1942. }{
  1943. {
  1944. name: "success",
  1945. inputBody: wire.SNAC_0x04_0x0B_ICBMClientErr{
  1946. Code: 4,
  1947. },
  1948. },
  1949. {
  1950. name: "service error",
  1951. inputBody: wire.SNAC_0x04_0x0B_ICBMClientErr{
  1952. Code: 4,
  1953. },
  1954. serviceError: assert.AnError,
  1955. expectedError: assert.AnError,
  1956. },
  1957. }
  1958. for _, tt := range tests {
  1959. t.Run(tt.name, func(t *testing.T) {
  1960. input := wire.SNACMessage{
  1961. Frame: wire.SNACFrame{
  1962. FoodGroup: wire.ICBM,
  1963. SubGroup: wire.ICBMClientErr,
  1964. },
  1965. Body: tt.inputBody,
  1966. }
  1967. svc := newMockICBMService(t)
  1968. svc.EXPECT().
  1969. ClientErr(mock.Anything, mock.Anything, input.Frame, input.Body).
  1970. Return(tt.serviceError)
  1971. h := Handler{
  1972. ICBMService: svc,
  1973. RouteLogger: middleware.RouteLogger{
  1974. Logger: slog.Default(),
  1975. },
  1976. }
  1977. responseWriter := newMockResponseWriter(t)
  1978. buf := &bytes.Buffer{}
  1979. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  1980. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  1981. if tt.expectedError != nil {
  1982. assert.ErrorIs(t, err, tt.expectedError)
  1983. } else {
  1984. assert.NoError(t, err)
  1985. }
  1986. })
  1987. }
  1988. }
  1989. func TestHandler_ICBMClientEvent(t *testing.T) {
  1990. tests := []struct {
  1991. name string
  1992. inputBody wire.SNAC_0x04_0x14_ICBMClientEvent
  1993. serviceError error
  1994. expectedError error
  1995. }{
  1996. {
  1997. name: "success",
  1998. inputBody: wire.SNAC_0x04_0x14_ICBMClientEvent{
  1999. ScreenName: "recipient-screen-name",
  2000. },
  2001. },
  2002. {
  2003. name: "service error",
  2004. inputBody: wire.SNAC_0x04_0x14_ICBMClientEvent{
  2005. ScreenName: "recipient-screen-name",
  2006. },
  2007. serviceError: assert.AnError,
  2008. expectedError: assert.AnError,
  2009. },
  2010. }
  2011. for _, tt := range tests {
  2012. t.Run(tt.name, func(t *testing.T) {
  2013. input := wire.SNACMessage{
  2014. Frame: wire.SNACFrame{
  2015. FoodGroup: wire.ICBM,
  2016. SubGroup: wire.ICBMClientEvent,
  2017. },
  2018. Body: tt.inputBody,
  2019. }
  2020. svc := newMockICBMService(t)
  2021. svc.EXPECT().
  2022. ClientEvent(mock.Anything, mock.Anything, input.Frame, input.Body).
  2023. Return(tt.serviceError)
  2024. h := Handler{
  2025. ICBMService: svc,
  2026. RouteLogger: middleware.RouteLogger{
  2027. Logger: slog.Default(),
  2028. },
  2029. }
  2030. responseWriter := newMockResponseWriter(t)
  2031. buf := &bytes.Buffer{}
  2032. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  2033. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  2034. if tt.expectedError != nil {
  2035. assert.ErrorIs(t, err, tt.expectedError)
  2036. } else {
  2037. assert.NoError(t, err)
  2038. }
  2039. })
  2040. }
  2041. }
  2042. func TestHandler_ICBMEvilRequest(t *testing.T) {
  2043. tests := []struct {
  2044. name string
  2045. inputBody wire.SNAC_0x04_0x08_ICBMEvilRequest
  2046. serviceError error
  2047. responseError error
  2048. expectedError error
  2049. }{
  2050. {
  2051. name: "success",
  2052. inputBody: wire.SNAC_0x04_0x08_ICBMEvilRequest{
  2053. ScreenName: "recipient-screen-name",
  2054. },
  2055. },
  2056. {
  2057. name: "service error",
  2058. inputBody: wire.SNAC_0x04_0x08_ICBMEvilRequest{
  2059. ScreenName: "recipient-screen-name",
  2060. },
  2061. serviceError: assert.AnError,
  2062. expectedError: assert.AnError,
  2063. },
  2064. {
  2065. name: "response writer error",
  2066. inputBody: wire.SNAC_0x04_0x08_ICBMEvilRequest{
  2067. ScreenName: "recipient-screen-name",
  2068. },
  2069. responseError: assert.AnError,
  2070. expectedError: assert.AnError,
  2071. },
  2072. }
  2073. for _, tt := range tests {
  2074. t.Run(tt.name, func(t *testing.T) {
  2075. input := wire.SNACMessage{
  2076. Frame: wire.SNACFrame{
  2077. FoodGroup: wire.ICBM,
  2078. SubGroup: wire.ICBMEvilRequest,
  2079. },
  2080. Body: tt.inputBody,
  2081. }
  2082. output := wire.SNACMessage{
  2083. Frame: wire.SNACFrame{
  2084. FoodGroup: wire.ICBM,
  2085. SubGroup: wire.ICBMEvilReply,
  2086. },
  2087. Body: wire.SNAC_0x04_0x09_ICBMEvilReply{
  2088. EvilDeltaApplied: 100,
  2089. },
  2090. }
  2091. svc := newMockICBMService(t)
  2092. svc.EXPECT().
  2093. EvilRequest(mock.Anything, mock.Anything, input.Frame, input.Body).
  2094. Return(output, tt.serviceError)
  2095. h := Handler{
  2096. ICBMService: svc,
  2097. RouteLogger: middleware.RouteLogger{
  2098. Logger: slog.Default(),
  2099. },
  2100. }
  2101. responseWriter := newMockResponseWriter(t)
  2102. if tt.serviceError == nil {
  2103. responseWriter.EXPECT().
  2104. SendSNAC(output.Frame, output.Body).
  2105. Return(tt.responseError)
  2106. }
  2107. buf := &bytes.Buffer{}
  2108. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  2109. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  2110. if tt.expectedError != nil {
  2111. assert.ErrorIs(t, err, tt.expectedError)
  2112. } else {
  2113. assert.NoError(t, err)
  2114. }
  2115. })
  2116. }
  2117. }
  2118. func TestHandler_ICBMParameterQuery(t *testing.T) {
  2119. tests := []struct {
  2120. name string
  2121. inputBody struct{}
  2122. responseError error
  2123. expectedError error
  2124. }{
  2125. {
  2126. name: "success",
  2127. inputBody: struct{}{},
  2128. },
  2129. {
  2130. name: "response writer error",
  2131. inputBody: struct{}{},
  2132. responseError: assert.AnError,
  2133. expectedError: assert.AnError,
  2134. },
  2135. }
  2136. for _, tt := range tests {
  2137. t.Run(tt.name, func(t *testing.T) {
  2138. input := wire.SNACMessage{
  2139. Frame: wire.SNACFrame{
  2140. FoodGroup: wire.ICBM,
  2141. SubGroup: wire.ICBMParameterQuery,
  2142. },
  2143. Body: tt.inputBody,
  2144. }
  2145. output := wire.SNACMessage{
  2146. Frame: wire.SNACFrame{
  2147. FoodGroup: wire.ICBM,
  2148. SubGroup: wire.ICBMParameterReply,
  2149. },
  2150. Body: wire.SNAC_0x04_0x05_ICBMParameterReply{
  2151. MaxSlots: 100,
  2152. },
  2153. }
  2154. svc := newMockICBMService(t)
  2155. svc.EXPECT().
  2156. ParameterQuery(mock.Anything, input.Frame).
  2157. Return(output)
  2158. h := Handler{
  2159. ICBMService: svc,
  2160. RouteLogger: middleware.RouteLogger{
  2161. Logger: slog.Default(),
  2162. },
  2163. }
  2164. responseWriter := newMockResponseWriter(t)
  2165. responseWriter.EXPECT().
  2166. SendSNAC(output.Frame, output.Body).
  2167. Return(tt.responseError)
  2168. buf := &bytes.Buffer{}
  2169. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  2170. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  2171. if tt.expectedError != nil {
  2172. assert.ErrorIs(t, err, tt.expectedError)
  2173. } else {
  2174. assert.NoError(t, err)
  2175. }
  2176. })
  2177. }
  2178. }
  2179. func TestHandler_ICQDBQuery(t *testing.T) {
  2180. type ICQMetaRequest struct {
  2181. wire.ICQMetadata
  2182. ReqSubType uint16
  2183. MetaRequest any
  2184. }
  2185. type reqParams struct {
  2186. ctx context.Context
  2187. sess *state.Session
  2188. inFrame wire.SNACFrame
  2189. inBody wire.SNAC_0x15_0x02_BQuery
  2190. rw ResponseWriter
  2191. seq uint16
  2192. wantErr error
  2193. }
  2194. type mockParam struct {
  2195. req any
  2196. wantErr error
  2197. }
  2198. type allMockParams struct {
  2199. deleteMsgReq *mockParam
  2200. findByDetails *mockParam
  2201. findByEmail *mockParam
  2202. findByEmail3 *mockParam
  2203. findByInterests *mockParam
  2204. findByUIN *mockParam
  2205. findByUIN2 *mockParam
  2206. findByWhitePages2 *mockParam
  2207. fullUserInfo *mockParam
  2208. offlineMsgReq *mockParam
  2209. setAffiliations *mockParam
  2210. setBasicInfo *mockParam
  2211. setEmails *mockParam
  2212. setInterests *mockParam
  2213. setMoreInfo *mockParam
  2214. setPermissions *mockParam
  2215. setUserNotes *mockParam
  2216. setWorkInfo *mockParam
  2217. shortUserInfo *mockParam
  2218. xmlReqData *mockParam
  2219. }
  2220. tests := []struct {
  2221. name string
  2222. reqParams reqParams
  2223. allMockParams allMockParams
  2224. }{
  2225. {
  2226. name: "MetaReqFullInfo - happy path",
  2227. reqParams: reqParams{
  2228. sess: &state.Session{},
  2229. inBody: wire.SNAC_0x15_0x02_BQuery{
  2230. TLVRestBlock: wire.TLVRestBlock{
  2231. TLVList: wire.TLVList{
  2232. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2233. Message: ICQMetaRequest{
  2234. ICQMetadata: wire.ICQMetadata{
  2235. ReqType: wire.ICQDBQueryMetaReq,
  2236. Seq: 1,
  2237. },
  2238. ReqSubType: wire.ICQDBQueryMetaReqFullInfo,
  2239. MetaRequest: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2240. UIN: 123456789,
  2241. },
  2242. },
  2243. }),
  2244. },
  2245. },
  2246. },
  2247. seq: 1,
  2248. },
  2249. allMockParams: allMockParams{
  2250. fullUserInfo: &mockParam{
  2251. req: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2252. UIN: 123456789,
  2253. },
  2254. },
  2255. },
  2256. },
  2257. {
  2258. name: "MetaReqShortInfo - happy path",
  2259. reqParams: reqParams{
  2260. sess: &state.Session{},
  2261. inBody: wire.SNAC_0x15_0x02_BQuery{
  2262. TLVRestBlock: wire.TLVRestBlock{
  2263. TLVList: wire.TLVList{
  2264. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2265. Message: ICQMetaRequest{
  2266. ICQMetadata: wire.ICQMetadata{
  2267. ReqType: wire.ICQDBQueryMetaReq,
  2268. Seq: 1,
  2269. },
  2270. ReqSubType: wire.ICQDBQueryMetaReqShortInfo,
  2271. MetaRequest: wire.ICQ_0x07D0_0x04BA_DBQueryMetaReqShortInfo{
  2272. UIN: 123456789,
  2273. },
  2274. },
  2275. }),
  2276. },
  2277. },
  2278. },
  2279. seq: 1,
  2280. },
  2281. allMockParams: allMockParams{
  2282. shortUserInfo: &mockParam{
  2283. req: wire.ICQ_0x07D0_0x04BA_DBQueryMetaReqShortInfo{
  2284. UIN: 123456789,
  2285. },
  2286. },
  2287. },
  2288. },
  2289. {
  2290. name: "MetaReqFullInfo2 - happy path",
  2291. reqParams: reqParams{
  2292. sess: &state.Session{},
  2293. inBody: wire.SNAC_0x15_0x02_BQuery{
  2294. TLVRestBlock: wire.TLVRestBlock{
  2295. TLVList: wire.TLVList{
  2296. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2297. Message: ICQMetaRequest{
  2298. ICQMetadata: wire.ICQMetadata{
  2299. ReqType: wire.ICQDBQueryMetaReq,
  2300. Seq: 1,
  2301. },
  2302. ReqSubType: wire.ICQDBQueryMetaReqFullInfo2,
  2303. MetaRequest: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2304. UIN: 123456789,
  2305. },
  2306. },
  2307. }),
  2308. },
  2309. },
  2310. },
  2311. seq: 1,
  2312. },
  2313. allMockParams: allMockParams{
  2314. fullUserInfo: &mockParam{
  2315. req: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2316. UIN: 123456789,
  2317. },
  2318. },
  2319. },
  2320. },
  2321. {
  2322. name: "MetaReqXMLReq - happy path",
  2323. reqParams: reqParams{
  2324. sess: &state.Session{},
  2325. inBody: wire.SNAC_0x15_0x02_BQuery{
  2326. TLVRestBlock: wire.TLVRestBlock{
  2327. TLVList: wire.TLVList{
  2328. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2329. Message: ICQMetaRequest{
  2330. ICQMetadata: wire.ICQMetadata{
  2331. ReqType: wire.ICQDBQueryMetaReq,
  2332. Seq: 1,
  2333. },
  2334. ReqSubType: wire.ICQDBQueryMetaReqXMLReq,
  2335. MetaRequest: wire.ICQ_0x07D0_0x0898_DBQueryMetaReqXMLReq{
  2336. XMLRequest: "<xml></xml>",
  2337. },
  2338. },
  2339. }),
  2340. },
  2341. },
  2342. },
  2343. seq: 1,
  2344. },
  2345. allMockParams: allMockParams{
  2346. xmlReqData: &mockParam{
  2347. req: wire.ICQ_0x07D0_0x0898_DBQueryMetaReqXMLReq{
  2348. XMLRequest: "<xml></xml>",
  2349. },
  2350. },
  2351. },
  2352. },
  2353. {
  2354. name: "MetaReqSetPermissions - happy path",
  2355. reqParams: reqParams{
  2356. sess: &state.Session{},
  2357. inBody: wire.SNAC_0x15_0x02_BQuery{
  2358. TLVRestBlock: wire.TLVRestBlock{
  2359. TLVList: wire.TLVList{
  2360. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2361. Message: ICQMetaRequest{
  2362. ICQMetadata: wire.ICQMetadata{
  2363. ReqType: wire.ICQDBQueryMetaReq,
  2364. Seq: 1,
  2365. },
  2366. ReqSubType: wire.ICQDBQueryMetaReqSetPermissions,
  2367. MetaRequest: wire.ICQ_0x07D0_0x0424_DBQueryMetaReqSetPermissions{
  2368. Authorization: 1,
  2369. },
  2370. },
  2371. }),
  2372. },
  2373. },
  2374. },
  2375. seq: 1,
  2376. },
  2377. allMockParams: allMockParams{
  2378. setPermissions: &mockParam{
  2379. req: wire.ICQ_0x07D0_0x0424_DBQueryMetaReqSetPermissions{
  2380. Authorization: 1,
  2381. },
  2382. },
  2383. },
  2384. },
  2385. {
  2386. name: "MetaReqSearchByUIN - happy path",
  2387. reqParams: reqParams{
  2388. sess: &state.Session{},
  2389. inBody: wire.SNAC_0x15_0x02_BQuery{
  2390. TLVRestBlock: wire.TLVRestBlock{
  2391. TLVList: wire.TLVList{
  2392. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2393. Message: ICQMetaRequest{
  2394. ICQMetadata: wire.ICQMetadata{
  2395. ReqType: wire.ICQDBQueryMetaReq,
  2396. Seq: 1,
  2397. },
  2398. ReqSubType: wire.ICQDBQueryMetaReqSearchByUIN,
  2399. MetaRequest: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2400. UIN: 123456789,
  2401. },
  2402. },
  2403. }),
  2404. },
  2405. },
  2406. },
  2407. seq: 1,
  2408. },
  2409. allMockParams: allMockParams{
  2410. findByUIN: &mockParam{
  2411. req: wire.ICQ_0x07D0_0x051F_DBQueryMetaReqSearchByUIN{
  2412. UIN: 123456789,
  2413. },
  2414. },
  2415. },
  2416. },
  2417. {
  2418. name: "MetaReqSearchByUIN2 - happy path",
  2419. reqParams: reqParams{
  2420. sess: &state.Session{},
  2421. inBody: wire.SNAC_0x15_0x02_BQuery{
  2422. TLVRestBlock: wire.TLVRestBlock{
  2423. TLVList: wire.TLVList{
  2424. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2425. Message: ICQMetaRequest{
  2426. ICQMetadata: wire.ICQMetadata{
  2427. ReqType: wire.ICQDBQueryMetaReq,
  2428. Seq: 1,
  2429. },
  2430. ReqSubType: wire.ICQDBQueryMetaReqSearchByUIN2,
  2431. MetaRequest: wire.ICQ_0x07D0_0x0569_DBQueryMetaReqSearchByUIN2{
  2432. TLVRestBlock: wire.TLVRestBlock{
  2433. TLVList: wire.TLVList{
  2434. wire.NewTLVBE(1, uint16(1)),
  2435. },
  2436. },
  2437. },
  2438. },
  2439. }),
  2440. },
  2441. },
  2442. },
  2443. seq: 1,
  2444. },
  2445. allMockParams: allMockParams{
  2446. findByUIN2: &mockParam{
  2447. req: wire.ICQ_0x07D0_0x0569_DBQueryMetaReqSearchByUIN2{
  2448. TLVRestBlock: wire.TLVRestBlock{
  2449. TLVList: wire.TLVList{
  2450. wire.NewTLVBE(1, uint16(1)),
  2451. },
  2452. },
  2453. },
  2454. },
  2455. },
  2456. },
  2457. {
  2458. name: "MetaReqSearchByEmail - happy path",
  2459. reqParams: reqParams{
  2460. sess: &state.Session{},
  2461. inBody: wire.SNAC_0x15_0x02_BQuery{
  2462. TLVRestBlock: wire.TLVRestBlock{
  2463. TLVList: wire.TLVList{
  2464. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2465. Message: ICQMetaRequest{
  2466. ICQMetadata: wire.ICQMetadata{
  2467. ReqType: wire.ICQDBQueryMetaReq,
  2468. Seq: 1,
  2469. },
  2470. ReqSubType: wire.ICQDBQueryMetaReqSearchByEmail,
  2471. MetaRequest: wire.ICQ_0x07D0_0x0529_DBQueryMetaReqSearchByEmail{
  2472. Email: "test@aol.com",
  2473. },
  2474. },
  2475. }),
  2476. },
  2477. },
  2478. },
  2479. seq: 1,
  2480. },
  2481. allMockParams: allMockParams{
  2482. findByEmail: &mockParam{
  2483. req: wire.ICQ_0x07D0_0x0529_DBQueryMetaReqSearchByEmail{
  2484. Email: "test@aol.com",
  2485. },
  2486. },
  2487. },
  2488. },
  2489. {
  2490. name: "MetaReqSearchByEmail3 - happy path",
  2491. reqParams: reqParams{
  2492. sess: &state.Session{},
  2493. inBody: wire.SNAC_0x15_0x02_BQuery{
  2494. TLVRestBlock: wire.TLVRestBlock{
  2495. TLVList: wire.TLVList{
  2496. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2497. Message: ICQMetaRequest{
  2498. ICQMetadata: wire.ICQMetadata{
  2499. ReqType: wire.ICQDBQueryMetaReq,
  2500. Seq: 1,
  2501. },
  2502. ReqSubType: wire.ICQDBQueryMetaReqSearchByEmail3,
  2503. MetaRequest: wire.ICQ_0x07D0_0x0573_DBQueryMetaReqSearchByEmail3{
  2504. TLVRestBlock: wire.TLVRestBlock{
  2505. TLVList: wire.TLVList{
  2506. wire.NewTLVBE(1, uint16(1)),
  2507. },
  2508. },
  2509. },
  2510. },
  2511. }),
  2512. },
  2513. },
  2514. },
  2515. seq: 1,
  2516. },
  2517. allMockParams: allMockParams{
  2518. findByEmail3: &mockParam{
  2519. req: wire.ICQ_0x07D0_0x0573_DBQueryMetaReqSearchByEmail3{
  2520. TLVRestBlock: wire.TLVRestBlock{
  2521. TLVList: wire.TLVList{
  2522. wire.NewTLVBE(1, uint16(1)),
  2523. },
  2524. },
  2525. },
  2526. },
  2527. },
  2528. },
  2529. {
  2530. name: "MetaReqSearchByDetails - happy path",
  2531. reqParams: reqParams{
  2532. sess: &state.Session{},
  2533. inBody: wire.SNAC_0x15_0x02_BQuery{
  2534. TLVRestBlock: wire.TLVRestBlock{
  2535. TLVList: wire.TLVList{
  2536. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2537. Message: ICQMetaRequest{
  2538. ICQMetadata: wire.ICQMetadata{
  2539. ReqType: wire.ICQDBQueryMetaReq,
  2540. Seq: 1,
  2541. },
  2542. ReqSubType: wire.ICQDBQueryMetaReqSearchByDetails,
  2543. MetaRequest: wire.ICQ_0x07D0_0x0515_DBQueryMetaReqSearchByDetails{
  2544. FirstName: "john",
  2545. },
  2546. },
  2547. }),
  2548. },
  2549. },
  2550. },
  2551. seq: 1,
  2552. },
  2553. allMockParams: allMockParams{
  2554. findByDetails: &mockParam{
  2555. req: wire.ICQ_0x07D0_0x0515_DBQueryMetaReqSearchByDetails{
  2556. FirstName: "john",
  2557. },
  2558. },
  2559. },
  2560. },
  2561. {
  2562. name: "MetaReqSearchWhitePages - happy path",
  2563. reqParams: reqParams{
  2564. sess: &state.Session{},
  2565. inBody: wire.SNAC_0x15_0x02_BQuery{
  2566. TLVRestBlock: wire.TLVRestBlock{
  2567. TLVList: wire.TLVList{
  2568. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2569. Message: ICQMetaRequest{
  2570. ICQMetadata: wire.ICQMetadata{
  2571. ReqType: wire.ICQDBQueryMetaReq,
  2572. Seq: 1,
  2573. },
  2574. ReqSubType: wire.ICQDBQueryMetaReqSearchWhitePages,
  2575. MetaRequest: wire.ICQ_0x07D0_0x0533_DBQueryMetaReqSearchWhitePages{
  2576. InterestsCode: 1,
  2577. },
  2578. },
  2579. }),
  2580. },
  2581. },
  2582. },
  2583. seq: 1,
  2584. },
  2585. allMockParams: allMockParams{
  2586. findByInterests: &mockParam{
  2587. req: wire.ICQ_0x07D0_0x0533_DBQueryMetaReqSearchWhitePages{
  2588. InterestsCode: 1,
  2589. },
  2590. },
  2591. },
  2592. },
  2593. {
  2594. name: "MetaReqSearchWhitePages2 - happy path",
  2595. reqParams: reqParams{
  2596. sess: &state.Session{},
  2597. inBody: wire.SNAC_0x15_0x02_BQuery{
  2598. TLVRestBlock: wire.TLVRestBlock{
  2599. TLVList: wire.TLVList{
  2600. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2601. Message: ICQMetaRequest{
  2602. ICQMetadata: wire.ICQMetadata{
  2603. ReqType: wire.ICQDBQueryMetaReq,
  2604. Seq: 1,
  2605. },
  2606. ReqSubType: wire.ICQDBQueryMetaReqSearchWhitePages2,
  2607. MetaRequest: wire.ICQ_0x07D0_0x055F_DBQueryMetaReqSearchWhitePages2{
  2608. TLVRestBlock: wire.TLVRestBlock{
  2609. TLVList: wire.TLVList{
  2610. wire.NewTLVBE(1, uint16(1)),
  2611. },
  2612. },
  2613. },
  2614. },
  2615. }),
  2616. },
  2617. },
  2618. },
  2619. seq: 1,
  2620. },
  2621. allMockParams: allMockParams{
  2622. findByWhitePages2: &mockParam{
  2623. req: wire.ICQ_0x07D0_0x055F_DBQueryMetaReqSearchWhitePages2{
  2624. TLVRestBlock: wire.TLVRestBlock{
  2625. TLVList: wire.TLVList{
  2626. wire.NewTLVBE(1, uint16(1)),
  2627. },
  2628. },
  2629. },
  2630. },
  2631. },
  2632. },
  2633. {
  2634. name: "MetaReqSetBasicInfo - happy path",
  2635. reqParams: reqParams{
  2636. sess: &state.Session{},
  2637. inBody: wire.SNAC_0x15_0x02_BQuery{
  2638. TLVRestBlock: wire.TLVRestBlock{
  2639. TLVList: wire.TLVList{
  2640. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2641. Message: ICQMetaRequest{
  2642. ICQMetadata: wire.ICQMetadata{
  2643. ReqType: wire.ICQDBQueryMetaReq,
  2644. Seq: 1,
  2645. },
  2646. ReqSubType: wire.ICQDBQueryMetaReqSetBasicInfo,
  2647. MetaRequest: wire.ICQ_0x07D0_0x03EA_DBQueryMetaReqSetBasicInfo{
  2648. FirstName: "john",
  2649. },
  2650. },
  2651. }),
  2652. },
  2653. },
  2654. },
  2655. seq: 1,
  2656. },
  2657. allMockParams: allMockParams{
  2658. setBasicInfo: &mockParam{
  2659. req: wire.ICQ_0x07D0_0x03EA_DBQueryMetaReqSetBasicInfo{
  2660. FirstName: "john",
  2661. },
  2662. },
  2663. },
  2664. },
  2665. {
  2666. name: "MetaReqSetWorkInfo - happy path",
  2667. reqParams: reqParams{
  2668. sess: &state.Session{},
  2669. inBody: wire.SNAC_0x15_0x02_BQuery{
  2670. TLVRestBlock: wire.TLVRestBlock{
  2671. TLVList: wire.TLVList{
  2672. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2673. Message: ICQMetaRequest{
  2674. ICQMetadata: wire.ICQMetadata{
  2675. ReqType: wire.ICQDBQueryMetaReq,
  2676. Seq: 1,
  2677. },
  2678. ReqSubType: wire.ICQDBQueryMetaReqSetWorkInfo,
  2679. MetaRequest: wire.ICQ_0x07D0_0x03F3_DBQueryMetaReqSetWorkInfo{
  2680. ZIP: "11111",
  2681. },
  2682. },
  2683. }),
  2684. },
  2685. },
  2686. },
  2687. seq: 1,
  2688. },
  2689. allMockParams: allMockParams{
  2690. setWorkInfo: &mockParam{
  2691. req: wire.ICQ_0x07D0_0x03F3_DBQueryMetaReqSetWorkInfo{
  2692. ZIP: "11111",
  2693. },
  2694. },
  2695. },
  2696. },
  2697. {
  2698. name: "MetaReqSetMoreInfo - happy path",
  2699. reqParams: reqParams{
  2700. sess: &state.Session{},
  2701. inBody: wire.SNAC_0x15_0x02_BQuery{
  2702. TLVRestBlock: wire.TLVRestBlock{
  2703. TLVList: wire.TLVList{
  2704. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2705. Message: ICQMetaRequest{
  2706. ICQMetadata: wire.ICQMetadata{
  2707. ReqType: wire.ICQDBQueryMetaReq,
  2708. Seq: 1,
  2709. },
  2710. ReqSubType: wire.ICQDBQueryMetaReqSetMoreInfo,
  2711. MetaRequest: wire.ICQ_0x07D0_0x03FD_DBQueryMetaReqSetMoreInfo{
  2712. Age: 100,
  2713. },
  2714. },
  2715. }),
  2716. },
  2717. },
  2718. },
  2719. seq: 1,
  2720. },
  2721. allMockParams: allMockParams{
  2722. setMoreInfo: &mockParam{
  2723. req: wire.ICQ_0x07D0_0x03FD_DBQueryMetaReqSetMoreInfo{
  2724. Age: 100,
  2725. },
  2726. },
  2727. },
  2728. },
  2729. {
  2730. name: "MetaReqSetNotes - happy path",
  2731. reqParams: reqParams{
  2732. sess: &state.Session{},
  2733. inBody: wire.SNAC_0x15_0x02_BQuery{
  2734. TLVRestBlock: wire.TLVRestBlock{
  2735. TLVList: wire.TLVList{
  2736. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2737. Message: ICQMetaRequest{
  2738. ICQMetadata: wire.ICQMetadata{
  2739. ReqType: wire.ICQDBQueryMetaReq,
  2740. Seq: 1,
  2741. },
  2742. ReqSubType: wire.ICQDBQueryMetaReqSetNotes,
  2743. MetaRequest: wire.ICQ_0x07D0_0x0406_DBQueryMetaReqSetNotes{
  2744. Notes: "my note",
  2745. },
  2746. },
  2747. }),
  2748. },
  2749. },
  2750. },
  2751. seq: 1,
  2752. },
  2753. allMockParams: allMockParams{
  2754. setUserNotes: &mockParam{
  2755. req: wire.ICQ_0x07D0_0x0406_DBQueryMetaReqSetNotes{
  2756. Notes: "my note",
  2757. },
  2758. },
  2759. },
  2760. },
  2761. {
  2762. name: "MetaReqSetEmails - happy path",
  2763. reqParams: reqParams{
  2764. sess: &state.Session{},
  2765. inBody: wire.SNAC_0x15_0x02_BQuery{
  2766. TLVRestBlock: wire.TLVRestBlock{
  2767. TLVList: wire.TLVList{
  2768. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2769. Message: ICQMetaRequest{
  2770. ICQMetadata: wire.ICQMetadata{
  2771. ReqType: wire.ICQDBQueryMetaReq,
  2772. Seq: 1,
  2773. },
  2774. ReqSubType: wire.ICQDBQueryMetaReqSetEmails,
  2775. MetaRequest: wire.ICQ_0x07D0_0x040B_DBQueryMetaReqSetEmails{
  2776. Emails: []struct {
  2777. Publish uint8
  2778. Email string `oscar:"len_prefix=uint16,nullterm"`
  2779. }{
  2780. {
  2781. Email: "test@aol.com",
  2782. },
  2783. },
  2784. },
  2785. },
  2786. }),
  2787. },
  2788. },
  2789. },
  2790. seq: 1,
  2791. },
  2792. allMockParams: allMockParams{
  2793. setEmails: &mockParam{
  2794. req: wire.ICQ_0x07D0_0x040B_DBQueryMetaReqSetEmails{
  2795. Emails: []struct {
  2796. Publish uint8
  2797. Email string `oscar:"len_prefix=uint16,nullterm"`
  2798. }{
  2799. {
  2800. Email: "test@aol.com",
  2801. },
  2802. },
  2803. },
  2804. },
  2805. },
  2806. },
  2807. {
  2808. name: "MetaReqSetInterests - happy path",
  2809. reqParams: reqParams{
  2810. sess: &state.Session{},
  2811. inBody: wire.SNAC_0x15_0x02_BQuery{
  2812. TLVRestBlock: wire.TLVRestBlock{
  2813. TLVList: wire.TLVList{
  2814. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2815. Message: ICQMetaRequest{
  2816. ICQMetadata: wire.ICQMetadata{
  2817. ReqType: wire.ICQDBQueryMetaReq,
  2818. Seq: 1,
  2819. },
  2820. ReqSubType: wire.ICQDBQueryMetaReqSetInterests,
  2821. MetaRequest: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
  2822. Interests: []struct {
  2823. Code uint16
  2824. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2825. }{
  2826. {
  2827. Keyword: "an_interest",
  2828. },
  2829. },
  2830. },
  2831. },
  2832. }),
  2833. },
  2834. },
  2835. },
  2836. seq: 1,
  2837. },
  2838. allMockParams: allMockParams{
  2839. setInterests: &mockParam{
  2840. req: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
  2841. Interests: []struct {
  2842. Code uint16
  2843. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2844. }{
  2845. {
  2846. Keyword: "an_interest",
  2847. },
  2848. },
  2849. },
  2850. },
  2851. },
  2852. },
  2853. {
  2854. name: "MetaReqSetAffiliations - happy path",
  2855. reqParams: reqParams{
  2856. sess: &state.Session{},
  2857. inBody: wire.SNAC_0x15_0x02_BQuery{
  2858. TLVRestBlock: wire.TLVRestBlock{
  2859. TLVList: wire.TLVList{
  2860. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2861. Message: ICQMetaRequest{
  2862. ICQMetadata: wire.ICQMetadata{
  2863. ReqType: wire.ICQDBQueryMetaReq,
  2864. Seq: 1,
  2865. },
  2866. ReqSubType: wire.ICQDBQueryMetaReqSetAffiliations,
  2867. MetaRequest: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
  2868. PastAffiliations: []struct {
  2869. Code uint16
  2870. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2871. }{
  2872. {
  2873. Keyword: "a_past_affiliation",
  2874. },
  2875. },
  2876. Affiliations: []struct {
  2877. Code uint16
  2878. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2879. }{
  2880. {
  2881. Keyword: "an_affiliation",
  2882. },
  2883. },
  2884. },
  2885. },
  2886. }),
  2887. },
  2888. },
  2889. },
  2890. seq: 1,
  2891. },
  2892. allMockParams: allMockParams{
  2893. setAffiliations: &mockParam{
  2894. req: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
  2895. PastAffiliations: []struct {
  2896. Code uint16
  2897. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2898. }{
  2899. {
  2900. Keyword: "a_past_affiliation",
  2901. },
  2902. },
  2903. Affiliations: []struct {
  2904. Code uint16
  2905. Keyword string `oscar:"len_prefix=uint16,nullterm"`
  2906. }{
  2907. {
  2908. Keyword: "an_affiliation",
  2909. },
  2910. },
  2911. },
  2912. },
  2913. },
  2914. },
  2915. {
  2916. name: "MetaReqStat - happy path",
  2917. reqParams: reqParams{
  2918. sess: &state.Session{},
  2919. inBody: wire.SNAC_0x15_0x02_BQuery{
  2920. TLVRestBlock: wire.TLVRestBlock{
  2921. TLVList: wire.TLVList{
  2922. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2923. Message: ICQMetaRequest{
  2924. ICQMetadata: wire.ICQMetadata{
  2925. ReqType: wire.ICQDBQueryMetaReq,
  2926. Seq: 1,
  2927. },
  2928. ReqSubType: wire.ICQDBQueryMetaReqStat0a8c,
  2929. MetaRequest: struct{}{},
  2930. },
  2931. }),
  2932. },
  2933. },
  2934. },
  2935. seq: 1,
  2936. },
  2937. },
  2938. {
  2939. name: "unknown metadata request subtype",
  2940. reqParams: reqParams{
  2941. sess: &state.Session{},
  2942. inBody: wire.SNAC_0x15_0x02_BQuery{
  2943. TLVRestBlock: wire.TLVRestBlock{
  2944. TLVList: wire.TLVList{
  2945. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2946. Message: ICQMetaRequest{
  2947. ICQMetadata: wire.ICQMetadata{
  2948. ReqType: wire.ICQDBQueryMetaReq,
  2949. Seq: 1,
  2950. },
  2951. ReqSubType: 0xCA8E,
  2952. MetaRequest: struct{}{},
  2953. },
  2954. }),
  2955. },
  2956. },
  2957. },
  2958. seq: 1,
  2959. wantErr: errUnknownICQMetaReqSubType,
  2960. },
  2961. },
  2962. {
  2963. name: "OfflineMsgReq - happy path",
  2964. reqParams: reqParams{
  2965. sess: &state.Session{},
  2966. inBody: wire.SNAC_0x15_0x02_BQuery{
  2967. TLVRestBlock: wire.TLVRestBlock{
  2968. TLVList: wire.TLVList{
  2969. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2970. Message: wire.ICQMetadataWithSubType{
  2971. ICQMetadata: wire.ICQMetadata{
  2972. ReqType: wire.ICQDBQueryOfflineMsgReq,
  2973. Seq: 1,
  2974. },
  2975. },
  2976. }),
  2977. },
  2978. },
  2979. },
  2980. seq: 1,
  2981. },
  2982. allMockParams: allMockParams{
  2983. offlineMsgReq: &mockParam{},
  2984. },
  2985. },
  2986. {
  2987. name: "DeleteMsgReq - happy path",
  2988. reqParams: reqParams{
  2989. sess: &state.Session{},
  2990. inBody: wire.SNAC_0x15_0x02_BQuery{
  2991. TLVRestBlock: wire.TLVRestBlock{
  2992. TLVList: wire.TLVList{
  2993. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  2994. Message: wire.ICQMetadataWithSubType{
  2995. ICQMetadata: wire.ICQMetadata{
  2996. ReqType: wire.ICQDBQueryDeleteMsgReq,
  2997. Seq: 1,
  2998. },
  2999. },
  3000. }),
  3001. },
  3002. },
  3003. },
  3004. seq: 1,
  3005. },
  3006. allMockParams: allMockParams{
  3007. deleteMsgReq: &mockParam{},
  3008. },
  3009. },
  3010. {
  3011. name: "unknown request type",
  3012. reqParams: reqParams{
  3013. sess: &state.Session{},
  3014. inBody: wire.SNAC_0x15_0x02_BQuery{
  3015. TLVRestBlock: wire.TLVRestBlock{
  3016. TLVList: wire.TLVList{
  3017. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  3018. Message: ICQMetaRequest{
  3019. ICQMetadata: wire.ICQMetadata{
  3020. ReqType: 0x13B4,
  3021. Seq: 1,
  3022. },
  3023. ReqSubType: 0xCA8E,
  3024. MetaRequest: struct{}{},
  3025. },
  3026. }),
  3027. },
  3028. },
  3029. },
  3030. seq: 1,
  3031. wantErr: errUnknownICQMetaReqType,
  3032. },
  3033. }, // todo: add to a separate test
  3034. }
  3035. for _, tt := range tests {
  3036. t.Run(tt.name, func(t *testing.T) {
  3037. icqService := newMockICQService(t)
  3038. switch {
  3039. case tt.allMockParams.fullUserInfo != nil:
  3040. icqService.EXPECT().
  3041. FullUserInfo(mock.Anything, tt.reqParams.sess, tt.allMockParams.fullUserInfo.req, tt.reqParams.seq).
  3042. Return(tt.allMockParams.fullUserInfo.wantErr)
  3043. case tt.allMockParams.shortUserInfo != nil:
  3044. icqService.EXPECT().
  3045. ShortUserInfo(mock.Anything, tt.reqParams.sess, tt.allMockParams.shortUserInfo.req, tt.reqParams.seq).
  3046. Return(tt.allMockParams.shortUserInfo.wantErr)
  3047. case tt.allMockParams.xmlReqData != nil:
  3048. icqService.EXPECT().
  3049. XMLReqData(mock.Anything, tt.reqParams.sess, tt.allMockParams.xmlReqData.req, tt.reqParams.seq).
  3050. Return(tt.allMockParams.xmlReqData.wantErr)
  3051. case tt.allMockParams.setPermissions != nil:
  3052. icqService.EXPECT().
  3053. SetPermissions(mock.Anything, tt.reqParams.sess, tt.allMockParams.setPermissions.req, tt.reqParams.seq).
  3054. Return(tt.allMockParams.setPermissions.wantErr)
  3055. case tt.allMockParams.findByUIN != nil:
  3056. icqService.EXPECT().
  3057. FindByUIN(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByUIN.req, tt.reqParams.seq).
  3058. Return(tt.allMockParams.findByUIN.wantErr)
  3059. case tt.allMockParams.findByUIN2 != nil:
  3060. icqService.EXPECT().
  3061. FindByUIN2(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByUIN2.req, tt.reqParams.seq).
  3062. Return(tt.allMockParams.findByUIN2.wantErr)
  3063. case tt.allMockParams.findByEmail != nil:
  3064. icqService.EXPECT().
  3065. FindByICQEmail(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByEmail.req, tt.reqParams.seq).
  3066. Return(tt.allMockParams.findByEmail.wantErr)
  3067. case tt.allMockParams.findByEmail3 != nil:
  3068. icqService.EXPECT().
  3069. FindByEmail3(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByEmail3.req, tt.reqParams.seq).
  3070. Return(tt.allMockParams.findByEmail3.wantErr)
  3071. case tt.allMockParams.findByDetails != nil:
  3072. icqService.EXPECT().
  3073. FindByICQName(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByDetails.req, tt.reqParams.seq).
  3074. Return(tt.allMockParams.findByDetails.wantErr)
  3075. case tt.allMockParams.findByInterests != nil:
  3076. icqService.EXPECT().
  3077. FindByICQInterests(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByInterests.req, tt.reqParams.seq).
  3078. Return(tt.allMockParams.findByInterests.wantErr)
  3079. case tt.allMockParams.findByWhitePages2 != nil:
  3080. icqService.EXPECT().
  3081. FindByWhitePages2(mock.Anything, tt.reqParams.sess, tt.allMockParams.findByWhitePages2.req, tt.reqParams.seq).
  3082. Return(tt.allMockParams.findByWhitePages2.wantErr)
  3083. case tt.allMockParams.setBasicInfo != nil:
  3084. icqService.EXPECT().
  3085. SetBasicInfo(mock.Anything, tt.reqParams.sess, tt.allMockParams.setBasicInfo.req, tt.reqParams.seq).
  3086. Return(tt.allMockParams.setBasicInfo.wantErr)
  3087. case tt.allMockParams.setWorkInfo != nil:
  3088. icqService.EXPECT().
  3089. SetWorkInfo(mock.Anything, tt.reqParams.sess, tt.allMockParams.setWorkInfo.req, tt.reqParams.seq).
  3090. Return(tt.allMockParams.setWorkInfo.wantErr)
  3091. case tt.allMockParams.setMoreInfo != nil:
  3092. icqService.EXPECT().
  3093. SetMoreInfo(mock.Anything, tt.reqParams.sess, tt.allMockParams.setMoreInfo.req, tt.reqParams.seq).
  3094. Return(tt.allMockParams.setMoreInfo.wantErr)
  3095. case tt.allMockParams.setUserNotes != nil:
  3096. icqService.EXPECT().
  3097. SetUserNotes(mock.Anything, tt.reqParams.sess, tt.allMockParams.setUserNotes.req, tt.reqParams.seq).
  3098. Return(tt.allMockParams.setUserNotes.wantErr)
  3099. case tt.allMockParams.setEmails != nil:
  3100. icqService.EXPECT().
  3101. SetEmails(mock.Anything, tt.reqParams.sess, tt.allMockParams.setEmails.req, tt.reqParams.seq).
  3102. Return(tt.allMockParams.setEmails.wantErr)
  3103. case tt.allMockParams.setInterests != nil:
  3104. icqService.EXPECT().
  3105. SetInterests(mock.Anything, tt.reqParams.sess, tt.allMockParams.setInterests.req, tt.reqParams.seq).
  3106. Return(tt.allMockParams.setInterests.wantErr)
  3107. case tt.allMockParams.setAffiliations != nil:
  3108. icqService.EXPECT().
  3109. SetAffiliations(mock.Anything, tt.reqParams.sess, tt.allMockParams.setAffiliations.req, tt.reqParams.seq).
  3110. Return(tt.allMockParams.setAffiliations.wantErr)
  3111. case tt.allMockParams.offlineMsgReq != nil:
  3112. icqService.EXPECT().
  3113. OfflineMsgReq(mock.Anything, tt.reqParams.sess, tt.reqParams.seq).
  3114. Return(tt.allMockParams.offlineMsgReq.wantErr)
  3115. case tt.allMockParams.deleteMsgReq != nil:
  3116. icqService.EXPECT().
  3117. DeleteMsgReq(mock.Anything, tt.reqParams.sess, tt.reqParams.seq).
  3118. Return(tt.allMockParams.deleteMsgReq.wantErr)
  3119. }
  3120. h := Handler{
  3121. ICQService: icqService,
  3122. RouteLogger: middleware.RouteLogger{
  3123. Logger: slog.Default(),
  3124. },
  3125. }
  3126. buf := &bytes.Buffer{}
  3127. assert.NoError(t, wire.MarshalBE(tt.reqParams.inBody, buf))
  3128. frame := wire.SNACFrame{
  3129. FoodGroup: wire.ICQ,
  3130. SubGroup: wire.ICQDBQuery,
  3131. }
  3132. err := h.Handle(context.TODO(), wire.BOS, tt.reqParams.sess, frame, buf, nil, config.Listener{})
  3133. assert.ErrorIs(t, err, tt.reqParams.wantErr)
  3134. })
  3135. }
  3136. }
  3137. // Test workaround for QIP 2005 bug where TLV length is incorrect.
  3138. func TestHandler_ICQDBQuery_QIP2005UINSearchBug(t *testing.T) {
  3139. icqService := newMockICQService(t)
  3140. type ICQMetaRequest struct {
  3141. wire.ICQMetadata
  3142. ReqSubType uint16
  3143. MetaRequest any
  3144. }
  3145. expect := wire.ICQ_0x07D0_0x0569_DBQueryMetaReqSearchByUIN2{
  3146. TLVRestBlock: wire.TLVRestBlock{
  3147. TLVList: wire.TLVList{
  3148. wire.NewTLVBE(wire.ICQTLVTagsUIN, uint32(100009)),
  3149. },
  3150. },
  3151. }
  3152. icqService.EXPECT().
  3153. FindByUIN2(mock.Anything, &state.Session{}, expect, uint16(1)).
  3154. Return(nil)
  3155. h := Handler{
  3156. ICQService: icqService,
  3157. RouteLogger: middleware.RouteLogger{
  3158. Logger: slog.Default(),
  3159. },
  3160. }
  3161. inBody := wire.SNAC_0x15_0x02_BQuery{
  3162. TLVRestBlock: wire.TLVRestBlock{
  3163. TLVList: wire.TLVList{
  3164. wire.NewTLVBE(wire.ICQTLVTagsMetadata, wire.ICQMessageReplyEnvelope{
  3165. Message: ICQMetaRequest{
  3166. ICQMetadata: wire.ICQMetadata{
  3167. ReqType: wire.ICQDBQueryMetaReq,
  3168. Seq: 1,
  3169. },
  3170. ReqSubType: wire.ICQDBQueryMetaReqSearchByUIN2,
  3171. MetaRequest: wire.ICQ_0x07D0_0x0569_DBQueryMetaReqSearchByUIN2{
  3172. TLVRestBlock: wire.TLVRestBlock{
  3173. TLVList: wire.TLVList{
  3174. wire.NewTLVBE(wire.ICQTLVTagsUIN, uint32(100009)),
  3175. },
  3176. },
  3177. },
  3178. },
  3179. }),
  3180. },
  3181. },
  3182. }
  3183. buf := &bytes.Buffer{}
  3184. assert.NoError(t, wire.MarshalBE(inBody, buf))
  3185. b := buf.Bytes()
  3186. b[18] = 6 // incorrectly set TLV length to 6 (should be 4)
  3187. err := h.ICQDBQuery(nil, &state.Session{}, wire.SNACFrame{}, buf, nil)
  3188. assert.NoError(t, err)
  3189. }
  3190. func TestHandler_ODirInfoQuery(t *testing.T) {
  3191. tests := []struct {
  3192. name string
  3193. inputBody wire.SNAC_0x0F_0x02_InfoQuery
  3194. serviceError error
  3195. responseError error
  3196. expectedError error
  3197. }{
  3198. {
  3199. name: "success",
  3200. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3201. TLVRestBlock: wire.TLVRestBlock{
  3202. TLVList: wire.TLVList{
  3203. wire.NewTLVBE(1, uint16(2)),
  3204. },
  3205. },
  3206. },
  3207. },
  3208. {
  3209. name: "service error",
  3210. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3211. TLVRestBlock: wire.TLVRestBlock{
  3212. TLVList: wire.TLVList{
  3213. wire.NewTLVBE(1, uint16(2)),
  3214. },
  3215. },
  3216. },
  3217. serviceError: assert.AnError,
  3218. expectedError: assert.AnError,
  3219. },
  3220. {
  3221. name: "response writer error",
  3222. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3223. TLVRestBlock: wire.TLVRestBlock{
  3224. TLVList: wire.TLVList{
  3225. wire.NewTLVBE(1, uint16(2)),
  3226. },
  3227. },
  3228. },
  3229. responseError: assert.AnError,
  3230. expectedError: assert.AnError,
  3231. },
  3232. }
  3233. for _, tt := range tests {
  3234. t.Run(tt.name, func(t *testing.T) {
  3235. input := wire.SNACMessage{
  3236. Frame: wire.SNACFrame{
  3237. FoodGroup: wire.ODir,
  3238. SubGroup: wire.ODirInfoQuery,
  3239. },
  3240. Body: tt.inputBody,
  3241. }
  3242. output := wire.SNACMessage{
  3243. Frame: wire.SNACFrame{
  3244. FoodGroup: wire.ODir,
  3245. SubGroup: wire.ODirInfoReply,
  3246. },
  3247. Body: wire.SNAC_0x0F_0x03_InfoReply{
  3248. Status: 5, // OK has results/not found
  3249. },
  3250. }
  3251. svc := newMockODirService(t)
  3252. svc.EXPECT().
  3253. InfoQuery(mock.Anything, input.Frame, input.Body).
  3254. Return(output, tt.serviceError)
  3255. h := Handler{
  3256. ODirService: svc,
  3257. RouteLogger: middleware.RouteLogger{
  3258. Logger: slog.Default(),
  3259. },
  3260. }
  3261. ss := newMockResponseWriter(t)
  3262. if tt.serviceError == nil {
  3263. ss.EXPECT().
  3264. SendSNAC(output.Frame, output.Body).
  3265. Return(tt.responseError)
  3266. }
  3267. buf := &bytes.Buffer{}
  3268. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3269. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, ss, config.Listener{})
  3270. if tt.expectedError != nil {
  3271. assert.ErrorIs(t, err, tt.expectedError)
  3272. } else {
  3273. assert.NoError(t, err)
  3274. }
  3275. })
  3276. }
  3277. }
  3278. func TestHandler_ODirKeywordListQuery(t *testing.T) {
  3279. tests := []struct {
  3280. name string
  3281. inputBody wire.SNAC_0x0F_0x02_InfoQuery
  3282. serviceError error
  3283. responseError error
  3284. expectedError error
  3285. }{
  3286. {
  3287. name: "success",
  3288. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3289. TLVRestBlock: wire.TLVRestBlock{
  3290. TLVList: wire.TLVList{
  3291. wire.NewTLVBE(1, uint16(2)),
  3292. },
  3293. },
  3294. },
  3295. },
  3296. {
  3297. name: "service error",
  3298. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3299. TLVRestBlock: wire.TLVRestBlock{
  3300. TLVList: wire.TLVList{
  3301. wire.NewTLVBE(1, uint16(2)),
  3302. },
  3303. },
  3304. },
  3305. serviceError: assert.AnError,
  3306. expectedError: assert.AnError,
  3307. },
  3308. {
  3309. name: "response writer error",
  3310. inputBody: wire.SNAC_0x0F_0x02_InfoQuery{
  3311. TLVRestBlock: wire.TLVRestBlock{
  3312. TLVList: wire.TLVList{
  3313. wire.NewTLVBE(1, uint16(2)),
  3314. },
  3315. },
  3316. },
  3317. responseError: assert.AnError,
  3318. expectedError: assert.AnError,
  3319. },
  3320. }
  3321. for _, tt := range tests {
  3322. t.Run(tt.name, func(t *testing.T) {
  3323. input := wire.SNACMessage{
  3324. Frame: wire.SNACFrame{
  3325. FoodGroup: wire.ODir,
  3326. SubGroup: wire.ODirKeywordListQuery,
  3327. },
  3328. Body: tt.inputBody,
  3329. }
  3330. output := wire.SNACMessage{
  3331. Frame: wire.SNACFrame{
  3332. FoodGroup: wire.ODir,
  3333. SubGroup: wire.ODirKeywordListReply,
  3334. },
  3335. Body: wire.SNAC_0x0F_0x04_KeywordListReply{
  3336. Status: 0x01,
  3337. },
  3338. }
  3339. svc := newMockODirService(t)
  3340. svc.EXPECT().
  3341. KeywordListQuery(mock.Anything, input.Frame).
  3342. Return(output, tt.serviceError)
  3343. h := Handler{
  3344. ODirService: svc,
  3345. RouteLogger: middleware.RouteLogger{
  3346. Logger: slog.Default(),
  3347. },
  3348. }
  3349. ss := newMockResponseWriter(t)
  3350. if tt.serviceError == nil {
  3351. ss.EXPECT().
  3352. SendSNAC(output.Frame, output.Body).
  3353. Return(tt.responseError)
  3354. }
  3355. buf := &bytes.Buffer{}
  3356. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3357. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, ss, config.Listener{})
  3358. if tt.expectedError != nil {
  3359. assert.ErrorIs(t, err, tt.expectedError)
  3360. } else {
  3361. assert.NoError(t, err)
  3362. }
  3363. })
  3364. }
  3365. }
  3366. func TestHandler_OServiceServiceClientOnline(t *testing.T) {
  3367. tests := []struct {
  3368. name string
  3369. inputBody wire.SNAC_0x01_0x02_OServiceClientOnline
  3370. serviceError error
  3371. expectedError error
  3372. }{
  3373. {
  3374. name: "success",
  3375. inputBody: wire.SNAC_0x01_0x02_OServiceClientOnline{
  3376. GroupVersions: []struct {
  3377. FoodGroup uint16
  3378. Version uint16
  3379. ToolID uint16
  3380. ToolVersion uint16
  3381. }{
  3382. {
  3383. FoodGroup: 10,
  3384. },
  3385. },
  3386. },
  3387. },
  3388. {
  3389. name: "service error",
  3390. inputBody: wire.SNAC_0x01_0x02_OServiceClientOnline{
  3391. GroupVersions: []struct {
  3392. FoodGroup uint16
  3393. Version uint16
  3394. ToolID uint16
  3395. ToolVersion uint16
  3396. }{
  3397. {
  3398. FoodGroup: 10,
  3399. },
  3400. },
  3401. },
  3402. serviceError: assert.AnError,
  3403. expectedError: assert.AnError,
  3404. },
  3405. }
  3406. for _, tt := range tests {
  3407. t.Run(tt.name, func(t *testing.T) {
  3408. input := wire.SNACMessage{
  3409. Frame: wire.SNACFrame{
  3410. FoodGroup: wire.OService,
  3411. SubGroup: wire.OServiceClientOnline,
  3412. },
  3413. Body: tt.inputBody,
  3414. }
  3415. svc := newMockOServiceService(t)
  3416. svc.EXPECT().
  3417. ClientOnline(mock.Anything, wire.BOS, input.Body, mock.Anything).
  3418. Return(tt.serviceError)
  3419. h := Handler{
  3420. OServiceService: svc,
  3421. RouteLogger: middleware.RouteLogger{
  3422. Logger: slog.Default(),
  3423. },
  3424. }
  3425. buf := &bytes.Buffer{}
  3426. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3427. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, nil, config.Listener{})
  3428. if tt.expectedError != nil {
  3429. assert.ErrorIs(t, err, tt.expectedError)
  3430. } else {
  3431. assert.NoError(t, err)
  3432. }
  3433. })
  3434. }
  3435. }
  3436. func TestHandler_OServiceServiceServiceRequest(t *testing.T) {
  3437. tests := []struct {
  3438. name string
  3439. inputBody wire.SNAC_0x01_0x04_OServiceServiceRequest
  3440. serviceError error
  3441. responseError error
  3442. expectedError error
  3443. }{
  3444. {
  3445. name: "success",
  3446. inputBody: wire.SNAC_0x01_0x04_OServiceServiceRequest{
  3447. FoodGroup: wire.Chat,
  3448. },
  3449. },
  3450. {
  3451. name: "service error",
  3452. inputBody: wire.SNAC_0x01_0x04_OServiceServiceRequest{
  3453. FoodGroup: wire.Chat,
  3454. },
  3455. serviceError: assert.AnError,
  3456. expectedError: assert.AnError,
  3457. },
  3458. {
  3459. name: "response writer error",
  3460. inputBody: wire.SNAC_0x01_0x04_OServiceServiceRequest{
  3461. FoodGroup: wire.Chat,
  3462. },
  3463. responseError: assert.AnError,
  3464. expectedError: assert.AnError,
  3465. },
  3466. }
  3467. for _, tt := range tests {
  3468. t.Run(tt.name, func(t *testing.T) {
  3469. input := wire.SNACMessage{
  3470. Frame: wire.SNACFrame{
  3471. FoodGroup: wire.OService,
  3472. SubGroup: wire.OServiceServiceRequest,
  3473. },
  3474. Body: tt.inputBody,
  3475. }
  3476. output := wire.SNACMessage{
  3477. Frame: wire.SNACFrame{
  3478. FoodGroup: wire.OService,
  3479. SubGroup: wire.OServiceServiceResponse,
  3480. },
  3481. Body: wire.SNAC_0x01_0x05_OServiceServiceResponse{
  3482. TLVRestBlock: wire.TLVRestBlock{
  3483. TLVList: wire.TLVList{
  3484. wire.NewTLVBE(0x01, uint16(1000)),
  3485. },
  3486. },
  3487. },
  3488. }
  3489. svc := newMockOServiceService(t)
  3490. svc.EXPECT().
  3491. ServiceRequest(mock.Anything, wire.BOS, mock.Anything, input.Frame, input.Body, config.Listener{BOSAdvertisedHostPlain: "127.0.0.1:1234"}).
  3492. Return(output, tt.serviceError)
  3493. h := Handler{
  3494. OServiceService: svc,
  3495. RouteLogger: middleware.RouteLogger{
  3496. Logger: slog.Default(),
  3497. },
  3498. }
  3499. responseWriter := newMockResponseWriter(t)
  3500. if tt.serviceError == nil {
  3501. responseWriter.EXPECT().
  3502. SendSNAC(output.Frame, output.Body).
  3503. Return(tt.responseError)
  3504. }
  3505. buf := &bytes.Buffer{}
  3506. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3507. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{BOSAdvertisedHostPlain: "127.0.0.1:1234"})
  3508. if tt.expectedError != nil {
  3509. assert.ErrorIs(t, err, tt.expectedError)
  3510. } else {
  3511. assert.NoError(t, err)
  3512. }
  3513. })
  3514. }
  3515. }
  3516. func TestHandler_OServiceServiceIdleNotification(t *testing.T) {
  3517. tests := []struct {
  3518. name string
  3519. inputBody wire.SNAC_0x01_0x11_OServiceIdleNotification
  3520. serviceError error
  3521. expectedError error
  3522. }{
  3523. {
  3524. name: "success",
  3525. inputBody: wire.SNAC_0x01_0x11_OServiceIdleNotification{
  3526. IdleTime: 10,
  3527. },
  3528. },
  3529. {
  3530. name: "service error",
  3531. inputBody: wire.SNAC_0x01_0x11_OServiceIdleNotification{
  3532. IdleTime: 10,
  3533. },
  3534. serviceError: assert.AnError,
  3535. expectedError: assert.AnError,
  3536. },
  3537. }
  3538. for _, tt := range tests {
  3539. t.Run(tt.name, func(t *testing.T) {
  3540. input := wire.SNACMessage{
  3541. Frame: wire.SNACFrame{
  3542. FoodGroup: wire.OService,
  3543. SubGroup: wire.OServiceIdleNotification,
  3544. },
  3545. Body: tt.inputBody,
  3546. }
  3547. svc := newMockOServiceService(t)
  3548. svc.EXPECT().
  3549. IdleNotification(mock.Anything, mock.Anything, input.Body).
  3550. Return(tt.serviceError)
  3551. h := Handler{
  3552. OServiceService: svc,
  3553. RouteLogger: middleware.RouteLogger{
  3554. Logger: slog.Default(),
  3555. },
  3556. }
  3557. responseWriter := newMockResponseWriter(t)
  3558. buf := &bytes.Buffer{}
  3559. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3560. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3561. if tt.expectedError != nil {
  3562. assert.ErrorIs(t, err, tt.expectedError)
  3563. } else {
  3564. assert.NoError(t, err)
  3565. }
  3566. })
  3567. }
  3568. }
  3569. func TestHandler_OServiceServiceClientVersions(t *testing.T) {
  3570. tests := []struct {
  3571. name string
  3572. inputBody wire.SNAC_0x01_0x17_OServiceClientVersions
  3573. responseError error
  3574. expectedError error
  3575. }{
  3576. {
  3577. name: "success",
  3578. inputBody: wire.SNAC_0x01_0x17_OServiceClientVersions{
  3579. Versions: []uint16{
  3580. 10,
  3581. },
  3582. },
  3583. },
  3584. {
  3585. name: "response writer error",
  3586. inputBody: wire.SNAC_0x01_0x17_OServiceClientVersions{
  3587. Versions: []uint16{
  3588. 10,
  3589. },
  3590. },
  3591. responseError: assert.AnError,
  3592. expectedError: assert.AnError,
  3593. },
  3594. }
  3595. for _, tt := range tests {
  3596. t.Run(tt.name, func(t *testing.T) {
  3597. input := wire.SNACMessage{
  3598. Frame: wire.SNACFrame{
  3599. FoodGroup: wire.OService,
  3600. SubGroup: wire.OServiceClientVersions,
  3601. },
  3602. Body: tt.inputBody,
  3603. }
  3604. output := wire.SNACMessage{
  3605. Frame: wire.SNACFrame{
  3606. FoodGroup: wire.OService,
  3607. SubGroup: wire.OServiceHostVersions,
  3608. },
  3609. Body: wire.SNAC_0x01_0x18_OServiceHostVersions{
  3610. Versions: []uint16{
  3611. 10,
  3612. },
  3613. },
  3614. }
  3615. sess := state.NewSession()
  3616. svc := newMockOServiceService(t)
  3617. svc.EXPECT().
  3618. ClientVersions(mock.Anything, sess, input.Frame, input.Body).
  3619. Return(output)
  3620. h := Handler{
  3621. OServiceService: svc,
  3622. RouteLogger: middleware.RouteLogger{
  3623. Logger: slog.Default(),
  3624. },
  3625. }
  3626. responseWriter := newMockResponseWriter(t)
  3627. responseWriter.EXPECT().
  3628. SendSNAC(output.Frame, output.Body).
  3629. Return(tt.responseError)
  3630. buf := &bytes.Buffer{}
  3631. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3632. err := h.Handle(context.Background(), wire.BOS, sess, input.Frame, buf, responseWriter, config.Listener{})
  3633. if tt.expectedError != nil {
  3634. assert.ErrorIs(t, err, tt.expectedError)
  3635. } else {
  3636. assert.NoError(t, err)
  3637. }
  3638. })
  3639. }
  3640. }
  3641. func TestHandler_OServiceServiceRateParamsQuery(t *testing.T) {
  3642. tests := []struct {
  3643. name string
  3644. inputBody struct{}
  3645. responseError error
  3646. expectedError error
  3647. }{
  3648. {
  3649. name: "success",
  3650. inputBody: struct{}{},
  3651. },
  3652. {
  3653. name: "response writer error",
  3654. inputBody: struct{}{},
  3655. responseError: assert.AnError,
  3656. expectedError: assert.AnError,
  3657. },
  3658. }
  3659. for _, tt := range tests {
  3660. t.Run(tt.name, func(t *testing.T) {
  3661. input := wire.SNACMessage{
  3662. Frame: wire.SNACFrame{
  3663. FoodGroup: wire.OService,
  3664. SubGroup: wire.OServiceRateParamsQuery,
  3665. },
  3666. Body: tt.inputBody,
  3667. }
  3668. output := wire.SNACMessage{
  3669. Frame: wire.SNACFrame{
  3670. FoodGroup: wire.OService,
  3671. SubGroup: wire.OServiceRateParamsReply,
  3672. },
  3673. Body: wire.SNAC_0x01_0x07_OServiceRateParamsReply{
  3674. RateGroups: []struct {
  3675. ID uint16
  3676. Pairs []struct {
  3677. FoodGroup uint16
  3678. SubGroup uint16
  3679. } `oscar:"count_prefix=uint16"`
  3680. }{
  3681. {
  3682. ID: 1,
  3683. },
  3684. },
  3685. },
  3686. }
  3687. svc := newMockOServiceService(t)
  3688. svc.EXPECT().
  3689. RateParamsQuery(mock.Anything, mock.Anything, input.Frame).
  3690. Return(output)
  3691. h := Handler{
  3692. OServiceService: svc,
  3693. RouteLogger: middleware.RouteLogger{
  3694. Logger: slog.Default(),
  3695. },
  3696. }
  3697. responseWriter := newMockResponseWriter(t)
  3698. responseWriter.EXPECT().
  3699. SendSNAC(output.Frame, output.Body).
  3700. Return(tt.responseError)
  3701. buf := &bytes.Buffer{}
  3702. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3703. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3704. if tt.expectedError != nil {
  3705. assert.ErrorIs(t, err, tt.expectedError)
  3706. } else {
  3707. assert.NoError(t, err)
  3708. }
  3709. })
  3710. }
  3711. }
  3712. func TestHandler_OServiceServiceRateParamsSubAdd(t *testing.T) {
  3713. tests := []struct {
  3714. name string
  3715. inputBody wire.SNAC_0x01_0x08_OServiceRateParamsSubAdd
  3716. expectedError error
  3717. }{
  3718. {
  3719. name: "success",
  3720. inputBody: wire.SNAC_0x01_0x08_OServiceRateParamsSubAdd{
  3721. ClassIDs: []uint16{1, 2, 3, 4},
  3722. },
  3723. },
  3724. }
  3725. for _, tt := range tests {
  3726. t.Run(tt.name, func(t *testing.T) {
  3727. input := wire.SNACMessage{
  3728. Frame: wire.SNACFrame{
  3729. FoodGroup: wire.OService,
  3730. SubGroup: wire.OServiceRateParamsSubAdd,
  3731. },
  3732. Body: tt.inputBody,
  3733. }
  3734. sess := state.NewSession()
  3735. svc := newMockOServiceService(t)
  3736. svc.EXPECT().
  3737. RateParamsSubAdd(mock.Anything, sess, input.Body)
  3738. h := Handler{
  3739. OServiceService: svc,
  3740. RouteLogger: middleware.RouteLogger{
  3741. Logger: slog.Default(),
  3742. },
  3743. }
  3744. buf := &bytes.Buffer{}
  3745. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3746. err := h.Handle(context.Background(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  3747. if tt.expectedError != nil {
  3748. assert.ErrorIs(t, err, tt.expectedError)
  3749. } else {
  3750. assert.NoError(t, err)
  3751. }
  3752. })
  3753. }
  3754. }
  3755. func TestHandler_OServiceServiceSetUserInfoFields(t *testing.T) {
  3756. tests := []struct {
  3757. name string
  3758. inputBody wire.SNAC_0x01_0x1E_OServiceSetUserInfoFields
  3759. serviceError error
  3760. responseError error
  3761. expectedError error
  3762. }{
  3763. {
  3764. name: "success",
  3765. inputBody: wire.SNAC_0x01_0x1E_OServiceSetUserInfoFields{
  3766. TLVRestBlock: wire.TLVRestBlock{
  3767. TLVList: wire.TLVList{
  3768. wire.NewTLVBE(0x01, []byte{1, 2, 3, 4}),
  3769. },
  3770. },
  3771. },
  3772. },
  3773. {
  3774. name: "service error",
  3775. inputBody: wire.SNAC_0x01_0x1E_OServiceSetUserInfoFields{
  3776. TLVRestBlock: wire.TLVRestBlock{
  3777. TLVList: wire.TLVList{
  3778. wire.NewTLVBE(0x01, []byte{1, 2, 3, 4}),
  3779. },
  3780. },
  3781. },
  3782. serviceError: assert.AnError,
  3783. expectedError: assert.AnError,
  3784. },
  3785. {
  3786. name: "response writer error",
  3787. inputBody: wire.SNAC_0x01_0x1E_OServiceSetUserInfoFields{
  3788. TLVRestBlock: wire.TLVRestBlock{
  3789. TLVList: wire.TLVList{
  3790. wire.NewTLVBE(0x01, []byte{1, 2, 3, 4}),
  3791. },
  3792. },
  3793. },
  3794. responseError: assert.AnError,
  3795. expectedError: assert.AnError,
  3796. },
  3797. }
  3798. for _, tt := range tests {
  3799. t.Run(tt.name, func(t *testing.T) {
  3800. input := wire.SNACMessage{
  3801. Frame: wire.SNACFrame{
  3802. FoodGroup: wire.OService,
  3803. SubGroup: wire.OServiceSetUserInfoFields,
  3804. },
  3805. Body: tt.inputBody,
  3806. }
  3807. output := wire.SNACMessage{
  3808. Frame: wire.SNACFrame{
  3809. FoodGroup: wire.OService,
  3810. SubGroup: wire.OServiceUserInfoUpdate,
  3811. },
  3812. Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
  3813. UserInfo: []wire.TLVUserInfo{
  3814. {ScreenName: "screen-name"},
  3815. {ScreenName: "screen-name"},
  3816. },
  3817. },
  3818. }
  3819. svc := newMockOServiceService(t)
  3820. svc.EXPECT().
  3821. SetUserInfoFields(mock.Anything, mock.Anything, input.Frame, input.Body).
  3822. Return(output, tt.serviceError)
  3823. h := Handler{
  3824. OServiceService: svc,
  3825. RouteLogger: middleware.RouteLogger{
  3826. Logger: slog.Default(),
  3827. },
  3828. }
  3829. responseWriter := newMockResponseWriter(t)
  3830. if tt.serviceError == nil {
  3831. responseWriter.EXPECT().
  3832. SendSNAC(output.Frame, output.Body).
  3833. Return(tt.responseError)
  3834. }
  3835. buf := &bytes.Buffer{}
  3836. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3837. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3838. if tt.expectedError != nil {
  3839. assert.ErrorIs(t, err, tt.expectedError)
  3840. } else {
  3841. assert.NoError(t, err)
  3842. }
  3843. })
  3844. }
  3845. }
  3846. func TestHandler_OServiceServiceUserInfoQuery(t *testing.T) {
  3847. tests := []struct {
  3848. name string
  3849. inputBody struct{}
  3850. responseError error
  3851. expectedError error
  3852. }{
  3853. {
  3854. name: "success",
  3855. inputBody: struct{}{},
  3856. },
  3857. {
  3858. name: "response writer error",
  3859. inputBody: struct{}{},
  3860. responseError: assert.AnError,
  3861. expectedError: assert.AnError,
  3862. },
  3863. }
  3864. for _, tt := range tests {
  3865. t.Run(tt.name, func(t *testing.T) {
  3866. input := wire.SNACMessage{
  3867. Frame: wire.SNACFrame{
  3868. FoodGroup: wire.OService,
  3869. SubGroup: wire.OServiceUserInfoQuery,
  3870. },
  3871. Body: tt.inputBody,
  3872. }
  3873. output := wire.SNACMessage{
  3874. Frame: wire.SNACFrame{
  3875. FoodGroup: wire.OService,
  3876. SubGroup: wire.OServiceUserInfoUpdate,
  3877. },
  3878. Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
  3879. UserInfo: []wire.TLVUserInfo{
  3880. {ScreenName: "screen-name"},
  3881. {ScreenName: "screen-name"},
  3882. },
  3883. },
  3884. }
  3885. svc := newMockOServiceService(t)
  3886. svc.EXPECT().
  3887. UserInfoQuery(mock.Anything, mock.Anything, input.Frame).
  3888. Return(output)
  3889. h := Handler{
  3890. OServiceService: svc,
  3891. RouteLogger: middleware.RouteLogger{
  3892. Logger: slog.Default(),
  3893. },
  3894. }
  3895. responseWriter := newMockResponseWriter(t)
  3896. responseWriter.EXPECT().
  3897. SendSNAC(output.Frame, output.Body).
  3898. Return(tt.responseError)
  3899. buf := &bytes.Buffer{}
  3900. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3901. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3902. if tt.expectedError != nil {
  3903. assert.ErrorIs(t, err, tt.expectedError)
  3904. } else {
  3905. assert.NoError(t, err)
  3906. }
  3907. })
  3908. }
  3909. }
  3910. func TestHandler_OServiceServiceNoop(t *testing.T) {
  3911. tests := []struct {
  3912. name string
  3913. inputBody struct{}
  3914. expectedError error
  3915. }{
  3916. {
  3917. name: "success",
  3918. inputBody: struct{}{},
  3919. },
  3920. }
  3921. for _, tt := range tests {
  3922. t.Run(tt.name, func(t *testing.T) {
  3923. input := wire.SNACMessage{
  3924. Frame: wire.SNACFrame{
  3925. FoodGroup: wire.OService,
  3926. SubGroup: wire.OServiceNoop,
  3927. },
  3928. Body: tt.inputBody,
  3929. }
  3930. h := Handler{
  3931. RouteLogger: middleware.RouteLogger{
  3932. Logger: slog.Default(),
  3933. },
  3934. }
  3935. responseWriter := newMockResponseWriter(t)
  3936. buf := &bytes.Buffer{}
  3937. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3938. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3939. if tt.expectedError != nil {
  3940. assert.ErrorIs(t, err, tt.expectedError)
  3941. } else {
  3942. assert.NoError(t, err)
  3943. }
  3944. })
  3945. }
  3946. }
  3947. func TestHandler_OServiceServiceSetPrivacyFlags(t *testing.T) {
  3948. tests := []struct {
  3949. name string
  3950. inputBody wire.SNAC_0x01_0x14_OServiceSetPrivacyFlags
  3951. expectedError error
  3952. }{
  3953. {
  3954. name: "success",
  3955. inputBody: wire.SNAC_0x01_0x14_OServiceSetPrivacyFlags{
  3956. PrivacyFlags: wire.OServicePrivacyFlagMember,
  3957. },
  3958. },
  3959. }
  3960. for _, tt := range tests {
  3961. t.Run(tt.name, func(t *testing.T) {
  3962. input := wire.SNACMessage{
  3963. Frame: wire.SNACFrame{
  3964. FoodGroup: wire.OService,
  3965. SubGroup: wire.OServiceSetPrivacyFlags,
  3966. },
  3967. Body: tt.inputBody,
  3968. }
  3969. svc := newMockOServiceService(t)
  3970. svc.EXPECT().
  3971. SetPrivacyFlags(mock.Anything, input.Body)
  3972. h := Handler{
  3973. OServiceService: svc,
  3974. RouteLogger: middleware.RouteLogger{
  3975. Logger: slog.Default(),
  3976. },
  3977. }
  3978. responseWriter := newMockResponseWriter(t)
  3979. buf := &bytes.Buffer{}
  3980. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  3981. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  3982. if tt.expectedError != nil {
  3983. assert.ErrorIs(t, err, tt.expectedError)
  3984. } else {
  3985. assert.NoError(t, err)
  3986. }
  3987. })
  3988. }
  3989. }
  3990. func TestHandler_PermitDenyRightsQuery(t *testing.T) {
  3991. tests := []struct {
  3992. name string
  3993. inputBody struct{}
  3994. responseError error
  3995. expectedError error
  3996. }{
  3997. {
  3998. name: "success",
  3999. inputBody: struct{}{},
  4000. },
  4001. {
  4002. name: "response writer error",
  4003. inputBody: struct{}{},
  4004. responseError: assert.AnError,
  4005. expectedError: assert.AnError,
  4006. },
  4007. }
  4008. for _, tt := range tests {
  4009. t.Run(tt.name, func(t *testing.T) {
  4010. input := wire.SNACMessage{
  4011. Frame: wire.SNACFrame{
  4012. FoodGroup: wire.PermitDeny,
  4013. SubGroup: wire.PermitDenyRightsQuery,
  4014. },
  4015. Body: tt.inputBody,
  4016. }
  4017. output := wire.SNACMessage{
  4018. Frame: wire.SNACFrame{
  4019. FoodGroup: wire.PermitDeny,
  4020. SubGroup: wire.PermitDenyRightsReply,
  4021. },
  4022. Body: wire.SNAC_0x09_0x03_PermitDenyRightsReply{
  4023. TLVRestBlock: wire.TLVRestBlock{
  4024. TLVList: wire.TLVList{
  4025. wire.NewTLVBE(0x01, uint16(1000)),
  4026. },
  4027. },
  4028. },
  4029. }
  4030. svc := newMockPermitDenyService(t)
  4031. svc.EXPECT().
  4032. RightsQuery(mock.Anything, input.Frame).
  4033. Return(output)
  4034. h := Handler{
  4035. PermitDenyService: svc,
  4036. RouteLogger: middleware.RouteLogger{
  4037. Logger: slog.Default(),
  4038. },
  4039. }
  4040. responseWriter := newMockResponseWriter(t)
  4041. responseWriter.EXPECT().
  4042. SendSNAC(output.Frame, output.Body).
  4043. Return(tt.responseError)
  4044. buf := &bytes.Buffer{}
  4045. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4046. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  4047. if tt.expectedError != nil {
  4048. assert.ErrorIs(t, err, tt.expectedError)
  4049. } else {
  4050. assert.NoError(t, err)
  4051. }
  4052. })
  4053. }
  4054. }
  4055. func TestHandler_PermitDenyAddDenyListEntries(t *testing.T) {
  4056. tests := []struct {
  4057. name string
  4058. inputBody wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries
  4059. serviceError error
  4060. expectedError error
  4061. }{
  4062. {
  4063. name: "success",
  4064. inputBody: wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries{
  4065. Users: []struct {
  4066. ScreenName string `oscar:"len_prefix=uint8"`
  4067. }{
  4068. {
  4069. ScreenName: "friend1",
  4070. },
  4071. {
  4072. ScreenName: "friend2",
  4073. },
  4074. },
  4075. },
  4076. },
  4077. {
  4078. name: "service error",
  4079. inputBody: wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries{
  4080. Users: []struct {
  4081. ScreenName string `oscar:"len_prefix=uint8"`
  4082. }{
  4083. {
  4084. ScreenName: "friend1",
  4085. },
  4086. {
  4087. ScreenName: "friend2",
  4088. },
  4089. },
  4090. },
  4091. serviceError: assert.AnError,
  4092. expectedError: assert.AnError,
  4093. },
  4094. }
  4095. for _, tt := range tests {
  4096. t.Run(tt.name, func(t *testing.T) {
  4097. sess := state.NewSession()
  4098. input := wire.SNACMessage{
  4099. Frame: wire.SNACFrame{
  4100. FoodGroup: wire.PermitDeny,
  4101. SubGroup: wire.PermitDenyAddDenyListEntries,
  4102. },
  4103. Body: tt.inputBody,
  4104. }
  4105. svc := newMockPermitDenyService(t)
  4106. svc.EXPECT().
  4107. AddDenyListEntries(mock.Anything, sess, input.Body).
  4108. Return(tt.serviceError)
  4109. h := Handler{
  4110. PermitDenyService: svc,
  4111. RouteLogger: middleware.RouteLogger{
  4112. Logger: slog.Default(),
  4113. },
  4114. }
  4115. buf := &bytes.Buffer{}
  4116. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4117. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  4118. if tt.expectedError != nil {
  4119. assert.ErrorIs(t, err, tt.expectedError)
  4120. } else {
  4121. assert.NoError(t, err)
  4122. }
  4123. })
  4124. }
  4125. }
  4126. func TestHandler_PermitDenyDelDenyListEntries(t *testing.T) {
  4127. tests := []struct {
  4128. name string
  4129. inputBody wire.SNAC_0x09_0x08_PermitDenyDelDenyListEntries
  4130. serviceError error
  4131. expectedError error
  4132. }{
  4133. {
  4134. name: "success",
  4135. inputBody: wire.SNAC_0x09_0x08_PermitDenyDelDenyListEntries{
  4136. Users: []struct {
  4137. ScreenName string `oscar:"len_prefix=uint8"`
  4138. }{
  4139. {
  4140. ScreenName: "friend1",
  4141. },
  4142. {
  4143. ScreenName: "friend2",
  4144. },
  4145. },
  4146. },
  4147. },
  4148. {
  4149. name: "service error",
  4150. inputBody: wire.SNAC_0x09_0x08_PermitDenyDelDenyListEntries{
  4151. Users: []struct {
  4152. ScreenName string `oscar:"len_prefix=uint8"`
  4153. }{
  4154. {
  4155. ScreenName: "friend1",
  4156. },
  4157. {
  4158. ScreenName: "friend2",
  4159. },
  4160. },
  4161. },
  4162. serviceError: assert.AnError,
  4163. expectedError: assert.AnError,
  4164. },
  4165. }
  4166. for _, tt := range tests {
  4167. t.Run(tt.name, func(t *testing.T) {
  4168. sess := state.NewSession()
  4169. input := wire.SNACMessage{
  4170. Frame: wire.SNACFrame{
  4171. FoodGroup: wire.PermitDeny,
  4172. SubGroup: wire.PermitDenyDelDenyListEntries,
  4173. },
  4174. Body: tt.inputBody,
  4175. }
  4176. svc := newMockPermitDenyService(t)
  4177. svc.EXPECT().
  4178. DelDenyListEntries(mock.Anything, sess, input.Body).
  4179. Return(tt.serviceError)
  4180. h := Handler{
  4181. PermitDenyService: svc,
  4182. RouteLogger: middleware.RouteLogger{
  4183. Logger: slog.Default(),
  4184. },
  4185. }
  4186. buf := &bytes.Buffer{}
  4187. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4188. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  4189. if tt.expectedError != nil {
  4190. assert.ErrorIs(t, err, tt.expectedError)
  4191. } else {
  4192. assert.NoError(t, err)
  4193. }
  4194. })
  4195. }
  4196. }
  4197. func TestHandler_PermitDenyAddPermListEntries(t *testing.T) {
  4198. tests := []struct {
  4199. name string
  4200. inputBody wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries
  4201. serviceError error
  4202. expectedError error
  4203. }{
  4204. {
  4205. name: "success",
  4206. inputBody: wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries{
  4207. Users: []struct {
  4208. ScreenName string `oscar:"len_prefix=uint8"`
  4209. }{
  4210. {
  4211. ScreenName: "friend1",
  4212. },
  4213. {
  4214. ScreenName: "friend2",
  4215. },
  4216. },
  4217. },
  4218. },
  4219. {
  4220. name: "service error",
  4221. inputBody: wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries{
  4222. Users: []struct {
  4223. ScreenName string `oscar:"len_prefix=uint8"`
  4224. }{
  4225. {
  4226. ScreenName: "friend1",
  4227. },
  4228. {
  4229. ScreenName: "friend2",
  4230. },
  4231. },
  4232. },
  4233. serviceError: assert.AnError,
  4234. expectedError: assert.AnError,
  4235. },
  4236. }
  4237. for _, tt := range tests {
  4238. t.Run(tt.name, func(t *testing.T) {
  4239. sess := state.NewSession()
  4240. input := wire.SNACMessage{
  4241. Frame: wire.SNACFrame{
  4242. FoodGroup: wire.PermitDeny,
  4243. SubGroup: wire.PermitDenyAddPermListEntries,
  4244. },
  4245. Body: tt.inputBody,
  4246. }
  4247. svc := newMockPermitDenyService(t)
  4248. svc.EXPECT().
  4249. AddPermListEntries(mock.Anything, sess, input.Body).
  4250. Return(tt.serviceError)
  4251. h := Handler{
  4252. PermitDenyService: svc,
  4253. RouteLogger: middleware.RouteLogger{
  4254. Logger: slog.Default(),
  4255. },
  4256. }
  4257. buf := &bytes.Buffer{}
  4258. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4259. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  4260. if tt.expectedError != nil {
  4261. assert.ErrorIs(t, err, tt.expectedError)
  4262. } else {
  4263. assert.NoError(t, err)
  4264. }
  4265. })
  4266. }
  4267. }
  4268. func TestHandler_PermitDenyDelPermListEntries(t *testing.T) {
  4269. tests := []struct {
  4270. name string
  4271. inputBody wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries
  4272. serviceError error
  4273. expectedError error
  4274. }{
  4275. {
  4276. name: "success",
  4277. inputBody: wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries{
  4278. Users: []struct {
  4279. ScreenName string `oscar:"len_prefix=uint8"`
  4280. }{
  4281. {
  4282. ScreenName: "friend1",
  4283. },
  4284. {
  4285. ScreenName: "friend2",
  4286. },
  4287. },
  4288. },
  4289. },
  4290. {
  4291. name: "service error",
  4292. inputBody: wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries{
  4293. Users: []struct {
  4294. ScreenName string `oscar:"len_prefix=uint8"`
  4295. }{
  4296. {
  4297. ScreenName: "friend1",
  4298. },
  4299. {
  4300. ScreenName: "friend2",
  4301. },
  4302. },
  4303. },
  4304. serviceError: assert.AnError,
  4305. expectedError: assert.AnError,
  4306. },
  4307. }
  4308. for _, tt := range tests {
  4309. t.Run(tt.name, func(t *testing.T) {
  4310. sess := state.NewSession()
  4311. input := wire.SNACMessage{
  4312. Frame: wire.SNACFrame{
  4313. FoodGroup: wire.PermitDeny,
  4314. SubGroup: wire.PermitDenyDelPermListEntries,
  4315. },
  4316. Body: tt.inputBody,
  4317. }
  4318. svc := newMockPermitDenyService(t)
  4319. svc.EXPECT().
  4320. DelPermListEntries(mock.Anything, sess, input.Body).
  4321. Return(tt.serviceError)
  4322. h := Handler{
  4323. PermitDenyService: svc,
  4324. RouteLogger: middleware.RouteLogger{
  4325. Logger: slog.Default(),
  4326. },
  4327. }
  4328. buf := &bytes.Buffer{}
  4329. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4330. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  4331. if tt.expectedError != nil {
  4332. assert.ErrorIs(t, err, tt.expectedError)
  4333. } else {
  4334. assert.NoError(t, err)
  4335. }
  4336. })
  4337. }
  4338. }
  4339. func TestHandler_PermitDenySetGroupPermitMask(t *testing.T) {
  4340. tests := []struct {
  4341. name string
  4342. inputBody wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries
  4343. expectedError error
  4344. }{
  4345. {
  4346. name: "success",
  4347. inputBody: wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries{
  4348. Users: []struct {
  4349. ScreenName string `oscar:"len_prefix=uint8"`
  4350. }{
  4351. {
  4352. ScreenName: "friend1",
  4353. },
  4354. },
  4355. },
  4356. },
  4357. }
  4358. for _, tt := range tests {
  4359. t.Run(tt.name, func(t *testing.T) {
  4360. sess := state.NewSession()
  4361. input := wire.SNACMessage{
  4362. Frame: wire.SNACFrame{
  4363. FoodGroup: wire.PermitDeny,
  4364. SubGroup: wire.PermitDenySetGroupPermitMask,
  4365. },
  4366. Body: tt.inputBody,
  4367. }
  4368. svc := newMockPermitDenyService(t)
  4369. h := Handler{
  4370. PermitDenyService: svc,
  4371. RouteLogger: middleware.RouteLogger{
  4372. Logger: slog.Default(),
  4373. },
  4374. }
  4375. buf := &bytes.Buffer{}
  4376. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4377. err := h.Handle(context.TODO(), wire.BOS, sess, input.Frame, buf, nil, config.Listener{})
  4378. if tt.expectedError != nil {
  4379. assert.ErrorIs(t, err, tt.expectedError)
  4380. } else {
  4381. assert.NoError(t, err)
  4382. }
  4383. })
  4384. }
  4385. }
  4386. func TestUserLookupHandler_FindByEmail(t *testing.T) {
  4387. tests := []struct {
  4388. name string
  4389. inputBody wire.SNAC_0x0A_0x02_UserLookupFindByEmail
  4390. serviceError error
  4391. responseError error
  4392. expectedError error
  4393. }{
  4394. {
  4395. name: "success",
  4396. inputBody: wire.SNAC_0x0A_0x02_UserLookupFindByEmail{
  4397. Email: []byte("haha@aol.com"),
  4398. },
  4399. },
  4400. {
  4401. name: "service error",
  4402. inputBody: wire.SNAC_0x0A_0x02_UserLookupFindByEmail{
  4403. Email: []byte("haha@aol.com"),
  4404. },
  4405. serviceError: assert.AnError,
  4406. expectedError: assert.AnError,
  4407. },
  4408. {
  4409. name: "response writer error",
  4410. inputBody: wire.SNAC_0x0A_0x02_UserLookupFindByEmail{
  4411. Email: []byte("haha@aol.com"),
  4412. },
  4413. responseError: assert.AnError,
  4414. expectedError: assert.AnError,
  4415. },
  4416. }
  4417. for _, tt := range tests {
  4418. t.Run(tt.name, func(t *testing.T) {
  4419. input := wire.SNACMessage{
  4420. Frame: wire.SNACFrame{
  4421. FoodGroup: wire.UserLookup,
  4422. SubGroup: wire.UserLookupFindByEmail,
  4423. },
  4424. Body: tt.inputBody,
  4425. }
  4426. output := wire.SNACMessage{
  4427. Frame: wire.SNACFrame{
  4428. FoodGroup: wire.UserLookup,
  4429. SubGroup: wire.UserLookupFindReply,
  4430. },
  4431. Body: wire.SNAC_0x0A_0x03_UserLookupFindReply{
  4432. TLVRestBlock: wire.TLVRestBlock{
  4433. TLVList: wire.TLVList{
  4434. wire.NewTLVBE(0x01, uint16(0x02)),
  4435. },
  4436. },
  4437. },
  4438. }
  4439. svc := newMockUserLookupService(t)
  4440. svc.EXPECT().
  4441. FindByEmail(mock.Anything, input.Frame, input.Body).
  4442. Return(output, tt.serviceError)
  4443. h := Handler{
  4444. UserLookupService: svc,
  4445. RouteLogger: middleware.RouteLogger{
  4446. Logger: slog.Default(),
  4447. },
  4448. }
  4449. ss := newMockResponseWriter(t)
  4450. if tt.serviceError == nil {
  4451. ss.EXPECT().
  4452. SendSNAC(output.Frame, output.Body).
  4453. Return(tt.responseError)
  4454. }
  4455. buf := &bytes.Buffer{}
  4456. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4457. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, ss, config.Listener{})
  4458. if tt.expectedError != nil {
  4459. assert.ErrorIs(t, err, tt.expectedError)
  4460. } else {
  4461. assert.NoError(t, err)
  4462. }
  4463. })
  4464. }
  4465. }
  4466. func TestHandler_LocateGetDirInfo(t *testing.T) {
  4467. tests := []struct {
  4468. name string
  4469. inputBody wire.SNAC_0x02_0x0B_LocateGetDirInfo
  4470. serviceError error
  4471. responseError error
  4472. expectedError error
  4473. }{
  4474. {
  4475. name: "success",
  4476. inputBody: wire.SNAC_0x02_0x0B_LocateGetDirInfo{
  4477. ScreenName: "screen-name",
  4478. },
  4479. },
  4480. {
  4481. name: "service error",
  4482. inputBody: wire.SNAC_0x02_0x0B_LocateGetDirInfo{
  4483. ScreenName: "screen-name",
  4484. },
  4485. serviceError: assert.AnError,
  4486. expectedError: assert.AnError,
  4487. },
  4488. {
  4489. name: "response writer error",
  4490. inputBody: wire.SNAC_0x02_0x0B_LocateGetDirInfo{
  4491. ScreenName: "screen-name",
  4492. },
  4493. responseError: assert.AnError,
  4494. expectedError: assert.AnError,
  4495. },
  4496. }
  4497. for _, tt := range tests {
  4498. t.Run(tt.name, func(t *testing.T) {
  4499. input := wire.SNACMessage{
  4500. Frame: wire.SNACFrame{
  4501. FoodGroup: wire.Locate,
  4502. SubGroup: wire.LocateGetDirInfo,
  4503. },
  4504. Body: tt.inputBody,
  4505. }
  4506. output := wire.SNACMessage{
  4507. Frame: wire.SNACFrame{
  4508. FoodGroup: wire.Locate,
  4509. SubGroup: wire.LocateGetDirReply,
  4510. },
  4511. Body: wire.SNAC_0x02_0x0C_LocateGetDirReply{
  4512. Status: 1,
  4513. },
  4514. }
  4515. svc := newMockLocateService(t)
  4516. svc.EXPECT().
  4517. DirInfo(mock.Anything, input.Frame, input.Body).
  4518. Return(output, tt.serviceError)
  4519. h := Handler{
  4520. LocateService: svc,
  4521. RouteLogger: middleware.RouteLogger{
  4522. Logger: slog.Default(),
  4523. },
  4524. }
  4525. responseWriter := newMockResponseWriter(t)
  4526. if tt.serviceError == nil {
  4527. responseWriter.EXPECT().
  4528. SendSNAC(output.Frame, output.Body).
  4529. Return(tt.responseError)
  4530. }
  4531. buf := &bytes.Buffer{}
  4532. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4533. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  4534. if tt.expectedError != nil {
  4535. assert.ErrorIs(t, err, tt.expectedError)
  4536. } else {
  4537. assert.NoError(t, err)
  4538. }
  4539. })
  4540. }
  4541. }
  4542. func TestHandler_LocateRightsQuery(t *testing.T) {
  4543. tests := []struct {
  4544. name string
  4545. inputBody struct{}
  4546. responseError error
  4547. expectedError error
  4548. }{
  4549. {
  4550. name: "success",
  4551. inputBody: struct{}{},
  4552. },
  4553. {
  4554. name: "response writer error",
  4555. inputBody: struct{}{},
  4556. responseError: assert.AnError,
  4557. expectedError: assert.AnError,
  4558. },
  4559. }
  4560. for _, tt := range tests {
  4561. t.Run(tt.name, func(t *testing.T) {
  4562. input := wire.SNACMessage{
  4563. Frame: wire.SNACFrame{
  4564. FoodGroup: wire.Locate,
  4565. SubGroup: wire.LocateRightsQuery,
  4566. },
  4567. Body: tt.inputBody,
  4568. }
  4569. output := wire.SNACMessage{
  4570. Frame: wire.SNACFrame{
  4571. FoodGroup: wire.Locate,
  4572. SubGroup: wire.LocateRightsReply,
  4573. },
  4574. Body: wire.SNAC_0x02_0x03_LocateRightsReply{
  4575. TLVRestBlock: wire.TLVRestBlock{
  4576. TLVList: wire.TLVList{
  4577. wire.NewTLVBE(0x01, uint16(1000)),
  4578. },
  4579. },
  4580. },
  4581. }
  4582. svc := newMockLocateService(t)
  4583. svc.EXPECT().
  4584. RightsQuery(mock.Anything, input.Frame).
  4585. Return(output)
  4586. h := Handler{
  4587. LocateService: svc,
  4588. RouteLogger: middleware.RouteLogger{
  4589. Logger: slog.Default(),
  4590. },
  4591. }
  4592. responseWriter := newMockResponseWriter(t)
  4593. responseWriter.EXPECT().
  4594. SendSNAC(output.Frame, output.Body).
  4595. Return(tt.responseError)
  4596. buf := &bytes.Buffer{}
  4597. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4598. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  4599. if tt.expectedError != nil {
  4600. assert.ErrorIs(t, err, tt.expectedError)
  4601. } else {
  4602. assert.NoError(t, err)
  4603. }
  4604. })
  4605. }
  4606. }
  4607. func TestHandler_LocateSetDirInfo(t *testing.T) {
  4608. tests := []struct {
  4609. name string
  4610. inputBody wire.SNAC_0x02_0x09_LocateSetDirInfo
  4611. serviceError error
  4612. responseError error
  4613. expectedError error
  4614. }{
  4615. {
  4616. name: "success",
  4617. inputBody: wire.SNAC_0x02_0x09_LocateSetDirInfo{
  4618. TLVRestBlock: wire.TLVRestBlock{
  4619. TLVList: wire.TLVList{
  4620. {
  4621. Tag: 0x01,
  4622. Value: []byte{1, 2, 3, 4},
  4623. },
  4624. },
  4625. },
  4626. },
  4627. },
  4628. {
  4629. name: "service error",
  4630. inputBody: wire.SNAC_0x02_0x09_LocateSetDirInfo{
  4631. TLVRestBlock: wire.TLVRestBlock{
  4632. TLVList: wire.TLVList{
  4633. {
  4634. Tag: 0x01,
  4635. Value: []byte{1, 2, 3, 4},
  4636. },
  4637. },
  4638. },
  4639. },
  4640. serviceError: assert.AnError,
  4641. expectedError: assert.AnError,
  4642. },
  4643. {
  4644. name: "response writer error",
  4645. inputBody: wire.SNAC_0x02_0x09_LocateSetDirInfo{
  4646. TLVRestBlock: wire.TLVRestBlock{
  4647. TLVList: wire.TLVList{
  4648. {
  4649. Tag: 0x01,
  4650. Value: []byte{1, 2, 3, 4},
  4651. },
  4652. },
  4653. },
  4654. },
  4655. responseError: assert.AnError,
  4656. expectedError: assert.AnError,
  4657. },
  4658. }
  4659. for _, tt := range tests {
  4660. t.Run(tt.name, func(t *testing.T) {
  4661. input := wire.SNACMessage{
  4662. Frame: wire.SNACFrame{
  4663. FoodGroup: wire.Locate,
  4664. SubGroup: wire.LocateSetDirInfo,
  4665. },
  4666. Body: tt.inputBody,
  4667. }
  4668. output := wire.SNACMessage{
  4669. Frame: wire.SNACFrame{
  4670. FoodGroup: wire.Locate,
  4671. SubGroup: wire.LocateSetDirReply,
  4672. },
  4673. Body: wire.SNAC_0x02_0x0A_LocateSetDirReply{
  4674. Result: 1,
  4675. },
  4676. }
  4677. svc := newMockLocateService(t)
  4678. svc.EXPECT().
  4679. SetDirInfo(mock.Anything, mock.Anything, input.Frame, input.Body).
  4680. Return(output, tt.serviceError)
  4681. h := Handler{
  4682. LocateService: svc,
  4683. RouteLogger: middleware.RouteLogger{
  4684. Logger: slog.Default(),
  4685. },
  4686. }
  4687. responseWriter := newMockResponseWriter(t)
  4688. if tt.serviceError == nil {
  4689. responseWriter.EXPECT().
  4690. SendSNAC(output.Frame, output.Body).
  4691. Return(tt.responseError)
  4692. }
  4693. buf := &bytes.Buffer{}
  4694. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4695. err := h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{})
  4696. if tt.expectedError != nil {
  4697. assert.ErrorIs(t, err, tt.expectedError)
  4698. } else {
  4699. assert.NoError(t, err)
  4700. }
  4701. })
  4702. }
  4703. }
  4704. func TestHandler_LocateSetInfo(t *testing.T) {
  4705. input := wire.SNACMessage{
  4706. Frame: wire.SNACFrame{
  4707. FoodGroup: wire.Locate,
  4708. SubGroup: wire.LocateSetInfo,
  4709. },
  4710. Body: wire.SNAC_0x02_0x04_LocateSetInfo{
  4711. TLVRestBlock: wire.TLVRestBlock{
  4712. TLVList: wire.TLVList{
  4713. {
  4714. Tag: 0x01,
  4715. Value: []byte{1, 2, 3, 4},
  4716. },
  4717. },
  4718. },
  4719. },
  4720. }
  4721. svc := newMockLocateService(t)
  4722. svc.EXPECT().
  4723. SetInfo(mock.Anything, mock.Anything, input.Body).
  4724. Return(nil)
  4725. h := Handler{
  4726. LocateService: svc,
  4727. RouteLogger: middleware.RouteLogger{
  4728. Logger: slog.Default(),
  4729. },
  4730. }
  4731. responseWriter := newMockResponseWriter(t)
  4732. buf := &bytes.Buffer{}
  4733. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4734. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{}))
  4735. }
  4736. func TestHandler_LocateSetKeywordInfo(t *testing.T) {
  4737. input := wire.SNACMessage{
  4738. Frame: wire.SNACFrame{
  4739. FoodGroup: wire.Locate,
  4740. SubGroup: wire.LocateSetKeywordInfo,
  4741. },
  4742. Body: wire.SNAC_0x02_0x0F_LocateSetKeywordInfo{
  4743. TLVRestBlock: wire.TLVRestBlock{
  4744. TLVList: wire.TLVList{
  4745. {
  4746. Tag: 0x01,
  4747. Value: []byte{1, 2, 3, 4},
  4748. },
  4749. },
  4750. },
  4751. },
  4752. }
  4753. output := wire.SNACMessage{
  4754. Frame: wire.SNACFrame{
  4755. FoodGroup: wire.Locate,
  4756. SubGroup: wire.LocateSetKeywordReply,
  4757. },
  4758. Body: wire.SNAC_0x02_0x10_LocateSetKeywordReply{
  4759. Unknown: 1,
  4760. },
  4761. }
  4762. svc := newMockLocateService(t)
  4763. svc.EXPECT().
  4764. SetKeywordInfo(mock.Anything, mock.Anything, input.Frame, input.Body).
  4765. Return(output, nil)
  4766. h := Handler{
  4767. LocateService: svc,
  4768. RouteLogger: middleware.RouteLogger{
  4769. Logger: slog.Default(),
  4770. },
  4771. }
  4772. responseWriter := newMockResponseWriter(t)
  4773. responseWriter.EXPECT().
  4774. SendSNAC(output.Frame, output.Body).
  4775. Return(nil)
  4776. buf := &bytes.Buffer{}
  4777. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4778. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{}))
  4779. }
  4780. func TestHandler_LocateUserInfoQuery(t *testing.T) {
  4781. input := wire.SNACMessage{
  4782. Frame: wire.SNACFrame{
  4783. FoodGroup: wire.Locate,
  4784. SubGroup: wire.LocateUserInfoQuery,
  4785. },
  4786. Body: wire.SNAC_0x02_0x05_LocateUserInfoQuery{
  4787. Type: 1,
  4788. },
  4789. }
  4790. output := wire.SNACMessage{
  4791. Frame: wire.SNACFrame{
  4792. FoodGroup: wire.Locate,
  4793. SubGroup: wire.LocateUserInfoReply,
  4794. },
  4795. Body: wire.SNAC_0x02_0x06_LocateUserInfoReply{
  4796. TLVUserInfo: wire.TLVUserInfo{
  4797. ScreenName: "screen-name",
  4798. },
  4799. LocateInfo: wire.TLVRestBlock{
  4800. TLVList: wire.TLVList{
  4801. {
  4802. Tag: 0x01,
  4803. Value: []byte{1, 2, 3, 4},
  4804. },
  4805. },
  4806. },
  4807. },
  4808. }
  4809. svc := newMockLocateService(t)
  4810. svc.EXPECT().
  4811. UserInfoQuery(mock.Anything, mock.Anything, input.Frame, input.Body).
  4812. Return(output, nil)
  4813. h := Handler{
  4814. LocateService: svc,
  4815. RouteLogger: middleware.RouteLogger{
  4816. Logger: slog.Default(),
  4817. },
  4818. }
  4819. responseWriter := newMockResponseWriter(t)
  4820. responseWriter.EXPECT().
  4821. SendSNAC(output.Frame, output.Body).
  4822. Return(nil)
  4823. buf := &bytes.Buffer{}
  4824. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4825. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{}))
  4826. }
  4827. func TestHandler_LocateUserInfoQuery2(t *testing.T) {
  4828. input := wire.SNACMessage{
  4829. Frame: wire.SNACFrame{
  4830. FoodGroup: wire.Locate,
  4831. SubGroup: wire.LocateUserInfoQuery2,
  4832. },
  4833. Body: wire.SNAC_0x02_0x15_LocateUserInfoQuery2{
  4834. Type2: 1,
  4835. },
  4836. }
  4837. output := wire.SNACMessage{
  4838. Frame: wire.SNACFrame{
  4839. FoodGroup: wire.Locate,
  4840. SubGroup: wire.LocateUserInfoReply,
  4841. },
  4842. Body: wire.SNAC_0x02_0x06_LocateUserInfoReply{
  4843. TLVUserInfo: wire.TLVUserInfo{
  4844. ScreenName: "screen-name",
  4845. },
  4846. LocateInfo: wire.TLVRestBlock{
  4847. TLVList: wire.TLVList{
  4848. {
  4849. Tag: 0x01,
  4850. Value: []byte{1, 2, 3, 4},
  4851. },
  4852. },
  4853. },
  4854. },
  4855. }
  4856. svc := newMockLocateService(t)
  4857. svc.EXPECT().
  4858. UserInfoQuery(mock.Anything, mock.Anything, input.Frame, wire.SNAC_0x02_0x05_LocateUserInfoQuery{Type: 1}).
  4859. Return(output, nil)
  4860. h := Handler{
  4861. LocateService: svc,
  4862. RouteLogger: middleware.RouteLogger{
  4863. Logger: slog.Default(),
  4864. },
  4865. }
  4866. responseWriter := newMockResponseWriter(t)
  4867. responseWriter.EXPECT().
  4868. SendSNAC(output.Frame, output.Body).
  4869. Return(nil)
  4870. buf := &bytes.Buffer{}
  4871. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4872. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, responseWriter, config.Listener{}))
  4873. }
  4874. func TestHandler_StatsReportEvents(t *testing.T) {
  4875. input := wire.SNACMessage{
  4876. Frame: wire.SNACFrame{
  4877. FoodGroup: wire.Stats,
  4878. SubGroup: wire.StatsReportEvents,
  4879. },
  4880. Body: wire.SNAC_0x0B_0x03_StatsReportEvents{},
  4881. }
  4882. output := wire.SNACMessage{
  4883. Frame: wire.SNACFrame{
  4884. FoodGroup: wire.Stats,
  4885. SubGroup: wire.StatsReportAck,
  4886. },
  4887. Body: wire.SNAC_0x0B_0x04_StatsReportAck{},
  4888. }
  4889. svc := newMockStatsService(t)
  4890. svc.EXPECT().
  4891. ReportEvents(mock.Anything, input.Frame, input.Body).
  4892. Return(output)
  4893. h := Handler{
  4894. StatsService: svc,
  4895. RouteLogger: middleware.RouteLogger{
  4896. Logger: slog.Default(),
  4897. },
  4898. }
  4899. ss := newMockResponseWriter(t)
  4900. ss.EXPECT().
  4901. SendSNAC(output.Frame, output.Body).
  4902. Return(nil)
  4903. buf := &bytes.Buffer{}
  4904. assert.NoError(t, wire.MarshalBE(input.Body, buf))
  4905. assert.NoError(t, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, buf, ss, config.Listener{}))
  4906. }
  4907. func TestHandler_RouteNotFound(t *testing.T) {
  4908. input := wire.SNACMessage{
  4909. Frame: wire.SNACFrame{
  4910. FoodGroup: wire.Stats,
  4911. SubGroup: math.MaxUint16,
  4912. },
  4913. Body: wire.SNAC_0x0B_0x03_StatsReportEvents{},
  4914. }
  4915. h := Handler{
  4916. RouteLogger: middleware.RouteLogger{
  4917. Logger: slog.Default(),
  4918. },
  4919. }
  4920. assert.ErrorIs(t, ErrRouteNotFound, h.Handle(context.TODO(), wire.BOS, nil, input.Frame, nil, nil, config.Listener{}))
  4921. }