rhoconnect 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data/CHANGELOG +208 -0
  2. data/CREDITS +38 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE +75 -0
  6. data/README.md +10 -0
  7. data/Rakefile +82 -0
  8. data/bench/bench +7 -0
  9. data/bench/bench_runner.rb +112 -0
  10. data/bench/benchapp/Gemfile +21 -0
  11. data/bench/benchapp/Gemfile.lock +76 -0
  12. data/bench/benchapp/Rakefile +22 -0
  13. data/bench/benchapp/application.rb +39 -0
  14. data/bench/benchapp/config.ru +36 -0
  15. data/bench/benchapp/settings/license.key +1 -0
  16. data/bench/benchapp/settings/settings.yml +20 -0
  17. data/bench/benchapp/sources/mock_adapter.rb +55 -0
  18. data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
  19. data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
  20. data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
  21. data/bench/benchapp/spec/spec_helper.rb +42 -0
  22. data/bench/blobapp/Gemfile +31 -0
  23. data/bench/blobapp/Gemfile.lock +103 -0
  24. data/bench/blobapp/Rakefile +25 -0
  25. data/bench/blobapp/application.rb +44 -0
  26. data/bench/blobapp/config.ru +36 -0
  27. data/bench/blobapp/settings/license.key +1 -0
  28. data/bench/blobapp/settings/settings.yml +16 -0
  29. data/bench/blobapp/sources/blob_adapter.rb +71 -0
  30. data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
  31. data/bench/blobapp/spec/spec_helper.rb +42 -0
  32. data/bench/lib/bench/cli.rb +16 -0
  33. data/bench/lib/bench/logging.rb +13 -0
  34. data/bench/lib/bench/mock_client.rb +41 -0
  35. data/bench/lib/bench/result.rb +50 -0
  36. data/bench/lib/bench/runner.rb +107 -0
  37. data/bench/lib/bench/session.rb +67 -0
  38. data/bench/lib/bench/statistics.rb +56 -0
  39. data/bench/lib/bench/test_data.rb +98 -0
  40. data/bench/lib/bench/timer.rb +10 -0
  41. data/bench/lib/bench/utils.rb +49 -0
  42. data/bench/lib/bench.rb +129 -0
  43. data/bench/lib/testdata/100-data.txt +148 -0
  44. data/bench/lib/testdata/5-data.txt +9 -0
  45. data/bench/lib/testdata/images/icon.ico +0 -0
  46. data/bench/lib/testdata/images/icon.png +0 -0
  47. data/bench/lib/testdata/images/loading-Landscape.png +0 -0
  48. data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
  49. data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
  50. data/bench/lib/testdata/images/loading-Portrait.png +0 -0
  51. data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
  52. data/bench/lib/testdata/images/loading.png +0 -0
  53. data/bench/lib/testdata/images/loading@2x.png +0 -0
  54. data/bench/run_bench.sh +42 -0
  55. data/bench/run_blob_script.sh +3 -0
  56. data/bench/run_cud_script.sh +3 -0
  57. data/bench/run_query_md_script.sh +3 -0
  58. data/bench/run_query_only_script.sh +3 -0
  59. data/bench/run_query_script.sh +3 -0
  60. data/bench/scripts/blob_cud_script.rb +98 -0
  61. data/bench/scripts/cud_script.rb +92 -0
  62. data/bench/scripts/helpers.rb +101 -0
  63. data/bench/scripts/query_md_script.rb +45 -0
  64. data/bench/scripts/query_only_script.rb +51 -0
  65. data/bench/scripts/query_script.rb +45 -0
  66. data/bench/spec/bench_spec_helper.rb +33 -0
  67. data/bench/spec/logging_spec.rb +15 -0
  68. data/bench/spec/mock_adapter_spec.rb +61 -0
  69. data/bench/spec/mock_client_spec.rb +65 -0
  70. data/bench/spec/result_spec.rb +61 -0
  71. data/bench/spec/utils_spec.rb +36 -0
  72. data/bin/rhoconnect +34 -0
  73. data/bin/rhoconnect-setup +84 -0
  74. data/doc/async-jobs.txt +69 -0
  75. data/doc/authentication.txt +76 -0
  76. data/doc/benchmarks.txt +168 -0
  77. data/doc/blob-sync.txt +130 -0
  78. data/doc/bulk-sync.txt +102 -0
  79. data/doc/client.txt +432 -0
  80. data/doc/command-line.txt +210 -0
  81. data/doc/contributing.txt +60 -0
  82. data/doc/deploying.txt +82 -0
  83. data/doc/install.txt +28 -0
  84. data/doc/introduction.txt +20 -0
  85. data/doc/licensing.txt +18 -0
  86. data/doc/metadata.txt +458 -0
  87. data/doc/migration.txt +182 -0
  88. data/doc/public/css/print.css +29 -0
  89. data/doc/public/css/screen.css +257 -0
  90. data/doc/public/css/style.css +20 -0
  91. data/doc/push.txt +135 -0
  92. data/doc/release.txt +41 -0
  93. data/doc/rest-api.txt +367 -0
  94. data/doc/source-adapters.txt +325 -0
  95. data/doc/stats-middleware.txt +69 -0
  96. data/doc/testing.txt +222 -0
  97. data/doc/tutorial.txt +315 -0
  98. data/doc/web-console.txt +35 -0
  99. data/examples/simple/Rakefile +14 -0
  100. data/examples/simple/application.rb +27 -0
  101. data/examples/simple/config.ru +49 -0
  102. data/examples/simple/settings/license.key +1 -0
  103. data/examples/simple/settings/settings.yml +23 -0
  104. data/examples/simple/sources/sample_adapter.rb +5 -0
  105. data/examples/simple/sources/simple_adapter.rb +5 -0
  106. data/generators/rhoconnect.rb +119 -0
  107. data/generators/templates/application/Gemfile +21 -0
  108. data/generators/templates/application/Rakefile +22 -0
  109. data/generators/templates/application/application.rb +39 -0
  110. data/generators/templates/application/config.ru +36 -0
  111. data/generators/templates/application/settings/license.key +1 -0
  112. data/generators/templates/application/settings/settings.yml +14 -0
  113. data/generators/templates/application/spec/spec_helper.rb +42 -0
  114. data/generators/templates/source/source_adapter.rb +47 -0
  115. data/generators/templates/source/source_spec.rb +25 -0
  116. data/install.sh +408 -0
  117. data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
  118. data/installer/unix-like/rho_connect_install_constants.rb +51 -0
  119. data/installer/unix-like/rho_connect_install_debian.rb +63 -0
  120. data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
  121. data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
  122. data/installer/unix-like/rho_connect_install_installers.rb +142 -0
  123. data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
  124. data/installer/unix-like/rho_connect_install_yum.rb +63 -0
  125. data/installer/unix-like/rhoinstaller.rb +89 -0
  126. data/installer/utils/create_texts.rb +366 -0
  127. data/installer/utils/install_test.rb +140 -0
  128. data/installer/windows/EnvVarUpdate.nsh +328 -0
  129. data/installer/windows/ServiceLib.nsh +369 -0
  130. data/installer/windows/configUi.ini +44 -0
  131. data/installer/windows/icon.ico +0 -0
  132. data/installer/windows/rhosync.nsi +418 -0
  133. data/installer/windows/uninstall.bat +7 -0
  134. data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
  135. data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
  136. data/lib/rhoconnect/api/admin/login.rb +6 -0
  137. data/lib/rhoconnect/api/admin/reset.rb +10 -0
  138. data/lib/rhoconnect/api/admin/stats.rb +21 -0
  139. data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
  140. data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
  141. data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
  142. data/lib/rhoconnect/api/application/clientregister.rb +6 -0
  143. data/lib/rhoconnect/api/application/clientreset.rb +6 -0
  144. data/lib/rhoconnect/api/application/query.rb +7 -0
  145. data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
  146. data/lib/rhoconnect/api/application/search.rb +6 -0
  147. data/lib/rhoconnect/api/client/create_client.rb +3 -0
  148. data/lib/rhoconnect/api/client/delete_client.rb +5 -0
  149. data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
  150. data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
  151. data/lib/rhoconnect/api/client/list_clients.rb +3 -0
  152. data/lib/rhoconnect/api/client/ping.rb +7 -0
  153. data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
  154. data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
  155. data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
  156. data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
  157. data/lib/rhoconnect/api/source/list_sources.rb +15 -0
  158. data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
  159. data/lib/rhoconnect/api/source/push_objects.rb +8 -0
  160. data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
  161. data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
  162. data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
  163. data/lib/rhoconnect/api/source/upload_file.rb +4 -0
  164. data/lib/rhoconnect/api/user/create_user.rb +7 -0
  165. data/lib/rhoconnect/api/user/delete_user.rb +9 -0
  166. data/lib/rhoconnect/api/user/list_users.rb +3 -0
  167. data/lib/rhoconnect/api/user/update_user.rb +4 -0
  168. data/lib/rhoconnect/api_token.rb +19 -0
  169. data/lib/rhoconnect/app.rb +76 -0
  170. data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
  171. data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
  172. data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
  173. data/lib/rhoconnect/bulk_data.rb +2 -0
  174. data/lib/rhoconnect/client.rb +96 -0
  175. data/lib/rhoconnect/client_sync.rb +412 -0
  176. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
  177. data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
  178. data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
  179. data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
  180. data/lib/rhoconnect/console/app/public/home.css +438 -0
  181. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  182. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  183. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  184. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  185. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  186. data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
  187. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  188. data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
  189. data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
  190. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
  191. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
  192. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
  193. data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
  194. data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
  195. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
  196. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
  197. data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
  198. data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
  199. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
  200. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
  201. data/lib/rhoconnect/console/app/public/main.css +7 -0
  202. data/lib/rhoconnect/console/app/public/reset.css +76 -0
  203. data/lib/rhoconnect/console/app/public/style.css +2201 -0
  204. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  205. data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
  206. data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
  207. data/lib/rhoconnect/console/app/routes/client.rb +31 -0
  208. data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
  209. data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
  210. data/lib/rhoconnect/console/app/routes/home.rb +63 -0
  211. data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
  212. data/lib/rhoconnect/console/app/routes/user.rb +117 -0
  213. data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
  214. data/lib/rhoconnect/console/app/views/client.erb +30 -0
  215. data/lib/rhoconnect/console/app/views/content.erb +14 -0
  216. data/lib/rhoconnect/console/app/views/doc.erb +8 -0
  217. data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
  218. data/lib/rhoconnect/console/app/views/docs.erb +30 -0
  219. data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
  220. data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
  221. data/lib/rhoconnect/console/app/views/home.erb +24 -0
  222. data/lib/rhoconnect/console/app/views/index.erb +58 -0
  223. data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
  224. data/lib/rhoconnect/console/app/views/layout.erb +165 -0
  225. data/lib/rhoconnect/console/app/views/login.erb +26 -0
  226. data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
  227. data/lib/rhoconnect/console/app/views/ping.erb +28 -0
  228. data/lib/rhoconnect/console/app/views/result.erb +11 -0
  229. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
  230. data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
  231. data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
  232. data/lib/rhoconnect/console/app/views/user.erb +29 -0
  233. data/lib/rhoconnect/console/app/views/users.erb +12 -0
  234. data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
  235. data/lib/rhoconnect/console/server.rb +32 -0
  236. data/lib/rhoconnect/console.rb +3 -0
  237. data/lib/rhoconnect/cors.rb +229 -0
  238. data/lib/rhoconnect/credential.rb +9 -0
  239. data/lib/rhoconnect/db_adapter.rb +46 -0
  240. data/lib/rhoconnect/document.rb +49 -0
  241. data/lib/rhoconnect/dynamic_adapter.rb +91 -0
  242. data/lib/rhoconnect/generator.rb +1 -0
  243. data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
  244. data/lib/rhoconnect/jobs/ping_job.rb +46 -0
  245. data/lib/rhoconnect/jobs/source_job.rb +16 -0
  246. data/lib/rhoconnect/license.rb +86 -0
  247. data/lib/rhoconnect/lock_ops.rb +11 -0
  248. data/lib/rhoconnect/model.rb +414 -0
  249. data/lib/rhoconnect/ping/android.rb +56 -0
  250. data/lib/rhoconnect/ping/apple.rb +52 -0
  251. data/lib/rhoconnect/ping/blackberry.rb +56 -0
  252. data/lib/rhoconnect/ping.rb +3 -0
  253. data/lib/rhoconnect/read_state.rb +31 -0
  254. data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
  255. data/lib/rhoconnect/server/views/index.erb +13 -0
  256. data/lib/rhoconnect/server.rb +286 -0
  257. data/lib/rhoconnect/source.rb +289 -0
  258. data/lib/rhoconnect/source_adapter.rb +123 -0
  259. data/lib/rhoconnect/source_sync.rb +302 -0
  260. data/lib/rhoconnect/stats/middleware.rb +20 -0
  261. data/lib/rhoconnect/stats/record.rb +108 -0
  262. data/lib/rhoconnect/store.rb +232 -0
  263. data/lib/rhoconnect/tasks.rb +350 -0
  264. data/lib/rhoconnect/test_methods.rb +220 -0
  265. data/lib/rhoconnect/user.rb +95 -0
  266. data/lib/rhoconnect/version.rb +3 -0
  267. data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
  268. data/lib/rhoconnect.rb +285 -0
  269. data/rhoconnect.gemspec +67 -0
  270. data/spec/api/admin/api_token_spec.rb +14 -0
  271. data/spec/api/admin/get_api_token_spec.rb +36 -0
  272. data/spec/api/admin/get_license_info_spec.rb +38 -0
  273. data/spec/api/admin/reset_spec.rb +22 -0
  274. data/spec/api/admin/stats_spec.rb +66 -0
  275. data/spec/api/api_helper.rb +21 -0
  276. data/spec/api/application/rhoconnect_api_spec.rb +548 -0
  277. data/spec/api/client/create_client_spec.rb +13 -0
  278. data/spec/api/client/delete_client_spec.rb +13 -0
  279. data/spec/api/client/get_client_params_spec.rb +18 -0
  280. data/spec/api/client/list_client_docs_spec.rb +32 -0
  281. data/spec/api/client/list_clients_spec.rb +22 -0
  282. data/spec/api/client/ping_spec.rb +23 -0
  283. data/spec/api/rhosync_api_spec.rb.orig +606 -0
  284. data/spec/api/source/adapter_spec.rb +29 -0
  285. data/spec/api/source/get_db_doc_spec.rb +21 -0
  286. data/spec/api/source/get_source_params_spec.rb +32 -0
  287. data/spec/api/source/list_source_docs_spec.rb +25 -0
  288. data/spec/api/source/list_sources_spec.rb +26 -0
  289. data/spec/api/source/push_deletes_spec.rb +18 -0
  290. data/spec/api/source/push_objects_spec.rb +27 -0
  291. data/spec/api/source/set_db_doc_spec.rb +19 -0
  292. data/spec/api/source/set_refresh_time_spec.rb +43 -0
  293. data/spec/api/source/upload_file_spec.rb +26 -0
  294. data/spec/api/user/create_user_spec.rb +16 -0
  295. data/spec/api/user/delete_user_spec.rb +36 -0
  296. data/spec/api/user/list_users_spec.rb +30 -0
  297. data/spec/api/user/update_user_spec.rb +31 -0
  298. data/spec/api_token_spec.rb +14 -0
  299. data/spec/app_spec.rb +18 -0
  300. data/spec/apps/emptyapp/application.rb +27 -0
  301. data/spec/apps/emptyapp/settings/license.key +1 -0
  302. data/spec/apps/emptyapp/settings/settings.yml +14 -0
  303. data/spec/apps/rhotestapp/Rakefile +1 -0
  304. data/spec/apps/rhotestapp/application.rb +19 -0
  305. data/spec/apps/rhotestapp/config.ru +1 -0
  306. data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
  307. data/spec/apps/rhotestapp/settings/license.key +1 -0
  308. data/spec/apps/rhotestapp/settings/settings.yml +36 -0
  309. data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
  310. data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
  311. data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
  312. data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
  313. data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
  314. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
  315. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
  316. data/spec/bulk_data/bulk_data_spec.rb +97 -0
  317. data/spec/client_spec.rb +124 -0
  318. data/spec/client_sync_spec.rb +774 -0
  319. data/spec/doc/base.html +72 -0
  320. data/spec/doc/doc_spec.rb +376 -0
  321. data/spec/doc/footer.html +4 -0
  322. data/spec/doc/header.html +30 -0
  323. data/spec/document_spec.rb +31 -0
  324. data/spec/dynamic_adapter_spec.rb +43 -0
  325. data/spec/factories/factories.rb +17 -0
  326. data/spec/generator/generator_spec.rb +58 -0
  327. data/spec/generator/generator_spec_helper.rb +9 -0
  328. data/spec/jobs/bulk_data_job_spec.rb +125 -0
  329. data/spec/jobs/ping_job_spec.rb +102 -0
  330. data/spec/jobs/source_job_spec.rb +29 -0
  331. data/spec/license_spec.rb +66 -0
  332. data/spec/model_spec.rb +273 -0
  333. data/spec/perf/bulk_data_perf_spec.rb +32 -0
  334. data/spec/perf/perf_spec_helper.rb +50 -0
  335. data/spec/perf/store_perf_spec.rb +27 -0
  336. data/spec/ping/android_spec.rb +91 -0
  337. data/spec/ping/apple_spec.rb +70 -0
  338. data/spec/ping/blackberry_spec.rb +62 -0
  339. data/spec/read_state_spec.rb +35 -0
  340. data/spec/rhosync_spec.rb +75 -0
  341. data/spec/server/cors_spec.rb +287 -0
  342. data/spec/server/server_spec.rb +470 -0
  343. data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
  344. data/spec/source_adapter_spec.rb +125 -0
  345. data/spec/source_spec.rb +114 -0
  346. data/spec/source_sync_spec.rb +328 -0
  347. data/spec/spec.opts +4 -0
  348. data/spec/spec_helper.rb +231 -0
  349. data/spec/stats/middleware_spec.rb +53 -0
  350. data/spec/stats/record_spec.rb +92 -0
  351. data/spec/store_spec.rb +251 -0
  352. data/spec/support/shared_examples.rb +168 -0
  353. data/spec/sync_states_spec.rb +72 -0
  354. data/spec/test_methods_spec.rb +134 -0
  355. data/spec/testdata/1000-data.txt +1414 -0
  356. data/spec/testdata/compressed/compress-data.txt +1 -0
  357. data/spec/testdata/upload1.txt +1 -0
  358. data/spec/testdata/upload2.txt +1 -0
  359. data/spec/user_spec.rb +139 -0
  360. data/tasks/redis.rake +206 -0
  361. metadata +706 -0
