helpers_test.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. package toc
  2. import (
  3. "context"
  4. "time"
  5. "github.com/stretchr/testify/mock"
  6. "github.com/mk6i/retro-aim-server/state"
  7. "github.com/mk6i/retro-aim-server/wire"
  8. )
  9. type adminParams struct {
  10. infoChangeRequestParams
  11. }
  12. type infoChangeRequestParams []struct {
  13. me state.IdentScreenName
  14. inBody wire.SNAC_0x07_0x04_AdminInfoChangeRequest
  15. msg wire.SNACMessage
  16. err error
  17. }
  18. type addBuddiesParams []struct {
  19. me state.IdentScreenName
  20. inBody wire.SNAC_0x03_0x04_BuddyAddBuddies
  21. err error
  22. }
  23. type broadcastBuddyDepartedParams []struct {
  24. me state.IdentScreenName
  25. err error
  26. }
  27. type delBuddiesParams []struct {
  28. me state.IdentScreenName
  29. inBody wire.SNAC_0x03_0x05_BuddyDelBuddies
  30. err error
  31. }
  32. type buddyParams struct {
  33. addBuddiesParams
  34. broadcastBuddyDepartedParams
  35. delBuddiesParams
  36. }
  37. type chatParams struct {
  38. channelMsgToHostParamsChat
  39. }
  40. type createRoomParams []struct {
  41. me state.IdentScreenName
  42. inBody wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate
  43. msg wire.SNACMessage
  44. err error
  45. }
  46. type requestRoomInfoParams []struct {
  47. inBody wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo
  48. msg wire.SNACMessage
  49. err error
  50. }
  51. type chatNavParams struct {
  52. createRoomParams
  53. requestRoomInfoParams
  54. }
  55. type channelMsgToHostParamsChat []struct {
  56. sender state.IdentScreenName
  57. inBody wire.SNAC_0x0E_0x05_ChatChannelMsgToHost
  58. result *wire.SNACMessage
  59. err error
  60. }
  61. type channelMsgToHostParamsICBM []struct {
  62. sender state.IdentScreenName
  63. inFrame wire.SNACFrame
  64. inBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost
  65. result *wire.SNACMessage
  66. err error
  67. }
  68. type evilRequestParams []struct {
  69. me state.IdentScreenName
  70. inBody wire.SNAC_0x04_0x08_ICBMEvilRequest
  71. msg wire.SNACMessage
  72. err error
  73. }
  74. type icbmParams struct {
  75. channelMsgToHostParamsICBM
  76. evilRequestParams
  77. }
  78. type clientOnlineParams []struct {
  79. body wire.SNAC_0x01_0x02_OServiceClientOnline
  80. me state.IdentScreenName
  81. err error
  82. }
  83. type idleNotificationParams []struct {
  84. me state.IdentScreenName
  85. bodyIn wire.SNAC_0x01_0x11_OServiceIdleNotification
  86. err error
  87. }
  88. type serviceRequestParams []struct {
  89. me state.IdentScreenName
  90. bodyIn wire.SNAC_0x01_0x04_OServiceServiceRequest
  91. msg wire.SNACMessage
  92. err error
  93. }
  94. type oServiceParams struct {
  95. clientOnlineParams
  96. idleNotificationParams
  97. serviceRequestParams
  98. }
  99. type flapLoginParams []struct {
  100. frame wire.FLAPSignonFrame
  101. newUserFn func(screenName state.DisplayScreenName) (state.User, error)
  102. tlv wire.TLVRestBlock
  103. err error
  104. }
  105. type registerBOSSessionParams []struct {
  106. authCookie state.ServerCookie
  107. sess *state.Session
  108. err error
  109. }
  110. type registerChatSessionParams []struct {
  111. authCookie state.ServerCookie
  112. sess *state.Session
  113. err error
  114. }
  115. type signoutParams []struct {
  116. me state.IdentScreenName
  117. }
  118. type signoutChatParams []struct {
  119. me state.IdentScreenName
  120. }
  121. type authParams struct {
  122. crackCookieParams
  123. flapLoginParams
  124. registerBOSSessionParams
  125. registerChatSessionParams
  126. signoutParams
  127. signoutChatParams
  128. }
  129. type crackCookieParams []struct {
  130. cookieIn []byte
  131. cookieOut state.ServerCookie
  132. err error
  133. }
  134. type setDirInfoParams []struct {
  135. me state.IdentScreenName
  136. inBody wire.SNAC_0x02_0x09_LocateSetDirInfo
  137. msg wire.SNACMessage
  138. err error
  139. }
  140. type setInfoParams []struct {
  141. me state.IdentScreenName
  142. inBody wire.SNAC_0x02_0x04_LocateSetInfo
  143. err error
  144. }
  145. type userInfoQueryParams []struct {
  146. me state.IdentScreenName
  147. inBody wire.SNAC_0x02_0x05_LocateUserInfoQuery
  148. msg wire.SNACMessage
  149. err error
  150. }
  151. type dirInfoParams []struct {
  152. body wire.SNAC_0x02_0x0B_LocateGetDirInfo
  153. msg wire.SNACMessage
  154. err error
  155. }
  156. type locateParams struct {
  157. setDirInfoParams
  158. setInfoParams
  159. userInfoQueryParams
  160. dirInfoParams
  161. }
  162. type infoQueryParams []struct {
  163. inBody wire.SNAC_0x0F_0x02_InfoQuery
  164. msg wire.SNACMessage
  165. err error
  166. }
  167. type dirSearchParams struct {
  168. infoQueryParams
  169. }
  170. type addDenyListEntriesParams []struct {
  171. me state.IdentScreenName
  172. body wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries
  173. err error
  174. }
  175. type addPermListEntriesParams []struct {
  176. me state.IdentScreenName
  177. body wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries
  178. err error
  179. }
  180. type permitDenyParams struct {
  181. addDenyListEntriesParams
  182. addPermListEntriesParams
  183. }
  184. type registerBuddyListParams []struct {
  185. user state.IdentScreenName
  186. err error
  187. }
  188. type unregisterBuddyListParams []struct {
  189. user state.IdentScreenName
  190. err error
  191. }
  192. type buddyListRegistryParams struct {
  193. registerBuddyListParams
  194. unregisterBuddyListParams
  195. }
  196. type setTOCConfigParams []struct {
  197. user state.IdentScreenName
  198. config string
  199. err error
  200. }
  201. type userParams []struct {
  202. screenName state.IdentScreenName
  203. returnedUser *state.User
  204. err error
  205. }
  206. type tocConfigParams struct {
  207. setTOCConfigParams
  208. userParams
  209. }
  210. type mockParams struct {
  211. adminParams
  212. authParams
  213. buddyListRegistryParams
  214. buddyParams
  215. chatNavParams
  216. chatParams
  217. cookieBakerParams
  218. dirSearchParams
  219. icbmParams
  220. locateParams
  221. oServiceParams
  222. permitDenyParams
  223. tocConfigParams
  224. }
  225. // issueParams holds multiple scenarios for the Issue method.
  226. type issueParams []struct {
  227. data []byte
  228. returnData []byte
  229. returnErr error
  230. }
  231. // cookieBakerParams groups the method scenarios for a CookieBaker.
  232. type cookieBakerParams struct {
  233. issueParams issueParams
  234. }
  235. // matchSession matches a mock call based session ident screen name.
  236. func matchSession(mustMatch state.IdentScreenName) interface{} {
  237. return mock.MatchedBy(func(s *state.Session) bool {
  238. return mustMatch == s.IdentScreenName()
  239. })
  240. }
  241. // newTestSession creates a session object with 0 or more functional options
  242. // applied
  243. func newTestSession(screenName state.DisplayScreenName, options ...func(session *state.Session)) *state.Session {
  244. s := state.NewSession()
  245. s.SetIdentScreenName(screenName.IdentScreenName())
  246. s.SetDisplayScreenName(screenName)
  247. s.SetRateClasses(time.Now(), wire.NewRateLimitClasses([5]wire.RateClass{
  248. {
  249. ID: 1,
  250. WindowSize: 80,
  251. ClearLevel: 2500,
  252. AlertLevel: 2000,
  253. LimitLevel: 1500,
  254. DisconnectLevel: 800,
  255. MaxLevel: 6000,
  256. },
  257. {
  258. ID: 2,
  259. WindowSize: 80,
  260. ClearLevel: 3000,
  261. AlertLevel: 2000,
  262. LimitLevel: 1500,
  263. DisconnectLevel: 1000,
  264. MaxLevel: 6000,
  265. },
  266. {
  267. ID: 3,
  268. WindowSize: 20,
  269. ClearLevel: 5100,
  270. AlertLevel: 5000,
  271. LimitLevel: 4000,
  272. DisconnectLevel: 3000,
  273. MaxLevel: 6000,
  274. },
  275. {
  276. ID: 4,
  277. WindowSize: 20,
  278. ClearLevel: 5500,
  279. AlertLevel: 5300,
  280. LimitLevel: 4200,
  281. DisconnectLevel: 3000,
  282. MaxLevel: 8000,
  283. },
  284. {
  285. ID: 5,
  286. WindowSize: 10,
  287. ClearLevel: 5500,
  288. AlertLevel: 5300,
  289. LimitLevel: 4200,
  290. DisconnectLevel: 3000,
  291. MaxLevel: 8000,
  292. },
  293. }))
  294. for _, op := range options {
  295. op(s)
  296. }
  297. return s
  298. }
  299. // matchContext matches any instance of Context interface.
  300. func matchContext() interface{} {
  301. return mock.MatchedBy(func(ctx any) bool {
  302. _, ok := ctx.(context.Context)
  303. return ok
  304. })
  305. }