Project

General

Profile

Bug #14481 ยป rubygems-276-for-ruby25.patch

hsbt (Hiroshi SHIBATA), 02/16/2018 10:55 AM

View differences:

lib/rubygems.rb
10 10
require 'thread'
11 11

  
12 12
module Gem
13
  VERSION = "2.7.3"
13
  VERSION = "2.7.6"
14 14
end
15 15

  
16 16
# Must be first since it unloads the prelude from 1.9.2
......
161 161
  # these are defined in Ruby 1.8.7, hence the need for this convoluted setup.
162 162

  
163 163
  READ_BINARY_ERRORS = begin
164
    read_binary_errors = [Errno::EACCES, Errno::EROFS]
164
    read_binary_errors = [Errno::EACCES, Errno::EROFS, Errno::ENOSYS]
165 165
    read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
166 166
    read_binary_errors
167 167
  end.freeze
......
171 171
  # these are defined in Ruby 1.8.7.
172 172

  
173 173
  WRITE_BINARY_ERRORS = begin
174
    write_binary_errors = []
174
    write_binary_errors = [Errno::ENOSYS]
175 175
    write_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
176 176
    write_binary_errors
177 177
  end.freeze
......
871 871
  # Safely read a file in binary mode on all platforms.
872 872

  
873 873
  def self.read_binary(path)
874
    open path, 'rb+' do |f|
874
    File.open path, 'rb+' do |f|
875 875
      f.flock(File::LOCK_EX)
876 876
      f.read
877 877
    end
878 878
  rescue *READ_BINARY_ERRORS
879
    open path, 'rb' do |f|
879
    File.open path, 'rb' do |f|
880 880
      f.read
881 881
    end
882 882
  rescue Errno::ENOLCK # NFS
883 883
    if Thread.main != Thread.current
884 884
      raise
885 885
    else
886
      open path, 'rb' do |f|
886
      File.open path, 'rb' do |f|
887 887
        f.read
888 888
      end
889 889
    end
lib/rubygems/commands/generate_index_command.rb
68 68

  
69 69
    if not File.exist?(options[:directory]) or
70 70
       not File.directory?(options[:directory]) then
71
      alert_error "unknown directory name #{directory}."
71
      alert_error "unknown directory name #{options[:directory]}."
72 72
      terminate_interaction 1
73 73
    else
74 74
      indexer = Gem::Indexer.new options.delete(:directory), options
lib/rubygems/commands/owner_command.rb
64 64
    end
65 65

  
66 66
    with_response response do |resp|
67
      owners = YAML.load resp.body
67
      owners = Gem::SafeYAML.load resp.body
68 68

  
69 69
      say "Owners for gem: #{name}"
70 70
      owners.each do |owner|
lib/rubygems/commands/setup_command.rb
350 350
  def install_default_bundler_gem
351 351
    return unless Gem::USE_BUNDLER_FOR_GEMDEPS
352 352

  
353
    mkdir_p Gem::Specification.default_specifications_dir
353
    specs_dir = Gem::Specification.default_specifications_dir
354
    File.join(options[:destdir], specs_dir) unless Gem.win_platform?
355
    mkdir_p specs_dir
354 356

  
355 357
    # Workaround for non-git environment.
356 358
    gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") }
......
359 361
    bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
360 362
    bundler_spec.files = Dir.chdir("bundler") { Dir["{*.md,{lib,exe,man}/**/*}"] }
361 363
    bundler_spec.executables -= %w[bundler bundle_ruby]
362
    Dir.entries(Gem::Specification.default_specifications_dir).
364

  
365
    # Remove bundler-*.gemspec in default specification directory.
366
    Dir.entries(specs_dir).
363 367
      select {|gs| gs.start_with?("bundler-") }.
364
      each {|gs| File.delete(File.join(Gem::Specification.default_specifications_dir, gs)) }
368
      each {|gs| File.delete(File.join(specs_dir, gs)) }
