Sha256: 49615f9f7edbb730f87dc5bc2615ebce138d7fa8b14dd4e5ca8402ab3f925140

Contents?: true

Size: 1.34 KB

Versions: 26

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class FilePermissionsTest < MiniTest::Test

  ZIPNAME = File.join(File.dirname(__FILE__), "umask.zip")
  FILENAME = File.join(File.dirname(__FILE__), "umask.txt")

  def teardown
    ::File.unlink(ZIPNAME)
    ::File.unlink(FILENAME)
  end

  def test_current_umask
    create_files
    assert_matching_permissions FILENAME, ZIPNAME
  end

  def test_umask_000
    set_umask(0000) do
      create_files
    end

    assert_matching_permissions FILENAME, ZIPNAME
  end

  def test_umask_066
    set_umask(0066) do
      create_files
    end

    assert_matching_permissions FILENAME, ZIPNAME
  end

  def test_umask_027
    set_umask(0027) do
      create_files
    end

    assert_matching_permissions FILENAME, ZIPNAME
  end

  def assert_matching_permissions(expected_file, actual_file)
    assert_equal(
      ::File.stat(expected_file).mode.to_s(8).rjust(4, '0'),
      ::File.stat(actual_file).mode.to_s(8).rjust(4, '0')
    )
  end

  def create_files
    ::Zip::File.open(ZIPNAME, ::Zip::File::CREATE) do |zip|
      zip.comment = "test"
    end

    ::File.open(FILENAME, 'w') do |file|
      file << 'test'
    end
  end

  # If anything goes wrong, make sure the umask is restored.
  def set_umask(umask, &block)
    begin
      saved_umask = ::File.umask(umask)
      yield
    ensure
      ::File.umask(saved_umask)
    end
  end

end

Version data entries

26 entries across 20 versions & 4 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.9 vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.8 vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.7 vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
tdiary-5.0.6 vendor/bundle/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/file_permissions_test.rb