web-console 2.0.0 → 2.1.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.
- checksums.yaml +4 -4
- data/README.markdown +132 -85
- data/lib/web_console.rb +14 -13
- data/lib/web_console/errors.rb +7 -0
- data/lib/web_console/{repl.rb → evaluator.rb} +7 -10
- data/lib/web_console/helper.rb +22 -0
- data/lib/web_console/integration.rb +8 -0
- data/lib/web_console/{core_ext/exception → integration}/cruby.rb +0 -0
- data/lib/web_console/integration/jruby.rb +111 -0
- data/lib/web_console/integration/rubinius.rb +66 -0
- data/lib/web_console/middleware.rb +117 -0
- data/lib/web_console/railtie.rb +61 -0
- data/lib/web_console/request.rb +30 -0
- data/lib/web_console/session.rb +65 -0
- data/lib/web_console/template.rb +49 -0
- data/lib/web_console/templates/_inner_console_markup.html +3 -0
- data/lib/web_console/templates/_markup.html +4 -0
- data/lib/web_console/templates/_prompt_box_markup.html +2 -0
- data/lib/web_console/templates/console.js +373 -0
- data/lib/web_console/templates/error_page.js +83 -0
- data/lib/web_console/templates/index.html +8 -0
- data/lib/web_console/templates/layouts/inlined_string.erb +1 -0
- data/lib/web_console/templates/layouts/javascript.erb +5 -0
- data/lib/web_console/templates/main.js +24 -0
- data/lib/web_console/templates/style.css +9 -0
- data/lib/web_console/version.rb +1 -1
- data/lib/web_console/whiny_request.rb +38 -0
- data/lib/web_console/whitelist.rb +42 -0
- data/test/dummy/config/environments/test.rb +0 -4
- data/test/dummy/log/development.log +7075 -0
- data/test/dummy/log/test.log +66006 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/support/scenarios/bad_custom_error_scenario.rb +17 -0
- data/test/support/scenarios/basic_nested_scenario.rb +15 -0
- data/test/support/scenarios/custom_error_scenario.rb +11 -0
- data/test/support/scenarios/eval_nested_scenario.rb +15 -0
- data/test/support/scenarios/flat_scenario.rb +9 -0
- data/test/support/scenarios/reraised_scenario.rb +21 -0
- data/test/test_helper.rb +50 -3
- data/test/web_console/evaluator_test.rb +73 -0
- data/test/web_console/helper_test.rb +76 -0
- data/test/web_console/integration_test.rb +47 -0
- data/test/web_console/middleware_test.rb +116 -0
- data/test/web_console/railtie_test.rb +99 -0
- data/test/web_console/request_test.rb +52 -0
- data/test/web_console/session_test.rb +59 -0
- data/test/web_console/whiny_request_test.rb +33 -0
- data/test/web_console/whitelist_test.rb +43 -0
- metadata +66 -56
- data/lib/action_dispatch/debug_exceptions.rb +0 -105
- data/lib/action_dispatch/exception_wrapper.rb +0 -38
- data/lib/action_dispatch/templates/rescues/_request_and_response.html.erb +0 -34
- data/lib/action_dispatch/templates/rescues/_request_and_response.text.erb +0 -23
- data/lib/action_dispatch/templates/rescues/_source.erb +0 -29
- data/lib/action_dispatch/templates/rescues/_trace.html.erb +0 -72
- data/lib/action_dispatch/templates/rescues/_trace.text.erb +0 -9
- data/lib/action_dispatch/templates/rescues/_web_console.html.erb +0 -420
- data/lib/action_dispatch/templates/rescues/diagnostics.html.erb +0 -18
- data/lib/action_dispatch/templates/rescues/diagnostics.text.erb +0 -9
- data/lib/action_dispatch/templates/rescues/layout.erb +0 -160
- data/lib/action_dispatch/templates/rescues/missing_template.html.erb +0 -13
- data/lib/action_dispatch/templates/rescues/missing_template.text.erb +0 -3
- data/lib/action_dispatch/templates/rescues/routing_error.html.erb +0 -34
- data/lib/action_dispatch/templates/rescues/routing_error.text.erb +0 -11
- data/lib/action_dispatch/templates/rescues/template_error.html.erb +0 -22
- data/lib/action_dispatch/templates/rescues/template_error.text.erb +0 -7
- data/lib/action_dispatch/templates/rescues/unknown_action.html.erb +0 -6
- data/lib/action_dispatch/templates/rescues/unknown_action.text.erb +0 -3
- data/lib/action_dispatch/templates/routes/_route.html.erb +0 -16
- data/lib/action_dispatch/templates/routes/_table.html.erb +0 -200
- data/lib/assets/javascripts/web-console.js +0 -1
- data/lib/assets/javascripts/web_console.js +0 -41
- data/lib/web_console/controller_helpers.rb +0 -46
- data/lib/web_console/core_ext/exception.rb +0 -7
- data/lib/web_console/core_ext/exception/jruby.rb +0 -25
- data/lib/web_console/core_ext/exception/rubinius.rb +0 -32
- data/lib/web_console/engine.rb +0 -47
- data/lib/web_console/repl_session.rb +0 -89
- data/lib/web_console/unsupported_platforms.rb +0 -28
- data/lib/web_console/view_helpers.rb +0 -16
- data/test/action_pack/exception_wrapper_test.rb +0 -26
- data/test/controllers/tests_controller_test.rb +0 -41
- data/test/web_console/core_ext/exception_test.rb +0 -46
- data/test/web_console/engine_test.rb +0 -108
- data/test/web_console/repl_session_test.rb +0 -32
- data/test/web_console/repl_test.rb +0 -75
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
module WebConsole
|
|
4
|
-
class EngineTest < ActiveSupport::TestCase
|
|
5
|
-
test 'whitelisted ips are courced to IPAddr' do
|
|
6
|
-
new_uninitialized_app do |app|
|
|
7
|
-
app.config.web_console.whitelisted_ips = '127.0.0.1'
|
|
8
|
-
app.initialize!
|
|
9
|
-
|
|
10
|
-
assert_equal [ IPAddr.new('127.0.0.1') ], app.config.web_console.whitelisted_ips
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
test 'whitelisted ips with IPv6 format as default' do
|
|
15
|
-
new_uninitialized_app do |app|
|
|
16
|
-
app.config.web_console.whitelisted_ips = [ '127.0.0.1', '::1' ]
|
|
17
|
-
app.initialize!
|
|
18
|
-
|
|
19
|
-
assert_equal [ IPAddr.new('127.0.0.1'), IPAddr.new('::1') ], app.config.web_console.whitelisted_ips
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test 'whitelisted ips are normalized and unique IPAddr' do
|
|
24
|
-
new_uninitialized_app do |app|
|
|
25
|
-
app.config.web_console.whitelisted_ips = [ '127.0.0.1', '127.0.0.1', nil, '', ' ' ]
|
|
26
|
-
app.initialize!
|
|
27
|
-
|
|
28
|
-
assert_equal [ IPAddr.new('127.0.0.1') ], app.config.web_console.whitelisted_ips
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test 'whitelisted_ips.include? coerces to IPAddr' do
|
|
33
|
-
new_uninitialized_app do |app|
|
|
34
|
-
app.config.web_console.whitelisted_ips = '127.0.0.1'
|
|
35
|
-
app.initialize!
|
|
36
|
-
|
|
37
|
-
assert app.config.web_console.whitelisted_ips.include?('127.0.0.1')
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test 'whitelisted_ips.include? works with IPAddr' do
|
|
42
|
-
new_uninitialized_app do |app|
|
|
43
|
-
app.config.web_console.whitelisted_ips = '127.0.0.1'
|
|
44
|
-
app.initialize!
|
|
45
|
-
|
|
46
|
-
assert app.config.web_console.whitelisted_ips.include?(IPAddr.new('127.0.0.1'))
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test 'whitelist whole networks' do
|
|
51
|
-
new_uninitialized_app do |app|
|
|
52
|
-
app.config.web_console.whitelisted_ips = '172.16.0.0/12'
|
|
53
|
-
app.initialize!
|
|
54
|
-
|
|
55
|
-
1.upto(255).each do |n|
|
|
56
|
-
assert_includes app.config.web_console.whitelisted_ips, "172.16.0.#{n}"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test 'whitelist multiple networks' do
|
|
62
|
-
new_uninitialized_app do |app|
|
|
63
|
-
app.config.web_console.whitelisted_ips = %w( 172.16.0.0/12 192.168.0.0/16 )
|
|
64
|
-
app.initialize!
|
|
65
|
-
|
|
66
|
-
1.upto(255).each do |n|
|
|
67
|
-
assert_includes app.config.web_console.whitelisted_ips, "172.16.0.#{n}"
|
|
68
|
-
assert_includes app.config.web_console.whitelisted_ips, "192.168.0.#{n}"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
private
|
|
74
|
-
|
|
75
|
-
def new_uninitialized_app(root = File.expand_path('../../dummy', __FILE__))
|
|
76
|
-
skip if Rails::VERSION::MAJOR == 3
|
|
77
|
-
|
|
78
|
-
old_app = Rails.application
|
|
79
|
-
|
|
80
|
-
FileUtils.mkdir_p(root)
|
|
81
|
-
Dir.chdir(root) do
|
|
82
|
-
Rails.application = nil
|
|
83
|
-
|
|
84
|
-
app = Class.new(Rails::Application)
|
|
85
|
-
app.config.eager_load = false
|
|
86
|
-
app.config.time_zone = 'UTC'
|
|
87
|
-
app.config.middleware ||= Rails::Configuration::MiddlewareStackProxy.new
|
|
88
|
-
app.config.active_support.deprecation = :notify
|
|
89
|
-
|
|
90
|
-
yield app
|
|
91
|
-
end
|
|
92
|
-
ensure
|
|
93
|
-
Rails.application = old_app
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def teardown_fixtures(*)
|
|
97
|
-
super
|
|
98
|
-
rescue
|
|
99
|
-
# This is nasty hack to prevent a connection to the database in JRuby's
|
|
100
|
-
# activerecord-jdbcsqlite3-adapter. We don't really require a database
|
|
101
|
-
# connection, for the tests to run.
|
|
102
|
-
#
|
|
103
|
-
# The sad thing is that I couldn't figure out why does it only happens
|
|
104
|
-
# on activerecord-jdbcsqlite3-adapter and how to actually prevent it,
|
|
105
|
-
# rather than work-around it.
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
module WebConsole
|
|
4
|
-
class REPLSessionTest < ActionView::TestCase
|
|
5
|
-
setup do
|
|
6
|
-
WebConsole::REPLSession::INMEMORY_STORAGE.clear
|
|
7
|
-
@model1 = @model = WebConsole::REPLSession.new binding: TOPLEVEL_BINDING
|
|
8
|
-
@model2 = WebConsole::REPLSession.new binding: TOPLEVEL_BINDING
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
test 'raises WebConsole::REPLSession::NotFound on not found sessions' do
|
|
12
|
-
assert_raises(WebConsole::REPLSession::NotFound) { WebConsole::REPLSession.find("nonexistent session") }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test 'find returns a persisted object' do
|
|
16
|
-
assert_equal @model.save, WebConsole::REPLSession.find(@model.id)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test 'not found exceptions are JSON serializable' do
|
|
20
|
-
exception = assert_raises(WebConsole::REPLSession::NotFound) { WebConsole::REPLSession.find("nonexistent session") }
|
|
21
|
-
assert_equal '{"error":"Session unavailable"}', exception.to_json
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test 'create gives already persisted models' do
|
|
25
|
-
assert WebConsole::REPLSession.create(binding: TOPLEVEL_BINDING).persisted?
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test 'no gives not persisted models' do
|
|
29
|
-
assert_not WebConsole::REPLSession.new(binding: TOPLEVEL_BINDING).persisted?
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class REPLTest < ActiveSupport::TestCase
|
|
4
|
-
class TestError < StandardError
|
|
5
|
-
def backtrace
|
|
6
|
-
[
|
|
7
|
-
"/web-console/lib/web_console/repl.rb:16:in `eval'",
|
|
8
|
-
"/web-console/lib/web_console/repl.rb:16:in `send_input'"
|
|
9
|
-
]
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class BadlyDefinedError < StandardError
|
|
14
|
-
def backtrace
|
|
15
|
-
nil
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
setup do
|
|
20
|
-
@repl1 = @repl = WebConsole::REPL.new
|
|
21
|
-
@repl2 = WebConsole::REPL.new
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test 'sending input returns the result as output' do
|
|
25
|
-
assert_equal "=> 42\n", @repl.send_input('foo = 42')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test 'preserves the session in the binding' do
|
|
29
|
-
assert_equal "=> 42\n", @repl.send_input('foo = 42')
|
|
30
|
-
assert_equal "=> 50\n", @repl.send_input('foo + 8')
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test 'session preservation requires same bindings' do
|
|
34
|
-
assert_equal "=> 42\n", @repl1.send_input('foo = 42')
|
|
35
|
-
assert_equal "=> 42\n", @repl2.send_input('foo')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
test 'prompt is present' do
|
|
39
|
-
assert_not_nil @repl.prompt
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test 'formats exceptions similarly to IRB' do
|
|
43
|
-
repl = WebConsole::REPL.new(binding)
|
|
44
|
-
|
|
45
|
-
assert_equal <<-END.strip_heredoc, repl.send_input("raise TestError, 'panic'")
|
|
46
|
-
#{TestError.name}: panic
|
|
47
|
-
\tfrom /web-console/lib/web_console/repl.rb:16:in `eval'
|
|
48
|
-
\tfrom /web-console/lib/web_console/repl.rb:16:in `send_input'
|
|
49
|
-
END
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test 'no backtrace is shown if exception backtrace is blank' do
|
|
53
|
-
repl = WebConsole::REPL.new(binding)
|
|
54
|
-
|
|
55
|
-
assert_equal <<-END.strip_heredoc, repl.send_input("raise BadlyDefinedError")
|
|
56
|
-
#{BadlyDefinedError.name}: #{BadlyDefinedError.name}
|
|
57
|
-
END
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test 'WebConsole::REPL callers are cleaned up of unneeded backtraces' do
|
|
61
|
-
# Those have to be on the same line to get the same trace.
|
|
62
|
-
repl, trace = WebConsole::REPL.new(binding), current_trace
|
|
63
|
-
|
|
64
|
-
assert_equal <<-END.strip_heredoc, repl.send_input("raise")
|
|
65
|
-
RuntimeError:
|
|
66
|
-
\tfrom #{trace}
|
|
67
|
-
END
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
private
|
|
71
|
-
|
|
72
|
-
def current_trace
|
|
73
|
-
caller.first
|
|
74
|
-
end
|
|
75
|
-
end
|