365 369

  
366
    default_spec_path = File.join(Gem::Specification.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
370
    default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec")
367 371
    Gem.write_binary(default_spec_path, bundler_spec.to_ruby)
368 372

  
369 373
    bundler_spec = Gem::Specification.load(default_spec_path)
370 374

  
375
    # Remove gemspec that was same version of vendored bundler.
376
    normal_gemspec = File.join(Gem.default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
377
    if File.file? normal_gemspec
378
      File.delete normal_gemspec
379
    end
380

  
381
    # Remove gem files that were same version of vendored bundler.
371 382
    if File.directory? bundler_spec.gems_dir
372 383
      Dir.entries(bundler_spec.gems_dir).
373
        select {|default_gem| File.basename(default_gem).match(/^bundler-#{Gem::Version::VERSION_PATTERN}$/) }.
384
        select {|default_gem| File.basename(default_gem) == "bundler-#{bundler_spec.version}" }.
374 385
        each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) }
375 386
    end
376 387

  
377
    mkdir_p bundler_spec.bin_dir
378
    bundler_spec.executables.each {|e| cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_spec.bin_dir, e) }
388
    bundler_bin_dir = File.join(Gem.default_dir, 'gems', bundler_spec.full_name, bundler_spec.bindir)
389
    File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform?
390
    mkdir_p bundler_bin_dir
391
    bundler_spec.executables.each do |e|
392
      cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
393
    end
379 394

  
380 395
    if Gem.win_platform?
381 396
      require 'rubygems/installer'
lib/rubygems/commands/unpack_command.rb
94 94

  
95 95
        spec_file = File.basename spec.spec_file
96 96

  
97
        open spec_file, 'w' do |io|
97
        File.open spec_file, 'w' do |io|
98 98
          io.write metadata
99 99
        end
100 100
      else
......
176 176

  
177 177
    metadata = nil
178 178

  
179
    open path, Gem.binary_mode do |io|
179
    File.open path, Gem.binary_mode do |io|
180 180
      tar = Gem::Package::TarReader.new io
181 181
      tar.each_entry do |entry|
182 182
        case entry.full_name
lib/rubygems/config_file.rb
458 458

  
459 459
  # Writes out this config file, replacing its source.
460 460
  def write
461
    open config_file_name, 'w' do |io|
461
    File.open config_file_name, 'w' do |io|
462 462
      io.write to_yaml
463 463
    end
464 464
  end
lib/rubygems/ext/builder.rb
212 212

  
213 213
    FileUtils.mkdir_p @spec.extension_dir
214 214

  
215
    open destination, 'wb' do |io| io.puts output end
215
    File.open destination, 'wb' do |io| io.puts output end
216 216

  
217 217
    destination
218 218
  end
lib/rubygems/indexer.rb
2 2
require 'rubygems'
3 3
require 'rubygems/package'
4 4
require 'time'
5
require 'tmpdir'
5 6

  
6 7
begin
7 8
  gem 'builder'
......
64 65
    @build_modern = options[:build_modern]
65 66

  
66 67
    @dest_directory = directory
67
    @directory = File.join(Dir.tmpdir, "gem_generate_index_#{$$}")
68
    @directory = Dir.mktmpdir 'gem_generate_index'
68 69

  
69 70
    marshal_name = "Marshal.#{Gem.marshal_version}"
70 71

  
......
123 124
        marshal_name = File.join @quick_marshal_dir, spec_file_name
124 125

  
125 126
        marshal_zipped = Gem.deflate Marshal.dump(spec)
126
        open marshal_name, 'wb' do |io| io.write marshal_zipped end
127
        File.open marshal_name, 'wb' do |io| io.write marshal_zipped end
127 128

  
128 129
        files << marshal_name
129 130

  
......
261 262

  
262 263
    zipped = Gem.deflate data
263 264

  
264
    open "#{filename}.#{extension}", 'wb' do |io|
265
    File.open "#{filename}.#{extension}", 'wb' do |io|
265 266
      io.write zipped
266 267
    end
267 268
  end
......
427 428

  
428 429
    specs_index = compact_specs specs_index.uniq.sort
429 430

  
430
    open dest, 'wb' do |io|
431
    File.open dest, 'wb' do |io|
431 432
      Marshal.dump specs_index, io
432 433
    end
433 434
  end
lib/rubygems/installer.rb
206 206
    ruby_executable = false
207 207
    existing = nil
208 208

  
209
    open generated_bin, 'rb' do |io|
209
    File.open generated_bin, 'rb' do |io|
210 210
      next unless io.gets =~ /^#!/ # shebang
211 211
      io.gets # blankline
212 212

  
......
427 427
  # specifications directory.
428 428

  
429 429
  def write_spec
430
    open spec_file, 'w' do |file|
430
    File.open spec_file, 'w' do |file|
431 431
      spec.installed_by_version = Gem.rubygems_version
432 432

  
433 433
      file.puts spec.to_ruby_for_cache
......
464 464
  def generate_bin # :nodoc:
465 465
    return if spec.executables.nil? or spec.executables.empty?
466 466

  
467
    Dir.mkdir @bin_dir unless File.exist? @bin_dir
467
    begin
468
      Dir.mkdir @bin_dir
469
    rescue SystemCallError
470
      raise unless File.directory? @bin_dir
471
    end
472

  
468 473
    raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir
469 474

  
470 475
    spec.executables.each do |filename|
......
863 868

  
864 869
    build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
865 870

  
866
    open build_info_file, 'w' do |io|
871
    File.open build_info_file, 'w' do |io|
867 872
      @build_args.each do |arg|
868 873
        io.puts arg
869 874
      end
lib/rubygems/package.rb
219 219
      next unless stat.file?
220 220

  
221 221
      tar.add_file_simple file, stat.mode, stat.size do |dst_io|
222
        open file, 'rb' do |src_io|
222
        File.open file, 'rb' do |src_io|
223 223
          dst_io.write src_io.read 16384 until src_io.eof?
224 224
        end
225 225
      end
......
378 378
            File.dirname destination
379 379
          end
380 380

  
381
        FileUtils.mkdir_p mkdir, mkdir_options
381
        mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name
382 382

  
383
        open destination, 'wb' do |out|
383
        File.open destination, 'wb' do |out|
384 384
          out.write entry.read
385 385
          FileUtils.chmod entry.header.mode, destination
386 386
        end if entry.file?
......
416 416
    raise Gem::Package::PathError.new(filename, destination_dir) if
417 417
      filename.start_with? '/'
418 418

  
419
    destination_dir = File.realpath destination_dir if
420
      File.respond_to? :realpath
419
    destination_dir = realpath destination_dir
421 420
    destination_dir = File.expand_path destination_dir
422 421

  
423 422
    destination = File.join destination_dir, filename
424 423
    destination = File.expand_path destination
425 424

  
426 425
    raise Gem::Package::PathError.new(destination, destination_dir) unless
427
      destination.start_with? destination_dir
426
      destination.start_with? destination_dir + '/'
428 427

  
429 428
    destination.untaint
430 429
    destination
431 430
  end
432 431

  
432
  def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name
433
    destination_dir = realpath File.expand_path(destination_dir)
434
    parts = mkdir.split(File::SEPARATOR)
435
    parts.reduce do |path, basename|
436
      path = realpath path  unless path == ""
437
      path = File.expand_path(path + File::SEPARATOR + basename)
438
      lstat = File.lstat path rescue nil
439
      if !lstat || !lstat.directory?
440
        unless path.start_with? destination_dir and (FileUtils.mkdir path, mkdir_options rescue false)
441
          raise Gem::Package::PathError.new(file_name, destination_dir)
442
        end
443
      end
444
      path
445
    end
446
  end
447

  
433 448
  ##
434 449
  # Loads a Gem::Specification from the TarEntry +entry+
435 450

  
......
603 618
      raise Gem::Package::FormatError.new \
604 619
              'package content (data.tar.gz) is missing', @gem
605 620
    end
621

  
622
    if duplicates = @files.group_by {|f| f }.select {|k,v| v.size > 1 }.map(&:first) and duplicates.any?
623
      raise Gem::Security::Exception, "duplicate files in the package: (#{duplicates.map(&:inspect).join(', ')})"
624
    end
606 625
  end
607 626

  
608 627
  ##
......
616 635
    raise Gem::Package::FormatError.new(e.message, entry.full_name)
617 636
  end
618 637

  
638
  if File.respond_to? :realpath
639
    def realpath file
640
      File.realpath file
641
    end
642
  else
643
    def realpath file
644
      file
645
    end
646
  end
647

  
619 648
end
620 649

  
621 650
require 'rubygems/package/digest_io'
lib/rubygems/package/file_source.rb
23 23
  end
24 24

  
25 25
  def with_write_io &block
26
    open path, 'wb', &block
26
    File.open path, 'wb', &block
27 27
  end
28 28

  
29 29
  def with_read_io &block
30
    open path, 'rb', &block
30
    File.open path, 'rb', &block
31 31
  end
32 32

  
33 33
end
lib/rubygems/package/old.rb
80 80

  
81 81
        FileUtils.mkdir_p File.dirname destination
82 82

  
83
        open destination, 'wb', entry['mode'] do |out|
83
        File.open destination, 'wb', entry['mode'] do |out|
84 84
          out.write file_data
85 85
        end
86 86

  
lib/rubygems/package/tar_header.rb
104 104
    fields = header.unpack UNPACK_FORMAT
105 105

  
106 106
    new :name     => fields.shift,
107
        :mode     => fields.shift.oct,
108
        :uid      => fields.shift.oct,
109
        :gid      => fields.shift.oct,
110
        :size     => fields.shift.oct,
111
        :mtime    => fields.shift.oct,
112
        :checksum => fields.shift.oct,
107
        :mode     => strict_oct(fields.shift),
108
        :uid      => strict_oct(fields.shift),
109
        :gid      => strict_oct(fields.shift),
110
        :size     => strict_oct(fields.shift),
111
        :mtime    => strict_oct(fields.shift),
112
        :checksum => strict_oct(fields.shift),
113 113
        :typeflag => fields.shift,
114 114
        :linkname => fields.shift,
115 115
        :magic    => fields.shift,
116
        :version  => fields.shift.oct,
116
        :version  => strict_oct(fields.shift),
117 117
        :uname    => fields.shift,
118 118
        :gname    => fields.shift,
119
        :devmajor => fields.shift.oct,
120
        :devminor => fields.shift.oct,
119
        :devmajor => strict_oct(fields.shift),
120
        :devminor => strict_oct(fields.shift),
121 121
        :prefix   => fields.shift,
122 122

  
123 123
        :empty => empty
124 124
  end
125 125

  
126
  def self.strict_oct(str)
127
    return str.oct if str =~ /\A[0-7]*\z/
128
    raise ArgumentError, "#{str.inspect} is not an octal string"
129
  end
130

  
126 131
  ##
127 132
  # Creates a new TarHeader using +vals+
128 133

  
lib/rubygems/package/tar_writer.rb
196 196
      digest_name == signer.digest_name
197 197
    end
198 198

  
199
    raise "no #{signer.digest_name} in #{digests.values.compact}" unless signature_digest
200

  
199 201
    if signer.key then
200 202
      signature = signer.sign signature_digest.digest
201 203

  
lib/rubygems/request_set/lockfile.rb
223 223
  def write
224 224
    content = to_s
225 225

  
226
    open "#{@gem_deps_file}.lock", 'w' do |io|
226
    File.open "#{@gem_deps_file}.lock", 'w' do |io|
227 227
      io.write content
228 228
    end
229 229
  end
lib/rubygems/security.rb
578 578
  def self.write pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER
579 579
    path = File.expand_path path
580 580

  
581
    open path, 'wb', permissions do |io|
581
    File.open path, 'wb', permissions do |io|
582 582
      if passphrase and cipher
583 583
        io.write pemmable.to_pem cipher, passphrase
584 584
      else
lib/rubygems/security/trust_dir.rb
93 93

  
94 94
    destination = cert_path certificate
95 95

  
96
    open destination, 'wb', @permissions[:trusted_cert] do |io|
96
    File.open destination, 'wb', @permissions[:trusted_cert] do |io|
97 97
      io.write certificate.to_pem
98 98
    end
99 99
  end
lib/rubygems/server.rb
623 623
      executables = nil if executables.empty?
624 624
      executables.last["is_last"] = true if executables
625 625

  
626
      # Pre-process spec homepage for safety reasons
627
      begin
628
        homepage_uri = URI.parse(spec.homepage)
629
        if [URI::HTTP, URI::HTTPS].member? homepage_uri.class
630
          homepage_uri = spec.homepage
631
        else
632
          homepage_uri = "."
633
        end
634
      rescue URI::InvalidURIError
635
        homepage_uri = "."
636
      end
637

  
626 638
      specs << {
627 639
        "authors"             => spec.authors.sort.join(", "),
628 640
        "date"                => spec.date.to_s,
......
632 644
        "only_one_executable" => (executables && executables.size == 1),
633 645
        "full_name"           => spec.full_name,
634 646
        "has_deps"            => !deps.empty?,
635
        "homepage"            => spec.homepage,
647
        "homepage"            => homepage_uri,
636 648
        "name"                => spec.name,
637 649
        "rdoc_installed"      => Gem::RDoc.new(spec).rdoc_installed?,
638 650
        "ri_installed"        => Gem::RDoc.new(spec).ri_installed?,
lib/rubygems/source.rb
160 160
    if update_cache? then
161 161
      FileUtils.mkdir_p cache_dir
162 162

  
163
      open local_spec, 'wb' do |io|
163
      File.open local_spec, 'wb' do |io|
164 164
        io.write spec
165 165
      end
166 166
    end
lib/rubygems/specification.rb
15 15
require 'rubygems/stub_specification'
16 16
require 'rubygems/util/list'
17 17
require 'stringio'
18
require 'uri'
18 19

  
19 20
##
20 21
# The Specification class contains the information for a Gem.  Typically
......
2822 2823
      raise Gem::InvalidSpecificationException, "#{lazy} is not a summary"
2823 2824
    end
2824 2825

  
2825
    if homepage and not homepage.empty? and
2826
       homepage !~ /\A[a-z][a-z\d+.-]*:/i then
2827
      raise Gem::InvalidSpecificationException,
2828
            "\"#{homepage}\" is not a URI"
2826
    # Make sure a homepage is valid HTTP/HTTPS URI
2827
    if homepage and not homepage.empty?
2828
      begin
2829
        homepage_uri = URI.parse(homepage)
2830
        unless [URI::HTTP, URI::HTTPS].member? homepage_uri.class
2831
          raise Gem::InvalidSpecificationException, "\"#{homepage}\" is not a valid HTTP URI"
2832
        end
2833
      rescue URI::InvalidURIError
2834
        raise Gem::InvalidSpecificationException, "\"#{homepage}\" is not a valid HTTP URI"
2835
      end
2829 2836
    end
2830 2837

  
2831 2838
    # Warnings
lib/rubygems/stub_specification.rb
113 113
    unless @data
114 114
      begin
115 115
        saved_lineno = $.
116

  
117
        # TODO It should be use `File.open`, but bundler-1.16.1 example expects Kernel#open.
116 118
        open loaded_from, OPEN_MODE do |file|
117 119
          begin
118 120
            file.readline # discard encoding line
lib/rubygems/test_case.rb
488 488

  
489 489
    gemspec = "#{name}.gemspec"
490 490

  
491
    open File.join(directory, gemspec), 'w' do |io|
491
    File.open File.join(directory, gemspec), 'w' do |io|
492 492
      io.write git_spec.to_ruby
493 493
    end
494 494

  
......
592 592
  # Reads a Marshal file at +path+
593 593

  
594 594
  def read_cache(path)
595
    open path.dup.untaint, 'rb' do |io|
595
    File.open path.dup.untaint, 'rb' do |io|
596 596
      Marshal.load io.read
597 597
    end
598 598
  end
......
612 612
    dir = File.dirname path
613 613
    FileUtils.mkdir_p dir unless File.directory? dir
614 614

  
615
    open path, 'wb' do |io|
615
    File.open path, 'wb' do |io|
616 616
      yield io if block_given?
617 617
    end
618 618

  
......
727 727
    install_default_specs(*specs)
728 728

  
729 729
    specs.each do |spec|
730
      open spec.loaded_from, 'w' do |io|
730
      File.open spec.loaded_from, 'w' do |io|
731 731
        io.write spec.to_ruby_for_cache
732 732
      end
733 733
    end
......
1363 1363
      yield specification if block_given?
1364 1364
    end
1365 1365

  
1366
    open File.join(directory, "#{name}.gemspec"), 'w' do |io|
1366
    File.open File.join(directory, "#{name}.gemspec"), 'w' do |io|
1367 1367
      io.write vendor_spec.to_ruby
1368 1368
    end
1369 1369

  
lib/rubygems/test_utilities.rb
346 346
  end
347 347

  
348 348
  def write_spec spec # :nodoc:
349
    open spec.spec_file, 'w' do |io|
349
    File.open spec.spec_file, 'w' do |io|
350 350
      io.write spec.to_ruby_for_cache
351 351
    end
352 352
  end
lib/rubygems/util.rb
114 114

  
115 115
    here = File.expand_path directory
116 116
    loop do
117
      Dir.chdir here, &block
117
      Dir.chdir here, &block rescue Errno::EACCES
118

  
118 119
      new_here = File.expand_path('..', here)
119 120
      return if new_here == here # toplevel
120 121
      here = new_here
lib/rubygems/validator.rb
34 34
  # gem_path:: [String] Path to gem file
35 35

  
36 36
  def verify_gem_file(gem_path)
37
    open gem_path, Gem.binary_mode do |file|
37
    File.open gem_path, Gem.binary_mode do |file|
38 38
      gem_data = file.read
39 39
      verify_gem gem_data
40 40
    end
......
109 109

  
110 110
        good, gone, unreadable = nil, nil, nil, nil
111 111

  
112
        open gem_path, Gem.binary_mode do |file|
112
        File.open gem_path, Gem.binary_mode do |file|
113 113
          package = Gem::Package.new gem_path
114 114

  
115 115
          good, gone = package.contents.partition { |file_name|
......
134 134

  
135 135
              source = File.join gem_directory, entry['path']
136 136

  
137
              open source, Gem.binary_mode do |f|
137
              File.open source, Gem.binary_mode do |f|
138 138
                unless f.read == data then
139 139
                  errors[gem_name][entry['path']] = "Modified from original"
140 140
                end
test/rubygems/test_gem.rb
7 7
require 'tmpdir'
8 8

  
9 9
# TODO: push this up to test_case.rb once battle tested
10
$SAFE=1
10

  
11 11
$LOAD_PATH.map! do |path|
12 12
  path.dup.untaint
13 13
end
......
463 463
    assert File.directory?(util_cache_dir)
464 464
  end
465 465

  
466
  unless win_platform? then # only for FS that support write protection
466
  unless win_platform? || Process.uid.zero? then # only for FS that support write protection
467 467
    def test_self_ensure_gem_directories_write_protected
468 468
      gemdir = File.join @tempdir, "egd"
469 469
      FileUtils.rm_r gemdir rescue nil
......
775 775
  end
776 776

  
777 777
  def test_self_read_binary
778
    open 'test', 'w' do |io|
778
    File.open 'test', 'w' do |io|
779 779
      io.write "\xCF\x80"
780 780
    end
781 781

  
......
1642 1642
    spec = Gem::Specification.find { |s| s == spec }
1643 1643
    refute spec.activated?
1644 1644

  
1645
    open gem_deps_file, 'w' do |io|
1645
    File.open gem_deps_file, 'w' do |io|
1646 1646
      io.write 'gem "a"'
1647 1647
    end
1648 1648

  
......
1661 1661

  
1662 1662
    refute spec.activated?
1663 1663

  
1664
    open 'gem.deps.rb', 'w' do |io|
1664
    File.open 'gem.deps.rb', 'w' do |io|
1665 1665
      io.write 'gem "a"'
1666 1666
    end
1667 1667

  
......
1705 1705

  
1706 1706
    refute spec.activated?
1707 1707

  
1708
    open 'Gemfile', 'w' do |io|
1708
    File.open 'Gemfile', 'w' do |io|
1709 1709
      io.write 'gem "a"'
1710 1710
    end
1711 1711

  
......
1734 1734

  
1735 1735
    refute spec.activated?
1736 1736

  
1737
    open 'gem.deps.rb', 'w' do |io|
1737
    File.open 'gem.deps.rb', 'w' do |io|
1738 1738
      io.write 'gem "a"'
1739 1739
    end
1740 1740

  
......
1749 1749
    skip 'Insecure operation - read' if RUBY_VERSION <= "1.8.7"
1750 1750
    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
1751 1751

  
1752
    open 'x', 'w' do |io|
1752
    File.open 'x', 'w' do |io|
1753 1753
      io.write 'gem "a"'
1754 1754
    end
1755 1755

  
......
1790 1790
    spec = Gem::Specification.find { |s| s == spec }
1791 1791
    refute spec.activated?
1792 1792

  
1793
    open 'x', 'w' do |io|
1793
    File.open 'x', 'w' do |io|
1794 1794
      io.write 'gem "a"'
1795 1795
    end
1796 1796

  
test/rubygems/test_gem_commands_cleanup_command.rb
158 158
    assert_path_exists @a_1_1.gem_dir
159 159
  ensure
160 160
    FileUtils.chmod 0755, @gemhome
161
  end unless win_platform?
161
  end unless win_platform? || Process.uid.zero?
162 162

  
163 163
  def test_execute_dry_run
164 164
    @cmd.options[:args] = %w[a]
test/rubygems/test_gem_commands_install_command.rb
131 131

  
132 132
  def test_execute_no_user_install
133 133
    skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
134
    skip 'skipped in root privilege' if Process.uid.zero?
134 135

  
135 136
    specs = spec_fetcher do |fetcher|
136 137
      fetcher.gem 'a', 2
test/rubygems/test_gem_commands_owner_command.rb
43 43
    assert_match %r{- 4}, @ui.output
44 44
  end
45 45

  
46
  def test_show_owners_dont_load_objects
47
    skip "testing a psych-only API" unless defined?(::Psych::DisallowedClass)
48

  
49
    response = <<EOF
50
---
51
- email: !ruby/object:Object {}
52
  id: 1
53
  handle: user1
54
- email: user2@example.com
55
- id: 3
56
  handle: user3
57
- id: 4
58
EOF
59

  
60
    @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
61

  
62
    assert_raises Psych::DisallowedClass do
63
      use_ui @ui do
64
        @cmd.show_owners("freewill")
65
      end
66
    end
67

  
68
  end
69

  
70

  
46 71
  def test_show_owners_setting_up_host_through_env_var
47 72
    response = "- email: user1@example.com\n"
48 73
    host = "http://rubygems.example"
test/rubygems/test_gem_commands_push_command.rb
132 132
    }
133 133

  
134 134
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
135
    open Gem.configuration.credentials_path, 'w' do |f|
135
    File.open Gem.configuration.credentials_path, 'w' do |f|
136 136
      f.write keys.to_yaml
137 137
    end
138 138
    Gem.configuration.load_api_keys
......
166 166
    }
167 167

  
168 168
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
169
    open Gem.configuration.credentials_path, 'w' do |f|
169
    File.open Gem.configuration.credentials_path, 'w' do |f|
170 170
      f.write keys.to_yaml
171 171
    end
172 172
    Gem.configuration.load_api_keys
......
193 193
    }
