secure 0.1.0 → 0.1.1
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.
- data/lib/secure/child_process.rb +6 -4
- data/lib/secure/runner.rb +1 -1
- data/lib/secure/version.rb +1 -1
- data/spec/secure_spec.rb +11 -0
- metadata +3 -3
data/lib/secure/child_process.rb
CHANGED
@@ -3,7 +3,7 @@ module Secure
|
|
3
3
|
def initialize(opts, read_file, write_file)
|
4
4
|
read_file.close
|
5
5
|
@pipe = write_file
|
6
|
-
@timeout = opts[:timeout]
|
6
|
+
@timeout = opts[:timeout]
|
7
7
|
end
|
8
8
|
|
9
9
|
def guard_threads
|
@@ -15,14 +15,16 @@ module Secure
|
|
15
15
|
$SAFE=3
|
16
16
|
yield
|
17
17
|
end
|
18
|
-
|
19
|
-
guard_threads << GuardThread.kill_thread_on_timeout(@timeout, thread)
|
20
|
-
|
18
|
+
decorate_with_guard_threads(thread)
|
21
19
|
Response.success(thread.value)
|
22
20
|
rescue Exception => e
|
23
21
|
Response.error(e)
|
24
22
|
end
|
25
23
|
|
24
|
+
def decorate_with_guard_threads(thread)
|
25
|
+
GuardThread.kill_thread_on_timeout(@timeout, thread) if @timeout
|
26
|
+
end
|
27
|
+
|
26
28
|
def execute
|
27
29
|
ret = safely_run_block { yield }
|
28
30
|
@pipe.write(Marshal.dump(ret))
|
data/lib/secure/runner.rb
CHANGED
data/lib/secure/version.rb
CHANGED
data/spec/secure_spec.rb
CHANGED
@@ -91,4 +91,15 @@ describe Secure do
|
|
91
91
|
response.should be_success
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
context "error information" do
|
96
|
+
it "should know where the syntax is invalid" do
|
97
|
+
string = "while true; end; end"
|
98
|
+
response = Secure.ly({}, string) do |string|
|
99
|
+
eval(string)
|
100
|
+
end
|
101
|
+
response.should_not be_success
|
102
|
+
response.error.should be_a(SyntaxError)
|
103
|
+
end
|
104
|
+
end
|
94
105
|
end
|
metadata
CHANGED