bullring 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bullring/version.rb +1 -1
- data/lib/bullring/workers/racer_dev_worker.rb +167 -0
- data/lib/bullring/workers/rhino_server.sh +1 -1
- metadata +21 -20
data/lib/bullring/version.rb
CHANGED
@@ -0,0 +1,167 @@
|
|
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
|
+
|
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.7.
|
4
|
+
version: 0.7.4
|
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-05-
|
12
|
+
date: 2012-05-04 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uglifier
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153389400 !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: *2153389400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: execjs
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153388520 !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: *2153388520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: therubyracer
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153387820 !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: *2153387820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: therubyrhino
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153387180 !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: *2153387180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3
|
60
|
-
requirement: &
|
60
|
+
requirement: &2153386180 !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: *2153386180
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &2153385360 !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: *2153385360
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: test-unit
|
82
|
-
requirement: &
|
82
|
+
requirement: &2153384700 !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: *2153384700
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: ruby-debug19
|
93
|
-
requirement: &
|
93
|
+
requirement: &2153383880 !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: *2153383880
|
102
102
|
description: Safely run untrusted Javascript from Ruby
|
103
103
|
email:
|
104
104
|
- jps@kindlinglabs.com
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/bullring/util/network.rb
|
115
115
|
- lib/bullring/version.rb
|
116
116
|
- lib/bullring/worker.rb
|
117
|
+
- lib/bullring/workers/racer_dev_worker.rb
|
117
118
|
- lib/bullring/workers/rhino_server.rb
|
118
119
|
- lib/bullring/workers/rhino_server.sh
|
119
120
|
- lib/bullring/workers/rhino_server_worker.rb
|
@@ -177,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
178
|
version: '0'
|
178
179
|
segments:
|
179
180
|
- 0
|
180
|
-
hash: -
|
181
|
+
hash: -2698416548869913159
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
none: false
|
183
184
|
requirements:
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
version: '0'
|
187
188
|
segments:
|
188
189
|
- 0
|
189
|
-
hash: -
|
190
|
+
hash: -2698416548869913159
|
190
191
|
requirements: []
|
191
192
|
rubyforge_project:
|
192
193
|
rubygems_version: 1.8.6
|