secure 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,9 @@ module Secure
8
8
  @timeout = opts[:timeout]
9
9
  @limit_memory = opts[:limit_memory]
10
10
  @limit_cpu = opts[:limit_cpu]
11
+ @pipe_stdout = opts[:pipe_stdout]
12
+ @pipe_stderr = opts[:pipe_stderr]
13
+ @pipe_stdin = opts[:pipe_stdin]
11
14
  end
12
15
 
13
16
  def guard_threads
@@ -17,6 +20,9 @@ module Secure
17
20
  def safely_run_block
18
21
  Process::setrlimit(Process::RLIMIT_AS, @limit_memory) if @limit_memory
19
22
  Process::setrlimit(Process::RLIMIT_CPU, @limit_cpu, 2 + @limit_cpu) if @limit_cpu
23
+ $stdout.reopen(@pipe_stdout) if @pipe_stdout
24
+ $stderr.reopen(@pipe_stderr) if @pipe_stderr
25
+ $stdin.reopen(@pipe_stdin) if @pipe_stdin
20
26
  thread = Thread.start do
21
27
  $SAFE=3
22
28
  yield
@@ -1,3 +1,3 @@
1
1
  module Secure
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -123,5 +123,42 @@ module Secure
123
123
  response.error.should be_a(SyntaxError)
124
124
  end
125
125
  end
126
+
127
+ context "redirections" do
128
+ let(:pipe) { IO.pipe }
129
+ let(:read_file) { pipe[0] }
130
+ let(:write_file) { pipe[1] }
131
+
132
+ after(:each) do
133
+ write_file.close unless write_file.closed?
134
+ read_file.close unless read_file.closed?
135
+ end
136
+
137
+ it "redirects standard output" do
138
+ response = Runner.new(:pipe_stdout => write_file).run do
139
+ p "foobar"
140
+ end
141
+ write_file.close
142
+ read_file.read.should == "\"foobar\"\n"
143
+ end
144
+
145
+ it "redirects standard output" do
146
+ response = Runner.new(:pipe_stderr => write_file).run do
147
+ $stderr.puts "\"foobar\""
148
+ end
149
+ write_file.close
150
+ read_file.read.should == "\"foobar\"\n"
151
+ end
152
+
153
+ # This is pending because of some rspec wierdness that readline reads the first line of spec fil
154
+ pending "redirects standard input" do
155
+ write_file.puts "foobar"
156
+ write_file.close
157
+ response = Runner.new(:pipe_stdin => read_file).run do
158
+ readline
159
+ end
160
+ response.value.should == "foobar\n"
161
+ end
162
+ end
126
163
  end
127
164
  end
metadata CHANGED
@@ -1,62 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: secure
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tejas Dinkar
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-05 00:00:00 +05:30
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70273000901040 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 2
32
- - 6
33
- version: "2.6"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
34
22
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70273000901040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70273000900500 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
48
33
  type: :development
49
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *70273000900500
50
36
  description: see summary
51
- email:
37
+ email:
52
38
  - tejas@gja.in
53
39
  executables: []
54
-
55
40
  extensions: []
56
-
57
41
  extra_rdoc_files: []
58
-
59
- files:
42
+ files:
60
43
  - .gitignore
61
44
  - Gemfile
62
45
  - Rakefile
@@ -73,41 +56,31 @@ files:
73
56
  - spec/secure/runner_spec.rb
74
57
  - spec/secure_spec.rb
75
58
  - spec/spec_helper.rb
76
- has_rdoc: true
77
- homepage: ""
59
+ homepage: ''
78
60
  licenses: []
79
-
80
61
  post_install_message:
81
62
  rdoc_options: []
82
-
83
- require_paths:
63
+ require_paths:
84
64
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
86
66
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
72
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
103
77
  requirements: []
104
-
105
78
  rubyforge_project: secure
106
- rubygems_version: 1.6.2
79
+ rubygems_version: 1.8.7
107
80
  signing_key:
108
81
  specification_version: 3
109
82
  summary: gem to do things securely using ruby $SAFE
110
- test_files:
83
+ test_files:
111
84
  - spec/secure/response_spec.rb
112
85
  - spec/secure/runner_spec.rb
113
86
  - spec/secure_spec.rb