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,27 @@
1
+ require File.join(File.dirname(__FILE__),'perf_spec_helper')
2
+
3
+ describe "Rhoconnect Performance" do
4
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
+ it "should process get/put for 1000 records (6000 elements)" do
6
+ @data = get_test_data(1000)
7
+ start = start_timer
8
+ Store.put_data('mdoc',@data).should == true
9
+ start = lap_timer('put_data duration',start)
10
+ Store.get_data('mdoc').should == @data
11
+ lap_timer('get_data duration',start)
12
+ end
13
+
14
+ it "should process single attribute update 1000-record doc" do
15
+ @data = get_test_data(1000)
16
+ @data1 = get_test_data(1000)
17
+ @data1['950']['Phone1'] = 'This is changed'
18
+ expected = {'950' => {'Phone1' => 'This is changed'}}
19
+ Store.put_data('mdoc',@data).should == true
20
+ Store.put_data('cdoc',@data1).should == true
21
+ start = start_timer
22
+ Store.get_diff_data('mdoc','cdoc').should == [expected,1]
23
+ lap_timer('get_diff_data duration', start)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,91 @@
1
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
2
+ require File.join(File.dirname(__FILE__), '..', 'support', 'shared_examples')
3
+
4
+ describe "Ping Android" do
5
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
6
+ def setup_post_yield(response)
7
+ if RUBY_VERSION =~ /1.9/ or defined?(JRUBY_VERSION)
8
+ RestClient.stub!(:post).and_yield(response, nil, nil)
9
+ else
10
+ RestClient.stub!(:post).and_yield(response)
11
+ end
12
+ end
13
+
14
+ before do
15
+ @params = {"device_pin" => @c.device_pin,
16
+ "sources" => [@s.name], "message" => 'hello world',
17
+ "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
18
+ @response = mock('response')
19
+ end
20
+
21
+ it "should ping android successfully" do
22
+ result = 'id=0:34234234134254%abc123\n'
23
+ @response.stub!(:code).and_return(200)
24
+ @response.stub!(:body).and_return(result)
25
+ @response.stub!(:[]).and_return(false)
26
+ @response.stub!(:return!).and_return(@response)
27
+ setup_post_yield(@response)
28
+ Android.ping(@params).body.should == result
29
+ end
30
+
31
+ it "should ping android with 503 connection error" do
32
+ error = 'Connection refused'
33
+ @response.stub!(:body).and_return(error)
34
+ RestClient.stub!(:post).and_return { raise RestClient::Exception.new(@response,503) }
35
+ Android.should_receive(:log).twice
36
+ lambda { Android.ping(@params) }.should raise_error(RestClient::Exception)
37
+ end
38
+
39
+ it "should ping android with 200 error message" do
40
+ error = 'Error=QuotaExceeded'
41
+ @response.stub!(:code).and_return(200)
42
+ @response.stub!(:body).and_return(error)
43
+ @response.stub!(:[]).and_return(nil)
44
+ setup_post_yield(@response)
45
+ Android.should_receive(:log).twice
46
+ lambda { Android.ping(@params) }.should raise_error(Android::AndroidPingError, "Android ping error: QuotaExceeded")
47
+ end
48
+
49
+ it "should ping android with stale auth token" do
50
+ @response.stub!(:code).and_return(200)
51
+ @response.stub!(:body).and_return('')
52
+ @response.stub!(:[]).and_return({:update_client_auth => 'abc123'})
53
+ setup_post_yield(@response)
54
+ Android.should_receive(:log).twice
55
+ lambda { Android.ping(@params) }.should raise_error(
56
+ Android::StaleAuthToken, "Stale auth token, please update :authtoken: in settings.yml."
57
+ )
58
+ end
59
+
60
+ it "should ping android with 401 error message" do
61
+ @response.stub!(:code).and_return(401)
62
+ @response.stub!(:body).and_return('')
63
+ setup_post_yield(@response)
64
+ Android.should_receive(:log).twice
65
+ lambda { Android.ping(@params) }.should raise_error(
66
+ Android::InvalidAuthToken, "Invalid auth token, please update :authtoken: in settings.yml."
67
+ )
68
+ end
69
+
70
+ it "should compute c2d_message" do
71
+ expected = {'registration_id' => @c.device_pin, 'collapse_key' => "RAND_KEY",
72
+ 'data.do_sync' => @s.name,
73
+ 'data.alert' => "hello world",
74
+ 'data.vibrate' => '5',
75
+ 'data.sound' => "hello.mp3"}
76
+ actual = Android.c2d_message(@params)
77
+ actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
78
+ actual.should == expected
79
+ end
80
+
81
+ it "should trim empty or nil params from c2d_message" do
82
+ expected = {'registration_id' => @c.device_pin, 'collapse_key' => "RAND_KEY",
83
+ 'data.vibrate' => '5', 'data.do_sync' => '', 'data.sound' => "hello.mp3"}
84
+ params = {"device_pin" => @c.device_pin,
85
+ "sources" => [], "message" => '', "vibrate" => '5', "sound" => 'hello.mp3'}
86
+ actual = Android.c2d_message(params)
87
+ actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
88
+ actual.should == expected
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
2
+ require File.join(File.dirname(__FILE__), '..', 'support', 'shared_examples')
3
+
4
+ describe "Ping Apple" do
5
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
6
+ before do
7
+ @params = {"user_id" => @u.id, "api_token" => @api_token,
8
+ "sources" => [@s.name], "message" => 'hello world',
9
+ "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
10
+ "device_pin" => @c.device_pin, "device_port" => @c.device_port}
11
+ ssl_ctx = mock("ssl_ctx")
12
+ ssl_ctx.stub!(:key=).and_return('key')
13
+ ssl_ctx.stub!(:cert=).and_return('cert')
14
+ OpenSSL::SSL::SSLContext.stub!(:new).and_return(ssl_ctx)
15
+ OpenSSL::PKey::RSA.stub!(:new)
16
+ OpenSSL::X509::Certificate.stub!(:new)
17
+
18
+ tcp_socket = mock("tcp_socket")
19
+ tcp_socket.stub!(:close)
20
+ TCPSocket.stub!(:new).and_return(tcp_socket)
21
+
22
+ @ssl_socket = mock("ssl_socket")
23
+ @ssl_socket.stub!(:sync=)
24
+ @ssl_socket.stub!(:connect)
25
+ @ssl_socket.stub!(:write)
26
+ @ssl_socket.stub!(:close)
27
+ OpenSSL::SSL::SSLSocket.stub!(:new).and_return(@ssl_socket)
28
+ end
29
+
30
+ # TODO: This should really test SSLSocket.write
31
+ it "should ping apple" do
32
+ Apple.ping(@params)
33
+ end
34
+
35
+ it "should log deprecation on iphone ping" do
36
+ Iphone.should_receive(
37
+ :log
38
+ ).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
39
+ Iphone.ping(@params)
40
+ end
41
+
42
+ it "should compute apn_message" do
43
+ expected_hash = {
44
+ "aps"=>{"vibrate"=>"5", "badge"=>5, "alert"=>"hello world", "sound"=>"hello.mp3"},
45
+ "do_sync"=>["SampleAdapter"]
46
+ }
47
+ apn_message = Apple.apn_message(@params)
48
+ apn_message.start_with?("\000\000 \253\315\000g").should be_true
49
+ JSON.parse(apn_message.sub("\000\000 \253\315\000g","")).should == expected_hash
50
+ end
51
+
52
+ it "should compute apn_message with source array" do
53
+ @params['sources'] << 'SimpleAdapter'
54
+ expected_hash = {
55
+ "aps"=>{"vibrate"=>"5", "badge"=>5, "alert"=>"hello world", "sound"=>"hello.mp3"},
56
+ "do_sync"=>["SampleAdapter", "SimpleAdapter"]
57
+ }
58
+ apn_message = Apple.apn_message(@params)
59
+ apn_message.start_with?("\000\000 \253\315\000w").should be_true
60
+ JSON.parse(apn_message.sub("\000\000 \253\315\000w","")).should == expected_hash
61
+ end
62
+
63
+ it "should raise SocketError if socket fails" do
64
+ error = 'socket error'
65
+ @ssl_socket.stub!(:write).and_return { raise SocketError.new(error) }
66
+ Apple.should_receive(:log).once.with("Error while sending ping: #{error}")
67
+ lambda { Apple.ping(@params) }.should raise_error(SocketError,error)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
2
+ require File.join(File.dirname(__FILE__), '..', 'support', 'shared_examples')
3
+
4
+ describe "Ping Blackberry" do
5
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
6
+ before do
7
+ @params = {"user_id" => @u.id, "api_token" => @api_token,
8
+ "sources" => [@s.name], "message" => 'hello world',
9
+ "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
10
+ "device_pin" => @c.device_pin, "device_port" => @c.device_port}
11
+ post = mock('post')
12
+ post.stub!(:new).and_return(post)
13
+ post.stub!(:body=)
14
+ Net::HTTP::Post.stub!(:new).and_return(post)
15
+
16
+ @http = mock('http')
17
+ @http.stub!(:request)
18
+ @http.stub!(:start).and_yield(@http)
19
+ Net::HTTP.stub!(:new).and_return(@http)
20
+ end
21
+
22
+ it "should ping blackberry" do
23
+ Blackberry.ping(@params)
24
+ end
25
+
26
+ it "should ping blackberry with connection error" do
27
+ error = 'Connection refused'
28
+ @http.stub!(:request).and_return { raise SocketError.new(error) }
29
+ Blackberry.should_receive(:log).once.with("Error while sending ping: #{error}")
30
+ lambda { Blackberry.ping(@params) }.should raise_error(SocketError,error)
31
+ end
32
+
33
+ it "should compute pap_message" do
34
+ expected = <<PAP
35
+ --asdlfkjiurwghasf
36
+ Content-Type: application/xml; charset=UTF-8
37
+
38
+ <?xml version="1.0"?>
39
+ <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
40
+ "http://www.wapforum.org/DTD/pap_2.0.dtd"
41
+ [<?wap-pap-ver supported-versions="2.0"?>]>
42
+ <pap>
43
+ <push-message push-id="pushID:RAND_ID" ppg-notify-requested-to="http://localhost:7778">
44
+
45
+ <address address-value="WAPPUSH=0%3A100/TYPE=USER@rim.net"/>
46
+ <quality-of-service delivery-method="preferconfirmed"/>
47
+ </push-message>
48
+ </pap>
49
+ --asdlfkjiurwghasf
50
+ Content-Type: text/plain
51
+
52
+ do_sync=SampleAdapter
53
+ alert=hello world
54
+ vibrate=5
55
+ sound=hello.mp3
56
+ --asdlfkjiurwghasf--
57
+ PAP
58
+ actual = Blackberry.pap_message(@params).gsub!(/pushID\:\d+/,'pushID:RAND_ID')
59
+ actual.gsub!(/\r|\n|\s/,"").should == expected.gsub!(/\r|\n|\s/,"")
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+ require File.join(File.dirname(__FILE__), 'support', 'shared_examples')
3
+
4
+ describe "ReadState" do
5
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
6
+ it "should create refresh with correct id" do
7
+ @r.id.should == "#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}"
8
+ end
9
+
10
+ it "should create refresh with default fields" do
11
+ @r.refresh_time.should <= Time.now.to_i
12
+ end
13
+
14
+ it "should load refresh with params" do
15
+ @r1 = ReadState.load(:app_id => @a_fields[:name],
16
+ :user_id => @u_fields[:login],:source_name => @s_fields[:name])
17
+ @r1.refresh_time.should <= Time.now.to_i
18
+ end
19
+
20
+ it "should delete read_state from db" do
21
+ ReadState.delete(@a_fields[:name])
22
+ Store.db.keys("read_state*").should == []
23
+ end
24
+
25
+ it "should delete read_state from source" do
26
+ time = Time.now.to_i
27
+ @s.read_state.refresh_time = time
28
+ @s.load_read_state.refresh_time.should == time
29
+
30
+ @s.delete_user_read_state
31
+ @s.load_read_state.should == nil
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,75 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+ require File.join(File.dirname(__FILE__), 'support', 'shared_examples')
3
+
4
+ describe "Rhoconnect" do
5
+ include TestHelpers
6
+ let(:test_app_name) { 'application' }
7
+
8
+ before(:each) do
9
+ Store.create
10
+ Store.db.flushdb
11
+ end
12
+
13
+ it "should bootstrap Rhoconnect with block" do
14
+ Rhoconnect.bootstrap(get_testapp_path) do |rhoconnect|
15
+ rhoconnect.vendor_directory = 'foo'
16
+ end
17
+ path = get_testapp_path
18
+ File.expand_path(Rhoconnect.base_directory).should == path
19
+ File.expand_path(Rhoconnect.app_directory).should == path
20
+ File.expand_path(Rhoconnect.data_directory).should == File.join(path,'data')
21
+ Rhoconnect.vendor_directory.should == 'foo'
22
+ Rhoconnect.blackberry_bulk_sync.should == false
23
+ Rhoconnect.bulk_sync_poll_interval.should == 3600
24
+ Rhoconnect.environment.should == :test
25
+ Rhoconnect.stats.should == false
26
+ Rhoconnect.appserver.should == 'http://test.rhoconnect.com'
27
+ Rhoconnect.cookie_expire.should == 9999999
28
+ App.is_exist?(test_app_name).should be_true
29
+ end
30
+
31
+ it "should bootstrap Rhoconnect with RHO_ENV provided" do
32
+ ENV['RHO_ENV'] = 'production'
33
+ Rhoconnect.bootstrap(get_testapp_path)
34
+ Rhoconnect.environment.should == :production
35
+ ENV.delete('RHO_ENV')
36
+ end
37
+
38
+ it "should bootstrap Rhoconnect with RACK_ENV provided" do
39
+ env = ENV['RACK_ENV'].dup
40
+ ENV['RACK_ENV'] = 'production'
41
+ Rhoconnect.bootstrap(get_testapp_path)
42
+ Rhoconnect.environment.should == :production
43
+ ENV['RACK_ENV'] = env
44
+ end
45
+
46
+ it "should bootstrap with existing app" do
47
+ app = App.create(:name => test_app_name)
48
+ App.should_receive(:load).once.with(test_app_name).and_return(app)
49
+ Rhoconnect.bootstrap(get_testapp_path)
50
+ end
51
+
52
+ it "should bootstrap app with no sources" do
53
+ App.create(:name => test_app_name).delete
54
+ Rhoconnect.bootstrap(get_emptyapp_path)
55
+ App.load(test_app_name).sources.should == []
56
+ end
57
+
58
+ it "should exit if schema config exists" do
59
+ config = Rhoconnect.get_config(get_testapp_path)
60
+ config[:sources]['FixedSchemaAdapter'].merge!(
61
+ 'schema' => {'property' => 'foo'}
62
+ )
63
+ Rhoconnect.stub!(:get_config).and_return(config)
64
+ Rhoconnect.should_receive(:log).once.with(
65
+ "ERROR: 'schema' field in settings.yml is not supported anymore, please use source adapter schema method!"
66
+ )
67
+ lambda { Rhoconnect.bootstrap(get_testapp_path) }.should raise_error(SystemExit)
68
+ end
69
+
70
+ it "should add associations during bootstrap" do
71
+ Rhoconnect.bootstrap(get_testapp_path)
72
+ s = Source.load('SampleAdapter',{:app_id => test_app_name,:user_id => '*'})
73
+ s.has_many.should == "FixedSchemaAdapter,brand"
74
+ end
75
+ end
@@ -0,0 +1,287 @@
1
+ require 'rhoconnect/cors'
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 "CORS middleware" do
23
+
24
+ class StubApp
25
+ def call(env)
26
+ [200, {'Set-Cookie' => 'someCookie=someValue', 'Content-Length' => '0'}, '']
27
+ end
28
+ end
29
+
30
+ before(:each) do
31
+ @app ||= StubApp.new
32
+
33
+ @middleware = Rack::Cors.new @app, {} do |cfg|
34
+ cfg.allow do |allow|
35
+ allow.origins /allowed_origin/, 'file://'
36
+ allow.resource '/application', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
37
+ allow.resource '/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => false
38
+ allow.resource '/api/application', :headers => 'allowed_header', :methods => [:get, :post, :put, :delete], :credentials => true, :expose => 'Content-Length'
39
+ allow.resource '/api/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
40
+ end
41
+ end
42
+ end
43
+
44
+ it "preflight check should allow unknown origins if public access is configured" do
45
+ mv = Rack::Cors.new @app, {} do |cfg|
46
+ cfg.allow do |allow|
47
+ allow.origins '*', 'mock_value'
48
+ allow.resource '/mock+path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
49
+ allow.resource '/mock%20path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
50
+ allow.resource /\/mock_path/, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
51
+
52
+ exception_happens = false
53
+ begin
54
+ allow.resource nil, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
55
+ rescue Exception => e
56
+ exception_happens = true
57
+ e.is_a?(TypeError).should == true
58
+ end
59
+ exception_happens.should == true
60
+
61
+ allow.resource '/application', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
62
+ allow.resource '/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => false
63
+ allow.resource '/api/application', :headers => 'allowed_header', :methods => [:get, :post, :put, :delete], :credentials => true, :expose => 'Content-Length'
64
+ allow.resource '/api/application/*', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
65
+ end
66
+ end
67
+
68
+ env = {
69
+ 'REQUEST_METHOD' => 'OPTIONS',
70
+ 'PATH_INFO' => '/api/application',
71
+ 'HTTP_ORIGIN' => 'wrong_origin',
72
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
73
+ }
74
+ status, headers, body = mv.call(env)
75
+ 200.should == status
76
+ headers['Access-Control-Allow-Origin'].should == '*'
77
+ end
78
+
79
+ it "preflight check should disable unknown origins" do
80
+ env = {
81
+ 'REQUEST_METHOD' => 'OPTIONS',
82
+ 'PATH_INFO' => '/api/application',
83
+ 'HTTP_ORIGIN' => 'wrong_origin',
84
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
85
+ }
86
+ status, headers, body = @middleware.call(env)
87
+ 200.should == status
88
+ headers['Access-Control-Allow-Origin'].should_not == 'wrong_origin'
89
+ end
90
+
91
+ it "preflight check should allow known origins" do
92
+ env = {
93
+ 'REQUEST_METHOD' => 'OPTIONS',
94
+ 'PATH_INFO' => '/api/application',
95
+ 'HTTP_ORIGIN' => 'allowed_origin',
96
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
97
+ }
98
+ status, headers, body = @middleware.call(env)
99
+ 200.should == status
100
+ headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
101
+ end
102
+
103
+ it "able to use fallback X-ORIGIN request header if ORIGIN header is undefined" do
104
+ env = {
105
+ 'REQUEST_METHOD' => 'POST',
106
+ 'PATH_INFO' => '/api/application',
107
+ 'HTTP_X_ORIGIN' => 'allowed_origin',
108
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
109
+ }
110
+ status, headers, body = @middleware.call(env)
111
+ 200.should == status
112
+ headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
113
+ end
114
+
115
+ it "preflight check treats empty 'null' origin as 'file://' one" do
116
+ env = {
117
+ 'REQUEST_METHOD' => 'OPTIONS',
118
+ 'PATH_INFO' => '/api/application',
119
+ 'HTTP_ORIGIN' => 'null',
120
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
121
+ }
122
+ status, headers, body = @middleware.call(env)
123
+ 200.should == status
124
+ headers['Access-Control-Allow-Origin'].should == 'file://'
125
+ end
126
+
127
+ it "preflight check should enable allowed request headers" do
128
+ env = {
129
+ 'REQUEST_METHOD' => 'OPTIONS',
130
+ 'PATH_INFO' => '/api/application',
131
+ 'HTTP_ORIGIN' => 'allowed_origin',
132
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
133
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'allowed_header'
134
+ }
135
+ status, headers, body = @middleware.call(env)
136
+ 200.should == status
137
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
138
+ headers['Access-Control-Allow-Headers'].should == 'allowed_header'
139
+ end
140
+
141
+ it "preflight check should disable not allowed request headers" do
142
+ env = {
143
+ 'REQUEST_METHOD' => 'OPTIONS',
144
+ 'PATH_INFO' => '/api/application',
145
+ 'HTTP_ORIGIN' => 'allowed_origin',
146
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
147
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
148
+ }
149
+ status, headers, body = @middleware.call(env)
150
+ 200.should == status
151
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
152
+ headers['Access-Control-Allow-Headers'].should_not == 'not_allowed_header'
153
+ end
154
+
155
+ it "preflight check should allow any request headers if configured so" do
156
+ env = {
157
+ 'REQUEST_METHOD' => 'OPTIONS',
158
+ 'PATH_INFO' => '/api/application/any_headers_allowed_here',
159
+ 'HTTP_ORIGIN' => 'allowed_origin',
160
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
161
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
162
+ }
163
+ status, headers, body = @middleware.call(env)
164
+ 200.should == status
165
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
166
+ headers['Access-Control-Allow-Headers'].should == 'not_allowed_header'
167
+ end
168
+
169
+
170
+ it "only allowed response headers should be exposed" do
171
+ env = {
172
+ 'REQUEST_METHOD' => 'POST',
173
+ 'PATH_INFO' => '/api/application',
174
+ 'HTTP_ORIGIN' => 'allowed_origin',
175
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
176
+ }
177
+ status, headers, body = @middleware.call(env)
178
+ 200.should == status
179
+ headers['Access-Control-Expose-Headers'].should == 'Content-Length'
180
+ end
181
+
182
+ it "no response headers should be exposed by default" do
183
+ env = {
184
+ 'REQUEST_METHOD' => 'POST',
185
+ 'PATH_INFO' => '/api/application/no_headers_exposed_here_by_default',
186
+ 'HTTP_ORIGIN' => 'allowed_origin',
187
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
188
+ }
189
+ status, headers, body = @middleware.call(env)
190
+ 200.should == status
191
+ headers['Access-Control-Expose-Headers'].should == ''
192
+ end
193
+
194
+
195
+ =begin
196
+ it "should skip if it isn't a sync protocol URI, for old REST routes" do
197
+ env = {
198
+ 'PATH_INFO' => WRONG_URI,
199
+ 'QUERY_STRING' => PROPER_QUERY_STRING
200
+ }
201
+ status, headers, body = @middleware_old_routes.call(env)
202
+ 200.should == status
203
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
204
+ COOKIE_NV.should_not == env['HTTP_COOKIE']
205
+ headers['Content-Length'].should == body.length.to_s
206
+ ''.should == body
207
+ end
208
+
209
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for new REST routes" do
210
+ env = {
211
+ 'PATH_INFO' => PROPER_URI_NEW,
212
+ 'QUERY_STRING' => PROPER_QUERY_STRING
213
+ }
214
+ status, headers, body = @middleware_new_routes.call(env)
215
+ 200.should == status
216
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
217
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
218
+ headers['Content-Length'].should == body.length.to_s
219
+ ''.should == body
220
+ end
221
+
222
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for old REST routes" do
223
+ env = {
224
+ 'PATH_INFO' => PROPER_URI_OLD,
225
+ 'QUERY_STRING' => PROPER_QUERY_STRING
226
+ }
227
+ status, headers, body = @middleware_old_routes.call(env)
228
+ 200.should == status
229
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
230
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
231
+ headers['Content-Length'].should == body.length.to_s
232
+ ''.should == body
233
+ end
234
+
235
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for new REST routes" do
236
+ env = {
237
+ 'PATH_INFO' => PROPER_URI_NEW,
238
+ 'QUERY_STRING' => WRONG_QUERY_STRING
239
+ }
240
+ status, headers, body = @middleware_new_routes.call(env)
241
+ 200.should == status
242
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
243
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
244
+ headers['Content-Length'].should == body.length.to_s
245
+ ''.should == body
246
+ end
247
+
248
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for old REST routes" do
249
+ env = {
250
+ 'PATH_INFO' => PROPER_URI_OLD,
251
+ 'QUERY_STRING' => WRONG_QUERY_STRING
252
+ }
253
+ status, headers, body = @middleware_old_routes.call(env)
254
+ 200.should == status
255
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
256
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
257
+ headers['Content-Length'].should == body.length.to_s
258
+ ''.should == body
259
+ end
260
+
261
+ it "should respond with cookie in a body if it is a login URI, for new REST routes" do
262
+ env = {
263
+ 'PATH_INFO' => LOGIN_URI_NEW,
264
+ 'QUERY_STRING' => PROPER_QUERY_STRING
265
+ }
266
+ status, headers, body = @middleware_new_routes.call(env)
267
+ 200.should == status
268
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
269
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
270
+ headers['Content-Length'].should == body.length.to_s
271
+ ''.should_not == body
272
+ end
273
+
274
+ it "should respond with cookie in a body if it is a login URI, for old REST routes" do
275
+ env = {
276
+ 'PATH_INFO' => LOGIN_URI_OLD,
277
+ 'QUERY_STRING' => PROPER_QUERY_STRING
278
+ }
279
+ status, headers, body = @middleware_old_routes.call(env)
280
+ 200.should == status
281
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
282
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
283
+ headers['Content-Length'].should == body.length.to_s
284
+ ''.should_not == body
285
+ end
286
+ =end
287
+ end