dia 1.4.pre.2 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS.md CHANGED
@@ -1,10 +1,13 @@
1
1
  ## NEWS
2
2
 
3
+ ### 1.4
4
+ * A typo broke support for launching applications in a sandbox. (Bug affects 1.3 and all the 1.4 *pre* releases)
3
5
  * Mac OSX 10.5 reported as working! (Bug fix)
4
6
  Many thanks to Josh Creek for reporting and helping me debug this bug.
5
7
  * Use ffi\_lib() to explicitly load the dynamic library "sandbox", or "System"
6
8
  * Depend explicitly on FFI v0.6.2
7
9
  * Dia::Sandbox#run accepts a variable amount of arguments that will be passed onto the block supplied to the constructer.
10
+ * Added "test/\*\*/*.rb" to the gem specification as test files..
8
11
 
9
12
  ### 1.3
10
13
  * Added Dia::Sandbox#running? to check if a process running a sandbox is alive or not.
data/TODO.md CHANGED
@@ -1,7 +1,8 @@
1
1
  ## TODO
2
2
 
3
3
  ### 1.4
4
- * If you're going to run a block under a sandbox, make Dia::Sandbox#run accept *args so they may be passed onto the block.
4
+ * Dia::Sandbox.run() doesn't use @app to launch a process, but uses @app\_path which was removed in 1.3
5
+ * If you're going to run a block under a sandbox, make Dia::Sandbox#run accept *args so they may be passed onto the block.
5
6
 
6
7
  ### 1.3
7
8
  * Remove link to experimental branch in gemspec before release
data/lib/dia.rb CHANGED
@@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), 'dia/commonapi.rb')
5
5
  require File.join(File.dirname(__FILE__), 'dia/sandbox.rb')
6
6
 
7
7
  module Dia
8
- VERSION = '1.4.pre.2'
8
+ VERSION = '1.4'
9
9
  class SandboxException < StandardError; end
10
10
  end
11
11
 
@@ -57,11 +57,11 @@ module Dia
57
57
 
58
58
  @pid = fork do
59
59
  if sandbox_init(FFI::MemoryPointer.from_string(@profile), 0x0001, err = FFI::MemoryPointer.new(:pointer)) == -1
60
- raise Dia::SandboxException, "Failed to initialize sandbox (#{err.read_pointer.read_string}"
60
+ raise Dia::SandboxException, "Failed to initialize sandbox (#{err.read_pointer.read_string})"
61
61
  end
62
62
 
63
- if @app_path
64
- exec(@app_path)
63
+ if @app
64
+ exec(@app)
65
65
  else
66
66
  @blk.call(*args)
67
67
  end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'socket'
