rhoconnect 5.1.1 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -8
  3. data/CREDITS +100 -100
  4. data/Gemfile +0 -2
  5. data/Gemfile.lock +56 -71
  6. data/LICENSE +5 -72
  7. data/README.md +0 -0
  8. data/Rakefile +0 -0
  9. data/bench/bench +0 -0
  10. data/bench/benchapp/settings/settings.yml +0 -3
  11. data/bench/blobapp/settings/settings.yml +0 -3
  12. data/bench/distr_bench/distr_bench +0 -0
  13. data/bench/distr_bench/distr_bench_main +0 -0
  14. data/bench/distr_bench/run_distr_client.sh +0 -0
  15. data/bench/distr_bench/run_test_query_script.sh +0 -0
  16. data/bench/lib/bench/bench_result_processor.rb +0 -0
  17. data/bench/lib/bench.rb +0 -8
  18. data/bench/lib/testdata/images/icon.ico +0 -0
  19. data/bench/lib/testdata/images/icon.png +0 -0
  20. data/bench/lib/testdata/images/loading-Landscape.png +0 -0
  21. data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
  22. data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
  23. data/bench/lib/testdata/images/loading-Portrait.png +0 -0
  24. data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
  25. data/bench/lib/testdata/images/loading.png +0 -0
  26. data/bench/lib/testdata/images/loading@2x.png +0 -0
  27. data/bench/prepare_bench +0 -0
  28. data/bench/run_bench.sh +0 -0
  29. data/bench/run_blob_script.sh +0 -0
  30. data/bench/run_cud_script.sh +0 -0
  31. data/bench/run_query_md_script.sh +0 -0
  32. data/bench/run_query_only_script.sh +0 -0
  33. data/bench/run_query_script.sh +0 -0
  34. data/bench/run_test_query_script.sh +0 -0
  35. data/bench/run_test_source_script.sh +0 -0
  36. data/bin/rhoconnect-benchmark +0 -22
  37. data/commands/rhoconnect/restart.rb +0 -1
  38. data/commands/rhoconnect/start.rb +2 -14
  39. data/doc/adapters-crm.txt +1 -1
  40. data/doc/benchmarks-running.txt +1 -1
  41. data/doc/benchmarks.txt +0 -1
  42. data/doc/bulk-sync.txt +0 -1
  43. data/doc/command-line.txt +0 -6
  44. data/doc/java-plugin.txt +0 -6
  45. data/doc/preparing-production.txt +1 -7
  46. data/doc/public/cli.txt +0 -2
  47. data/doc/public/css/print.css +0 -0
  48. data/doc/public/css/screen.css +0 -0
  49. data/doc/public/css/style.css +0 -0
  50. data/doc/push-client-setup-android.txt +0 -1
  51. data/doc/push-client-setup-ios.txt +0 -1
  52. data/doc/push-client-setup-rps.txt +3 -3
  53. data/doc/push-server-setup.txt +1 -4
  54. data/doc/rails-plugin.txt +0 -5
  55. data/doc/rest-api.txt +2 -14
  56. data/doc/rhoconnect-redis-stack.txt +0 -1
  57. data/doc/settings.txt +0 -3
  58. data/doc/supported-platforms.txt +0 -1
  59. data/doc/tutorial.txt +0 -2
  60. data/examples/simple/config.ru +0 -0
  61. data/examples/simple/settings/settings.yml +1 -4
  62. data/generators/rhoconnect.rb +0 -1
  63. data/generators/templates/application/config.ru +0 -0
  64. data/generators/templates/application/rcgemfile +1 -0
  65. data/generators/templates/application/settings/settings.yml +0 -3
  66. data/install.sh +0 -0
  67. data/installer/utils/create_sha1.rb +0 -0
  68. data/installer/utils/delete_from_s3.rb +0 -0
  69. data/installer/utils/download_from_s3.rb +0 -0
  70. data/installer/utils/nix_install_test.rb +0 -0
  71. data/installer/utils/package_upload/repos.rake +2 -2
  72. data/installer/utils/package_upload/s3_single_file.rb +0 -0
  73. data/installer/utils/package_upload/s3_upload.rb +0 -0
  74. data/installer/utils/verify_checksum.rb +0 -0
  75. data/lib/rhoconnect/api_token.rb +0 -0
  76. data/lib/rhoconnect/app.rb +0 -0
  77. data/lib/rhoconnect/bulk_data/bulk_data.rb +0 -0
  78. data/lib/rhoconnect/bulk_data/syncdb.index.schema +0 -0
  79. data/lib/rhoconnect/bulk_data/syncdb.schema +0 -0
  80. data/lib/rhoconnect/bulk_data.rb +0 -0
  81. data/lib/rhoconnect/client.rb +0 -2
  82. data/lib/rhoconnect/controller/system_controller.rb +0 -9
  83. data/lib/rhoconnect/credential.rb +0 -0
  84. data/lib/rhoconnect/document.rb +0 -0
  85. data/lib/rhoconnect/middleware/cors.rb +209 -209
  86. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +57 -57
  87. data/lib/rhoconnect/model/base.rb +0 -0
  88. data/lib/rhoconnect/read_state.rb +0 -0
  89. data/lib/rhoconnect/rho_indifferent_access.rb +0 -0
  90. data/lib/rhoconnect/server.rb +0 -0
  91. data/lib/rhoconnect/source.rb +0 -0
  92. data/lib/rhoconnect/store.rb +2 -0
  93. data/lib/rhoconnect/store_orm.rb +0 -0
  94. data/lib/rhoconnect/user.rb +0 -0
  95. data/lib/rhoconnect/version.rb +1 -1
  96. data/lib/rhoconnect/web-console/models/doc.js +0 -13
  97. data/lib/rhoconnect/web-console/models/source.js +0 -31
  98. data/lib/rhoconnect/web-console/public/logo.png +0 -0
  99. data/lib/rhoconnect/web-console/server.rb +0 -0
  100. data/lib/rhoconnect/web-console/templates/index.erb +1 -2
  101. data/lib/rhoconnect/web-console/views/home.js +4 -6
  102. data/lib/rhoconnect.rb +1 -3
  103. data/spec/api/api_helper.rb +0 -0
  104. data/spec/api/system/login_spec.rb +0 -0
  105. data/spec/api/system/reset_spec.rb +0 -0
  106. data/spec/api/user/create_user_spec.rb +0 -0
  107. data/spec/api/user/update_user_spec.rb +0 -0
  108. data/spec/api_token_spec.rb +0 -0
  109. data/spec/app_spec.rb +0 -0
  110. data/spec/apps/emptyapp/settings/settings.yml +1 -4
  111. data/spec/apps/jstestapp/settings/settings.yml +0 -3
  112. data/spec/apps/rhotestapp/controllers/ruby/application_controller.rb +0 -0
  113. data/spec/apps/rhotestapp/models/ruby/sample_adapter.rb +0 -0
  114. data/spec/apps/rhotestapp/models/ruby/simple_adapter.rb +0 -0
  115. data/spec/apps/rhotestapp/settings/settings.yml +0 -3
  116. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +0 -0
  117. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +0 -0
  118. data/spec/bulk_data/bulk_data_spec.rb +0 -0
  119. data/spec/client_spec.rb +0 -14
  120. data/spec/client_sync_spec.rb +0 -0
  121. data/spec/doc/base.html +0 -0
  122. data/spec/doc/doc_spec.rb +0 -0
  123. data/spec/doc/footer.html +0 -0
  124. data/spec/doc/header.html +0 -0
  125. data/spec/document_spec.rb +0 -0
  126. data/spec/generator/generator_spec.rb +1 -3
  127. data/spec/jobs/bulk_data_job_spec.rb +0 -0
  128. data/spec/perf/bulk_data_perf_spec.rb +0 -0
  129. data/spec/perf/perf_spec_helper.rb +0 -0
  130. data/spec/perf/store_perf_spec.rb +0 -0
  131. data/spec/read_state_spec.rb +0 -0
  132. data/spec/server/cors_spec.rb +283 -283
  133. data/spec/server/server_spec.rb +0 -15
  134. data/spec/server/x_domain_session_wrapper_spec.rb +150 -150
  135. data/spec/source_adapter_spec.rb +0 -0
  136. data/spec/source_spec.rb +0 -0
  137. data/spec/source_sync_spec.rb +0 -0
  138. data/spec/spec_helper.rb +0 -0
  139. data/spec/store_orm_spec.rb +0 -0
  140. data/spec/store_spec.rb +0 -0
  141. data/spec/sync_states_spec.rb +0 -0
  142. data/spec/testdata/1000-data.txt +0 -0
  143. data/spec/testdata/compressed/compress-data.txt +0 -0
  144. data/spec/user_spec.rb +0 -9
  145. metadata +116 -132
  146. data/bench/benchapp/settings/license.key +0 -1
  147. data/bench/blobapp/settings/license.key +0 -1
  148. data/doc/licensing.txt +0 -18
  149. data/examples/simple/settings/license.key +0 -1
  150. data/generators/templates/application/settings/license.key +0 -1
  151. data/lib/rhoconnect/license.rb +0 -94
  152. data/spec/api/system/get_license_info_spec.rb +0 -15
  153. data/spec/apps/emptyapp/settings/license.key +0 -1
  154. data/spec/apps/jstestapp/settings/license.key +0 -1
  155. data/spec/apps/rhotestapp/settings/license.key +0 -1
  156. data/spec/license_spec.rb +0 -67
