secure 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/secure/child_process.rb +11 -1
- data/lib/secure/version.rb +1 -1
- data/spec/secure/runner_spec.rb +9 -0
- metadata +6 -6
data/lib/secure/child_process.rb
CHANGED
@@ -11,19 +11,29 @@ module Secure
|
|
11
11
|
@pipe_stdout = opts[:pipe_stdout]
|
12
12
|
@pipe_stderr = opts[:pipe_stderr]
|
13
13
|
@pipe_stdin = opts[:pipe_stdin]
|
14
|
+
@run_before = opts[:run_before]
|
14
15
|
end
|
15
16
|
|
16
17
|
def guard_threads
|
17
18
|
@guard_threads || []
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def set_resource_limits
|
21
22
|
Process::setrlimit(Process::RLIMIT_AS, @limit_memory) if @limit_memory
|
22
23
|
Process::setrlimit(Process::RLIMIT_CPU, @limit_cpu, 2 + @limit_cpu) if @limit_cpu
|
24
|
+
end
|
25
|
+
|
26
|
+
def redirect_files
|
23
27
|
$stdout.reopen(@pipe_stdout) if @pipe_stdout
|
24
28
|
$stderr.reopen(@pipe_stderr) if @pipe_stderr
|
25
29
|
$stdin.reopen(@pipe_stdin) if @pipe_stdin
|
30
|
+
end
|
31
|
+
|
32
|
+
def safely_run_block
|
33
|
+
set_resource_limits
|
34
|
+
redirect_files
|
26
35
|
thread = Thread.start do
|
36
|
+
@run_before.call if @run_before
|
27
37
|
$SAFE=3
|
28
38
|
yield
|
29
39
|
end
|
data/lib/secure/version.rb
CHANGED
data/spec/secure/runner_spec.rb
CHANGED
@@ -24,6 +24,15 @@ module Secure
|
|
24
24
|
response.value.should == 6
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should accept a block that is run before safeing" do
|
28
|
+
run_before = lambda { $FOO = $SAFE }
|
29
|
+
response = Runner.new(:run_before => run_before ).run do
|
30
|
+
$FOO
|
31
|
+
end
|
32
|
+
response.should be_success
|
33
|
+
response.value.should == 0
|
34
|
+
end
|
35
|
+
|
27
36
|
context "safe value" do
|
28
37
|
it "should be set to 3" do
|
29
38
|
response = Runner.new.run do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
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: 2011-
|
12
|
+
date: 2011-10-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70187516791060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70187516791060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70187516790620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70187516790620
|
36
36
|
description: see summary
|
37
37
|
email:
|
38
38
|
- tejas@gja.in
|