Skip to content
Browse files

Testing and such

  • Loading branch information...
1 parent e33a252 commit 5d100de1559e3b026194754fc7b120e3f551fb02 @duckinator committed Feb 3, 2012
Showing with 54 additions and 7 deletions.
  1. 0 .gemtest
  2. +14 −2 Rakefile
  3. 0 bin/sicuro
  4. +3 −3 lib/sicuro/base.rb
  5. +4 −2 sicuro.gemspec
  6. +23 −0 test/sicuro_test.rb
  7. +10 −0 test/teststrap.rb
View
0 .gemtest
No changes.
View
16 Rakefile
@@ -1,3 +1,15 @@
-require 'bundler'
+require 'bundler/gem_tasks'
-Bundler::GemHelper.install_tasks
+require 'rake'
+require 'rake/testtask'
+
+desc "Run all tests"
+task :test do
+ Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.pattern = "test/**/*_test.rb"
+ t.verbose = false
+ end
+end
+
+task :default => :test
View
0 bin/sicuro 100644 → 100755
File mode changed.
View
6 lib/sicuro/base.rb
@@ -9,8 +9,8 @@ def self.setup(timelimit=5, memlimit=10)
@@code_start =
"require #{__FILE__.inspect};" +
- "#{self.class.name}.setup(#{@@timelimit.inspect}, #{@@memlimit.inspect});" +
- "puts #{self.class.name}._safe_eval "
+ "Sicuro.setup(#{@@timelimit.inspect}, #{@@memlimit.inspect});" +
+ "print Sicuro._safe_eval "
end
def self.eval(code)
@@ -21,7 +21,7 @@ def self.eval(code)
rescue Timeout::Error
'<timeout hit>'
rescue NameError
- SafeEval.setup
+ Sicuro.setup
retry
end
end
View
6 sicuro.gemspec
@@ -4,7 +4,7 @@ require 'sicuro/version'
Gem::Specification.new do |s|
s.name = 'sicuro'
- s.version = Mygem::VERSION
+ s.version = Sicuro::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Nick Markwell']
s.email = ['nick@duckinator.net']
@@ -13,7 +13,9 @@ Gem::Specification.new do |s|
s.description = %q{Safe ruby code execution in a standard ruby environment. Does not use a chroot, jail, etc. No special permissions required.}
s.add_runtime_dependency 'fakefs'
- s.add_development_dependency 'rspec', '~>2.5.0'
+ #s.add_development_dependency 'rspec', '~>2.5.0'
+ s.add_development_dependency 'riot', '>= 0'
+ s.add_development_dependency 'bundler', '~> 1.0.0'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
View
23 test/sicuro_test.rb
@@ -0,0 +1,23 @@
+require 'teststrap'
+
+context 'Sicuro - ' do
+ context 'printing text' do
+ asserts('hi') { Sicuro.eval('puts "hi"') }
+ end
+
+ context 'return value' do
+ asserts('"hi"') { Sicuro.eval('"hi"') }
+ asserts('"hi"') { Sicuro.eval("'hi'") }
+ asserts('1') { Sicuro.eval('1') }
+ asserts('RuntimeError: ') { Sicuro.eval('fail') }
+ asserts('RuntimeError: ') { Sicuro.eval('fail') }
+ end
+
+ context 'timeout' do
+ asserts('<timeout hit>') { Sicuro.eval('sleep 6') }
+
+ # The following crashed many safe eval systems, including many versions of
+ # rubino, where sicuro was pulled from.
+ asserts('<timeout hit>') { Sicuro.eval('def Exception.to_s;loop{};end;loop{}') }
+ end
+end
View
10 test/teststrap.rb
@@ -0,0 +1,10 @@
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'riot'
+require 'sicuro'

0 comments on commit 5d100de

Please sign in to comment.
Something went wrong with that request. Please try again.