web-console 2.3.0 → 4.2.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 +5 -5
- data/CHANGELOG.markdown +133 -1
- data/MIT-LICENSE +1 -1
- data/README.markdown +48 -86
- data/Rakefile +14 -12
- data/lib/web-console.rb +3 -1
- data/lib/web_console/context.rb +45 -0
- data/lib/web_console/errors.rb +2 -0
- data/lib/web_console/evaluator.rb +14 -5
- data/lib/web_console/exception_mapper.rb +56 -0
- data/lib/web_console/extensions.rb +28 -17
- data/lib/web_console/injector.rb +32 -0
- data/lib/web_console/interceptor.rb +18 -0
- data/lib/web_console/locales/en.yml +1 -1
- data/lib/web_console/middleware.rb +31 -31
- data/lib/web_console/permissions.rb +42 -0
- data/lib/web_console/railtie.rb +38 -24
- data/lib/web_console/request.rb +8 -20
- data/lib/web_console/session.rb +32 -18
- data/lib/web_console/source_location.rb +15 -0
- data/lib/web_console/tasks/extensions.rake +15 -13
- data/lib/web_console/tasks/templates.rake +56 -0
- data/lib/web_console/template.rb +4 -3
- data/lib/web_console/templates/console.js.erb +497 -37
- data/lib/web_console/templates/error_page.js.erb +7 -8
- data/lib/web_console/templates/index.html.erb +4 -0
- data/lib/web_console/templates/layouts/inlined_string.erb +1 -1
- data/lib/web_console/templates/layouts/javascript.erb +1 -1
- data/lib/web_console/templates/regular_page.js.erb +24 -0
- data/lib/web_console/templates/style.css.erb +182 -27
- data/lib/web_console/testing/erb_precompiler.rb +5 -3
- data/lib/web_console/testing/fake_middleware.rb +7 -10
- data/lib/web_console/testing/helper.rb +3 -1
- data/lib/web_console/version.rb +3 -1
- data/lib/web_console/view.rb +24 -3
- data/lib/web_console/whiny_request.rb +8 -6
- data/lib/web_console.rb +28 -20
- metadata +28 -63
- data/lib/web_console/helper.rb +0 -22
- data/lib/web_console/integration/cruby.rb +0 -40
- data/lib/web_console/integration/jruby.rb +0 -111
- data/lib/web_console/integration/rubinius.rb +0 -67
- data/lib/web_console/integration.rb +0 -8
- data/lib/web_console/response.rb +0 -23
- data/lib/web_console/tasks/test_templates.rake +0 -50
- data/lib/web_console/whitelist.rb +0 -42
metadata
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: web-console
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Hailey Somerville
|
|
8
8
|
- Genadi Samokovarov
|
|
9
9
|
- Guillermo Iguaran
|
|
10
10
|
- Ryan Dao
|
|
11
|
-
autorequire:
|
|
11
|
+
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date:
|
|
14
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: railties
|
|
@@ -19,93 +19,59 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - ">="
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version:
|
|
22
|
+
version: 6.0.0
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
29
|
+
version: 6.0.0
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: activemodel
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
|
34
34
|
- - ">="
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version:
|
|
36
|
+
version: 6.0.0
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version:
|
|
43
|
+
version: 6.0.0
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
|
-
name:
|
|
45
|
+
name: actionview
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
|
48
48
|
- - ">="
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
|
-
version:
|
|
51
|
-
- - "<"
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: '4.0'
|
|
50
|
+
version: 6.0.0
|
|
54
51
|
type: :runtime
|
|
55
52
|
prerelease: false
|
|
56
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
54
|
requirements:
|
|
58
55
|
- - ">="
|
|
59
56
|
- !ruby/object:Gem::Version
|
|
60
|
-
version:
|
|
61
|
-
- - "<"
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: '4.0'
|
|
57
|
+
version: 6.0.0
|
|
64
58
|
- !ruby/object:Gem::Dependency
|
|
65
|
-
name:
|
|
59
|
+
name: bindex
|
|
66
60
|
requirement: !ruby/object:Gem::Requirement
|
|
67
61
|
requirements:
|
|
68
62
|
- - ">="
|
|
69
63
|
- !ruby/object:Gem::Version
|
|
70
|
-
version: 0.
|
|
64
|
+
version: 0.4.0
|
|
71
65
|
type: :runtime
|
|
72
66
|
prerelease: false
|
|
73
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
74
68
|
requirements:
|
|
75
69
|
- - ">="
|
|
76
70
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: 0.
|
|
78
|
-
|
|
79
|
-
name: actionmailer
|
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
|
81
|
-
requirements:
|
|
82
|
-
- - ">="
|
|
83
|
-
- !ruby/object:Gem::Version
|
|
84
|
-
version: '4.0'
|
|
85
|
-
type: :development
|
|
86
|
-
prerelease: false
|
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
88
|
-
requirements:
|
|
89
|
-
- - ">="
|
|
90
|
-
- !ruby/object:Gem::Version
|
|
91
|
-
version: '4.0'
|
|
92
|
-
- !ruby/object:Gem::Dependency
|
|
93
|
-
name: activerecord
|
|
94
|
-
requirement: !ruby/object:Gem::Requirement
|
|
95
|
-
requirements:
|
|
96
|
-
- - ">="
|
|
97
|
-
- !ruby/object:Gem::Version
|
|
98
|
-
version: '4.0'
|
|
99
|
-
type: :development
|
|
100
|
-
prerelease: false
|
|
101
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
102
|
-
requirements:
|
|
103
|
-
- - ">="
|
|
104
|
-
- !ruby/object:Gem::Version
|
|
105
|
-
version: '4.0'
|
|
106
|
-
description:
|
|
71
|
+
version: 0.4.0
|
|
72
|
+
description:
|
|
107
73
|
email:
|
|
108
|
-
-
|
|
74
|
+
- hailey@hailey.lol
|
|
109
75
|
- gsamokovarov@gmail.com
|
|
110
76
|
- guilleiguaran@gmail.com
|
|
111
77
|
- daoduyducduong@gmail.com
|
|
@@ -119,22 +85,22 @@ files:
|
|
|
119
85
|
- Rakefile
|
|
120
86
|
- lib/web-console.rb
|
|
121
87
|
- lib/web_console.rb
|
|
88
|
+
- lib/web_console/context.rb
|
|
122
89
|
- lib/web_console/errors.rb
|
|
123
90
|
- lib/web_console/evaluator.rb
|
|
91
|
+
- lib/web_console/exception_mapper.rb
|
|
124
92
|
- lib/web_console/extensions.rb
|
|
125
|
-
- lib/web_console/
|
|
126
|
-
- lib/web_console/
|
|
127
|
-
- lib/web_console/integration/cruby.rb
|
|
128
|
-
- lib/web_console/integration/jruby.rb
|
|
129
|
-
- lib/web_console/integration/rubinius.rb
|
|
93
|
+
- lib/web_console/injector.rb
|
|
94
|
+
- lib/web_console/interceptor.rb
|
|
130
95
|
- lib/web_console/locales/en.yml
|
|
131
96
|
- lib/web_console/middleware.rb
|
|
97
|
+
- lib/web_console/permissions.rb
|
|
132
98
|
- lib/web_console/railtie.rb
|
|
133
99
|
- lib/web_console/request.rb
|
|
134
|
-
- lib/web_console/response.rb
|
|
135
100
|
- lib/web_console/session.rb
|
|
101
|
+
- lib/web_console/source_location.rb
|
|
136
102
|
- lib/web_console/tasks/extensions.rake
|
|
137
|
-
- lib/web_console/tasks/
|
|
103
|
+
- lib/web_console/tasks/templates.rake
|
|
138
104
|
- lib/web_console/template.rb
|
|
139
105
|
- lib/web_console/templates/_inner_console_markup.html.erb
|
|
140
106
|
- lib/web_console/templates/_markup.html.erb
|
|
@@ -145,6 +111,7 @@ files:
|
|
|
145
111
|
- lib/web_console/templates/layouts/inlined_string.erb
|
|
146
112
|
- lib/web_console/templates/layouts/javascript.erb
|
|
147
113
|
- lib/web_console/templates/main.js.erb
|
|
114
|
+
- lib/web_console/templates/regular_page.js.erb
|
|
148
115
|
- lib/web_console/templates/style.css.erb
|
|
149
116
|
- lib/web_console/testing/erb_precompiler.rb
|
|
150
117
|
- lib/web_console/testing/fake_middleware.rb
|
|
@@ -152,12 +119,11 @@ files:
|
|
|
152
119
|
- lib/web_console/version.rb
|
|
153
120
|
- lib/web_console/view.rb
|
|
154
121
|
- lib/web_console/whiny_request.rb
|
|
155
|
-
- lib/web_console/whitelist.rb
|
|
156
122
|
homepage: https://github.com/rails/web-console
|
|
157
123
|
licenses:
|
|
158
124
|
- MIT
|
|
159
125
|
metadata: {}
|
|
160
|
-
post_install_message:
|
|
126
|
+
post_install_message:
|
|
161
127
|
rdoc_options: []
|
|
162
128
|
require_paths:
|
|
163
129
|
- lib
|
|
@@ -165,16 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
165
131
|
requirements:
|
|
166
132
|
- - ">="
|
|
167
133
|
- !ruby/object:Gem::Version
|
|
168
|
-
version: '
|
|
134
|
+
version: '2.5'
|
|
169
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
136
|
requirements:
|
|
171
137
|
- - ">="
|
|
172
138
|
- !ruby/object:Gem::Version
|
|
173
139
|
version: '0'
|
|
174
140
|
requirements: []
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
signing_key:
|
|
141
|
+
rubygems_version: 3.1.6
|
|
142
|
+
signing_key:
|
|
178
143
|
specification_version: 4
|
|
179
144
|
summary: A debugging tool for your Ruby on Rails applications.
|
|
180
145
|
test_files: []
|
data/lib/web_console/helper.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module WebConsole
|
|
2
|
-
module Helper
|
|
3
|
-
# Communicates with the middleware to render a console in a +binding+.
|
|
4
|
-
#
|
|
5
|
-
# If +bidning+ isn't explicitly given, Binding#of_caller will be used to
|
|
6
|
-
# get the binding of the previous frame. E.g. the one that invoked
|
|
7
|
-
# +console+.
|
|
8
|
-
#
|
|
9
|
-
# Raises DoubleRenderError if a double +console+ invocation per request is
|
|
10
|
-
# detected.
|
|
11
|
-
def console(binding = nil)
|
|
12
|
-
raise DoubleRenderError if request.env['web_console.binding']
|
|
13
|
-
|
|
14
|
-
request.env['web_console.binding'] = binding || ::Kernel.binding.of_caller(1)
|
|
15
|
-
|
|
16
|
-
# Make sure nothing is rendered from the view helper. Otherwise
|
|
17
|
-
# you're gonna see unexpected #<Binding:0x007fee4302b078> in the
|
|
18
|
-
# templates.
|
|
19
|
-
nil
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
class Exception
|
|
2
|
-
begin
|
|
3
|
-
# We share the same exception binding extraction mechanism as better_errors,
|
|
4
|
-
# so try to use it if it is already available. It also solves problems like
|
|
5
|
-
# charliesome/better_errors#272, caused by an infinite recursion.
|
|
6
|
-
require 'better_errors'
|
|
7
|
-
|
|
8
|
-
# The bindings in which the exception originated in.
|
|
9
|
-
def bindings
|
|
10
|
-
@bindings || __better_errors_bindings_stack
|
|
11
|
-
end
|
|
12
|
-
rescue LoadError
|
|
13
|
-
# The bindings in which the exception originated in.
|
|
14
|
-
def bindings
|
|
15
|
-
@bindings || []
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# CRuby calls #set_backtrace every time it raises an exception. Overriding
|
|
19
|
-
# it to assign the #bindings.
|
|
20
|
-
def set_backtrace_with_binding_of_caller(*args)
|
|
21
|
-
# Thanks to @charliesome who wrote this bit for better_errors.
|
|
22
|
-
unless Thread.current[:__web_console_exception_lock]
|
|
23
|
-
Thread.current[:__web_console_exception_lock] = true
|
|
24
|
-
begin
|
|
25
|
-
# Raising an exception here will cause all of the rubies to go into a
|
|
26
|
-
# stack overflow. Some rubies may even segfault. See
|
|
27
|
-
# https://bugs.ruby-lang.org/issues/10164 for details.
|
|
28
|
-
@bindings = binding.callers.drop(1)
|
|
29
|
-
ensure
|
|
30
|
-
Thread.current[:__web_console_exception_lock] = false
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
set_backtrace_without_binding_of_caller(*args)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
alias_method :set_backtrace_without_binding_of_caller, :set_backtrace
|
|
38
|
-
alias_method :set_backtrace, :set_backtrace_with_binding_of_caller
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'English'
|
|
2
|
-
require 'active_support/core_ext/string/strip'
|
|
3
|
-
|
|
4
|
-
java_import org.jruby.RubyInstanceConfig
|
|
5
|
-
|
|
6
|
-
module WebConsole
|
|
7
|
-
module JRuby
|
|
8
|
-
class << self
|
|
9
|
-
# Returns whether JRuby is ran in interpreted mode.
|
|
10
|
-
def interpreted_mode?
|
|
11
|
-
compile_mode = ::JRuby.runtime.instance_config.compile_mode
|
|
12
|
-
interpreted_mode = RubyInstanceConfig::CompileMode::OFF
|
|
13
|
-
|
|
14
|
-
compile_mode == interpreted_mode
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# A proc to be used in Kernel#set_trace_func.
|
|
18
|
-
#
|
|
19
|
-
# It sets Exception#bindings for an error with all the bindings the
|
|
20
|
-
# current ThreadContext contains.
|
|
21
|
-
def set_exception_bindings_trace_func
|
|
22
|
-
proc do |event, file, line, id, binding, classname|
|
|
23
|
-
case event
|
|
24
|
-
when 'raise'
|
|
25
|
-
if $ERROR_INFO.bindings.empty?
|
|
26
|
-
# binding_of_caller will generate an improperly built binding at
|
|
27
|
-
# caller[1]. Every call to a non existent method, constant or a
|
|
28
|
-
# local variable will result in a Java NullPointerException.
|
|
29
|
-
#
|
|
30
|
-
# The binding that Kernel#set_trace_func is giving us is properly
|
|
31
|
-
# built, so we can use in place of the broken one.
|
|
32
|
-
bindings = ::Kernel.binding.callers.drop(2).unshift(binding)
|
|
33
|
-
$ERROR_INFO.instance_variable_set(:@bindings, bindings)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# A fake binding for JRuby in non interpreted mode.
|
|
41
|
-
#
|
|
42
|
-
# It won't actually evaluate any code, rather it will tell the user how to
|
|
43
|
-
# enable interpreted mode.
|
|
44
|
-
class FakeJRubyBinding
|
|
45
|
-
TURN_ON_INTERPRETED_MODE_TEXT = <<-END.strip_heredoc
|
|
46
|
-
JRuby needs to run in interpreted mode for introspection support.
|
|
47
|
-
|
|
48
|
-
To turn on interpreted mode, put -J-Djruby.compile.mode=OFF in the
|
|
49
|
-
JRUBY_OPTS environment variable.
|
|
50
|
-
END
|
|
51
|
-
|
|
52
|
-
def TURN_ON_INTERPRETED_MODE_TEXT.inspect
|
|
53
|
-
self
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
TURN_ON_INTERPRETED_MODE_TEXT.freeze
|
|
57
|
-
|
|
58
|
-
def eval(*)
|
|
59
|
-
TURN_ON_INTERPRETED_MODE_TEXT
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# A fake array of FakeJRubyBinding objects.
|
|
64
|
-
#
|
|
65
|
-
# It is used in Exception#bindings to make sure that when users switch
|
|
66
|
-
# bindings on the UI, they get a FakeJRubyBinding notifying them what to do
|
|
67
|
-
# if they want introspection.
|
|
68
|
-
class FakeJRubyBindingsArray < Array
|
|
69
|
-
def [](*)
|
|
70
|
-
FakeJRubyBinding.new
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# For Kernel#Array and other implicit conversion API. JRuby expects it to
|
|
74
|
-
# return an object that is_a? an Array. This is the reasoning of
|
|
75
|
-
# FakeJRubyBindingsArray being a subclass of Array.
|
|
76
|
-
def to_ary
|
|
77
|
-
self
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
if WebConsole::JRuby.interpreted_mode?
|
|
84
|
-
::Exception.class_eval do
|
|
85
|
-
def bindings
|
|
86
|
-
@bindings || []
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Kernel#set_trace_func will complain about not being able to capture all the
|
|
91
|
-
# events without the JRuby --debug flag.
|
|
92
|
-
silence_warnings do
|
|
93
|
-
set_trace_func WebConsole::JRuby.set_exception_bindings_trace_func
|
|
94
|
-
end
|
|
95
|
-
else
|
|
96
|
-
::Exception.class_eval do
|
|
97
|
-
def bindings
|
|
98
|
-
WebConsole::JRuby::FakeJRubyBindingsArray.new
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
::Binding.class_eval do
|
|
103
|
-
def of_caller(*)
|
|
104
|
-
WebConsole::JRuby::FakeJRubyBinding.new
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def callers
|
|
108
|
-
WebConsole::JRuby::FakeJRubyBindingsArray.new
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
module WebConsole
|
|
2
|
-
module Rubinius
|
|
3
|
-
# Filters internal Rubinius locations.
|
|
4
|
-
#
|
|
5
|
-
# There are a couple of reasons why we wanna filter out the locations.
|
|
6
|
-
#
|
|
7
|
-
# * ::Kernel.raise, is implemented in Ruby for Rubinius. We don't wanna
|
|
8
|
-
# have the frame for it to align with the CRuby and JRuby implementations.
|
|
9
|
-
#
|
|
10
|
-
# * For internal methods location variables can be nil. We can't create a
|
|
11
|
-
# bindings for them.
|
|
12
|
-
#
|
|
13
|
-
# * Bindings from the current file are considered internal and ignored.
|
|
14
|
-
#
|
|
15
|
-
# We do that all that so we can align the bindings with the backtraces
|
|
16
|
-
# entries.
|
|
17
|
-
class InternalLocationFilter
|
|
18
|
-
def initialize(locations)
|
|
19
|
-
@locations = locations
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def filter
|
|
23
|
-
@locations.reject do |location|
|
|
24
|
-
location.file.start_with?('kernel/delta/kernel.rb') ||
|
|
25
|
-
location.file == __FILE__ ||
|
|
26
|
-
location.variables.nil?
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Gets the current bindings for all available Ruby frames.
|
|
32
|
-
#
|
|
33
|
-
# Filters the internal Rubinius and WebConsole frames.
|
|
34
|
-
def self.current_bindings
|
|
35
|
-
locations = ::Rubinius::VM.backtrace(1, true)
|
|
36
|
-
|
|
37
|
-
InternalLocationFilter.new(locations).filter.map do |location|
|
|
38
|
-
Binding.setup(
|
|
39
|
-
location.variables,
|
|
40
|
-
location.variables.method,
|
|
41
|
-
location.constant_scope,
|
|
42
|
-
location.variables.self,
|
|
43
|
-
location
|
|
44
|
-
)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
::Exception.class_eval do
|
|
51
|
-
def bindings
|
|
52
|
-
@bindings || []
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
::Rubinius.singleton_class.class_eval do
|
|
57
|
-
def raise_exception_with_current_bindings(exc)
|
|
58
|
-
if exc.bindings.empty?
|
|
59
|
-
exc.instance_variable_set(:@bindings, WebConsole::Rubinius.current_bindings)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
raise_exception_without_current_bindings(exc)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
alias_method :raise_exception_without_current_bindings, :raise_exception
|
|
66
|
-
alias_method :raise_exception, :raise_exception_with_current_bindings
|
|
67
|
-
end
|
data/lib/web_console/response.rb
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module WebConsole
|
|
2
|
-
# A response object that writes content before the closing </body> tag, if
|
|
3
|
-
# possible.
|
|
4
|
-
#
|
|
5
|
-
# The object quacks like Rack::Response.
|
|
6
|
-
class Response < Struct.new(:body, :status, :headers)
|
|
7
|
-
def write(content)
|
|
8
|
-
raw_body = Array(body).first.to_s
|
|
9
|
-
|
|
10
|
-
if position = raw_body.rindex('</body>')
|
|
11
|
-
raw_body.insert(position, content)
|
|
12
|
-
else
|
|
13
|
-
raw_body << content
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
self.body = raw_body
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def finish
|
|
20
|
-
Rack::Response.new(body, status, headers).finish
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
namespace :test do
|
|
2
|
-
desc "Run tests for templates"
|
|
3
|
-
task templates: "templates:all"
|
|
4
|
-
|
|
5
|
-
namespace :templates do
|
|
6
|
-
task all: [ :daemonize, :npm, :rackup, :wait, :mocha, :kill, :exit ]
|
|
7
|
-
task serve: [ :npm, :rackup ]
|
|
8
|
-
|
|
9
|
-
work_dir = Pathname(EXPANDED_CWD).join("test/templates")
|
|
10
|
-
pid_file = Pathname(Dir.tmpdir).join("web_console.#{SecureRandom.uuid}.pid")
|
|
11
|
-
runner_uri = URI.parse("http://localhost:29292/html/spec_runner.html")
|
|
12
|
-
rackup_opts = "-p #{runner_uri.port}"
|
|
13
|
-
test_result = nil
|
|
14
|
-
|
|
15
|
-
def need_to_wait?(uri)
|
|
16
|
-
Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
|
|
17
|
-
rescue Errno::ECONNREFUSED
|
|
18
|
-
retry if yield
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
task :daemonize do
|
|
22
|
-
rackup_opts += " -D -P #{pid_file}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
task :npm do
|
|
26
|
-
Dir.chdir(work_dir) { system "npm install --silent" }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
task :rackup do
|
|
30
|
-
Dir.chdir(work_dir) { system "bundle exec rackup #{rackup_opts}" }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
task :wait do
|
|
34
|
-
cnt = 0
|
|
35
|
-
need_to_wait?(runner_uri) { sleep 1; cnt += 1; cnt < 5 }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
task :mocha do
|
|
39
|
-
Dir.chdir(work_dir) { test_result = system("$(npm bin)/mocha-phantomjs #{runner_uri}") }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
task :kill do
|
|
43
|
-
system "kill #{File.read pid_file}"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
task :exit do
|
|
47
|
-
exit test_result
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require 'ipaddr'
|
|
2
|
-
|
|
3
|
-
module WebConsole
|
|
4
|
-
# Whitelist of allowed networks that can access Web Console.
|
|
5
|
-
#
|
|
6
|
-
# Networks are represented by standard IPAddr and can be either IPv4 or IPv6
|
|
7
|
-
# networks.
|
|
8
|
-
class Whitelist
|
|
9
|
-
# IPv4 and IPv6 localhost should be always whitelisted.
|
|
10
|
-
ALWAYS_WHITELISTED_NETWORKS = %w( 127.0.0.0/8 ::1 )
|
|
11
|
-
|
|
12
|
-
def initialize(networks = nil)
|
|
13
|
-
@networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def include?(network)
|
|
17
|
-
@networks.any? { |whitelist| whitelist.include?(network.to_s) }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def to_s
|
|
21
|
-
@networks.map(&method(:human_readable_ipaddr)).join(', ')
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def normalize_networks(networks)
|
|
27
|
-
Array(networks).concat(ALWAYS_WHITELISTED_NETWORKS)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def coerce_network_to_ipaddr(network)
|
|
31
|
-
if network.is_a?(IPAddr)
|
|
32
|
-
network
|
|
33
|
-
else
|
|
34
|
-
IPAddr.new(network)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def human_readable_ipaddr(ipaddr)
|
|
39
|
-
ipaddr.to_range.to_s.split('..').uniq.join('/')
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|