3
+ require 'baretest'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dia')
@@ -0,0 +1,23 @@
1
+ BareTest.suite "Dia::Sandbox#running?", :tags => [ :running? ] do
2
+
3
+ assert 'Confirm that Dia::Sandbox#running? returns true when a sandbox is running' do
4
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
5
+ sleep(20)
6
+ end
7
+
8
+ sandbox.run
9
+ equal(true, sandbox.running?)
10
+ sandbox.terminate
11
+ end
12
+
13
+ assert 'Confirm that Dia::Sandbox#running? returns false when a sandbox is not running' do
14
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
15
+ sleep(20)
16
+ end
17
+ sandbox.run
18
+ sandbox.terminate
19
+ sleep(1)
20
+ equal(false, sandbox.running?)
21
+ end
22
+
23
+ end
@@ -0,0 +1,34 @@
1
+ # See /test/suite/run_block_in_sandbox_test.rb for tests that confirm sandboxes are successfully created ..
2
+ BareTest.suite 'Dia::Sandbox.new', :tags => [ :new ] do
3
+
4
+ assert 'Passing no arguments to the constructer will raise an ArgumentError' do
5
+ raises(ArgumentError) do
6
+ Dia::Sandbox.new
7
+ end
8
+ end
9
+
10
+ assert 'Passing only a profile to the constructer will raise an ArgumentError' do
11
+ raises(ArgumentError) do
12
+ Dia::Sandbox.new(Dia::Profiles::NO_INTERNET)
13
+ end
14
+ end
15
+
16
+ assert 'Passing a profile, application path, and a block will raise an ArgumentError' do
17
+ raises(ArgumentError) do
18
+ Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES, 'ls') do
19
+ puts "foo"
20
+ end
21
+ end
22
+ end
23
+
24
+ assert 'Passing an application path and a profile will raise nothing' do
25
+ Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES, 'ls')
26
+ end
27
+
28
+ assert 'Passing a block and a profile will raise nothing' do
29
+ Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
30
+ puts "foo"
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,126 @@
1
+ # TODO: Add assertion for Dia::Profiles::NO_OS_SERVICES
2
+
3
+ BareTest.suite 'Dia::Sandbox#run', :tags => [ :run ] do
4
+
5
+ setup do
6
+ @reader, @writer = IO.pipe
7
+ end
8
+
9
+ assert 'A Ruby block will not be able to access the internet' do
10
+
11
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_INTERNET) do
12
+ begin
13
+ @reader.close
14
+ TCPSocket.open('http://www.google.com', 80)
15
+ @writer.write('false')
16
+ rescue SocketError, SystemCallError => e
17
+ @writer.write('true')
18
+ end
19
+ end
20
+
21
+ # a child process is spawned, and the block passed to the constructer executed.
22
+ sandbox.run
23
+
24
+ # back in the parent.
25
+ @writer.close
26
+ successful = @reader.gets
27
+ @reader.close
28
+
29
+ equal('true', successful)
30
+ end
31
+
32
+ assert 'A Ruby block will not be able to write the filesystem' do
33
+
34
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_FILESYSTEM_WRITE) do
35
+ begin
36
+ @reader.close
37
+ File.open('foo.txt', 'w')
38
+ @writer.write('false')
39
+ rescue SystemCallError => e
40
+ @writer.write('true')
41
+ end
42
+ end
43
+
44
+ # a child process is spawned, and the block passed to the constructer executed.
45
+ sandbox.run
46
+
47
+ # back in the parent.
48
+ @writer.close
49
+ successful = @reader.gets
50
+ @reader.close
51
+
52
+ equal('true', successful)
53
+ end
54
+
55
+ assert 'A Ruby block will not be able to write to the filesystem except when writing to /tmp' do
56
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_FILESYSTEM_WRITE_EXCEPT_TMP) do
57
+ marshal = []
58
+ begin
59
+ marshal = Marshal.dump(marshal)
60
+ @reader.close
61
+ File.open('foo.txt', 'w')
62
+ @writer.write('false')
63
+ rescue SystemCallError => e
64
+ marshal = Marshal.dump(Marshal.load(marshal) << 'true')
65
+ end
66
+
67
+ begin
68
+ File.open('/tmp/foo.txt', 'w') do |f|
69
+ f.puts 'foo'
70
+ end
71
+ @writer.write(marshal = Marshal.dump(Marshal.load(marshal) << 'true'))
72
+ rescue SystemCallError => e
73
+ @writer.write('false')
74
+ end
75
+ end
76
+
77
+ # a child process is spawned, and the block passed to the constructer executed.
78
+ sandbox.run
79
+
80
+ # back in the parent.
81
+ @writer.close
82
+ successful = Marshal.load(@reader.gets)
83
+ @reader.close
84
+
85
+ equal(['true', 'true'], successful)
86
+ end
87
+
88
+ assert 'A Ruby block will not be able to do any socket based communication' do
89
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_NETWORKING) do
90
+ begin
91
+ @reader.close
92
+ TCPSocket.open('http://www.youtube.com', 80)
93
+ @writer.write('false')
94
+ rescue SocketError => e
95
+ @writer.write('true')
96
+ end
97
+ end
98
+
99
+ # a child process is spawned, and the block passed to the constructer executed.
100
+ sandbox.run
101
+
102
+ # back in the parent.
103
+ @writer.close
104
+ successful = @reader.gets
105
+ @reader.close
106
+
107
+ equal('true', successful)
108
+ end
109
+
110
+ assert 'A Ruby block will be able to receive arguments through #run' do
111
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_INTERNET) do |foo, bar|
112
+ @reader.close
113
+ @writer.write(foo+bar)
114
+ @writer.close
115
+ end
116
+ sandbox.run('foo', 'bar')
117
+
118
+ # back in the parent..
119
+ @writer.close
120
+ answer = @reader.gets
121
+ @reader.close
122
+
123
+ equal('foobar', answer)
124
+ end
125
+
126
+ end
@@ -0,0 +1,21 @@
1
+ BareTest.suite 'Dia::Sandbox#terminate', :tags => [ :terminate ] do
2
+
3
+ assert 'A spawned sandbox will be terminated with the #terminate method' do
4
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
5
+ sleep(100)
6
+ end
7
+
8
+ sandbox.run
9
+ sandbox.terminate
10
+ sleep(1) # Allow the process time to die ..
11
+
12
+ begin
13
+ Process.kill('SIGKILL', sandbox.pid)
14
+ false
15
+ rescue Errno::ESRCH => e
16
+ true
17
+ end
18
+
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,13 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dia
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - pre
9
- - 2
10
- version: 1.4.pre.2
8
+ version: "1.4"
11
9
  platform: ruby
