ghazel-erubis_rails_helper 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/README.rdoc +66 -0
  2. data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
  3. data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
  4. data/lib/erubis_rails_helper.rb +20 -0
  5. data/test/abstract_unit.rb +51 -0
  6. data/test/controller/action_pack_assertions_test.rb +516 -0
  7. data/test/controller/addresses_render_test.rb +37 -0
  8. data/test/controller/assert_select_test.rb +734 -0
  9. data/test/controller/base_test.rb +217 -0
  10. data/test/controller/benchmark_test.rb +32 -0
  11. data/test/controller/caching_test.rb +690 -0
  12. data/test/controller/capture_test.rb +66 -0
  13. data/test/controller/content_type_test.rb +168 -0
  14. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  15. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  16. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  17. data/test/controller/cookie_test.rb +111 -0
  18. data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
  19. data/test/controller/dispatcher_test.rb +103 -0
  20. data/test/controller/fake_controllers.rb +33 -0
  21. data/test/controller/fake_models.rb +19 -0
  22. data/test/controller/filter_params_test.rb +49 -0
  23. data/test/controller/filters_test.rb +885 -0
  24. data/test/controller/flash_test.rb +142 -0
  25. data/test/controller/header_test.rb +14 -0
  26. data/test/controller/helper_test.rb +224 -0
  27. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  28. data/test/controller/html-scanner/document_test.rb +148 -0
  29. data/test/controller/html-scanner/node_test.rb +89 -0
  30. data/test/controller/html-scanner/sanitizer_test.rb +273 -0
  31. data/test/controller/html-scanner/tag_node_test.rb +238 -0
  32. data/test/controller/html-scanner/text_node_test.rb +50 -0
  33. data/test/controller/html-scanner/tokenizer_test.rb +131 -0
  34. data/test/controller/http_basic_authentication_test.rb +88 -0
  35. data/test/controller/http_digest_authentication_test.rb +178 -0
  36. data/test/controller/integration_test.rb +417 -0
  37. data/test/controller/layout_test.rb +204 -0
  38. data/test/controller/logging_test.rb +46 -0
  39. data/test/controller/middleware_stack_test.rb +90 -0
  40. data/test/controller/mime_responds_test.rb +536 -0
  41. data/test/controller/mime_type_test.rb +93 -0
  42. data/test/controller/polymorphic_routes_test.rb +293 -0
  43. data/test/controller/rack_test.rb +294 -0
  44. data/test/controller/record_identifier_test.rb +139 -0
  45. data/test/controller/redirect_test.rb +282 -0
  46. data/test/controller/render_test.rb +1752 -0
  47. data/test/controller/request/json_params_parsing_test.rb +45 -0
  48. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  49. data/test/controller/request/query_string_parsing_test.rb +120 -0
  50. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  51. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  52. data/test/controller/request_forgery_protection_test.rb +246 -0
  53. data/test/controller/request_test.rb +407 -0
  54. data/test/controller/rescue_test.rb +536 -0
  55. data/test/controller/resources_test.rb +1341 -0
  56. data/test/controller/routing_test.rb +2557 -0
  57. data/test/controller/selector_test.rb +628 -0
  58. data/test/controller/send_file_test.rb +161 -0
  59. data/test/controller/session/cookie_store_test.rb +239 -0
  60. data/test/controller/session/mem_cache_store_test.rb +127 -0
  61. data/test/controller/session/test_session_test.rb +58 -0
  62. data/test/controller/test_test.rb +692 -0
  63. data/test/controller/translation_test.rb +26 -0
  64. data/test/controller/url_rewriter_test.rb +359 -0
  65. data/test/controller/verification_test.rb +270 -0
  66. data/test/controller/view_paths_test.rb +141 -0
  67. data/test/controller/webservice_test.rb +260 -0
  68. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  69. data/test/fixtures/company.rb +10 -0
  70. data/test/fixtures/developer.rb +9 -0
  71. data/test/fixtures/helpers/abc_helper.rb +5 -0
  72. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  73. data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
  74. data/test/fixtures/mascot.rb +3 -0
  75. data/test/fixtures/project.rb +3 -0
  76. data/test/fixtures/reply.rb +7 -0
  77. data/test/fixtures/topic.rb +3 -0
  78. data/test/template/asset_tag_helper_test.rb +713 -0
  79. data/test/template/atom_feed_helper_test.rb +286 -0
  80. data/test/template/benchmark_helper_test.rb +86 -0
  81. data/test/template/compiled_templates_test.rb +203 -0
  82. data/test/template/date_helper_i18n_test.rb +120 -0
  83. data/test/template/date_helper_test.rb +2469 -0
  84. data/test/template/erb_util_test.rb +24 -0
  85. data/test/template/form_helper_test.rb +1176 -0
  86. data/test/template/form_options_helper_test.rb +751 -0
  87. data/test/template/form_tag_helper_test.rb +327 -0
  88. data/test/template/javascript_helper_test.rb +106 -0
  89. data/test/template/number_helper_i18n_test.rb +69 -0
  90. data/test/template/number_helper_test.rb +128 -0
  91. data/test/template/prototype_helper_test.rb +639 -0
  92. data/test/template/record_tag_helper_test.rb +58 -0
  93. data/test/template/render_test.rb +291 -0
  94. data/test/template/sanitize_helper_test.rb +48 -0
  95. data/test/template/scriptaculous_helper_test.rb +90 -0
  96. data/test/template/tag_helper_test.rb +97 -0
  97. data/test/template/test_test.rb +54 -0
  98. data/test/template/text_helper_test.rb +520 -0
  99. data/test/template/translation_helper_test.rb +32 -0
  100. data/test/template/url_helper_test.rb +614 -0
  101. data/test/test_erubis_rails_helper.rb +4 -0
  102. data/test/testing_sandbox.rb +15 -0
  103. data/test/view/test_case_test.rb +8 -0
  104. metadata +174 -0