194 194

  
195 195
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
196
    open Gem.configuration.credentials_path, 'w' do |f|
196
    File.open Gem.configuration.credentials_path, 'w' do |f|
197 197
      f.write keys.to_yaml
198 198
    end
199 199
    Gem.configuration.load_api_keys
......
235 235
    }
236 236

  
237 237
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
238
    open Gem.configuration.credentials_path, 'w' do |f|
238
    File.open Gem.configuration.credentials_path, 'w' do |f|
239 239
      f.write keys.to_yaml
240 240
    end
241 241
    Gem.configuration.load_api_keys
......
266 266
    }
267 267

  
268 268
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
269
    open Gem.configuration.credentials_path, 'w' do |f|
269
    File.open Gem.configuration.credentials_path, 'w' do |f|
270 270
      f.write keys.to_yaml
271 271
    end
272 272
    Gem.configuration.load_api_keys
test/rubygems/test_gem_commands_setup_command.rb
6 6

  
7 7
class TestGemCommandsSetupCommand < Gem::TestCase
8 8

  
9
  bundler_gemspec = File.expand_path("../../../bundler/lib/bundler/version.rb", __FILE__)
10
  if File.exist?(bundler_gemspec)
11
    BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1]
12
  else
13
    BUNDLER_VERS = "1.16.1"
