dia 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
1
+ suite('RubyBlock') do
2
+ suite('#run_nonblock') do
3
+ suite('Return values') do
4
+
5
+ exercise('When #run_nonblock has finished executing.') do
6
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
7
+ @result = dia.run_nonblock
8
+ end
9
+
10
+ verify('It will return the PID of the child process used to execute a sandbox.') do
11
+ @result.class == Fixnum
12
+ end
13
+
14
+ end
15
+
16
+ suite('Behavior') do
17
+
18
+ setup do
19
+ @result = nil
20
+ @reader, @writer = IO.pipe
21
+ end
22
+
23
+ exercise('Confirm the profile ' \
24
+ 'Dia::Profiles::NO_INTERNET ' \
25
+ 'is creating a working sandbox environment.') do
26
+
27
+ sandbox = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) do
28
+ begin
29
+ @reader.close
30
+ TCPSocket.open('http://www.google.com', 80)
31
+ @writer.write('false')
32
+ rescue SocketError, SystemCallError => e
33
+ @writer.write('true')
34
+ ensure
35
+ @writer.close
36
+ end
37
+ end
38
+
39
+ sandbox.run_nonblock
40
+ sleep(1)
41
+
42
+ @writer.close
43
+ @result = @reader.gets
44
+ @reader.close
45
+ end
46
+
47
+ verify(nil) do
48
+ @result == 'true'
49
+ end
50
+
51
+ exercise('Confirm the profile ' \
52
+ 'Dia::Profiles::NO_FILESYSTEM_WRITE ' \
53
+ 'is creating a working sandbox environment.') do
54
+ sandbox = Dia::RubyBlock.new(Dia::Profiles::NO_FILESYSTEM_WRITE) do
55
+ begin
56
+ @reader.close
57
+ File.open('/tmp/foo.txt', 'w') { |f| f.puts('fail') }
58
+ @writer.write('false')
59
+ rescue SocketError, SystemCallError => e
60
+ @writer.write('true')
61
+ ensure
62
+ @writer.close
63
+ end
64
+ end
65
+
66
+
67
+ sandbox.run_nonblock
68
+ sleep(1)
69
+
70
+ @writer.close
71
+ @result = @reader.gets
72
+ @reader.close
73
+ end
74
+
75
+ verify(nil) do
76
+ @result == 'true'
77
+ end
78
+
79
+ exercise('Confirm the profile ' \
80
+ 'Dia::Profiles::NO_FILESYSTEM_WRITE_EXCEPT_TMP ' \
81
+ 'is creating a working sandbox environment. ') do
82
+ sandbox = Dia::RubyBlock.new(Dia::Profiles::NO_FILESYSTEM_WRITE_EXCEPT_TMP) do
83
+ begin
84
+ @reader.close
85
+ out = Time.now.to_s
86
+ File.open('/tmp/%s.dia_test' % [ out ] , 'w') { |f| f.puts('success') }
87
+ File.open(File.join(ENV['HOME'], 'fail.txt')) { |f| f.puts('fail') }
88
+ @writer.write('false')
89
+ rescue SocketError, SystemCallError => e
90
+ if File.exists?('/tmp/%s.dia_test' % [ out ])
91
+ @writer.write('true')
92
+ else
93
+ @writer.write('false')
94
+ end
95
+ ensure
96
+ @writer.close
97
+ end
98
+ end
99
+
100
+ sandbox.run_nonblock
101
+ sleep(1)
102
+
103
+ @writer.close
104
+ @result = @reader.gets
105
+ @reader.close
106
+ end
107
+
108
+ verify(nil) do
109
+ @result == 'true'
110
+ end
111
+
112
+ exercise('Confirm the profile ' \
113
+ 'Dia::Profiles::NO_NETWORKING ' \
114
+ 'is creating a working sandbox environment') do
115
+ sandbox = Dia::RubyBlock.new(Dia::Profiles::NO_NETWORKING) do
116
+ begin
117
+ @reader.close
118
+ TCPSocket.open('http://www.youtube.com', 80)
119
+ @writer.write('false')
120
+ rescue SocketError => e
121
+ @writer.write('true')
122
+ end
123
+ end
124
+
125
+ sandbox.run_nonblock
126
+ sleep(1)
127
+
128
+ @writer.close
129
+ @result = @reader.gets
130
+ @reader.close
131
+ end
132
+
133
+ verify(nil) do
134
+ @result == 'true'
135
+ end
136
+
137
+ exercise('#run_nonblock called. ') do
138
+
139
+ sandbox = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
140
+ @result = sandbox.run_nonblock
141
+ end
142
+
143
+ verify('returns the Process ID(PID) of spawned process as a Fixnum') do
144
+ @result.class == Fixnum
145
+ end
146
+
147
+ end
148
+ end
149
+ end
150
+
@@ -0,0 +1,48 @@
1
+ suite('RubyBlock') do
2
+ suite('#stderr') do
3
+ suite('Return values') do
4
+
5
+ setup do
6
+ @result = nil
7
+ end
8
+
9
+ exercise('When stderr redirection is enabled, and $stderr is written to.') do
10
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) do
11
+ $stderr.print('I have been written to.')
12
+ end
13
+ dia.redirect_stderr = true
14
+ dia.run
15
+ @result = dia.stderr
16
+ end
17
+
18
+ verify('#stderr returns the contents of $stderr as a String.') do
19
+ @result == 'I have been written to.'
20
+ end
21
+
22
+ exercise('When stderr redirection is enabled, but $stderr is not written to.') do
23
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
24
+ dia.redirect_stderr = true
25
+ dia.run
26
+ @result = dia.stderr
27
+ end
28
+
29
+ verify('#stderr returns nil as no data is available on $stderr.') do
30
+ @result == nil
31
+ end
32
+
33
+ exercise('When stderr redirection is disabled, and $stderr is written to.') do
34
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) do
35
+ $stderr.print "\b"
36
+ end
37
+ dia.redirect_stderr = false # default, but lets be explicit.
38
+ dia.run
39
+ @result = dia.stderr
40
+ end
41
+
42
+ verify('#stderr returns nil.') do
43
+ @result == nil
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ suite('RubyBlock') do
2
+ suite('#stdout') do
3
+ suite('Return values') do
4
+
5
+ exercise('When stdout redirection is enabled, and $stdout is written to.') do
6
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) do
7
+ $stdout.print 'Hello!'
8
+ end
9
+ dia.redirect_stdout = true
10
+ dia.run
11
+ @result = dia.stdout
12
+ end
13
+
14
+ verify('#stdout returns the contents of stdout as a String') do
15
+ @result == 'Hello!'
16
+ end
17
+
18
+ exercise('When stdout redirection is enabled, and $stdout is not written to.') do
19
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
20
+ dia.redirect_stdout = true
21
+ @result = dia.stdout
22
+ end
23
+
24
+ verify('#stdout returns nil as no data has been written to $stdout') do
25
+ @result == nil
26
+ end
27
+
28
+ exercise('When stdout redirection is disabled, and $stdout is written to.') do
29
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) do
30
+ $stdout.print "\b"
31
+ end
32
+ dia.redirect_stdout = false
33
+ dia.run
34
+ @result = dia.stdout
35
+ end
36
+
37
+ verify('#stdout returns nil.') do
38
+ @result == nil
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ suite('SharedFeatures') do
2
+ suite('#exit_status') do
3
+ suite('Return values') do
4
+
5
+ exercise('When #exit_status is called after #run.') do
6
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { exit(5) }
7
+ dia.run
8
+ @result = dia.exit_status
9
+ end
10
+
11
+ verify('#exit_status returns the exit status as a Fixnum') do
12
+ @result == 5
13
+ end
14
+
15
+ exercise('When #exit_status is called, and #run is not.') do
16
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
17
+ @result = dia.exit_status
18
+ end
19
+
20
+ verify('#exit_status returns nil.') do
21
+ @result == nil
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ suite('SharedFeatures') do
2
+ suite('#pid') do
3
+ suite('Return values') do
4
+
5
+ exercise('When #run has been called.') do
6
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
7
+ dia.run
8
+ @result = dia.pid
9
+ end
10
+
11
+ verify('It returns the Process ID of the spawned process.') do
12
+ @result.class == Fixnum
13
+ end
14
+
15
+ exercise('When #run has not been called.') do
16
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
17
+ @result = dia.pid
18
+ end
19
+
20
+ verify('#pid returns nil.') do
21
+ @result == nil
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ suite('SharedFeatures') do
2
+ suite('#running?') do
3
+ suite('Return values') do
4
+ exercise('When a sandbox is running.') do
5
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { sleep(50) }
6
+ dia.run_nonblock
7
+ @result = dia.running?
8
+ dia.terminate
9
+ end
10
+
11
+ verify('#running? returns true.') do
12
+ @result == true
13
+ end
14
+
15
+ exercise('When a sandbox is not running.') do
16
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
17
+ dia.run
18
+ @result = dia.running?
19
+ end
20
+
21
+ verify('#running? returns false.') do
22
+ @result == false
23
+ end
24
+
25
+ exercise('When #run or #run_nonblock has not been called.') do
26
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
27
+ @result = dia.running?
28
+ end
29
+
30
+ verify('#running? returns nil') do
31
+ @result == nil
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,26 @@
1
+ suite('SharedFeatures') do
2
+ suite('#terminate') do
3
+ suite('Return values') do
4
+
5
+ exercise('When #terminate terminates a sandbox.') do
6
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { sleep(10) }
7
+ dia.run_nonblock
8
+ @result = dia.terminate
9
+ end
10
+
11
+ verify('#terminate returns 1.') do
12
+ @result == 1
13
+ end
14
+
15
+ exercise('When #run or #run_nonblock has not been called.') do
16
+ dia = Dia::RubyBlock.new(Dia::Profiles::NO_INTERNET) { }
17
+ @result = dia.terminate
18
+ end
19
+
20
+ verify('#terminate returns nil.') do
21
+ @result == nil
22
+ end
23
+
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ version: 2.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Gleeson
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-19 00:00:00 +01:00
17
+ date: 2010-07-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - "="
26
27
  - !ruby/object:Gem::Version
