[macruby-changes] [4414] MacRuby/trunk/spec/macruby/core/sandbox

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 6 13:57:21 PDT 2010


Revision: 4414
          http://trac.macosforge.org/projects/ruby/changeset/4414
Author:   pthomson at apple.com
Date:     2010-08-06 13:57:20 -0700 (Fri, 06 Aug 2010)
Log Message:
-----------
Even more tests.

Modified Paths:
--------------
    MacRuby/trunk/spec/macruby/core/sandbox/no_writes_spec.rb
    MacRuby/trunk/spec/macruby/core/sandbox/pure_computation_spec.rb
    MacRuby/trunk/spec/macruby/core/sandbox/shared/no_network.rb
    MacRuby/trunk/spec/macruby/core/sandbox/shared/no_write.rb
    MacRuby/trunk/spec/macruby/core/sandbox/spec_helper.rb

Added Paths:
-----------
    MacRuby/trunk/spec/macruby/core/sandbox/no_internet_spec.rb
    MacRuby/trunk/spec/macruby/core/sandbox/no_network_spec.rb
    MacRuby/trunk/spec/macruby/core/sandbox/temporary_writes_spec.rb

Added: MacRuby/trunk/spec/macruby/core/sandbox/no_internet_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/no_internet_spec.rb	                        (rev 0)
+++ MacRuby/trunk/spec/macruby/core/sandbox/no_internet_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Sandbox, ".no_network" do
+  
+  before do
+    add_line "framework 'Cocoa'"
+    add_line "Sandbox.no_network.apply!"
+  end
+  
+  it_behaves_like :sandbox_no_network, :no_network
+  
+  after do
+    ScratchPad.clear
+  end
+  
+end
\ No newline at end of file

Added: MacRuby/trunk/spec/macruby/core/sandbox/no_network_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/no_network_spec.rb	                        (rev 0)
+++ MacRuby/trunk/spec/macruby/core/sandbox/no_network_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Sandbox, ".no_network" do
+  
+  before do
+    add_line "framework 'Cocoa'"
+    add_line "Sandbox.no_network.apply!"
+  end
+  
+  it_behaves_like :sandbox_no_network, :no_network
+  
+  after do
+    ScratchPad.clear
+  end
+  
+end
\ No newline at end of file

Modified: MacRuby/trunk/spec/macruby/core/sandbox/no_writes_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/no_writes_spec.rb	2010-08-06 20:57:18 UTC (rev 4413)
+++ MacRuby/trunk/spec/macruby/core/sandbox/no_writes_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -1,6 +1,6 @@
 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
 
-describe "Sandbox.no_writes" do
+describe Sandbox, ".no_writes" do
   
   before do
     add_line "framework 'Cocoa'"

Modified: MacRuby/trunk/spec/macruby/core/sandbox/pure_computation_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/pure_computation_spec.rb	2010-08-06 20:57:18 UTC (rev 4413)
+++ MacRuby/trunk/spec/macruby/core/sandbox/pure_computation_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -1,6 +1,6 @@
 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
 
-describe Sandbox, "pure_computation" do
+describe Sandbox, ".pure_computation" do
   
   it_behaves_like :sandbox_no_write, :no_write
   it_behaves_like :sandbox_no_network, :no_network

Modified: MacRuby/trunk/spec/macruby/core/sandbox/shared/no_network.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/shared/no_network.rb	2010-08-06 20:57:18 UTC (rev 4413)
+++ MacRuby/trunk/spec/macruby/core/sandbox/shared/no_network.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -1,12 +1,5 @@
 describe :sandbox_no_network, :shared => true do
   
-  it "disallows looking up the address of the current NSHost" do
-    unless NSHost.currentHost.address.empty?
-      add_line "print NSHost.currentHost.address"
-      result.should be_empty
-    end
-  end
-  
   it "disallows DNS requests through NSHost" do
     add_line 'print NSHost.hostWithName("apple.com").address'
     result.should be_empty
@@ -17,10 +10,4 @@
     add_line 'print NSString.stringWithContentsOfURL(url)'
     result.should be_empty
   end
-  
-  it "disallows NSURLConnection.connectionWithRequest:delegate:" do
-    add_line 'req = NSURLRequest.requestWithURL(NSURL.URLWithString("http://apple.com"))'
-    add_line 'print NSURLConnection.connectionWithRequest(req, delegate:nil)'
-    result.should be_empty
-  end
 end

Modified: MacRuby/trunk/spec/macruby/core/sandbox/shared/no_write.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/shared/no_write.rb	2010-08-06 20:57:18 UTC (rev 4413)
+++ MacRuby/trunk/spec/macruby/core/sandbox/shared/no_write.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -7,4 +7,11 @@
     end
   end
   
+  it "throws an error when trying to write to a Ruby IO object" do
+    with_temporary_file do |fn|
+      add_line "open('#{fn}', 'w').puts 'This must fail'"
+      result.should_not be_empty
+    end
+  end
+  
 end

Modified: MacRuby/trunk/spec/macruby/core/sandbox/spec_helper.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/spec_helper.rb	2010-08-06 20:57:18 UTC (rev 4413)
+++ MacRuby/trunk/spec/macruby/core/sandbox/spec_helper.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -11,10 +11,8 @@
 end
 
 def with_temporary_file(temp = tmp('sandbox', false))
-  p "Creating #{temp}"
   FileUtils.touch temp
   yield temp
   FileUtils.rm temp
-  p "Deleting #{temp}"
 end
   
\ No newline at end of file

Copied: MacRuby/trunk/spec/macruby/core/sandbox/temporary_writes_spec.rb (from rev 4413, MacRuby/trunk/spec/macruby/core/sandbox/no_writes_spec.rb)
===================================================================
--- MacRuby/trunk/spec/macruby/core/sandbox/temporary_writes_spec.rb	                        (rev 0)
+++ MacRuby/trunk/spec/macruby/core/sandbox/temporary_writes_spec.rb	2010-08-06 20:57:20 UTC (rev 4414)
@@ -0,0 +1,24 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Sandbox, ".temporary_writes" do
+  
+  before do
+    add_line "framework 'Cocoa'"
+    add_line "Sandbox.temporary_writes.apply!"
+  end
+  
+  it_behaves_like :sandbox_no_write, :no_write
+  
+  it "should allow writing to a file in /tmp" do
+    with_temporary_file("/tmp/sandboxed") do
+      add_line "open('/tmp/sandboxed', 'w').puts 'This must succeed'"
+      add_line "print 'Success'"
+      result.should == "Success"
+    end
+  end
+  
+  after do
+    ScratchPad.clear
+  end
+  
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100806/7125ace5/attachment-0001.html>


More information about the macruby-changes mailing list