14
  end
15

  
9 16
  def setup
10 17
    super
11 18

  
......
16 23
    FileUtils.mkdir_p 'bin'
17 24
    FileUtils.mkdir_p 'lib/rubygems/ssl_certs/rubygems.org'
18 25

  
19
    open 'bin/gem',                   'w' do |io| io.puts '# gem'          end
20
    open 'lib/rubygems.rb',           'w' do |io| io.puts '# rubygems.rb'  end
21
    open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end
22
    open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM'       end
26
    File.open 'bin/gem',                   'w' do |io| io.puts '# gem'          end
27
    File.open 'lib/rubygems.rb',           'w' do |io| io.puts '# rubygems.rb'  end
28
    File.open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end
29
    File.open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM'       end
23 30

  
24 31
    FileUtils.mkdir_p 'bundler/exe'
25 32
    FileUtils.mkdir_p 'bundler/lib/bundler'
26 33

  
27
    open 'bundler/exe/bundle',        'w' do |io| io.puts '# bundle'       end
28
    open 'bundler/lib/bundler.rb',    'w' do |io| io.puts '# bundler.rb'   end
29
    open 'bundler/lib/bundler/b.rb',  'w' do |io| io.puts '# b.rb'         end
34
    File.open 'bundler/exe/bundle',        'w' do |io| io.puts '# bundle'       end
