bullring 0.7.4 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bullring.rb +16 -22
- data/lib/bullring/util/dummy_logger.rb +10 -0
- data/lib/bullring/util/exceptions.rb +0 -1
- data/lib/bullring/util/server_proxy.rb +96 -0
- data/lib/bullring/util/server_registry.rb +283 -0
- data/lib/bullring/version.rb +1 -1
- data/lib/bullring/worker.rb +33 -13
- data/lib/bullring/workers/common.rb +66 -0
- data/lib/bullring/workers/racer_worker.rb +77 -0
- data/lib/bullring/workers/rhino_server.rb +81 -120
- data/lib/bullring/workers/rhino_server.sh +6 -5
- data/lib/bullring/workers/rhino_server_worker.rb +32 -61
- data/test/bullring_test.rb +44 -183
- data/test/dummy/log/development.log +152042 -0
- metadata +25 -22
- data/lib/bullring/workers/racer_dev_worker.rb +0 -167
- data/lib/bullring/workers/rhino_simple_worker.rb +0 -0
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.8'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uglifier
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164603660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164603660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: execjs
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164602220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164602220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: therubyracer
|
38
|
-
requirement: &
|
38
|
+
requirement: &2164600820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164600820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: therubyrhino
|
49
|
-
requirement: &
|
49
|
+
requirement: &2164599600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164599600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3
|
60
|
-
requirement: &
|
60
|
+
requirement: &2164598740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2164598740
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &2164597580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 3.2.2
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2164597580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: test-unit
|
82
|
-
requirement: &
|
82
|
+
requirement: &2164596700 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2164596700
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: ruby-debug19
|
93
|
-
requirement: &
|
93
|
+
requirement: &2164595620 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2164595620
|
102
102
|
description: Safely run untrusted Javascript from Ruby
|
103
103
|
email:
|
104
104
|
- jps@kindlinglabs.com
|
@@ -110,15 +110,18 @@ files:
|
|
110
110
|
- lib/bullring/js/jslint.js
|
111
111
|
- lib/bullring/js/jslint.min.js
|
112
112
|
- lib/bullring/util/drubied_process.rb
|
113
|
+
- lib/bullring/util/dummy_logger.rb
|
113
114
|
- lib/bullring/util/exceptions.rb
|
114
115
|
- lib/bullring/util/network.rb
|
116
|
+
- lib/bullring/util/server_proxy.rb
|
117
|
+
- lib/bullring/util/server_registry.rb
|
115
118
|
- lib/bullring/version.rb
|
116
119
|
- lib/bullring/worker.rb
|
117
|
-
- lib/bullring/workers/
|
120
|
+
- lib/bullring/workers/common.rb
|
121
|
+
- lib/bullring/workers/racer_worker.rb
|
118
122
|
- lib/bullring/workers/rhino_server.rb
|
119
123
|
- lib/bullring/workers/rhino_server.sh
|
120
124
|
- lib/bullring/workers/rhino_server_worker.rb
|
121
|
-
- lib/bullring/workers/rhino_simple_worker.rb
|
122
125
|
- lib/bullring.rb
|
123
126
|
- lib/scripts/server_console.sh
|
124
127
|
- lib/tasks/bullring_tasks.rake
|
@@ -178,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
181
|
version: '0'
|
179
182
|
segments:
|
180
183
|
- 0
|
181
|
-
hash: -
|
184
|
+
hash: -1121246813312791925
|
182
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
186
|
none: false
|
184
187
|
requirements:
|
@@ -187,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
190
|
version: '0'
|
188
191
|
segments:
|
189
192
|
- 0
|
190
|
-
hash: -
|
193
|
+
hash: -1121246813312791925
|
191
194
|
requirements: []
|
192
195
|
rubyforge_project:
|
193
196
|
rubygems_version: 1.8.6
|
@@ -1,167 +0,0 @@
|
|
1
|
-
require 'bullring/util/drubied_process'
|
2
|
-
|
3
|
-
module Bullring
|
4
|
-
|
5
|
-
class RacerDevWorker < Bullring::Worker
|
6
|
-
|
7
|
-
attr_reader :libraries
|
8
|
-
|
9
|
-
def discard
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@libraries = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def add_library(name, script)
|
17
|
-
rescue_me do
|
18
|
-
Bullring.logger.debug { "Bullring: Adding library named '#{name}'" }
|
19
|
-
@libraries[name] = script
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_library_file(name, filename)
|
24
|
-
raise NotYetImplemented
|
25
|
-
end
|
26
|
-
|
27
|
-
def check(script, options)
|
28
|
-
Bullring.logger.debug { "Bullring: Checking script with hash '#{script.hash}'" }
|
29
|
-
rescue_me do
|
30
|
-
V8::Context.open do |context|
|
31
|
-
context_wrapper {context.load(File.expand_path("../../js/jslint.min.js", __FILE__))}
|
32
|
-
|
33
|
-
jslintCall = <<-RACER_CALL
|
34
|
-
JSLINT("#{prepare_source(script)}", {devel: false,
|
35
|
-
bitwise: true,
|
36
|
-
undef: true,
|
37
|
-
continue: true,
|
38
|
-
unparam: true,
|
39
|
-
debug: true,
|
40
|
-
sloppy: true,
|
41
|
-
eqeq: true,
|
42
|
-
sub: true,
|
43
|
-
es5: true,
|
44
|
-
vars: true,
|
45
|
-
evil: true,
|
46
|
-
white: true,
|
47
|
-
forin: true,
|
48
|
-
passfail: false,
|
49
|
-
newcap: true,
|
50
|
-
nomen: true,
|
51
|
-
plusplus: true,
|
52
|
-
regexp: true,
|
53
|
-
maxerr: 50,
|
54
|
-
indent: 4});
|
55
|
-
RACER_CALL
|
56
|
-
|
57
|
-
duration, result = context_wrapper {context.eval(jslintCall + "JSLINT.errors")}
|
58
|
-
|
59
|
-
result = result.collect{|obj| obj.respond_to?(:to_h) ? obj.to_h : obj}
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def run(script, options)
|
65
|
-
Bullring.logger.debug { "Bullring: Running script with hash '#{script.hash}'" }
|
66
|
-
|
67
|
-
V8::Context.open(:sealed => @options[:run_is_sealed], :restrictable => @options[:run_is_restrictable]) do |context|
|
68
|
-
|
69
|
-
(options['library_names'] || []).each do |library_name|
|
70
|
-
library = @libraries[library_name] || fetch_library_script!(library_name)
|
71
|
-
context_wrapper {context.eval(library)}
|
72
|
-
end
|
73
|
-
|
74
|
-
duration, result = context_wrapper {context.eval(script)}
|
75
|
-
result.respond_to?(:to_h) ? result.to_h : result
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def alive?
|
80
|
-
true
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
|
85
|
-
def context_wrapper
|
86
|
-
begin
|
87
|
-
start_time = Time.now
|
88
|
-
result = yield
|
89
|
-
duration = Time.now - start_time
|
90
|
-
|
91
|
-
logger.debug {"#{logname}: Ran script (#{duration} secs); result: " + result.inspect}
|
92
|
-
|
93
|
-
return duration, result
|
94
|
-
rescue Rhino::JSError => e
|
95
|
-
logger.debug {"#{logname}: JSError! Cause: " + e.cause + "; Message: " + e.message}
|
96
|
-
raise Bullring::JSError, e.message.to_s, caller
|
97
|
-
rescue Rhino::RunawayScriptError, Rhino::ScriptTimeoutError => e
|
98
|
-
logger.debug {"#{logname}: Runaway Script: " + e.inspect}
|
99
|
-
raise Bullring::JSError, "Script took too long to run", caller
|
100
|
-
rescue NameError => e
|
101
|
-
logger.debug {"#{logname}: Name error: " + e.inspect}
|
102
|
-
rescue StandardError => e
|
103
|
-
logger.debug {"#{logname}: StandardError: " + e.inspect}
|
104
|
-
raise
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
ESCAPE_MAP = {
|
109
|
-
'\\' => '\\\\',
|
110
|
-
"\r\n" => '\n',
|
111
|
-
"\n" => '\n',
|
112
|
-
"\r" => '\n',
|
113
|
-
'"' => '\"',
|
114
|
-
"'" => '\''
|
115
|
-
}
|
116
|
-
|
117
|
-
def prepare_source(source)
|
118
|
-
# escape javascript characters (similar to Rails escape_javascript)
|
119
|
-
source.gsub!(/(\\|\r\n|[\n\r"'])/u) {|match| ESCAPE_MAP[match] }
|
120
|
-
source
|
121
|
-
end
|
122
|
-
|
123
|
-
# Goes back to the setup provider to the get the named script or throws an
|
124
|
-
# exception if there is no such script to retrieve.
|
125
|
-
def fetch_library_script!(name)
|
126
|
-
logger.debug {"#{logname}: The script named #{name} was not available so trying to fetch from clients"}
|
127
|
-
|
128
|
-
while (provider = @setup_providers.last)
|
129
|
-
begin
|
130
|
-
library_script = provider.libraries[name]
|
131
|
-
break if !library_script.nil?
|
132
|
-
rescue DRb::DRbConnError => e
|
133
|
-
logger.debug {"#{logname}: Could not connect to setup provider (its process probably died): " + e.inspect}
|
134
|
-
rescue StandardError => e
|
135
|
-
logger.error {"#{logname}: Encountered an unknown error searching setup providers for a script named #{name}: " + e.inspect}
|
136
|
-
ensure
|
137
|
-
# Toss the last element so we can continue searching prior elements
|
138
|
-
setup_providers.pop
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# If after looking through the providers we are still empty handed, raise an error
|
143
|
-
raise NameError, "Client doesn't have script named #{name}", caller if library_script.nil?
|
144
|
-
|
145
|
-
add_library(name, library_script)
|
146
|
-
end
|
147
|
-
|
148
|
-
def logname; "Bullring Server"; end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
class JSError < StandardError; end
|
153
|
-
|
154
|
-
def rescue_me
|
155
|
-
@times_rescued = 0
|
156
|
-
begin
|
157
|
-
yield
|
158
|
-
rescue Bullring::JSError => e
|
159
|
-
Bullring.logger.debug {"Bullring: Encountered a JSError: " + e.inspect}
|
160
|
-
raise e
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
File without changes
|