@@ -54,8 +54,28 @@ def fetch(url, body = nil, headers = nil, limit = nil)
54
54
55
55
OpenID . fetcher = MockFetcher . new ( RotsApp )
56
56
57
+ module RackTestHelpers
58
+ private
59
+
60
+ def process ( *args )
61
+ env = Rack ::MockRequest . env_for ( *args )
62
+ @response = Rack ::MockResponse . new ( *@app . call ( env ) )
63
+ end
64
+
65
+ def follow_redirect!
66
+ assert @response
67
+ assert_equal 303 , @response . status
68
+
69
+ env = Rack ::MockRequest . env_for ( @response . headers [ 'Location' ] )
70
+ _status , headers , _body = RotsApp . call ( env )
71
+
72
+ uri = URI ( headers [ 'Location' ] )
73
+ process ( "#{ uri . path } ?#{ uri . query } " )
74
+ end
75
+ end
76
+
57
77
describe "headers" do
58
- def test_build_header
78
+ it "builds header" do
59
79
assert_equal 'OpenID identity="http://example.com/"' ,
60
80
Rack ::OpenID . build_header ( :identity => "http://example.com/" )
61
81
assert_equal 'OpenID identity="http://example.com/?foo=bar"' ,
@@ -72,7 +92,7 @@ def test_build_header
72
92
assert_match ( /required="nickname,email"/ , header )
73
93
end
74
94
75
- def test_parse_header
95
+ it "parses header" do
76
96
assert_equal ( { "identity" => "http://example.com/" } ,
77
97
Rack ::OpenID . parse_header ( 'OpenID identity="http://example.com/"' ) )
78
98
assert_equal ( { "identity" => "http://example.com/?foo=bar" } ,
@@ -88,30 +108,10 @@ def test_parse_header
88
108
end
89
109
end
90
110
91
- module RackTestHelpers
92
- private
93
-
94
- def process ( *args )
95
- env = Rack ::MockRequest . env_for ( *args )
96
- @response = Rack ::MockResponse . new ( *@app . call ( env ) )
97
- end
98
-
99
- def follow_redirect!
100
- assert @response
101
- assert_equal 303 , @response . status
102
-
103
- env = Rack ::MockRequest . env_for ( @response . headers [ 'Location' ] )
104
- _status , headers , _body = RotsApp . call ( env )
105
-
106
- uri = URI ( headers [ 'Location' ] )
107
- process ( "#{ uri . path } ?#{ uri . query } " )
108
- end
109
- end
110
-
111
111
describe "openid" do
112
112
include RackTestHelpers
113
113
114
- def test_with_get
114
+ it "with_get" do
115
115
@app = app
116
116
process ( '/' , :method => 'GET' )
117
117
follow_redirect!
@@ -121,7 +121,7 @@ def test_with_get
121
121
assert_equal 'success' , @response . body
122
122
end
123
123
124
- def test_with_deprecated_identity
124
+ it "with_deprecated_identity" do
125
125
@app = app
126
126
process ( '/' , :method => 'GET' , :identity => "#{ RotsServerUrl } /john.doe?openid.success=true" )
127
127
follow_redirect!
@@ -131,7 +131,7 @@ def test_with_deprecated_identity
131
131
assert_equal 'success' , @response . body
132
132
end
133
133
134
- def test_with_post_method
134
+ it "with_post_method" do
135
135
@app = app
136
136
process ( '/' , :method => 'POST' )
137
137
follow_redirect!
@@ -141,7 +141,7 @@ def test_with_post_method
141
141
assert_equal 'success' , @response . body
142
142
end
143
143
144
- def test_with_custom_return_to
144
+ it "with_custom_return_to" do
145
145
@app = app ( :return_to => 'http://example.org/complete' )
146
146
process ( '/' , :method => 'GET' )
147
147
follow_redirect!
@@ -151,7 +151,7 @@ def test_with_custom_return_to
151
151
assert_equal 'success' , @response . body
152
152
end
153
153
154
- def test_with_get_nested_params_custom_return_to
154
+ it "with_get_nested_params_custom_return_to" do
155
155
url = 'http://example.org/complete?user[remember_me]=true'
156
156
@app = app ( :return_to => url )
157
157
process ( '/' , :method => 'GET' )
@@ -163,7 +163,7 @@ def test_with_get_nested_params_custom_return_to
163
163
assert_match ( /remember_me/ , @response . headers [ 'X-Query-String' ] )
164
164
end
165
165
166
- def test_with_post_nested_params_custom_return_to
166
+ it "with_post_nested_params_custom_return_to" do
167
167
url = 'http://example.org/complete?user[remember_me]=true'
168
168
@app = app ( :return_to => url )
169
169
process ( '/' , :method => 'POST' )
@@ -182,7 +182,7 @@ def test_with_post_nested_params_custom_return_to
182
182
assert_match ( /remember_me/ , @response . headers [ 'X-Query-String' ] )
183
183
end
184
184
185
- def test_with_post_method_custom_return_to
185
+ it "with_post_method_custom_return_to" do
186
186
@app = app ( :return_to => 'http://example.org/complete' )
187
187
process ( '/' , :method => 'POST' )
188
188
follow_redirect!
@@ -192,7 +192,7 @@ def test_with_post_method_custom_return_to
192
192
assert_equal 'success' , @response . body
193
193
end
194
194
195
- def test_with_custom_return_method
195
+ it "with_custom_return_method" do
196
196
@app = app ( :method => 'put' )
197
197
process ( '/' , :method => 'GET' )
198
198
follow_redirect!
@@ -202,7 +202,7 @@ def test_with_custom_return_method
202
202
assert_equal 'success' , @response . body
203
203
end
204
204
205
- def test_with_simple_registration_fields
205
+ it "with_simple_registration_fields" do
206
206
@app = app ( :required => [ 'nickname' , 'email' ] , :optional => 'fullname' )
207
207
process ( '/' , :method => 'GET' )
208
208
follow_redirect!
@@ -212,7 +212,7 @@ def test_with_simple_registration_fields
212
212
assert_equal 'success' , @response . body
213
213
end
214
214
215
- def test_with_attribute_exchange
215
+ it "with_attribute_exchange" do
216
216
@app = app (
217
217
:required => [ 'http://axschema.org/namePerson/friendly' , 'http://axschema.org/contact/email' ] ,
218
218
:optional => 'http://axschema.org/namePerson' )
@@ -224,7 +224,7 @@ def test_with_attribute_exchange
224
224
assert_equal 'success' , @response . body
225
225
end
226
226
227
- def test_with_oauth
227
+ it "with_oauth" do
228
228
@app = app (
229
229
:'oauth[consumer]' => 'www.example.com' ,
230
230
:'oauth[scope]' => [ 'http://docs.google.com/feeds/' , 'http://spreadsheets.google.com/feeds/' ]
@@ -242,7 +242,7 @@ def test_with_oauth
242
242
assert_equal 'success' , @response . body
243
243
end
244
244
245
- def test_with_pape
245
+ it "with_pape" do
246
246
@app = app (
247
247
:'pape[preferred_auth_policies]' => [ 'test_policy1' , 'test_policy2' ] ,
248
248
:'pape[max_auth_age]' => 600
@@ -260,7 +260,7 @@ def test_with_pape
260
260
assert_equal 'success' , @response . body
261
261
end
262
262
263
- def test_with_immediate_mode_setup_needed
263
+ it "with_immediate_mode_setup_needed" do
264
264
skip do
265
265
@app = app ( :identifier => "#{ RotsServerUrl } /john.doe?openid.success=false" , :immediate => true )
266
266
process ( '/' , :method => 'GET' )
@@ -277,7 +277,7 @@ def test_with_immediate_mode_setup_needed
277
277
end
278
278
end
279
279
280
- def test_with_realm_wildcard
280
+ it "with_realm_wildcard" do
281
281
@app = app (
282
282
:realm_domain => "*.example.org"
283
283
)
@@ -290,7 +290,7 @@ def test_with_realm_wildcard
290
290
assert_equal 200 , @response . status
291
291
end
292
292
293
- def test_with_inferred_realm
293
+ it "with_inferred_realm" do
294
294
@app = app
295
295
process ( '/' , :method => 'GET' )
296
296
@@ -301,7 +301,7 @@ def test_with_inferred_realm
301
301
assert_equal 200 , @response . status
302
302
end
303
303
304
- def test_with_missing_id
304
+ it "with_missing_id" do
305
305
@app = app ( :identifier => "#{ RotsServerUrl } /john.doe" )
306
306
process ( '/' , :method => 'GET' )
307
307
follow_redirect!
@@ -311,7 +311,7 @@ def test_with_missing_id
311
311
assert_equal 'cancel' , @response . body
312
312
end
313
313
314
- def test_with_timeout
314
+ it "with_timeout" do
315
315
@app = app ( :identifier => RotsServerUrl )
316
316
process ( '/' , :method => "GET" )
317
317
assert_equal 400 , @response . status
@@ -320,7 +320,7 @@ def test_with_timeout
320
320
assert_equal 'missing' , @response . body
321
321
end
322
322
323
- def test_sanitize_query_string
323
+ it "sanitize_query_string" do
324
324
@app = app
325
325
process ( '/' , :method => 'GET' )
326
326
follow_redirect!
@@ -329,7 +329,7 @@ def test_sanitize_query_string
329
329
assert_equal '' , @response . headers [ 'X-Query-String' ]
330
330
end
331
331
332
- def test_passthrough_standard_http_basic_auth
332
+ it "passthrough_standard_http_basic_auth" do
333
333
@app = app
334
334
process ( '/' , :method => 'GET' , "MOCK_HTTP_BASIC_AUTH" => '1' )
335
335
assert_equal 401 , @response . status
@@ -368,7 +368,7 @@ def app(options = {})
368
368
describe "simple auth" do
369
369
include RackTestHelpers
370
370
371
- def test_successful_login
371
+ it "can login" do
372
372
@app = app "#{ RotsServerUrl } /john.doe?openid.success=true"
373
373
374
374
process '/dashboard'
@@ -383,7 +383,7 @@ def test_successful_login
383
383
assert_equal 'Hello' , @response . body
384
384
end
385
385
386
- def test_failed_login
386
+ it "fails login" do
387
387
@app = app "#{ RotsServerUrl } /john.doe"
388
388
389
389
process '/dashboard'
0 commit comments