35
    File.open 'bundler/lib/bundler.rb',    'w' do |io| io.puts '# bundler.rb'   end
36
    File.open 'bundler/lib/bundler/b.rb',  'w' do |io| io.puts '# b.rb'         end
30 37

  
31 38
    FileUtils.mkdir_p 'default/gems'
32 39

  
33 40
    gemspec = Gem::Specification.new
34 41
    gemspec.name = "bundler"
35
    gemspec.version = "1.16.0"
42
    gemspec.version = BUNDLER_VERS
36 43
    gemspec.bindir = "exe"
37 44
    gemspec.executables = ["bundle"]
38 45

  
39
    open 'bundler/bundler.gemspec',   'w' do |io|
46
    File.open 'bundler/bundler.gemspec',   'w' do |io|
40 47
      io.puts gemspec.to_ruby
41 48
    end
42 49

  
......
46 53
    end
47 54

  
48 55
    FileUtils.mkdir_p File.join(Gem.default_dir, "specifications")
56

  
57
    open(File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec"), 'w') do |io|
58
      io.puts "# bundler-#{BUNDLER_VERS}"
59
    end
60

  
49 61
    open(File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec"), 'w') do |io|
50 62
      io.puts '# bundler-audit'
51 63
    end
......
134 146

  
135 147
    default_dir = Gem::Specification.default_specifications_dir
136 148

  
149
    # expect to remove other versions of bundler gemspecs on default specification directory.
137 150
    refute_path_exists File.join(default_dir, "bundler-1.15.4.gemspec")
138
    refute_path_exists 'default/gems/bundler-1.15.4'
139

  
140
    assert_path_exists File.join(default_dir, "bundler-1.16.0.gemspec")
141
    assert_path_exists 'default/gems/bundler-1.16.0'
151
    assert_path_exists File.join(default_dir, "bundler-#{BUNDLER_VERS}.gemspec")
142 152

  
153
    # expect to not remove bundler-* gemspecs.
143 154
    assert_path_exists File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec")
155

  
156
    # expect to remove normal gem that was same version. because it's promoted default gems.
157
    refute_path_exists File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec")
158

  
159
    # expect to install default gems. It location was `site_ruby` directory on real world.
160
    assert_path_exists "default/gems/bundler-#{BUNDLER_VERS}"
161

  
162
    # expect to not remove other versions of bundler on `site_ruby`
163
    assert_path_exists 'default/gems/bundler-1.15.4'
164

  
165
    # TODO: We need to assert to remove same version of bundler on gem_dir directory(It's not site_ruby dir)
166

  
167
    # expect to not remove bundler-* direcotyr.
144 168
    assert_path_exists 'default/gems/bundler-audit-1.0.0'
145 169
  end if Gem::USE_BUNDLER_FOR_GEMDEPS
146 170

  
......
162 186
    FileUtils.mkdir_p lib_rubygems_defaults
163 187
    FileUtils.mkdir_p lib_bundler
164 188

  
165
    open securerandom_rb,    'w' do |io| io.puts '# securerandom.rb'     end
189
    File.open securerandom_rb,    'w' do |io| io.puts '# securerandom.rb'     end
166 190

  
167
    open old_builder_rb,     'w' do |io| io.puts '# builder.rb'          end
168
    open old_format_rb,      'w' do |io| io.puts '# format.rb'           end
169
    open old_bundler_c_rb,   'w' do |io| io.puts '# c.rb'                end
191
    File.open old_builder_rb,     'w' do |io| io.puts '# builder.rb'          end
192
    File.open old_format_rb,      'w' do |io| io.puts '# format.rb'           end
193
    File.open old_bundler_c_rb,   'w' do |io| io.puts '# c.rb'                end
170 194

  
171
    open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb'            end
172
    open os_defaults_rb,     'w' do |io| io.puts '# operating_system.rb' end
195
    File.open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb'            end
196
    File.open os_defaults_rb,     'w' do |io| io.puts '# operating_system.rb' end
173 197

  
174 198
    @cmd.remove_old_lib_files lib
175 199

  
......
191 215

  
192 216
    @cmd.options[:previous_version] = Gem::Version.new '2.0.2'
193 217

  
194
    open 'History.txt', 'w' do |io|
218
    File.open 'History.txt', 'w' do |io|
195 219
      io.puts <<-History_txt
196 220
# coding: UTF-8
197 221

  
test/rubygems/test_gem_commands_uninstall_command.rb
92 92
    # Evil hack to prevent false removal success
93 93
    FileUtils.rm_f @executable
94 94

  
95
    open @executable, "wb+" do |f| f.puts "binary" end
95
    File.open @executable, "wb+" do |f| f.puts "binary" end
96 96

  
97 97
    @cmd.options[:executables] = true
98 98
    @cmd.options[:args] = [@spec.name]
......
204 204
    end
205 205

  
206 206
    assert Gem::Specification.find_all_by_name('dep_x').length > 0
207
    assert Gem::Specification.find_all_by_name('x').length == 0
207
    assert Gem::Specification.find_all_by_name('x').length.zero?
208 208
  end
209 209

  
210 210
  def test_execute_all
test/rubygems/test_gem_dependency_installer.rb
424 424
    extconf_rb = File.join @gemhome, 'gems', 'e-1', 'extconf.rb'
425 425
    FileUtils.mkdir_p File.dirname extconf_rb
426 426

  
427
    open extconf_rb, 'w' do |io|
427
    File.open extconf_rb, 'w' do |io|
428 428
      io.write <<-EXTCONF_RB
429 429
        require 'mkmf'
430 430
        create_makefile 'e'
test/rubygems/test_gem_doctor.rb
24 24

  
25 25
    FileUtils.rm b.spec_file
26 26

  
27
    open c.spec_file, 'w' do |io|
27
    File.open c.spec_file, 'w' do |io|
28 28
      io.write 'this will raise an exception when evaluated.'
29 29
    end
30 30

  
......
77 77

  
78 78
    FileUtils.rm b.spec_file
79 79

  
80
    open c.spec_file, 'w' do |io|
80
    File.open c.spec_file, 'w' do |io|
81 81
      io.write 'this will raise an exception when evaluated.'
82 82
    end
83 83

  
test/rubygems/test_gem_ext_builder.rb
32 32
    results = []
33 33

  
34 34
    Dir.chdir @ext do
35
      open 'Makefile', 'w' do |io|
35
      File.open 'Makefile', 'w' do |io|
36 36
        io.puts <<-MAKEFILE
37 37
all:
38 38
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
......
72 72
    results = []
73 73

  
74 74
    Dir.chdir @ext do
75
      open 'Makefile', 'w' do |io|
75
      File.open 'Makefile', 'w' do |io|
76 76
        io.puts <<-MAKEFILE
77 77
all:
78 78
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
......
107 107

  
108 108
    extconf_rb = File.join ext_dir, 'extconf.rb'
109 109

  
110
    open extconf_rb, 'w' do |f|
110
    File.open extconf_rb, 'w' do |f|
111 111
      f.write <<-'RUBY'
112 112
        require 'mkmf'
113 113

  
......
168 168

  
169 169
    extconf_rb = File.join ext_dir, 'extconf.rb'
170 170

  
171
    open extconf_rb, 'w' do |f|
171
    File.open extconf_rb, 'w' do |f|
172 172
      f.write <<-'RUBY'
173 173
        require 'mkmf'
174 174

  
......
290 290

  
291 291
    FileUtils.mkdir_p @spec.gem_dir
292 292

  
293
    open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f|
293
    File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f|
294 294
      f.write <<-'RUBY'
295 295
        puts "IN EXTCONF"
296 296
        extconf_args = File.join File.dirname(__FILE__), 'extconf_args'
......
323 323

  
324 324
    build_info_file = File.join build_info_dir, "#{@spec.full_name}.info"
325 325

  
326
    open build_info_file, 'w' do |io|
326
    File.open build_info_file, 'w' do |io|
327 327
      io.puts '--with-foo-dir=/nonexistent'
328 328
    end
329 329

  
test/rubygems/test_gem_gem_runner.rb
1 1
# frozen_string_literal: true
2 2
require 'rubygems/test_case'
3
begin
4
  gem_home_files = lambda{
5
    if Dir.exist?(ENV["GEM_HOME"])
6
      require "find"
7
      ary = Find.find(ENV["GEM_HOME"]).to_a
8
    else
9
      []
10
    end
11
  }
12
  prev_gem_home = ENV["GEM_HOME"]
13
  prev_gem_home_files = gem_home_files.call
14
  prev_threads = Thread.list.map{|e| e.inspect}
15

  
16
  require 'rubygems/gem_runner'
17
ensure
18
  if $!
19
    msg = <<eom
20
***************
21
PREV
22
  GEM_HOME: #{prev_gem_home}
23
  Files in GEM_HOME: #{prev_gem_home_files.inspect}
24
  Threads: #{prev_threads.inspect}
25
Current:
26
  GEM_HOME: #{ENV["GEM_HOME"]}
27
  Files in GEM_HOME: #{gem_home_files.call}
28
  Threads: #{Thread.list.map{|e| e.inspect}.inspect}
29
Exception: #{$!.message}
30
eom
31
    p $!.class
32
    p $!.message.frozen?
33
    raise $!.class, msg, $!.backtrace
34
  end
35
end
3
require 'rubygems/gem_runner'
36 4

  
37 5
class TestGemGemRunner < Gem::TestCase
38 6

  
test/rubygems/test_gem_gemcutter_utilities.rb
31 31

  
32 32
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
33 33

  
34
    open Gem.configuration.credentials_path, 'w' do |f|
34
    File.open Gem.configuration.credentials_path, 'w' do |f|
35 35
      f.write keys.to_yaml
36 36
    end
37 37

  
......
46 46
    keys = { :rubygems_api_key => 'KEY' }
47 47
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
48 48

  
49
    open Gem.configuration.credentials_path, 'w' do |f|
49
    File.open Gem.configuration.credentials_path, 'w' do |f|
50 50
      f.write keys.to_yaml
51 51
    end
52 52

  
......
59 59
    keys = { :rubygems_api_key => 'KEY', :other => 'OTHER' }
60 60
    FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
61 61

  
62
    open Gem.configuration.credentials_path, 'w' do |f|
62
    File.open Gem.configuration.credentials_path, 'w' do |f|
63 63
      f.write keys.to_yaml
64 64
    end
65 65

  
......
163 163
    other_api_key = 'f46dbb18bb6a9c97cdc61b5b85c186a17403cdcbf'
164 164

  
165 165
    FileUtils.mkdir_p File.dirname(Gem.configuration.credentials_path)
166
    open Gem.configuration.credentials_path, 'w' do |f|
166
    File.open Gem.configuration.credentials_path, 'w' do |f|
167 167
      f.write Hash[:other_api_key, other_api_key].to_yaml
168 168
    end
169 169
    util_sign_in [api_key, 200, 'OK']
test/rubygems/test_gem_indexer.rb
39 39

  
40 40
  def test_initialize
41 41
    assert_equal @tempdir, @indexer.dest_directory
42
    assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"),
43
                 @indexer.directory
42
    assert_match %r{#{Dir.mktmpdir('gem_generate_index').match(/.*-/)}}, @indexer.directory
44 43

  
45 44
    indexer = Gem::Indexer.new @tempdir
46 45
    assert indexer.build_modern
test/rubygems/test_gem_install_update_options.rb
141 141
  def test_user_install_disabled_read_only
142 142
    if win_platform?
143 143
      skip('test_user_install_disabled_read_only test skipped on MS Windows')
144
    elsif Process.uid.zero?
145
      skip('test_user_install_disabled_read_only test skipped in root privilege')
144 146
    else
145 147
      @cmd.handle_options %w[--no-user-install]
146 148

  
test/rubygems/test_gem_installer.rb
140 140
      s.require_path = 'lib'
141 141
    end
142 142

  
143
    open File.join(util_inst_bindir, 'executable'), 'w' do |io|
143
    File.open File.join(util_inst_bindir, 'executable'), 'w' do |io|
144 144
     io.write <<-EXEC
145 145
#!/usr/local/bin/ruby
146 146
#
......
437 437

  
438 438
    if win_platform?
439 439
      skip('test_generate_bin_script_no_perms skipped on MS Windows')
440
    elsif Process.uid.zero?
441
      skip('test_generate_bin_script_no_perms skipped in root privilege')
440 442
    else
441 443
      FileUtils.chmod 0000, util_inst_bindir
442 444

  
......
529 531

  
530 532
    if win_platform?
531 533
      skip('test_generate_bin_symlink_no_perms skipped on MS Windows')
534
    elsif Process.uid.zero?
535
      skip('test_user_install_disabled_read_only test skipped in root privilege')
532 536
    else
533 537
      FileUtils.chmod 0000, util_inst_bindir
534 538

  
test/rubygems/test_gem_package.rb
24 24
  end
25 25

  
26 26
  def test_class_new_old_format
27
    open 'old_format.gem', 'wb' do |io|
27
    File.open 'old_format.gem', 'wb' do |io|
28 28
      io.write SIMPLE_GEM
29 29
    end
30 30

  
......
45 45

  
46 46
    FileUtils.mkdir 'lib'
47 47

  
48
    open 'lib/code.rb', 'w' do |io|
48
    File.open 'lib/code.rb', 'w' do |io|
49 49
      io.write '# lib/code.rb'
50 50
    end
51 51

  
......
110 110

  
111 111
    FileUtils.mkdir_p 'lib/empty'
112 112

  
113
    open 'lib/code.rb',  'w' do |io| io.write '# lib/code.rb'  end
114
    open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end
113
    File.open 'lib/code.rb',  'w' do |io| io.write '# lib/code.rb'  end
114
    File.open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end
115 115

  
116 116
    package = Gem::Package.new 'bogus.gem'
117 117
    package.spec = spec
......
140 140
    spec.files = %w[lib/code.rb lib/code_sym.rb]
141 141

  
142 142
    FileUtils.mkdir_p 'lib'
143
    open 'lib/code.rb',  'w' do |io| io.write '# lib/code.rb'  end
143
    File.open 'lib/code.rb',  'w' do |io| io.write '# lib/code.rb'  end
144 144

  
145 145
    # NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb
146 146
    File.symlink('code.rb', 'lib/code_sym.rb')
......
179 179

  
180 180
    FileUtils.mkdir 'lib'
181 181

  
182
    open 'lib/code.rb', 'w' do |io|
182
    File.open 'lib/code.rb', 'w' do |io|
183 183
      io.write '# lib/code.rb'
184 184
    end
185 185

  
......
218 218

  
219 219
    FileUtils.mkdir 'lib'
220 220

  
221
    open 'lib/code.rb', 'w' do |io|
221
    File.open 'lib/code.rb', 'w' do |io|
222 222
      io.write '# lib/code.rb'
223 223
    end
224 224

  
......
261 261

  
262 262
    FileUtils.mkdir 'lib'
263 263

  
264
    open 'lib/code.rb', 'w' do |io|
264
    File.open 'lib/code.rb', 'w' do |io|
265 265
      io.write '# lib/code.rb'
266 266
    end
267 267

  
......
311 311

  
312 312
    FileUtils.mkdir 'lib'
313 313

  
314
    open 'lib/code.rb', 'w' do |io|
314
    File.open 'lib/code.rb', 'w' do |io|
315 315
      io.write '# lib/code.rb'
316 316
    end
317 317

  
......
348 348

  
349 349
    FileUtils.mkdir 'lib'
350 350

  
351
    open 'lib/code.rb', 'w' do |io|
351
    File.open 'lib/code.rb', 'w' do |io|
352 352
      io.write '# lib/code.rb'
353 353
    end
354 354

  
......
408 408
      end
409 409
    end
410 410

  
411
    open 'empty.gem', 'wb' do |io|
411
    File.open 'empty.gem', 'wb' do |io|
412 412
      io.write gem.string
413 413
    end
414 414

  
......
455 455
                 File.read(extracted)
456 456
  end
457 457

  
458
  def test_extract_symlink_parent
459
   skip 'symlink not supported' if Gem.win_platform?
460

  
461
   package = Gem::Package.new @gem
462

  
463
   tgz_io = util_tar_gz do |tar|
464
     tar.mkdir       'lib',               0755
465
     tar.add_symlink 'lib/link', '../..', 0644
466
     tar.add_file    'lib/link/outside.txt', 0644 do |io| io.write 'hi' end
467
   end
468

  
469
   # Extract into a subdirectory of @destination; if this test fails it writes
470
   # a file outside destination_subdir, but we want the file to remain inside
471
   # @destination so it will be cleaned up.
472
   destination_subdir = File.join @destination, 'subdir'
473
   FileUtils.mkdir_p destination_subdir
474

  
475
   e = assert_raises Gem::Package::PathError do
476
     package.extract_tar_gz tgz_io, destination_subdir
477
   end
478

  
479
   assert_equal("installing into parent path lib/link/outside.txt of " +
480
                 "#{destination_subdir} is not allowed", e.message)
481
  end
482

  
458 483
  def test_extract_tar_gz_directory
459 484
    package = Gem::Package.new @gem
460 485

  
......
566 591
                 "#{@destination} is not allowed", e.message)
567 592
  end
568 593

  
594
  def test_install_location_suffix
595
    package = Gem::Package.new @gem
596

  
597
    filename = "../#{File.basename(@destination)}suffix.rb"
598

  
599
    e = assert_raises Gem::Package::PathError do
600
      package.install_location filename, @destination
601
    end
602

  
603
    parent = File.expand_path File.join @destination, filename
604

  
605
    assert_equal("installing into parent path #{parent} of " +
606
                 "#{@destination} is not allowed", e.message)
607
  end
608

  
569 609
  def test_load_spec
570 610
    entry = StringIO.new Gem.gzip @spec.to_yaml
571 611
    def entry.full_name() 'metadata.gz' end
......
620 660
      end
621 661
    end
622 662

  
623
    open 'mismatch.gem', 'wb' do |io|
663
    File.open 'mismatch.gem', 'wb' do |io|
624 664
      io.write gem.string
625 665
    end
626 666

  
......
670 710
      end
671 711
    end
672 712

  
673
    open 'data_checksum_missing.gem', 'wb' do |io|
713
    File.open 'data_checksum_missing.gem', 'wb' do |io|
674 714
      io.write gem.string
675 715
    end
676 716

  
......
723 763
    assert_match %r%nonexistent.gem$%,           e.message
724 764
  end
725 765

  
766
  def test_verify_duplicate_file
767
    FileUtils.mkdir_p 'lib'
768
    FileUtils.touch 'lib/code.rb'
769

  
770
    build = Gem::Package.new @gem
771
    build.spec = @spec
772
    build.setup_signer
773
    open @gem, 'wb' do |gem_io|
774
      Gem::Package::TarWriter.new gem_io do |gem|
775
        build.add_metadata gem
776
        build.add_contents gem
777

  
778
        gem.add_file_simple 'a.sig', 0444, 0
779
        gem.add_file_simple 'a.sig', 0444, 0
780
      end
781
    end
782

  
783
    package = Gem::Package.new @gem
784

  
785
    e = assert_raises Gem::Security::Exception do
786
      package.verify
787
    end
788

  
789
    assert_equal 'duplicate files in the package: ("a.sig")', e.message
790
  end
791

  
726 792
  def test_verify_security_policy
727 793
    skip 'openssl is missing' unless defined?(OpenSSL::SSL)
728 794

  
......
773 839
    FileUtils.mkdir 'lib'
774 840
    FileUtils.touch 'lib/code.rb'
775 841

  
776
    open @gem, 'wb' do |gem_io|
842
    File.open @gem, 'wb' do |gem_io|
777 843
      Gem::Package::TarWriter.new gem_io do |gem|
778 844
        build.add_metadata gem
779 845
        build.add_contents gem
780 846

  
781 847
        # write bogus data.tar.gz to foil signature
782 848
        bogus_data = Gem.gzip 'hello'
783
        gem.add_file_simple 'data.tar.gz', 0444, bogus_data.length do |io|
849
        fake_signer = Class.new do
850
          def digest_name; 'SHA512'; end
851
          def digest_algorithm; Digest(:SHA512); end
852
          def key; 'key'; end
853
          def sign(*); 'fake_sig'; end
854
        end
855
        gem.add_file_signed 'data2.tar.gz', 0444, fake_signer.new do |io|
784 856
          io.write bogus_data
785 857
        end
786 858

  
......
804 876
  end
... This diff was truncated because it exceeds the maximum size that can be displayed.