@@ -0,0 +1,470 @@
1
+ require 'rack/test'
2
+
3
+ require File.join(File.dirname(__FILE__),'..','..','lib','rhoconnect','server.rb')
4
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
5
+ require File.join(File.dirname(__FILE__), '..', 'support', 'shared_examples')
6
+
7
+ describe "Server" do
8
+ include Rack::Test::Methods
9
+ include Rhoconnect
10
+
11
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
12
+ before(:each) do
13
+ require File.join(get_testapp_path,test_app_name)
14
+ Rhoconnect.bootstrap(get_testapp_path) do |rhoconnect|
15
+ rhoconnect.vendor_directory = File.join(rhoconnect.base_directory,'..','..','..','vendor')
16
+ rhoconnect.appserver = nil
17
+ end
18
+ Rhoconnect::Server.set :environment, :test
19
+ Rhoconnect::Server.set :run, false
20
+ Rhoconnect::Server.set :secret, "secure!"
21
+ Rhoconnect::Server.use Rack::Static, :urls => ["/data"],
22
+ :root => File.expand_path(File.join(File.dirname(__FILE__),'..','apps','rhotestapp'))
23
+ end
24
+
25
+ def app
26
+ @app ||= Rhoconnect::Server.new
27
+ end
28
+
29
+ it "should show status page" do
30
+ get '/'
31
+ last_response.body.match(Rhoconnect::VERSION)[0].should == Rhoconnect::VERSION
32
+ end
33
+
34
+ it "should login if content-type contains extra parameters" do
35
+ post "/api/admin/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
36
+ last_response.should be_ok
37
+ end
38
+
39
+ it "should fail to login if wrong content-type" do
40
+ post "/api/admin/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/x-www-form-urlencoded'}
41
+ last_response.should_not be_ok
42
+ end
43
+
44
+ it "should login as rhoadmin user" do
45
+ post "/api/admin/login", "login" => 'rhoadmin', "password" => ''
46
+ last_response.should be_ok
47
+ end
48
+
49
+ it "should respond with 401 to /:app_name" do
50
+ get "/api/application/query"
51
+ last_response.status.should == 401
52
+ end
53
+
54
+ it "should have default session secret" do
55
+ Rhoconnect::Server.secret.should == "secure!"
56
+ end
57
+
58
+ it "should use Stats::Middleware if stats enabled" do
59
+ Rhoconnect::Server.enable :stats
60
+ Rhoconnect::Server.new
61
+ Rhoconnect.stats.should == true
62
+ Rhoconnect.stats = nil
63
+ Rhoconnect::Server.disable :stats
64
+ end
65
+
66
+ it "should update session secret to default" do
67
+ Rhoconnect::Server.set :secret, "<changeme>"
68
+ Rhoconnect::Server.secret.should == "<changeme>"
69
+ Rhoconnect::Server.should_receive(:log).any_number_of_times.with(any_args())
70
+ check_default_secret!("<changeme>")
71
+ Rhoconnect::Server.set :secret, "secure!"
72
+ end
73
+
74
+ it "should complain about hsqldata.jar missing" do
75
+ Rhoconnect.vendor_directory = 'missing'
76
+ Rhoconnect::Server.should_receive(:log).any_number_of_times.with(any_args())
77
+ check_hsql_lib!
78
+ end
79
+
80
+ describe "helpers" do
81
+ before(:each) do
82
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
83
+ end
84
+
85
+ it "should return nil if params[:source_name] is missing" do
86
+ #stub_request(:post, "http://test.rhoconnect.com/rhoconnect/query")
87
+ get "/api/application/query"
88
+ last_response.status.should == 500
89
+ end
90
+ end
91
+
92
+ describe "auth routes" do
93
+ it "should login user with correct username,password" do
94
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
95
+ last_response.should be_ok
96
+ end
97
+
98
+ it "should login user with correct username,password if backend servcie defined" do
99
+ stub_request(:post, "http://test.com/rhoconnect/authenticate").to_return(:body => "lucas")
100
+ Rhoconnect.appserver = 'http://test.com'
101
+ do_post "/api/application/clientlogin", "login" => 'lucas', "password" => 'testpass'
102
+ last_response.should be_ok
103
+ end
104
+
105
+ it "should return 401 and LoginException messsage from authenticate" do
106
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'wrongpass'
107
+ last_response.status.should == 401
108
+ last_response.body.should == 'login exception'
109
+ end
110
+
111
+ it "should return 500 and Exception messsage from authenticate" do
112
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'server error'
113
+ last_response.status.should == 500
114
+ last_response.body.should == 'server error'
115
+ end
116
+
117
+ it "should return 401 and no messsage from authenticate if no exception raised" do
118
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'wrongpassnomsg'
119
+ last_response.status.should == 401
120
+ last_response.body.should == ''
121
+ end
122
+
123
+ it "should create unknown user through delegated authentication" do
124
+ do_post "/api/application/clientlogin", "login" => 'newuser', "password" => 'testpass'
125
+ User.is_exist?('newuser').should == true
126
+ @a.users.members.sort.should == ['newuser','testuser']
127
+ end
128
+
129
+ it "should create a different username through delegated authentication" do
130
+ do_post "/api/application/clientlogin", "login" => 'newuser', "password" => 'diffuser'
131
+ User.is_exist?('different').should == true
132
+ @a.users.members.sort.should == ['different','testuser']
133
+ end
134
+ end
135
+
136
+ describe "client management routes" do
137
+ before(:each) do
138
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
139
+ @source_config = {
140
+ "sources"=>
141
+ {"FixedSchemaAdapter"=>
142
+ {"poll_interval"=>300,
143
+ "sync_type"=>"incremental",
144
+ "belongs_to"=>[{"brand"=>"SampleAdapter"}]},
145
+ "SampleAdapter"=>{"poll_interval"=>300},
146
+ "SimpleAdapter"=>{"partition_type"=>"app", "poll_interval"=>600}}
147
+ }
148
+ end
149
+
150
+ it "should respond to clientcreate" do
151
+ get "/api/application/clientcreate?device_type=blackberry"
152
+ last_response.should be_ok
153
+ last_response.content_type.should =~ /application\/json/
154
+ id = JSON.parse(last_response.body)['client']['client_id']
155
+ id.length.should == 32
156
+ JSON.parse(last_response.body).should ==
157
+ {"client"=>{"client_id"=>id}}.merge!(@source_config)
158
+ c = Client.load(id,{:source_name => '*'})
159
+ c.user_id.should == 'testuser'
160
+ c.device_type.should == 'blackberry'
161
+ end
162
+
163
+ it "should respond to clientregister" do
164
+ do_post "/api/application/clientregister",
165
+ "device_type" => "iPhone", "device_pin" => 'abcd', "client_id" => @c.id
166
+ last_response.should be_ok
167
+ JSON.parse(last_response.body).should == @source_config
168
+ @c.device_type.should == 'Apple'
169
+ @c.device_pin.should == 'abcd'
170
+ @c.id.length.should == 32
171
+ end
172
+
173
+ it "should respond to clientreset" do
174
+ set_state(@c.docname(:cd) => @data)
175
+ get "/api/application/clientreset", :client_id => @c.id,:version => ClientSync::VERSION
176
+ JSON.parse(last_response.body).should == @source_config
177
+ verify_result(@c.docname(:cd) => {})
178
+ end
179
+
180
+ it "should respond to clientreset with individual adapters" do
181
+ @c.source_name = 'SimpleAdapter'
182
+ set_state(@c.docname(:cd) => @data)
183
+ @c.source_name = 'SampleAdapter'
184
+ set_state(@c.docname(:cd) => @data)
185
+ sources = [{'name' => 'SimpleAdapter'}]
186
+ get "/api/application/clientreset", :client_id => @c.id,:version => ClientSync::VERSION, :sources => sources
187
+ JSON.parse(last_response.body).should == @source_config
188
+ @c.source_name = 'SampleAdapter'
189
+ verify_result(@c.docname(:cd) => @data)
190
+ @c.source_name = 'SimpleAdapter'
191
+ verify_result(@c.docname(:cd) => {})
192
+ end
193
+
194
+ it "should switch client user if client user_id doesn't match session user" do
195
+ set_test_data('test_db_storage',@data)
196
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
197
+ JSON.parse(last_response.body).last['insert'].should == @data
198
+ do_post "/api/application/clientlogin", "login" => 'user2', "password" => 'testpass'
199
+ data = {'1'=>@product1,'2'=>@product2}
200
+ set_test_data('test_db_storage',data)
201
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
202
+ JSON.parse(last_response.body).last['insert'].should == data
203
+ end
204
+
205
+ it "should return error on routes if client doesn't exist" do
206
+ get "/api/application/query",:client_id => "missingclient",:source_name => @s.name,:version => ClientSync::VERSION
207
+ last_response.body.should == "Unknown client"
208
+ last_response.status.should == 500
209
+ end
210
+ end
211
+
212
+ describe "source routes" do
213
+ before(:each) do
214
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
215
+ end
216
+
217
+ it "should return 404 message with version < 3" do
218
+ get "/api/application/query",:source_name => @s.name,:version => 2
219
+ last_response.status.should == 404
220
+ last_response.body.should == "Server supports version 3 or higher of the protocol."
221
+ end
222
+
223
+ it "should post records for create" do
224
+ @product1['_id'] = '1'
225
+ params = {'create'=>{'1'=>@product1},:client_id => @c.id,:source_name => @s.name,
226
+ :version => ClientSync::VERSION}
227
+ do_post "/api/application/queue_updates", params
228
+ last_response.should be_ok
229
+ last_response.body.should == ''
230
+ verify_result("test_create_storage" => {'1'=>@product1})
231
+ end
232
+
233
+ it "should post records for update" do
234
+ params = {'update'=>{'1'=>@product1},:client_id => @c.id,:source_name => @s.name,
235
+ :version => ClientSync::VERSION}
236
+ do_post "/api/application/queue_updates", params
237
+ last_response.should be_ok
238
+ last_response.body.should == ''
239
+ verify_result("test_update_storage" => {'1'=>@product1})
240
+ end
241
+
242
+ it "should post records for update using the old route and have the deprecation warning" do
243
+ params = {'update'=>{'1'=>@product1},:client_id => @c.id,:source_name => @s.name,
244
+ :version => ClientSync::VERSION}
245
+ do_post "/application", params
246
+ last_response.should be_ok
247
+ last_response.body.should == ''
248
+ last_response.headers["Warning"].index('deprecated').should_not == nil
249
+ verify_result("test_update_storage" => {'1'=>@product1})
250
+ end
251
+
252
+ it "should post records for delete" do
253
+ params = {'delete'=>{'1'=>@product1},:client_id => @c.id,:source_name => @s.name,
254
+ :version => ClientSync::VERSION}
255
+ do_post "/api/application/queue_updates", params
256
+ last_response.should be_ok
257
+ last_response.body.should == ''
258
+ verify_result("test_delete_storage" => {'1'=>@product1})
259
+ end
260
+
261
+ it "should handle client posting broken json" do
262
+ broken_json = "{\"foo\":\"bar\"\"}"
263
+ post "/api/application/queue_updates", broken_json, {'CONTENT_TYPE'=>'application/json'}
264
+ last_response.status.should == 500
265
+ last_response.body.should == "Server error while processing client data"
266
+ end
267
+
268
+ it "should handle client posting broken body" do
269
+ broken_json = ['foo']
270
+ post "/api/application/queue_updates", broken_json, {'CONTENT_TYPE'=>'application/json'}
271
+ last_response.status.should == 500
272
+ last_response.body.should == "Internal server error"
273
+ end
274
+
275
+ it "should get inserts json" do
276
+ cs = ClientSync.new(@s,@c,1)
277
+ data = {'1'=>@product1,'2'=>@product2}
278
+ set_test_data('test_db_storage',data)
279
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
280
+ last_response.should be_ok
281
+ last_response.content_type.should =~ /application\/json/
282
+ token = @c.get_value(:page_token)
283
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
284
+ {"count"=>2}, {"progress_count"=>0},{"total_count"=>2},{'insert'=>data}]
285
+ end
286
+
287
+ it "should get inserts json with the old route and show deprecation warning" do
288
+ cs = ClientSync.new(@s,@c,1)
289
+ data = {'1'=>@product1,'2'=>@product2}
290
+ set_test_data('test_db_storage',data)
291
+ get "/application",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
292
+ last_response.should be_ok
293
+ last_response.headers["Warning"].index('deprecated').should_not == nil
294
+ last_response.content_type.should =~ /application\/json/
295
+ token = @c.get_value(:page_token)
296
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
297
+ {"count"=>2}, {"progress_count"=>0},{"total_count"=>2},{'insert'=>data}]
298
+ end
299
+
300
+ it "should get inserts json and confirm token" do
301
+ cs = ClientSync.new(@s,@c,1)
302
+ data = {'1'=>@product1,'2'=>@product2}
303
+ set_test_data('test_db_storage',data)
304
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
305
+ last_response.should be_ok
306
+ token = @c.get_value(:page_token)
307
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
308
+ {"count"=>2}, {"progress_count"=>0}, {"total_count"=>2},{'insert'=>data}]
309
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:token => token,
310
+ :version => ClientSync::VERSION
311
+ last_response.should be_ok
312
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>''},
313
+ {"count"=>0}, {"progress_count"=>2}, {"total_count"=>2},{}]
314
+ end
315
+
316
+ it "should create source for dynamic adapter if source_name is unknown" do
317
+ get "/api/application/query",:client_id => @c.id,:source_name => 'Broken',:version => ClientSync::VERSION
318
+ last_response.status.should == 200
319
+ end
320
+
321
+ it "should get deletes json" do
322
+ @s = Source.load(@s_fields[:name],@s_params)
323
+ cs = ClientSync.new(@s,@c,1)
324
+ data = {'1'=>@product1,'2'=>@product2}
325
+ set_test_data('test_db_storage',data)
326
+
327
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
328
+ last_response.should be_ok
329
+ token = @c.get_value(:page_token)
330
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
331
+ {"count"=>2}, {"progress_count"=>0}, {"total_count"=>2},{'insert'=>data}]
332
+
333
+ Store.flash_data('test_db_storage')
334
+ @s.read_state.refresh_time = Time.now.to_i
335
+
336
+ get "/api/application/query",:client_id => @c.id,:source_name => @s.name,:token => token,
337
+ :version => ClientSync::VERSION
338
+ last_response.should be_ok
339
+ token = @c.get_value(:page_token)
340
+ JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
341
+ {"count"=>2}, {"progress_count"=>0}, {"total_count"=>0},{'delete'=>data}]
342
+ end
343
+
344
+ it "should get search results" do
345
+ sources = [{:name=>'SampleAdapter'}]
346
+ cs = ClientSync.new(@s,@c,1)
347
+ Store.put_data('test_db_storage',@data)
348
+ params = {:client_id => @c.id,:sources => sources,:search => {'name' => 'iPhone'},
349
+ :version => ClientSync::VERSION}
350
+ get "/api/application/search",params
351
+ last_response.content_type.should =~ /application\/json/
352
+ token = @c.get_value(:search_token)
353
+ JSON.parse(last_response.body).should == [[{'version'=>ClientSync::VERSION},{'token'=>token},
354
+ {'source'=>sources[0][:name]},{'count'=>1},{'insert'=>{'1'=>@product1}}]]
355
+ end
356
+
357
+ it "should get search results with error" do
358
+ sources = [{:name=>'SampleAdapter'}]
359
+ msg = "Error during search"
360
+ error = set_test_data('test_db_storage',@data,msg,'search error')
361
+ params = {:client_id => @c.id,:sources => sources,:search => {'name' => 'iPhone'},
362
+ :version => ClientSync::VERSION}
363
+ get "/api/application/search",params
364
+ JSON.parse(last_response.body).should == [[{'version'=>ClientSync::VERSION},
365
+ {'source'=>sources[0][:name]},{'search-error'=>{'search-error'=>{'message'=>msg}}}]]
366
+ end
367
+
368
+ it "should get multiple source search results" do
369
+ Store.put_data('test_db_storage',@data)
370
+ sources = [{:name=>'SimpleAdapter'},{:name=>'SampleAdapter'}]
371
+ params = {:client_id => @c.id,:sources => sources,:search => {'search' => 'bar'},
372
+ :version => ClientSync::VERSION}
373
+ get "/api/application/search",params
374
+ @c.source_name = 'SimpleAdapter'
375
+ token1 = @c.get_value(:search_token)
376
+ @c.source_name = 'SampleAdapter'
377
+ token = @c.get_value(:search_token)
378
+ JSON.parse(last_response.body).should == [
379
+ [{"version"=>ClientSync::VERSION},{'token'=>token1},{"source"=>"SimpleAdapter"},
380
+ {"count"=>1}, {"insert"=>{'obj'=>{'foo'=>'bar'}}}],
381
+ [{"version"=>ClientSync::VERSION},{'token'=>token},{"source"=>"SampleAdapter"},
382
+ {"count"=>1}, {"insert"=>{'1'=>@product1}}]]
383
+ end
384
+ end
385
+
386
+ describe "bulk data routes" do
387
+ before(:each) do
388
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
389
+ end
390
+
391
+ after(:each) do
392
+ delete_data_directory
393
+ end
394
+
395
+ it "should make initial bulk data request and receive wait (and no deprecation warning)" do
396
+ set_state('test_db_storage' => @data)
397
+ get "/api/application/bulk_data", :partition => :user, :client_id => @c.id
398
+ last_response.should be_ok
399
+ last_response.body.should == {:result => :wait}.to_json
400
+ warning_header = last_response.headers['Warning']
401
+ warning_header.should == nil or warning_header.index('deprecated').should == nil
402
+ end
403
+
404
+ it "should make old-way initial bulk data request and receive wait along with deprecation warning" do
405
+ set_state('test_db_storage' => @data)
406
+ get "/application/bulk_data", :partition => :user, :client_id => @c.id
407
+ last_response.should be_ok
408
+ last_response.body.should == {:result => :wait}.to_json
409
+ last_response.headers['Warning'].index('deprecated').should_not == nil
410
+ end
411
+
412
+ it "should receive url when bulk data is available" do
413
+ set_state('test_db_storage' => @data)
414
+ get "/api/application/bulk_data", :partition => :user, :client_id => @c.id
415
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
416
+ get "/api/application/bulk_data", :partition => :user, :client_id => @c.id
417
+ last_response.should be_ok
418
+ data = BulkData.load(bulk_data_docname(@a.id,@u.id))
419
+ last_response.body.should == {:result => :url,
420
+ :url => data.url}.to_json
421
+ validate_db(data,{@s.name => @data, 'FixedSchemaAdapter' => @data})
422
+ end
423
+
424
+ it "should download bulk data file" do
425
+ set_state('test_db_storage' => @data)
426
+ get "/api/application/bulk_data", :partition => :user, :client_id => @c.id
427
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
428
+ get "/api/application/bulk_data", :partition => :user, :client_id => @c.id
429
+ get JSON.parse(last_response.body)["url"]
430
+ last_response.should be_ok
431
+ File.open('test.data','wb') {|f| f.puts last_response.body}
432
+ validate_db_file('test.data',[@s.name,'FixedSchemaAdapter'],{@s.name => @data, 'FixedSchemaAdapter' => @data})
433
+ File.delete('test.data')
434
+ end
435
+
436
+ it "should receive nop when no sources are available for partition" do
437
+ set_state('test_db_storage' => @data)
438
+ Source.load('SimpleAdapter',@s_params).partition = :user
439
+ get "/api/application/bulk_data", :partition => :app, :client_id => @c.id
440
+ last_response.should be_ok
441
+ last_response.body.should == {:result => :nop}.to_json
442
+ end
443
+ end
444
+
445
+ describe "blob sync" do
446
+ before(:each) do
447
+ do_post "/api/application/clientlogin", "login" => @u.login, "password" => 'testpass'
448
+ end
449
+ it "should upload blob in multipart post" do
450
+ file1,file2 = 'upload1.txt','upload2.txt'
451
+ @product1['txtfile-rhoblob'] = file1
452
+ @product1['_id'] = 'tempobj1'
453
+ @product2['txtfile-rhoblob'] = file2
454
+ @product2['_id'] = 'tempobj2'
455
+ cud = {'create'=>{'1'=>@product1,'2'=>@product2},
456
+ :client_id => @c.id,:source_name => @s.name,
457
+ :version => ClientSync::VERSION,
458
+ :blob_fields => ['txtfile-rhoblob']}.to_json
459
+ post "/api/application/queue_updates",
460
+ {:cud => cud,'txtfile-rhoblob-1' =>
461
+ Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__),'..','testdata',file1), "application/octet-stream"),
462
+ 'txtfile-rhoblob-2' =>
463
+ Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__),'..','testdata',file2), "application/octet-stream")}
464
+ Store.get_data('test_create_storage').each do |id,obj|
465
+ File.exists?(obj['txtfile-rhoblob']).should == true
466
+ end
467
+ end
468
+ end
469
+ end
470
+ end
@@ -0,0 +1,150 @@
1
+ require 'rhoconnect/x_domain_session_wrapper'
2
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
3
+
4
+ require "cgi"
5
+
6
+ COOKIE_NAME = 'some_cookie'
7
+ COOKIE_VALUE = 'some_session_key=some_session_value'
8
+
9
+ COOKIE_NV = "#{COOKIE_NAME}=#{COOKIE_VALUE}"
10
+ COOKIE_ANOTHER_NV = "#{COOKIE_NAME}=#{COOKIE_VALUE}_another"
11
+
12
+ PROPER_QUERY_STRING = "?abc=123&#{COOKIE_NAME}=#{CGI.escape(COOKIE_VALUE)}&de=45"
13
+ WRONG_QUERY_STRING = "?abc=123&#{COOKIE_NAME}_wrong=#{CGI.escape(COOKIE_VALUE)}&de=45"
14
+
15
+ PROPER_URI_NEW = '/api/application'
16
+ PROPER_URI_OLD = '/application'
17
+ WRONG_URI = '/some/wrong/path/to/rhoconnect/application'
18
+
19
+ LOGIN_URI_NEW = '/api/application/clientlogin'
20
+ LOGIN_URI_OLD = '/application/clientlogin'
21
+
22
+ describe "XDomainSessionWrapper middleware" do
23
+
24
+ class StubApp
25
+ def call(env)
26
+ [200, {'Set-Cookie' => COOKIE_ANOTHER_NV, 'Content-Length' => '0'}, ['']]
27
+ end
28
+ end
29
+
30
+ before(:each) do
31
+ app ||= StubApp.new
32
+
33
+ @middleware_new_routes = XDomainSessionWrapper.new(app, {
34
+ :session_cookie => COOKIE_NAME,
35
+ :api_uri_regexp => /\A\/api\/application/,
36
+ :login_uri_regexp => /\A\/api\/application\/clientlogin/
37
+ })
38
+
39
+ @middleware_old_routes = XDomainSessionWrapper.new(app, {
40
+ :session_cookie => COOKIE_NAME,
41
+ :api_uri_regexp => /\A\/application/,
42
+ :login_uri_regexp => /\A\/application\/clientlogin/
43
+ })
44
+
45
+ end
46
+
47
+ it "should skip if it isn't a sync protocol URI, for new REST routes" do
48
+ env = {
49
+ 'PATH_INFO' => WRONG_URI,
50
+ 'QUERY_STRING' => PROPER_QUERY_STRING
51
+ }
52
+ status, headers, body = @middleware_new_routes.call(env)
53
+ 200.should == status
54
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
55
+ COOKIE_NV.should_not == env['HTTP_COOKIE']
56
+ headers['Content-Length'].should == body[0].length.to_s
57
+ ''.should == body[0]
58
+ end
59
+
60
+ it "should skip if it isn't a sync protocol URI, for old REST routes" do
61
+ env = {
62
+ 'PATH_INFO' => WRONG_URI,
63
+ 'QUERY_STRING' => PROPER_QUERY_STRING
64
+ }
65
+ status, headers, body = @middleware_old_routes.call(env)
66
+ 200.should == status
67
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
68
+ COOKIE_NV.should_not == env['HTTP_COOKIE']
69
+ headers['Content-Length'].should == body[0].length.to_s
70
+ ''.should == body[0]
71
+ end
72
+
73
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for new REST routes" do
74
+ env = {
75
+ 'PATH_INFO' => PROPER_URI_NEW,
76
+ 'QUERY_STRING' => PROPER_QUERY_STRING
77
+ }
78
+ status, headers, body = @middleware_new_routes.call(env)
79
+ 200.should == status
80
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
81
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
82
+ headers['Content-Length'].should == body[0].length.to_s
83
+ ''.should == body[0]
84
+ end
85
+
86
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for old REST routes" do
87
+ env = {
88
+ 'PATH_INFO' => PROPER_URI_OLD,
89
+ 'QUERY_STRING' => PROPER_QUERY_STRING
90
+ }
91
+ status, headers, body = @middleware_old_routes.call(env)
92
+ 200.should == status
93
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
94
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
95
+ headers['Content-Length'].should == body[0].length.to_s
96
+ ''.should == body[0]
97
+ end
98
+
99
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for new REST routes" do
100
+ env = {
101
+ 'PATH_INFO' => PROPER_URI_NEW,
102
+ 'QUERY_STRING' => WRONG_QUERY_STRING
103
+ }
104
+ status, headers, body = @middleware_new_routes.call(env)
105
+ 200.should == status
106
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
107
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
108
+ headers['Content-Length'].should == body[0].length.to_s
109
+ ''.should == body[0]
110
+ end
111
+
112
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for old REST routes" do
113
+ env = {
114
+ 'PATH_INFO' => PROPER_URI_OLD,
115
+ 'QUERY_STRING' => WRONG_QUERY_STRING
116
+ }
117
+ status, headers, body = @middleware_old_routes.call(env)
118
+ 200.should == status
119
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
120
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
121
+ headers['Content-Length'].should == body[0].length.to_s
122
+ ''.should == body[0]
123
+ end
124
+
125
+ it "should respond with cookie in a body if it is a login URI, for new REST routes" do
126
+ env = {
127
+ 'PATH_INFO' => LOGIN_URI_NEW,
128
+ 'QUERY_STRING' => PROPER_QUERY_STRING
129
+ }
130
+ status, headers, body = @middleware_new_routes.call(env)
131
+ 200.should == status
132
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
133
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
134
+ headers['Content-Length'].should == body[0].length.to_s
135
+ ''.should_not == body[0]
136
+ end
137
+
138
+ it "should respond with cookie in a body if it is a login URI, for old REST routes" do
139
+ env = {
140
+ 'PATH_INFO' => LOGIN_URI_OLD,
141
+ 'QUERY_STRING' => PROPER_QUERY_STRING
142
+ }
143
+ status, headers, body = @middleware_old_routes.call(env)
144
+ 200.should == status
145
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
146
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
147
+ headers['Content-Length'].should == body[0].length.to_s
148
+ ''.should_not == body[0]
149
+ end
150
+ end