tame 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/spec/tame_spec.rb +112 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9d2493ff758b598a3988a39552012eb3b086e22
4
- data.tar.gz: 6ed68100d75fc8fc524ba0955b3d4f5d18f53139
3
+ metadata.gz: 412c68e7811b25741099daa630f9a57ae84cdd1f
4
+ data.tar.gz: a4bdb9fcecebb3ccd0387a94f0eeb715d60d5333
5
5
  SHA512:
6
- metadata.gz: 1afe5a3f09dc781dd35e3c70720434178861aec0aa9171453929c34842b022d003bb940f59d05857cc73db44f096b0b689db3cc1de02cfbec265200809755bc0
7
- data.tar.gz: eb16dcd0a7b6b5b981ca3f9eb7c8e41648d2668bf4022d10060f51e854f3fb10631861a3ca7bb8a5e2df2b577dfab0f587914787bff14486f8a5ebecf3e057db
6
+ metadata.gz: 65ae3d8a4e5ae5dcb63f73ced86b063cb4d6f947bbad34c0e20b60f8991c8a8ebcecaadd8c1b6680694809bc1ab433bb561e8aa9a57cab11dee9fa6e466704db
7
+ data.tar.gz: c1e31b7af453ee250e4e3fd4aabb0c25319418b8046ff29b95634683a7233cc5f3cd41afab186997211c4572f57450e9653cb87c1d85ab2c053b97553ae471f5
@@ -0,0 +1,112 @@
1
+ require './lib/tame'
2
+
3
+ gem 'minitest'
4
+ require 'minitest/autorun'
5
+
6
+ RUBY = ENV['RUBY'] || 'ruby'
7
+
8
+ describe "Tame.tame" do
9
+ def _tamed(status, args, code)
10
+ system(RUBY, '-I', 'lib', '-r', 'tame', '-e', "Tame.tame(#{Array(args).map(&:inspect).join(',')}); #{code}").must_equal status
11
+ end
12
+
13
+ def tamed(code, *args)
14
+ _tamed(true, args, code)
15
+ end
16
+
17
+ def untamed(code, *args)
18
+ _tamed(false, args, code)
19
+ end
20
+
21
+ def with_lib(lib)
22
+ rubyopt = ENV['RUBYOPT']
23
+ ENV['RUBYOPT'] = "#{rubyopt} -r#{lib}"
24
+ yield
25
+ ensure
26
+ ENV['RUBYOPT'] = rubyopt
27
+ end
28
+
29
+ after do
30
+ Dir['spec/_*'].each{|f| File.delete(f)}
31
+ Dir['*.core'].each{|f| File.delete(f)}
32
+ end
33
+
34
+ it "should raise a KeyError for unsupported exceptions" do
35
+ proc{Tame.tame(:foo)}.must_raise ArgumentError
36
+ end
37
+
38
+ it "should produce a core file on failure if abort is use" do
39
+ Dir['*.core'].must_equal []
40
+ untamed("File.read('#{__FILE__}')")
41
+ Dir['*.core'].must_equal []
42
+ untamed("File.read('#{__FILE__}')", :abort)
43
+ Dir['*.core'].wont_equal []
44
+ end
45
+
46
+ it "should allow reading files if :rpath is used" do
47
+ untamed("File.read('#{__FILE__}')")
48
+ tamed("File.read('#{__FILE__}')", :rpath)
49
+ end
50
+
51
+ it "should allow creating files if :cpath and :wpath are used" do
52
+ untamed("File.open('spec/_test', 'w'){}")
53
+ untamed("File.open('spec/_test', 'w'){}", :cpath)
54
+ untamed("File.open('spec/_test', 'w'){}", :wpath)
55
+ File.file?('spec/_test').must_equal false
56
+ tamed("File.open('#{'spec/_test'}', 'w'){}", :cpath, :wpath)
57
+ File.file?('spec/_test').must_equal true
58
+ end
59
+
60
+ it "should allow writing to files if :wpath and rpath are used" do
61
+ File.open('spec/_test', 'w'){}
62
+ untamed("File.open('spec/_test', 'r+'){}")
63
+ tamed("File.open('#{'spec/_test'}', 'r+'){|f| f.write '1'}", :wpath, :rpath)
64
+ File.read('spec/_test').must_equal '1'
65
+ end
66
+
67
+ it "should allow dns lookups if :dns is used" do
68
+ with_lib('socket') do
69
+ untamed("Socket.gethostbyname('google.com')")
70
+ tamed("Socket.gethostbyname('google.com')", :dns)
71
+ end
72
+ end
73
+
74
+ it "should allow internet access if :inet is used" do
75
+ with_lib('net/http') do
76
+ untamed("Net::HTTP.get('127.0.0.1', '/index.html') rescue nil")
77
+ args = [:inet]
78
+ # rpath necessary on ruby < 2.1, as it calls stat
79
+ args << :rpath if RUBY_VERSION < '2.1'
80
+ tamed("Net::HTTP.get('127.0.0.1', '/index.html') rescue nil", *args)
81
+ end
82
+ end
83
+
84
+ it "should allow killing programs if :proc is used" do
85
+ untamed("Process.kill(:INFO, $$)")
86
+ tamed("Process.kill(:INFO, $$)", :proc)
87
+ end
88
+
89
+ it "should allow creating temp files if :tmppath and :rpath are used" do
90
+ with_lib('tempfile') do
91
+ untamed("Tempfile.new('foo')")
92
+ untamed("Tempfile.new('foo')", :tmppath)
93
+ untamed("Tempfile.new('foo')", :rpath)
94
+ args = [:tmppath, :rpath]
95
+ # cpath necessary on ruby < 2.0, as it calls mkdir
96
+ args << :cpath if RUBY_VERSION < '2.0'
97
+ tamed("Tempfile.new('foo')", *args)
98
+ end
99
+ end
100
+
101
+ it "should allow unix sockets if :unix and :rpath is used" do
102
+ require 'socket'
103
+ us = UNIXServer.new('spec/_sock')
104
+ with_lib('socket') do
105
+ untamed("UNIXSocket.new('spec/_sock').send('u', 0)")
106
+ untamed("UNIXSocket.new('spec/_sock').send('u', 0)", :unix)
107
+ untamed("UNIXSocket.new('spec/_sock').send('u', 0)" ,:rpath)
108
+ tamed("UNIXSocket.new('spec/_sock').send('t', 0)", :unix, :rpath)
109
+ end
110
+ us.accept.read.must_equal 't'
111
+ end
112
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tame
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -33,7 +33,8 @@ files:
33
33
  - Rakefile
34
34
  - ext/tame/extconf.rb
35
35
  - ext/tame/tame.c
36
- homepage: http://github.com/jeremyevans/tame_libs/ruby
36
+ - spec/tame_spec.rb
37
+ homepage: https://github.com/jeremyevans/tame_libs/tree/master/ruby
37
38
  licenses:
38
39
  - MIT
39
40
  metadata: {}