@@ -0,0 +1,131 @@
1
+ require 'abstract_unit'
2
+
3
+ class TokenizerTest < Test::Unit::TestCase
4
+
5
+ def test_blank
6
+ tokenize ""
7
+ assert_end
8
+ end
9
+
10
+ def test_space
11
+ tokenize " "
12
+ assert_next " "
13
+ assert_end
14
+ end
15
+
16
+ def test_tag_simple_open
17
+ tokenize "<tag>"
18
+ assert_next "<tag>"
19
+ assert_end
20
+ end
21
+
22
+ def test_tag_simple_self_closing
23
+ tokenize "<tag />"
24
+ assert_next "<tag />"
25
+ assert_end
26
+ end
27
+
28
+ def test_tag_simple_closing
29
+ tokenize "</tag>"
30
+ assert_next "</tag>"
31
+ end
32
+
33
+ def test_tag_with_single_quoted_attribute
34
+ tokenize %{<tag a='hello'>x}
35
+ assert_next %{<tag a='hello'>}
36
+ end
37
+
38
+ def test_tag_with_single_quoted_attribute_with_escape
39
+ tokenize %{<tag a='hello\\''>x}
40
+ assert_next %{<tag a='hello\\''>}
41
+ end
42
+
43
+ def test_tag_with_double_quoted_attribute
44
+ tokenize %{<tag a="hello">x}
45
+ assert_next %{<tag a="hello">}
46
+ end
47
+
48
+ def test_tag_with_double_quoted_attribute_with_escape
49
+ tokenize %{<tag a="hello\\"">x}
50
+ assert_next %{<tag a="hello\\"">}
51
+ end
52
+
53
+ def test_tag_with_unquoted_attribute
54
+ tokenize %{<tag a=hello>x}
55
+ assert_next %{<tag a=hello>}
56
+ end
57
+
58
+ def test_tag_with_lt_char_in_attribute
59
+ tokenize %{<tag a="x < y">x}
60
+ assert_next %{<tag a="x < y">}
61
+ end
62
+
63
+ def test_tag_with_gt_char_in_attribute
64
+ tokenize %{<tag a="x > y">x}
65
+ assert_next %{<tag a="x > y">}
66
+ end
67
+
68
+ def test_doctype_tag
69
+ tokenize %{<!DOCTYPE "blah" "blah" "blah">\n <html>}
70
+ assert_next %{<!DOCTYPE "blah" "blah" "blah">}
71
+ assert_next %{\n }
72
+ assert_next %{<html>}
73
+ end
74
+
75
+ def test_cdata_tag
76
+ tokenize %{<![CDATA[<br>]]>}
77
+ assert_next %{<![CDATA[<br>]]>}
78
+ assert_end
79
+ end
80
+
81
+ def test_unterminated_cdata_tag
82
+ tokenize %{<content:encoded><![CDATA[ neverending...}
83
+ assert_next %{<content:encoded>}
84
+ assert_next %{<![CDATA[ neverending...}
85
+ assert_end
86
+ end
87
+
88
+ def test_less_than_with_space
89
+ tokenize %{original < hello > world}
90
+ assert_next %{original }
91
+ assert_next %{< hello > world}
92
+ end
93
+
94
+ def test_less_than_without_matching_greater_than
95
+ tokenize %{hello <span onmouseover="gotcha"\n<b>foo</b>\nbar</span>}
96
+ assert_next %{hello }
97
+ assert_next %{<span onmouseover="gotcha"\n}
98
+ assert_next %{<b>}
99
+ assert_next %{foo}
100
+ assert_next %{</b>}
101
+ assert_next %{\nbar}
102
+ assert_next %{</span>}
103
+ assert_end
104
+ end
105
+
106
+ def test_unterminated_comment
107
+ tokenize %{hello <!-- neverending...}
108
+ assert_next %{hello }
109
+ assert_next %{<!-- neverending...}
110
+ assert_end
111
+ end
112
+
113
+ private
114
+
115
+ def tokenize(text)
116
+ @tokenizer = HTML::Tokenizer.new(text)
117
+ end
118
+
119
+ def assert_next(expected, message=nil)
120
+ token = @tokenizer.next
121
+ assert_equal expected, token, message
122
+ end
123
+
124
+ def assert_sequence(*expected)
125
+ assert_next expected.shift until expected.empty?
126
+ end
127
+
128
+ def assert_end(message=nil)
129
+ assert_nil @tokenizer.next, message
130
+ end
131
+ end
@@ -0,0 +1,88 @@
1
+ require 'abstract_unit'
2
+
3
+ class HttpBasicAuthenticationTest < ActionController::TestCase
4
+ class DummyController < ActionController::Base
5
+ before_filter :authenticate, :only => :index
6
+ before_filter :authenticate_with_request, :only => :display
7
+
8
+ def index
9
+ render :text => "Hello Secret"
10
+ end
11
+
12
+ def display
13
+ render :text => 'Definitely Maybe'
14
+ end
15
+
16
+ private
17
+
18
+ def authenticate
19
+ authenticate_or_request_with_http_basic do |username, password|
20
+ username == 'lifo' && password == 'world'
21
+ end
22
+ end
23
+
24
+ def authenticate_with_request
25
+ if authenticate_with_http_basic { |username, password| username == 'pretty' && password == 'please' }
26
+ @logged_in = true
27
+ else
28
+ request_http_basic_authentication("SuperSecret")
29
+ end
30
+ end
31
+ end
32
+
33
+ AUTH_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION']
34
+
35
+ tests DummyController
36
+
37
+ AUTH_HEADERS.each do |header|
38
+ test "successful authentication with #{header.downcase}" do
39
+ @request.env[header] = encode_credentials('lifo', 'world')
40
+ get :index
41
+
42
+ assert_response :success
43
+ assert_equal 'Hello Secret', @response.body, "Authentication failed for request header #{header}"
44
+ end
45
+ end
46
+
47
+ AUTH_HEADERS.each do |header|
48
+ test "unsuccessful authentication with #{header.downcase}" do
49
+ @request.env[header] = encode_credentials('h4x0r', 'world')
50
+ get :index
51
+
52
+ assert_response :unauthorized
53
+ assert_equal "HTTP Basic: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header}"
54
+ end
55
+ end
56
+
57
+ test "authentication request without credential" do
58
+ get :display
59
+
60
+ assert_response :unauthorized
61
+ assert_equal "HTTP Basic: Access denied.\n", @response.body
62
+ assert_equal 'Basic realm="SuperSecret"', @response.headers['WWW-Authenticate']
63
+ end
64
+
65
+ test "authentication request with invalid credential" do
66
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials('pretty', 'foo')
67
+ get :display
68
+
69
+ assert_response :unauthorized
70
+ assert_equal "HTTP Basic: Access denied.\n", @response.body
71
+ assert_equal 'Basic realm="SuperSecret"', @response.headers['WWW-Authenticate']
72
+ end
73
+
74
+ test "authentication request with valid credential" do
75
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials('pretty', 'please')
76
+ get :display
77
+
78
+ assert_response :success
79
+ assert assigns(:logged_in)
80
+ assert_equal 'Definitely Maybe', @response.body
81
+ end
82
+
83
+ private
84
+
85
+ def encode_credentials(username, password)
86
+ "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
87
+ end
88
+ end
@@ -0,0 +1,178 @@
1
+ require 'abstract_unit'
2
+
3
+ class HttpDigestAuthenticationTest < ActionController::TestCase
4
+ class DummyDigestController < ActionController::Base
5
+ before_filter :authenticate, :only => :index
6
+ before_filter :authenticate_with_request, :only => :display
7
+
8
+ USERS = { 'lifo' => 'world', 'pretty' => 'please',
9
+ 'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))}
10
+
11
+ def index
12
+ render :text => "Hello Secret"
13
+ end
14
+
15
+ def display
16
+ render :text => 'Definitely Maybe'
17
+ end
18
+
19
+ private
20
+
21
+ def authenticate
22
+ authenticate_or_request_with_http_digest("SuperSecret") do |username|
23
+ # Return the password
24
+ USERS[username]
25
+ end
26
+ end
27
+
28
+ def authenticate_with_request
29
+ if authenticate_with_http_digest("SuperSecret") { |username| USERS[username] }
30
+ @logged_in = true
31
+ else
32
+ request_http_digest_authentication("SuperSecret", "Authentication Failed")
33
+ end
34
+ end
35
+ end
36
+
37
+ AUTH_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION']
38
+
39
+ tests DummyDigestController
40
+
41
+ AUTH_HEADERS.each do |header|
42
+ test "successful authentication with #{header.downcase}" do
43
+ @request.env[header] = encode_credentials(:username => 'lifo', :password => 'world')
44
+ get :index
45
+
46
+ assert_response :success
47
+ assert_equal 'Hello Secret', @response.body, "Authentication failed for request header #{header}"
48
+ end
49
+ end
50
+
51
+ AUTH_HEADERS.each do |header|
52
+ test "unsuccessful authentication with #{header.downcase}" do
53
+ @request.env[header] = encode_credentials(:username => 'h4x0r', :password => 'world')
54
+ get :index
55
+
56
+ assert_response :unauthorized
57
+ assert_equal "HTTP Digest: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header}"
58
+ end
59
+ end
60
+
61
+ test "authentication request without credential" do
62
+ get :display
63
+
64
+ assert_response :unauthorized
65
+ assert_equal "Authentication Failed", @response.body
66
+ credentials = decode_credentials(@response.headers['WWW-Authenticate'])
67
+ assert_equal 'SuperSecret', credentials[:realm]
68
+ end
69
+
70
+ test "authentication request with invalid password" do
71
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo')
72
+ get :display
73
+
74
+ assert_response :unauthorized
75
+ assert_equal "Authentication Failed", @response.body
76
+ end
77
+
78
+ test "authentication request with invalid nonce" do
79
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :nonce => "xxyyzz")
80
+ get :display
81
+
82
+ assert_response :unauthorized
83
+ assert_equal "Authentication Failed", @response.body
84
+ end
85
+
86
+ test "authentication request with invalid opaque" do
87
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo', :opaque => "xxyyzz")
88
+ get :display
89
+
90
+ assert_response :unauthorized
91
+ assert_equal "Authentication Failed", @response.body
92
+ end
93
+
94
+ test "authentication request with invalid realm" do
95
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo', :realm => "NotSecret")
96
+ get :display
97
+
98
+ assert_response :unauthorized
99
+ assert_equal "Authentication Failed", @response.body
100
+ end
101
+
102
+ test "authentication request with valid credential" do
103
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
104
+ get :display
105
+
106
+ assert_response :success
107
+ assert assigns(:logged_in)
108
+ assert_equal 'Definitely Maybe', @response.body
109
+ end
110
+
111
+ test "authentication request with valid credential and nil session" do
112
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
113
+
114
+ # session_id = "" in functional test, but is +nil+ in real life
115
+ @request.session.session_id = nil
116
+ get :display
117
+
118
+ assert_response :success
119
+ assert assigns(:logged_in)
120
+ assert_equal 'Definitely Maybe', @response.body
121
+ end
122
+
123
+ test "authentication request with request-uri that doesn't match credentials digest-uri" do
124
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
125
+ @request.env['REQUEST_URI'] = "/http_digest_authentication_test/dummy_digest/altered/uri"
126
+ get :display
127
+
128
+ assert_response :unauthorized
129
+ assert_equal "Authentication Failed", @response.body
130
+ end
131
+
132
+ test "authentication request with absolute uri" do
133
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:uri => "http://test.host/http_digest_authentication_test/dummy_digest/display",
134
+ :username => 'pretty', :password => 'please')
135
+ @request.env['REQUEST_URI'] = "http://test.host/http_digest_authentication_test/dummy_digest/display"
136
+ get :display
137
+
138
+ assert_response :success
139
+ assert assigns(:logged_in)
140
+ assert_equal 'Definitely Maybe', @response.body
141
+ end
142
+
143
+ test "authentication request with password stored as ha1 digest hash" do
144
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'dhh',
145
+ :password => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")),
146
+ :password_is_ha1 => true)
147
+ get :display
148
+
149
+ assert_response :success
150
+ assert assigns(:logged_in)
151
+ assert_equal 'Definitely Maybe', @response.body
152
+ end
153
+
154
+ private
155
+
156
+ def encode_credentials(options)
157
+ options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b", :password_is_ha1 => false)
158
+ password = options.delete(:password)
159
+
160
+ # Set in /initializers/session_store.rb. Used as secret in generating nonce
161
+ # to prevent tampering of timestamp
162
+ ActionController::Base.session_options[:secret] = "session_options_secret"
163
+
164
+ # Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
165
+ get :index
166
+
167
+ assert_response :unauthorized
168
+
169
+ credentials = decode_credentials(@response.headers['WWW-Authenticate'])
170
+ credentials.merge!(options)
171
+ credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
172
+ ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
173
+ end
174
+
175
+ def decode_credentials(header)
176
+ ActionController::HttpAuthentication::Digest.decode_credentials(@response.headers['WWW-Authenticate'])
177
+ end
178
+ end