@@ -1,283 +1,283 @@
1
- require 'rhoconnect/middleware/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 "/StubAdapter", :headers => 'allowed_header', :methods => [:get, :post, :put, :delete], :credentials => true, :expose => 'Content-Length'
37
- allow.resource "/StubAdapter/any_header_allowed_here", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
38
- allow.resource "/StubAdapter/no_default_exposed_headers", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
39
- end
40
- end
41
- end
42
-
43
- it "preflight check should allow unknown origins if public access is configured" do
44
- mv = Rack::Cors.new @app, {} do |cfg|
45
- cfg.allow do |allow|
46
- allow.origins '*', 'mock_value'
47
- allow.resource '/mock+path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
48
- allow.resource '/mock%20path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
49
- allow.resource /\/mock_path/, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
50
-
51
- exception_happens = false
52
- begin
53
- allow.resource nil, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
54
- rescue Exception => e
55
- exception_happens = true
56
- e.is_a?(TypeError).should == true
57
- end
58
- exception_happens.should == true
59
-
60
- allow.resource "/*", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
61
- end
62
- end
63
-
64
- env = {
65
- 'REQUEST_METHOD' => 'OPTIONS',
66
- 'PATH_INFO' => '/StubAdapter',
67
- 'HTTP_ORIGIN' => 'wrong_origin',
68
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
69
- }
70
- status, headers, body = mv.call(env)
71
- 200.should == status
72
- headers['Access-Control-Allow-Origin'].should == '*'
73
- end
74
-
75
- it "preflight check should disable unknown origins" do
76
- env = {
77
- 'REQUEST_METHOD' => 'OPTIONS',
78
- 'PATH_INFO' => '/StubAdapter',
79
- 'HTTP_ORIGIN' => 'wrong_origin',
80
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
81
- }
82
- status, headers, body = @middleware.call(env)
83
- 200.should == status
84
- headers['Access-Control-Allow-Origin'].should_not == 'wrong_origin'
85
- end
86
-
87
- it "preflight check should allow known origins" do
88
- env = {
89
- 'REQUEST_METHOD' => 'OPTIONS',
90
- 'PATH_INFO' => '/StubAdapter',
91
- 'HTTP_ORIGIN' => 'allowed_origin',
92
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
93
- }
94
- status, headers, body = @middleware.call(env)
95
- 200.should == status
96
- headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
97
- end
98
-
99
- it "able to use fallback X-ORIGIN request header if ORIGIN header is undefined" do
100
- env = {
101
- 'REQUEST_METHOD' => 'POST',
102
- 'PATH_INFO' => '/StubAdapter',
103
- 'HTTP_X_ORIGIN' => 'allowed_origin',
104
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
105
- }
106
- status, headers, body = @middleware.call(env)
107
- 200.should == status
108
- headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
109
- end
110
-
111
- it "preflight check treats empty 'null' origin as 'file://' one" do
112
- env = {
113
- 'REQUEST_METHOD' => 'OPTIONS',
114
- 'PATH_INFO' => '/StubAdapter',
115
- 'HTTP_ORIGIN' => 'null',
116
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
117
- }
118
- status, headers, body = @middleware.call(env)
119
- 200.should == status
120
- headers['Access-Control-Allow-Origin'].should == 'file://'
121
- end
122
-
123
- it "preflight check should enable allowed request headers" do
124
- env = {
125
- 'REQUEST_METHOD' => 'OPTIONS',
126
- 'PATH_INFO' => '/StubAdapter',
127
- 'HTTP_ORIGIN' => 'allowed_origin',
128
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
129
- 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'allowed_header'
130
- }
131
- status, headers, body = @middleware.call(env)
132
- 200.should == status
133
- #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
134
- headers['Access-Control-Allow-Headers'].should == 'allowed_header'
135
- end
136
-
137
- it "preflight check should disable not allowed request headers" do
138
- env = {
139
- 'REQUEST_METHOD' => 'OPTIONS',
140
- 'PATH_INFO' => '/StubAdapter',
141
- 'HTTP_ORIGIN' => 'allowed_origin',
142
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
143
- 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
144
- }
145
- status, headers, body = @middleware.call(env)
146
- 200.should == status
147
- #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
148
- headers['Access-Control-Allow-Headers'].should_not == 'not_allowed_header'
149
- end
150
-
151
- it "preflight check should allow any request headers if configured so" do
152
- env = {
153
- 'REQUEST_METHOD' => 'OPTIONS',
154
- 'PATH_INFO' => '/StubAdapter/any_header_allowed_here',
155
- 'HTTP_ORIGIN' => 'allowed_origin',
156
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
157
- 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
158
- }
159
- status, headers, body = @middleware.call(env)
160
- 200.should == status
161
- #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
162
- headers['Access-Control-Allow-Headers'].should == 'not_allowed_header'
163
- end
164
-
165
-
166
- it "only allowed response headers should be exposed" do
167
- env = {
168
- 'REQUEST_METHOD' => 'POST',
169
- 'PATH_INFO' => '/StubAdapter',
170
- 'HTTP_ORIGIN' => 'allowed_origin',
171
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
172
- }
173
- status, headers, body = @middleware.call(env)
174
- 200.should == status
175
- headers['Access-Control-Expose-Headers'].should == 'Content-Length'
176
- end
177
-
178
- it "no response headers should be exposed by default" do
179
- env = {
180
- 'REQUEST_METHOD' => 'POST',
181
- 'PATH_INFO' => '/StubAdapter/no_default_exposed_headers',
182
- 'HTTP_ORIGIN' => 'allowed_origin',
183
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
184
- }
185
- status, headers, body = @middleware.call(env)
186
- 200.should == status
187
- headers['Access-Control-Expose-Headers'].should == ''
188
- end
189
-
190
-
191
- =begin
192
- it "should skip if it isn't a sync protocol URI, for old REST routes" do
193
- env = {
194
- 'PATH_INFO' => WRONG_URI,
195
- 'QUERY_STRING' => PROPER_QUERY_STRING
196
- }
197
- status, headers, body = @middleware_old_routes.call(env)
198
- 200.should == status
199
- COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
200
- COOKIE_NV.should_not == env['HTTP_COOKIE']
201
- headers['Content-Length'].should == body.length.to_s
202
- ''.should == body
203
- end
204
-
205
- it "should process cookie from QUERY_STRING if it is a sync protocol URI, for new REST routes" do
206
- env = {
207
- 'PATH_INFO' => PROPER_URI_NEW,
208
- 'QUERY_STRING' => PROPER_QUERY_STRING
209
- }
210
- status, headers, body = @middleware_new_routes.call(env)
211
- 200.should == status
212
- COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
213
- env['HTTP_COOKIE'].should == COOKIE_VALUE
214
- headers['Content-Length'].should == body.length.to_s
215
- ''.should == body
216
- end
217
-
218
- it "should process cookie from QUERY_STRING if it is a sync protocol URI, for old REST routes" do
219
- env = {
220
- 'PATH_INFO' => PROPER_URI_OLD,
221
- 'QUERY_STRING' => PROPER_QUERY_STRING
222
- }
223
- status, headers, body = @middleware_old_routes.call(env)
224
- 200.should == status
225
- COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
226
- env['HTTP_COOKIE'].should == COOKIE_VALUE
227
- headers['Content-Length'].should == body.length.to_s
228
- ''.should == body
229
- end
230
-
231
- it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for new REST routes" do
232
- env = {
233
- 'PATH_INFO' => PROPER_URI_NEW,
234
- 'QUERY_STRING' => WRONG_QUERY_STRING
235
- }
236
- status, headers, body = @middleware_new_routes.call(env)
237
- 200.should == status
238
- COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
239
- env['HTTP_COOKIE'].should_not == COOKIE_VALUE
240
- headers['Content-Length'].should == body.length.to_s
241
- ''.should == body
242
- end
243
-
244
- it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for old REST routes" do
245
- env = {
246
- 'PATH_INFO' => PROPER_URI_OLD,
247
- 'QUERY_STRING' => WRONG_QUERY_STRING
248
- }
249
- status, headers, body = @middleware_old_routes.call(env)
250
- 200.should == status
251
- COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
252
- env['HTTP_COOKIE'].should_not == COOKIE_VALUE
253
- headers['Content-Length'].should == body.length.to_s
254
- ''.should == body
255
- end
256
-
257
- it "should respond with cookie in a body if it is a login URI, for new REST routes" do
258
- env = {
259
- 'PATH_INFO' => LOGIN_URI_NEW,
260
- 'QUERY_STRING' => PROPER_QUERY_STRING
261
- }
262
- status, headers, body = @middleware_new_routes.call(env)
263
- 200.should == status
264
- headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
265
- env['HTTP_COOKIE'].should == COOKIE_VALUE
266
- headers['Content-Length'].should == body.length.to_s
267
- ''.should_not == body
268
- end
269
-
270
- it "should respond with cookie in a body if it is a login URI, for old REST routes" do
271
- env = {
272
- 'PATH_INFO' => LOGIN_URI_OLD,
273
- 'QUERY_STRING' => PROPER_QUERY_STRING
274
- }
275
- status, headers, body = @middleware_old_routes.call(env)
276
- 200.should == status
277
- headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
278
- env['HTTP_COOKIE'].should == COOKIE_VALUE
279
- headers['Content-Length'].should == body.length.to_s
280
- ''.should_not == body
281
- end
282
- =end
283
- end
1
+ require 'rhoconnect/middleware/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 "/StubAdapter", :headers => 'allowed_header', :methods => [:get, :post, :put, :delete], :credentials => true, :expose => 'Content-Length'
37
+ allow.resource "/StubAdapter/any_header_allowed_here", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
38
+ allow.resource "/StubAdapter/no_default_exposed_headers", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
39
+ end
40
+ end
41
+ end
42
+
43
+ it "preflight check should allow unknown origins if public access is configured" do
44
+ mv = Rack::Cors.new @app, {} do |cfg|
45
+ cfg.allow do |allow|
46
+ allow.origins '*', 'mock_value'
47
+ allow.resource '/mock+path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
48
+ allow.resource '/mock%20path', :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
49
+ allow.resource /\/mock_path/, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
50
+
51
+ exception_happens = false
52
+ begin
53
+ allow.resource nil, :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
54
+ rescue Exception => e
55
+ exception_happens = true
56
+ e.is_a?(TypeError).should == true
57
+ end
58
+ exception_happens.should == true
59
+
60
+ allow.resource "/*", :headers => :any, :methods => [:get, :post, :put, :delete], :credentials => true
61
+ end
62
+ end
63
+
64
+ env = {
65
+ 'REQUEST_METHOD' => 'OPTIONS',
66
+ 'PATH_INFO' => '/StubAdapter',
67
+ 'HTTP_ORIGIN' => 'wrong_origin',
68
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
69
+ }
70
+ status, headers, body = mv.call(env)
71
+ 200.should == status
72
+ headers['Access-Control-Allow-Origin'].should == '*'
73
+ end
74
+
75
+ it "preflight check should disable unknown origins" do
76
+ env = {
77
+ 'REQUEST_METHOD' => 'OPTIONS',
78
+ 'PATH_INFO' => '/StubAdapter',
79
+ 'HTTP_ORIGIN' => 'wrong_origin',
80
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
81
+ }
82
+ status, headers, body = @middleware.call(env)
83
+ 200.should == status
84
+ headers['Access-Control-Allow-Origin'].should_not == 'wrong_origin'
85
+ end
86
+
87
+ it "preflight check should allow known origins" do
88
+ env = {
89
+ 'REQUEST_METHOD' => 'OPTIONS',
90
+ 'PATH_INFO' => '/StubAdapter',
91
+ 'HTTP_ORIGIN' => 'allowed_origin',
92
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
93
+ }
94
+ status, headers, body = @middleware.call(env)
95
+ 200.should == status
96
+ headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
97
+ end
98
+
99
+ it "able to use fallback X-ORIGIN request header if ORIGIN header is undefined" do
100
+ env = {
101
+ 'REQUEST_METHOD' => 'POST',
102
+ 'PATH_INFO' => '/StubAdapter',
103
+ 'HTTP_X_ORIGIN' => 'allowed_origin',
104
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
105
+ }
106
+ status, headers, body = @middleware.call(env)
107
+ 200.should == status
108
+ headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
109
+ end
110
+
111
+ it "preflight check treats empty 'null' origin as 'file://' one" do
112
+ env = {
113
+ 'REQUEST_METHOD' => 'OPTIONS',
114
+ 'PATH_INFO' => '/StubAdapter',
115
+ 'HTTP_ORIGIN' => 'null',
116
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
117
+ }
118
+ status, headers, body = @middleware.call(env)
119
+ 200.should == status
120
+ headers['Access-Control-Allow-Origin'].should == 'file://'
121
+ end
122
+
123
+ it "preflight check should enable allowed request headers" do
124
+ env = {
125
+ 'REQUEST_METHOD' => 'OPTIONS',
126
+ 'PATH_INFO' => '/StubAdapter',
127
+ 'HTTP_ORIGIN' => 'allowed_origin',
128
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
129
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'allowed_header'
130
+ }
131
+ status, headers, body = @middleware.call(env)
132
+ 200.should == status
133
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
134
+ headers['Access-Control-Allow-Headers'].should == 'allowed_header'
135
+ end
136
+
137
+ it "preflight check should disable not allowed request headers" do
138
+ env = {
139
+ 'REQUEST_METHOD' => 'OPTIONS',
140
+ 'PATH_INFO' => '/StubAdapter',
141
+ 'HTTP_ORIGIN' => 'allowed_origin',
142
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
143
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
144
+ }
145
+ status, headers, body = @middleware.call(env)
146
+ 200.should == status
147
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
148
+ headers['Access-Control-Allow-Headers'].should_not == 'not_allowed_header'
149
+ end
150
+
151
+ it "preflight check should allow any request headers if configured so" do
152
+ env = {
153
+ 'REQUEST_METHOD' => 'OPTIONS',
154
+ 'PATH_INFO' => '/StubAdapter/any_header_allowed_here',
155
+ 'HTTP_ORIGIN' => 'allowed_origin',
156
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
157
+ 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'not_allowed_header'
158
+ }
159
+ status, headers, body = @middleware.call(env)
160
+ 200.should == status
161
+ #headers['Access-Control-Allow-Origin'].should == 'allowed_origin'
162
+ headers['Access-Control-Allow-Headers'].should == 'not_allowed_header'
163
+ end
164
+
165
+
166
+ it "only allowed response headers should be exposed" do
167
+ env = {
168
+ 'REQUEST_METHOD' => 'POST',
169
+ 'PATH_INFO' => '/StubAdapter',
170
+ 'HTTP_ORIGIN' => 'allowed_origin',
171
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
172
+ }
173
+ status, headers, body = @middleware.call(env)
174
+ 200.should == status
175
+ headers['Access-Control-Expose-Headers'].should == 'Content-Length'
176
+ end
177
+
178
+ it "no response headers should be exposed by default" do
179
+ env = {
180
+ 'REQUEST_METHOD' => 'POST',
181
+ 'PATH_INFO' => '/StubAdapter/no_default_exposed_headers',
182
+ 'HTTP_ORIGIN' => 'allowed_origin',
183
+ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST'
184
+ }
185
+ status, headers, body = @middleware.call(env)
186
+ 200.should == status
187
+ headers['Access-Control-Expose-Headers'].should == ''
188
+ end
189
+
190
+
191
+ =begin
192
+ it "should skip if it isn't a sync protocol URI, for old REST routes" do
193
+ env = {
194
+ 'PATH_INFO' => WRONG_URI,
195
+ 'QUERY_STRING' => PROPER_QUERY_STRING
196
+ }
197
+ status, headers, body = @middleware_old_routes.call(env)
198
+ 200.should == status
199
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
200
+ COOKIE_NV.should_not == env['HTTP_COOKIE']
201
+ headers['Content-Length'].should == body.length.to_s
202
+ ''.should == body
203
+ end
204
+
205
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for new REST routes" do
206
+ env = {
207
+ 'PATH_INFO' => PROPER_URI_NEW,
208
+ 'QUERY_STRING' => PROPER_QUERY_STRING
209
+ }
210
+ status, headers, body = @middleware_new_routes.call(env)
211
+ 200.should == status
212
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
213
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
214
+ headers['Content-Length'].should == body.length.to_s
215
+ ''.should == body
216
+ end
217
+
218
+ it "should process cookie from QUERY_STRING if it is a sync protocol URI, for old REST routes" do
219
+ env = {
220
+ 'PATH_INFO' => PROPER_URI_OLD,
221
+ 'QUERY_STRING' => PROPER_QUERY_STRING
222
+ }
223
+ status, headers, body = @middleware_old_routes.call(env)
224
+ 200.should == status
225
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
226
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
227
+ headers['Content-Length'].should == body.length.to_s
228
+ ''.should == body
229
+ end
230
+
231
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for new REST routes" do
232
+ env = {
233
+ 'PATH_INFO' => PROPER_URI_NEW,
234
+ 'QUERY_STRING' => WRONG_QUERY_STRING
235
+ }
236
+ status, headers, body = @middleware_new_routes.call(env)
237
+ 200.should == status
238
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
239
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
240
+ headers['Content-Length'].should == body.length.to_s
241
+ ''.should == body
242
+ end
243
+
244
+ it "shouldn't process cookie from QUERY_STRING if there is no appropriate parameter name or value, for old REST routes" do
245
+ env = {
246
+ 'PATH_INFO' => PROPER_URI_OLD,
247
+ 'QUERY_STRING' => WRONG_QUERY_STRING
248
+ }
249
+ status, headers, body = @middleware_old_routes.call(env)
250
+ 200.should == status
251
+ COOKIE_ANOTHER_NV.should == headers['Set-Cookie']
252
+ env['HTTP_COOKIE'].should_not == COOKIE_VALUE
253
+ headers['Content-Length'].should == body.length.to_s
254
+ ''.should == body
255
+ end
256
+
257
+ it "should respond with cookie in a body if it is a login URI, for new REST routes" do
258
+ env = {
259
+ 'PATH_INFO' => LOGIN_URI_NEW,
260
+ 'QUERY_STRING' => PROPER_QUERY_STRING
261
+ }
262
+ status, headers, body = @middleware_new_routes.call(env)
263
+ 200.should == status
264
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
265
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
266
+ headers['Content-Length'].should == body.length.to_s
267
+ ''.should_not == body
268
+ end
269
+
270
+ it "should respond with cookie in a body if it is a login URI, for old REST routes" do
271
+ env = {
272
+ 'PATH_INFO' => LOGIN_URI_OLD,
273
+ 'QUERY_STRING' => PROPER_QUERY_STRING
274
+ }
275
+ status, headers, body = @middleware_old_routes.call(env)
276
+ 200.should == status
277
+ headers['Set-Cookie'].should == COOKIE_ANOTHER_NV
278
+ env['HTTP_COOKIE'].should == COOKIE_VALUE
279
+ headers['Content-Length'].should == body.length.to_s
280
+ ''.should_not == body
281
+ end
282
+ =end
283
+ end
@@ -38,21 +38,6 @@ describe "Server" do
38
38
  last_response.should be_ok
39
39
  end
40
40
 
41
- it "should extract api token from the header" do
42
- post "/rc/#{Rhoconnect::API_VERSION}/system/login", "login" => 'rhoadmin', "password" => ''
43
- last_response.should be_ok
44
- api_token = last_response.body
45
-
46
- get "/rc/#{Rhoconnect::API_VERSION}/system/license", {}, {Rhoconnect::API_TOKEN_HEADER => api_token}
47
- last_response.should be_ok
48
- JSON.parse(last_response.body).should == {
49
- "available" => 9,
50
- "issued" => "Fri Apr 23 17:20:13 -0700 2010",
51
- "seats" => 10,
52
- "rhoconnect_version" => "Version 1",
53
- "licensee" => "Rhomobile" }
54
- end
55
-
56
41
  it "should respond with 404 if controller name is not specified" do
57
42
  get "/app/#{Rhoconnect::API_VERSION}/"
58
43
  last_response.status.should == 404