@@ -35,6 +36,7 @@ dependencies:
35
36
  name: yard
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
@@ -66,9 +68,22 @@ files:
66
68
  - lib/dia/shared_features.rb
67
69
  - lib/dia.rb
68
70
  - test/setup.rb
69
- - test/suite/lib/dia/exception_struct.rb
70
- - test/suite/lib/dia/ruby_block.rb
71
- - test/suite/lib/dia/shared_features.rb
71
+ - test/suite/lib/dia/Application#initialize.rb
72
+ - test/suite/lib/dia/Application#run.rb
73
+ - test/suite/lib/dia/Application#run_nonblock.rb
74
+ - test/suite/lib/dia/RubyBlock#exception.rb
75
+ - test/suite/lib/dia/RubyBlock#exception_raised?.rb
76
+ - test/suite/lib/dia/RubyBlock#redirect_stderr?.rb
77
+ - test/suite/lib/dia/RubyBlock#redirect_stdout?.rb
78
+ - test/suite/lib/dia/RubyBlock#rescue_exception?.rb
79
+ - test/suite/lib/dia/RubyBlock#run.rb
80
+ - test/suite/lib/dia/RubyBlock#run_nonblock.rb
81
+ - test/suite/lib/dia/RubyBlock#stderr.rb
82
+ - test/suite/lib/dia/RubyBlock#stdout.rb
83
+ - test/suite/lib/dia/SharedFeatures#exit_status.rb
84
+ - test/suite/lib/dia/SharedFeatures#pid.rb
85
+ - test/suite/lib/dia/SharedFeatures#running?.rb
86
+ - test/suite/lib/dia/SharedFeatures#terminate.rb
72
87
  - COPYING