12
10
  authors:
13
11
  - Robert Gleeson
@@ -15,7 +13,7 @@ autorequire:
15
13
  bindir: bin
16
14
  cert_chain: []
17
15
 
18
- date: 2010-02-25 00:00:00 +00:00
16
+ date: 2010-02-27 00:00:00 +00:00
19
17
  default_executable:
20
18
  dependencies:
21
19
  - !ruby/object:Gem::Dependency
@@ -46,6 +44,18 @@ dependencies:
46
44
  version: 0.2.4
47
45
  type: :development
48
46
  version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
49
59
  description: Dia allows you to sandbox application(s) or block(s) of ruby on the OSX platform by restricting access to operating system resources
50
60
  email: rob@flowof.info
51
61
  executables: []
@@ -68,7 +78,7 @@ has_rdoc: yard
68
78
  homepage:
69
79
  licenses: []
70
80
 
71
- post_install_message: " ********************************************************************\n Dia (1.4.pre.2)\n \n The Mac OSX 10.5 bug has been reported as fixed! \n Many thanks to \"Josh Creek\" for reporting, and helping me debug the\n problem until we solved it.\n ********************************************************************\n"
81
+ post_install_message: " ********************************************************************\n Dia (1.4)\n \n * A typo that would result in being unable to launch an application\n under a sandbox has been fixed (1.3 and 1.4.pre were affected)\n \n * The Mac OSX 10.5 bug has been reported as fixed! \n Many thanks to \"Josh Creek\" for reporting, and helping me debug the\n problem until we solved it.\n ********************************************************************\n"
72
82
  rdoc_options: []
73
83
 
74
84
  require_paths:
@@ -82,13 +92,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
92
  version: "0"
83
93
  required_rubygems_version: !ruby/object:Gem::Requirement
84
94
  requirements:
85
- - - ">"
95
+ - - ">="
86
96
  - !ruby/object:Gem::Version
87
97
  segments:
88
- - 1
89
- - 3
90
- - 1
91
- version: 1.3.1
98
+ - 0
99
+ version: "0"
92
100
  requirements: []
93
101
 
94
102
  rubyforge_project:
@@ -96,5 +104,9 @@ rubygems_version: 1.3.6
96
104
  signing_key:
97
105
  specification_version: 3
98
106
  summary: Dia allows you to sandbox application(s) or block(s) of ruby on the OSX platform by restricting access to operating system resources
99
- test_files: []
100
-
107
+ test_files:
108
+ - test/setup.rb
109
+ - test/suite/check_if_sandbox_is_alive_test.rb
110
+ - test/suite/passing_parameters_to_constructer_test.rb
111
+ - test/suite/run_block_in_sandbox_test.rb
112
+ - test/suite/terminate_sandbox_test.rb