73
88
  - README.mkd
74
89
  - dia.gemspec
@@ -76,12 +91,13 @@ has_rdoc: yard
76
91
  homepage:
77
92
  licenses: []
78
93
 
79
- post_install_message: " -------------------------------------------------------------------- \n Dia (2.0.0)\n \n Thanks for installing Dia, 2.0.0! \n\n >=2.0.0 releases include public API changes that are not backward\n compatiable with older releases. Be sure to check the docs!\n \n [Github] http://github.com/robgleeson/dia\n [API Documentation] http://yardoc.org/docs/robgleeson-dia/\n [Mailing List (new)] http://groups.google.com/group/ruby-dia\n -------------------------------------------------------------------- \n"
94
+ post_install_message: " -------------------------------------------------------------------- \n Dia (2.0.1)\n \n Thanks for installing Dia, 2.0.1! \n\n The >=2.0.0 releases are not backward compatiable with the 1.5 \n releases.\n\n Details of this release can be read at the mailing list:\n http://groups.google.com/group/ruby-dia/browse_thread/thread/fc255eeee8c59eeb\n \n [Github] http://github.com/robgleeson/dia\n [API Documentation] http://yardoc.org/docs/robgleeson-dia/\n -------------------------------------------------------------------- \n"
80
95
  rdoc_options: []
81
96
 
82
97
  require_paths:
83
98
  - lib
84
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
85
101
  requirements:
86
102
  - - ">="
87
103
  - !ruby/object:Gem::Version
@@ -89,6 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
105
  - 0
90
106
  version: "0"
91
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
92
109
  requirements:
93
110
  - - ">="
94
111
  - !ruby/object:Gem::Version
@@ -98,12 +115,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
115
  requirements: []
99
116
 
100
117
  rubyforge_project:
101
- rubygems_version: 1.3.6
118
+ rubygems_version: 1.3.7
102
119
  signing_key:
103
120
  specification_version: 3
104
121
  summary: Through the use of technology found on Apple's Leopard and Snow Leopard operating systems, Dia can create dynamic and robust sandbox environments for applications and for blocks of ruby code. The Ruby API was designed to be simple, and a joy to use. I hope you feel the same way :-)
105
122
  test_files:
106
123
  - test/setup.rb
107
- - test/suite/lib/dia/exception_struct.rb
108
- - test/suite/lib/dia/ruby_block.rb
109
- - test/suite/lib/dia/shared_features.rb
124
+ - test/suite/lib/dia/Application#initialize.rb
125
+ - test/suite/lib/dia/Application#run.rb
126
+ - test/suite/lib/dia/Application#run_nonblock.rb
127
+ - test/suite/lib/dia/RubyBlock#exception.rb
128
+ - test/suite/lib/dia/RubyBlock#exception_raised?.rb
129
+ - test/suite/lib/dia/RubyBlock#redirect_stderr?.rb
130
+ - test/suite/lib/dia/RubyBlock#redirect_stdout?.rb
131
+ - test/suite/lib/dia/RubyBlock#rescue_exception?.rb
132
+ - test/suite/lib/dia/RubyBlock#run.rb
133
+ - test/suite/lib/dia/RubyBlock#run_nonblock.rb
134
+ - test/suite/lib/dia/RubyBlock#stderr.rb
135
+ - test/suite/lib/dia/RubyBlock#stdout.rb
136
+ - test/suite/lib/dia/SharedFeatures#exit_status.rb
137
+ - test/suite/lib/dia/SharedFeatures#pid.rb
138
+ - test/suite/lib/dia/SharedFeatures#running?.rb
139
+ - test/suite/lib/dia/SharedFeatures#terminate.rb