rubygems-update 2.0.17 → 2.1.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/.autotest +1 -1
  5. data/History.txt +82 -153
  6. data/Manifest.txt +35 -9
  7. data/Rakefile +35 -36
  8. data/lib/rubygems.rb +106 -18
  9. data/lib/rubygems/available_set.rb +68 -0
  10. data/lib/rubygems/basic_specification.rb +139 -0
  11. data/lib/rubygems/command_manager.rb +37 -40
  12. data/lib/rubygems/commands/cert_command.rb +78 -29
  13. data/lib/rubygems/commands/cleanup_command.rb +2 -2
  14. data/lib/rubygems/commands/contents_command.rb +101 -58
  15. data/lib/rubygems/commands/dependency_command.rb +94 -53
  16. data/lib/rubygems/commands/environment_command.rb +70 -53
  17. data/lib/rubygems/commands/fetch_command.rb +1 -2
  18. data/lib/rubygems/commands/help_command.rb +85 -55
  19. data/lib/rubygems/commands/install_command.rb +84 -42
  20. data/lib/rubygems/commands/outdated_command.rb +2 -12
  21. data/lib/rubygems/commands/owner_command.rb +6 -0
  22. data/lib/rubygems/commands/pristine_command.rb +26 -16
  23. data/lib/rubygems/commands/sources_command.rb +85 -70
  24. data/lib/rubygems/commands/uninstall_command.rb +32 -2
  25. data/lib/rubygems/commands/update_command.rb +111 -75
  26. data/lib/rubygems/config_file.rb +15 -3
  27. data/lib/rubygems/core_ext/kernel_require.rb +9 -31
  28. data/lib/rubygems/defaults.rb +8 -0
  29. data/lib/rubygems/dependency.rb +4 -2
  30. data/lib/rubygems/dependency_installer.rb +180 -170
  31. data/lib/rubygems/dependency_resolver.rb +191 -526
  32. data/lib/rubygems/dependency_resolver/activation_request.rb +109 -0
  33. data/lib/rubygems/dependency_resolver/api_set.rb +65 -0
  34. data/lib/rubygems/dependency_resolver/api_specification.rb +36 -0
  35. data/lib/rubygems/dependency_resolver/composed_set.rb +18 -0
  36. data/lib/rubygems/dependency_resolver/current_set.rb +16 -0
  37. data/lib/rubygems/dependency_resolver/dependency_conflict.rb +85 -0
  38. data/lib/rubygems/dependency_resolver/dependency_request.rb +51 -0
  39. data/lib/rubygems/dependency_resolver/index_set.rb +59 -0
  40. data/lib/rubygems/dependency_resolver/index_specification.rb +53 -0
  41. data/lib/rubygems/dependency_resolver/installed_specification.rb +38 -0
  42. data/lib/rubygems/dependency_resolver/installer_set.rb +130 -0
  43. data/lib/rubygems/exceptions.rb +88 -1
  44. data/lib/rubygems/ext/builder.rb +1 -1
  45. data/lib/rubygems/gem_runner.rb +17 -9
  46. data/lib/rubygems/gemcutter_utilities.rb +72 -42
  47. data/lib/rubygems/install_default_message.rb +12 -0
  48. data/lib/rubygems/install_update_options.rb +3 -0
  49. data/lib/rubygems/installer.rb +55 -30
  50. data/lib/rubygems/name_tuple.rb +18 -7
  51. data/lib/rubygems/package.rb +50 -25
  52. data/lib/rubygems/package/tar_test_case.rb +9 -9
  53. data/lib/rubygems/package/tar_writer.rb +35 -12
  54. data/lib/rubygems/package_task.rb +2 -5
  55. data/lib/rubygems/path_support.rb +10 -0
  56. data/lib/rubygems/platform.rb +9 -3
  57. data/lib/rubygems/psych_additions.rb +1 -1
  58. data/lib/rubygems/remote_fetcher.rb +9 -276
  59. data/lib/rubygems/request.rb +267 -0
  60. data/lib/rubygems/request_set.rb +123 -125
  61. data/lib/rubygems/request_set/gem_dependency_api.rb +39 -0
  62. data/lib/rubygems/security.rb +32 -23
  63. data/lib/rubygems/security/policy.rb +35 -9
  64. data/lib/rubygems/security/signer.rb +2 -2
  65. data/lib/rubygems/server.rb +8 -16
  66. data/lib/rubygems/source.rb +25 -14
  67. data/lib/rubygems/source/installed.rb +28 -0
  68. data/lib/rubygems/source/local.rb +122 -0
  69. data/lib/rubygems/source/specific_file.rb +28 -0
  70. data/lib/rubygems/source_local.rb +2 -89
  71. data/lib/rubygems/source_specific_file.rb +2 -26
  72. data/lib/rubygems/spec_fetcher.rb +11 -11
  73. data/lib/rubygems/specification.rb +186 -198
  74. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  75. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  76. data/lib/rubygems/ssl_certs/{GeoTrustGlobalCA.pem → GeoTrust_Global_CA.pem} +20 -20
  77. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  78. data/lib/rubygems/stub_specification.rb +119 -0
  79. data/lib/rubygems/test_case.rb +117 -49
  80. data/lib/rubygems/uninstaller.rb +14 -9
  81. data/lib/rubygems/uri_formatter.rb +39 -0
  82. data/lib/rubygems/util/list.rb +44 -0
  83. data/lib/rubygems/version.rb +15 -5
  84. data/lib/rubygems/version_option.rb +8 -2
  85. data/test/rubygems/ca_cert.pem +23 -0
  86. data/test/rubygems/client.pem +49 -0
  87. data/test/rubygems/encrypted_private_key.pem +30 -0
  88. data/test/rubygems/invalid_client.pem +49 -0
  89. data/test/rubygems/specifications/bar-0.0.2.gemspec +9 -0
  90. data/test/rubygems/specifications/foo-0.0.1.gemspec +0 -0
  91. data/test/rubygems/test_gem.rb +76 -454
  92. data/test/rubygems/test_gem_command_manager.rb +23 -21
  93. data/test/rubygems/test_gem_commands_cert_command.rb +154 -14
  94. data/test/rubygems/test_gem_commands_cleanup_command.rb +15 -0
  95. data/test/rubygems/test_gem_commands_contents_command.rb +32 -4
  96. data/test/rubygems/test_gem_commands_environment_command.rb +9 -1
  97. data/test/rubygems/test_gem_commands_fetch_command.rb +2 -28
  98. data/test/rubygems/test_gem_commands_help_command.rb +6 -3
  99. data/test/rubygems/test_gem_commands_install_command.rb +2 -65
  100. data/test/rubygems/test_gem_commands_owner_command.rb +49 -0
  101. data/test/rubygems/test_gem_commands_pristine_command.rb +30 -0
  102. data/test/rubygems/test_gem_commands_sources_command.rb +1 -1
  103. data/test/rubygems/test_gem_commands_uninstall_command.rb +33 -0
  104. data/test/rubygems/test_gem_commands_update_command.rb +2 -1
  105. data/test/rubygems/test_gem_config_file.rb +12 -0
  106. data/test/rubygems/test_gem_dependency_installer.rb +58 -65
  107. data/test/rubygems/test_gem_dependency_resolver.rb +6 -3
  108. data/test/rubygems/test_gem_dependency_resolver_dependency_conflict.rb +36 -0
  109. data/test/rubygems/test_gem_ext_builder.rb +2 -4
  110. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +7 -2
  111. data/test/rubygems/test_gem_gem_runner.rb +17 -13
  112. data/test/rubygems/test_gem_gemcutter_utilities.rb +6 -19
  113. data/test/rubygems/test_gem_impossible_dependencies_error.rb +41 -0
  114. data/test/rubygems/test_gem_install_update_options.rb +4 -1
  115. data/test/rubygems/test_gem_installer.rb +31 -2
  116. data/test/rubygems/test_gem_name_tuple.rb +22 -0
  117. data/test/rubygems/test_gem_package.rb +122 -11
  118. data/test/rubygems/test_gem_package_old.rb +8 -0
  119. data/test/rubygems/test_gem_package_tar_reader.rb +9 -8
  120. data/test/rubygems/test_gem_package_tar_reader_entry.rb +1 -1
  121. data/test/rubygems/test_gem_package_tar_writer.rb +78 -56
  122. data/test/rubygems/test_gem_package_task.rb +2 -23
  123. data/test/rubygems/test_gem_path_support.rb +17 -0
  124. data/test/rubygems/test_gem_platform.rb +18 -0
  125. data/test/rubygems/test_gem_remote_fetcher.rb +106 -385
  126. data/test/rubygems/test_gem_request.rb +239 -0
  127. data/test/rubygems/test_gem_requirement.rb +9 -11
  128. data/test/rubygems/test_gem_security.rb +58 -2
  129. data/test/rubygems/test_gem_security_policy.rb +42 -1
  130. data/test/rubygems/test_gem_security_signer.rb +13 -1
  131. data/test/rubygems/test_gem_security_trust_dir.rb +5 -1
  132. data/test/rubygems/test_gem_server.rb +1 -105
  133. data/test/rubygems/test_gem_source.rb +4 -14
  134. data/test/rubygems/test_gem_source_local.rb +4 -4
  135. data/test/rubygems/test_gem_source_specific_file.rb +1 -1
  136. data/test/rubygems/test_gem_spec_fetcher.rb +0 -12
  137. data/test/rubygems/test_gem_specification.rb +452 -28
  138. data/test/rubygems/test_gem_stub_specification.rb +30 -0
  139. data/test/rubygems/test_gem_uninstaller.rb +14 -0
  140. data/test/rubygems/test_gem_uri_formatter.rb +20 -0
  141. data/test/rubygems/test_gem_version.rb +23 -13
  142. data/test/rubygems/test_gem_version_option.rb +63 -1
  143. data/test/rubygems/test_require.rb +0 -12
  144. data/util/create_encrypted_key.rb +16 -0
  145. metadata +161 -23
  146. metadata.gz.sig +0 -0
  147. data/CVE-2013-4287.txt +0 -36
  148. data/CVE-2013-4363.txt +0 -45
  149. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  150. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  151. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  152. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  153. data/test/rubygems/test_bundled_ca.rb +0 -59
  154. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -21,6 +21,8 @@ class TestGemPackageOld < Gem::TestCase
21
21
  end
22
22
 
23
23
  def test_contents_security_policy
24
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
25
+
24
26
  @package.security_policy = Gem::Security::AlmostNoSecurity
25
27
 
26
28
  assert_raises Gem::Security::Exception do
@@ -40,6 +42,8 @@ class TestGemPackageOld < Gem::TestCase
40
42
  end
41
43
 
42
44
  def test_extract_files_security_policy
45
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
46
+
43
47
  @package.security_policy = Gem::Security::AlmostNoSecurity
44
48
 
45
49
  assert_raises Gem::Security::Exception do
@@ -52,6 +56,8 @@ class TestGemPackageOld < Gem::TestCase
52
56
  end
53
57
 
54
58
  def test_spec_security_policy
59
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
60
+
55
61
  @package.security_policy = Gem::Security::AlmostNoSecurity
56
62
 
57
63
  assert_raises Gem::Security::Exception do
@@ -60,6 +66,8 @@ class TestGemPackageOld < Gem::TestCase
60
66
  end
61
67
 
62
68
  def test_verify
69
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
70
+
63
71
  assert @package.verify
64
72
 
65
73
  @package.security_policy = Gem::Security::NoSecurity
@@ -4,8 +4,8 @@ require 'rubygems/package'
4
4
  class TestGemPackageTarReader < Gem::Package::TarTestCase
5
5
 
6
6
  def test_each_entry
7
- tar = tar_dir_header "foo", "bar", 0
8
- tar << tar_file_header("bar", "baz", 0, 0)
7
+ tar = tar_dir_header "foo", "bar", 0, Time.now
8
+ tar << tar_file_header("bar", "baz", 0, 0, Time.now)
9
9
 
10
10
  io = TempIO.new tar
11
11
 
@@ -25,8 +25,9 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
25
25
  def test_rewind
26
26
  content = ('a'..'z').to_a.join(" ")
27
27
 
28
- str = tar_file_header("lib/foo", "", 010644, content.size) + content +
29
- "\0" * (512 - content.size)
28
+ str =
29
+ tar_file_header("lib/foo", "", 010644, content.size, Time.now) +
30
+ content + "\0" * (512 - content.size)
30
31
  str << "\0" * 1024
31
32
 
32
33
  Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
@@ -43,8 +44,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
43
44
  end
44
45
 
45
46
  def test_seek
46
- tar = tar_dir_header "foo", "bar", 0
47
- tar << tar_file_header("bar", "baz", 0, 0)
47
+ tar = tar_dir_header "foo", "bar", 0, Time.now
48
+ tar << tar_file_header("bar", "baz", 0, 0, Time.now)
48
49
 
49
50
  io = TempIO.new tar
50
51
 
@@ -60,8 +61,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
60
61
  end
61
62
 
62
63
  def test_seek_missing
63
- tar = tar_dir_header "foo", "bar", 0
64
- tar << tar_file_header("bar", "baz", 0, 0)
64
+ tar = tar_dir_header "foo", "bar", 0, Time.now
65
+ tar << tar_file_header("bar", "baz", 0, 0, Time.now)
65
66
 
66
67
  io = TempIO.new tar
67
68
 
@@ -9,7 +9,7 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
9
9
  @contents = ('a'..'z').to_a.join * 100
10
10
 
11
11
  @tar = ''
12
- @tar << tar_file_header("lib/foo", "", 0, @contents.size)
12
+ @tar << tar_file_header("lib/foo", "", 0, @contents.size, Time.now)
13
13
  @tar << @contents
14
14
  @tar << "\0" * (512 - (@tar.size % 512))
15
15
 
@@ -1,5 +1,6 @@
1
1
  require 'rubygems/package/tar_test_case'
2
2
  require 'rubygems/package/tar_writer'
3
+ require 'minitest/mock'
3
4
 
4
5
  class TestGemPackageTarWriter < Gem::Package::TarTestCase
5
6
 
@@ -18,112 +19,130 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
18
19
  end
19
20
 
20
21
  def test_add_file
21
- @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end
22
+ Time.stub :now, Time.at(1458518157) do
23
+ @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end
22
24
 
23
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
25
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
24
26
  @io.string[0, 512])
27
+ end
25
28
  assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
26
29
  assert_equal 1024, @io.pos
27
30
  end
28
31
 
29
32
  def test_add_file_digest
30
- digest_algorithms = OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512
33
+ digest_algorithms = Digest::SHA1, Digest::SHA512
31
34
 
32
- digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
33
- io.write 'a' * 10
34
- end
35
+ Time.stub :now, Time.at(1458518157) do
36
+ digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
37
+ io.write 'a' * 10
38
+ end
35
39
 
36
- assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
37
- digests['SHA1'].hexdigest
38
- assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
39
- '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
40
- '4993d6b40a4e4d8424196afc347e97640d68de61' \
41
- 'e1cf14b0',
42
- digests['SHA512'].hexdigest
40
+ assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
41
+ digests['SHA1'].hexdigest
42
+ assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
43
+ '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
44
+ '4993d6b40a4e4d8424196afc347e97640d68de61' \
45
+ 'e1cf14b0',
46
+ digests['SHA512'].hexdigest
43
47
 
44
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
48
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
45
49
  @io.string[0, 512])
50
+ end
46
51
  assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
47
52
  assert_equal 1024, @io.pos
48
53
  end
49
54
 
50
55
  def test_add_file_digest_multiple
51
- digest_algorithms = [OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512]
56
+ digest_algorithms = [Digest::SHA1, Digest::SHA512]
52
57
 
53
- digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
54
- io.write 'a' * 10
55
- end
58
+ Time.stub :now, Time.at(1458518157) do
59
+ digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
60
+ io.write 'a' * 10
61
+ end
56
62
 
57
- assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
58
- digests['SHA1'].hexdigest
59
- assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
60
- '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
61
- '4993d6b40a4e4d8424196afc347e97640d68de61' \
62
- 'e1cf14b0',
63
- digests['SHA512'].hexdigest
63
+ assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
64
+ digests['SHA1'].hexdigest
65
+ assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
66
+ '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
67
+ '4993d6b40a4e4d8424196afc347e97640d68de61' \
68
+ 'e1cf14b0',
69
+ digests['SHA512'].hexdigest
64
70
 
65
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
66
- @io.string[0, 512])
71
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
72
+ @io.string[0, 512])
73
+ end
67
74
  assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
68
75
  assert_equal 1024, @io.pos
69
76
  end
70
77
 
71
78
  def test_add_file_signer
79
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
80
+
72
81
  signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT]
73
82
 
74
- @tar_writer.add_file_signed 'x', 0644, signer do |io|
75
- io.write 'a' * 10
76
- end
83
+ Time.stub :now, Time.at(1458518157) do
84
+ @tar_writer.add_file_signed 'x', 0644, signer do |io|
85
+ io.write 'a' * 10
86
+ end
87
+
88
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
89
+ @io.string[0, 512])
77
90
 
78
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
79
- @io.string[0, 512])
80
- assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
81
91
 
82
- digest = signer.digest_algorithm.new
83
- digest.update 'a' * 10
92
+ assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
84
93
 
85
- signature = signer.sign digest.digest
94
+ digest = signer.digest_algorithm.new
95
+ digest.update 'a' * 10
86
96
 
87
- assert_headers_equal(tar_file_header('x.sig', '', 0444, signature.length),
88
- @io.string[1024, 512])
89
- assert_equal "#{signature}#{"\0" * (512 - signature.length)}",
90
- @io.string[1536, 512]
97
+ signature = signer.sign digest.digest
98
+
99
+ assert_headers_equal(tar_file_header('x.sig', '', 0444, signature.length,
100
+ Time.now),
101
+ @io.string[1024, 512])
102
+ assert_equal "#{signature}#{"\0" * (512 - signature.length)}",
103
+ @io.string[1536, 512]
104
+
105
+ assert_equal 2048, @io.pos
106
+ end
91
107
 
92
- assert_equal 2048, @io.pos
93
108
  end
94
109
 
95
110
  def test_add_file_signer_empty
96
111
  signer = Gem::Security::Signer.new nil, nil
97
112
 
98
- @tar_writer.add_file_signed 'x', 0644, signer do |io|
99
- io.write 'a' * 10
100
- end
113
+ Time.stub :now, Time.at(1458518157) do
101
114
 
102
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
115
+ @tar_writer.add_file_signed 'x', 0644, signer do |io|
116
+ io.write 'a' * 10
117
+ end
118
+
119
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
103
120
  @io.string[0, 512])
121
+ end
104
122
  assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
105
123
 
106
- digest = signer.digest_algorithm.new
107
- digest.update 'a' * 10
108
-
109
124
  assert_equal 1024, @io.pos
110
125
  end
111
126
 
112
127
  def test_add_file_simple
113
- @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
128
+ Time.stub :now, Time.at(1458518157) do
129
+ @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
114
130
 
115
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
131
+ assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now),
116
132
  @io.string[0, 512])
133
+ end
117
134
 
118
135
  assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
119
136
  assert_equal 1024, @io.pos
120
137
  end
121
138
 
122
139
  def test_add_file_simple_padding
123
- @tar_writer.add_file_simple 'x', 0, 100
140
+ Time.stub :now, Time.at(1458518157) do
141
+ @tar_writer.add_file_simple 'x', 0, 100
124
142
 
125
- assert_headers_equal tar_file_header('x', '', 0, 100),
143
+ assert_headers_equal tar_file_header('x', '', 0, 100, Time.now),
126
144
  @io.string[0, 512]
145
+ end
127
146
 
128
147
  assert_equal "\0" * 512, @io.string[512, 512]
129
148
  end
@@ -182,11 +201,14 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
182
201
  end
183
202
 
184
203
  def test_mkdir
185
- @tar_writer.mkdir 'foo', 0644
204
+ Time.stub :now, Time.at(1458518157) do
205
+ @tar_writer.mkdir 'foo', 0644
186
206
 
187
- assert_headers_equal tar_dir_header('foo', '', 0644),
188
- @io.string[0, 512]
189
- assert_equal 512, @io.pos
207
+ assert_headers_equal tar_dir_header('foo', '', 0644, Time.now),
208
+ @io.string[0, 512]
209
+
210
+ assert_equal 512, @io.pos
211
+ end
190
212
  end
191
213
 
192
214
  def test_split_name
@@ -4,37 +4,16 @@ require 'rubygems/package_task'
4
4
 
5
5
  class TestGemPackageTask < Gem::TestCase
6
6
 
7
- def setup
8
- super
9
-
10
- Rake.application = Rake::Application.new
11
- RakeFileUtils.verbose_flag = false
12
- end
13
-
14
7
  def test_gem_package
15
8
  gem = Gem::Specification.new do |g|
16
9
  g.name = "pkgr"
17
10
  g.version = "1.2.3"
18
-
19
- g.authors = %w[author]
20
- g.files = %w[x]
21
- g.summary = 'summary'
11
+ g.files = Rake::FileList["x"].resolve
22
12
  end
23
-
24
13
  pkg = Gem::PackageTask.new(gem) do |p|
25
14
  p.package_files << "y"
26
15
  end
27
-
28
- assert_equal %w[x y], pkg.package_files
29
-
30
- Dir.chdir @tempdir do
31
- FileUtils.touch 'x'
32
- FileUtils.touch 'y'
33
-
34
- Rake.application['package'].invoke
35
-
36
- assert_path_exists 'pkg/pkgr-1.2.3.gem'
37
- end
16
+ assert_equal ["x", "y"], pkg.package_files
38
17
  end
39
18
 
40
19
  def test_gem_package_with_current_platform
@@ -64,4 +64,21 @@ class TestGemPathSupport < Gem::TestCase
64
64
  def util_path
65
65
  ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
66
66
  end
67
+
68
+ def test_initialize_spec
69
+ ENV["GEM_SPEC_CACHE"] = nil
70
+
71
+ ps = Gem::PathSupport.new
72
+ assert_equal Gem.default_spec_cache_dir, ps.spec_cache_dir
73
+
74
+ ENV["GEM_SPEC_CACHE"] = 'bar'
75
+
76
+ ps = Gem::PathSupport.new
77
+ assert_equal ENV["GEM_SPEC_CACHE"], ps.spec_cache_dir
78
+
79
+ ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
80
+
81
+ ps = Gem::PathSupport.new "GEM_SPEC_CACHE" => "foo"
82
+ assert_equal "foo", ps.spec_cache_dir
83
+ end
67
84
  end
@@ -186,6 +186,24 @@ class TestGemPlatform < Gem::TestCase
186
186
  assert((x86_darwin8 === Gem::Platform.local), 'universal =~ x86')
187
187
  end
188
188
 
189
+ def test_equals3_cpu_arm
190
+ arm = Gem::Platform.new 'arm-linux'
191
+ armv5 = Gem::Platform.new 'armv5-linux'
192
+ armv7 = Gem::Platform.new 'armv7-linux'
193
+
194
+ util_set_arch 'armv5-linux'
195
+ assert((arm === Gem::Platform.local), 'arm === armv5')
196
+ assert((armv5 === Gem::Platform.local), 'armv5 === armv5')
197
+ refute((armv7 === Gem::Platform.local), 'armv7 === armv5')
198
+ refute((Gem::Platform.local === arm), 'armv5 === arm')
199
+
200
+ util_set_arch 'armv7-linux'
201
+ assert((arm === Gem::Platform.local), 'arm === armv7')
202
+ refute((armv5 === Gem::Platform.local), 'armv5 === armv7')
203
+ assert((armv7 === Gem::Platform.local), 'armv7 === armv7')
204
+ refute((Gem::Platform.local === arm), 'armv7 === arm')
205
+ end
206
+
189
207
  def test_equals3_version
190
208
  util_set_arch 'i686-darwin8'
191
209
 
@@ -1,7 +1,13 @@
1
1
  require 'rubygems/test_case'
2
- require 'ostruct'
2
+
3
3
  require 'webrick'
4
- require 'webrick/https'
4
+ begin
5
+ require 'webrick/https'
6
+ rescue LoadError => e
7
+ raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
8
+ e.message =~ / -- openssl$/
9
+ end
10
+
5
11
  require 'rubygems/remote_fetcher'
6
12
  require 'rubygems/package'
7
13
  require 'minitest/mock'
@@ -69,6 +75,12 @@ gems:
69
75
 
70
76
  PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, '0.4.2')
71
77
 
78
+ # don't let 1.8 and 1.9 autotest collide
79
+ RUBY_VERSION =~ /(\d+)\.(\d+)\.(\d+)/
80
+ # don't let parallel runners collide
81
+ PROXY_PORT = process_based_port + 100 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
82
+ SERVER_PORT = process_based_port + 200 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
83
+
72
84
  DIR = File.expand_path(File.dirname(__FILE__))
73
85
 
74
86
  def setup
@@ -81,8 +93,8 @@ gems:
81
93
  self.class.enable_yaml = true
82
94
  self.class.enable_zip = false
83
95
 
84
- base_server_uri = "http://localhost:#{self.class.normal_server_port}"
85
- @proxy_uri = "http://localhost:#{self.class.proxy_server_port}"
96
+ base_server_uri = "http://localhost:#{SERVER_PORT}"
97
+ @proxy_uri = "http://localhost:#{PROXY_PORT}"
86
98
 
87
99
  @server_uri = base_server_uri + "/yaml"
88
100
  @server_z_uri = base_server_uri + "/yaml.Z"
@@ -122,27 +134,7 @@ gems:
122
134
 
123
135
  refute_nil fetcher
124
136
  assert_kind_of Gem::RemoteFetcher, fetcher
125
- assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s
126
- end
127
-
128
- def test_self_fetcher_with_proxy_URI
129
- proxy_uri = URI.parse 'http://proxy.example.com'
130
- Gem.configuration[:http_proxy] = proxy_uri
131
- Gem::RemoteFetcher.fetcher = nil
132
-
133
- fetcher = Gem::RemoteFetcher.fetcher
134
- refute_nil fetcher
135
-
136
- assert_kind_of Gem::RemoteFetcher, fetcher
137
- assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri)
138
- end
139
-
140
- def test_escape_auth_info
141
- assert_equal 'a%40b%5Cc', @fetcher.escape_auth_info('a@b\c')
142
- end
143
-
144
- def test_unescape_auth_info
145
- assert_equal 'a@b\c', @fetcher.unescape_auth_info('a%40b%5Cc')
137
+ assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy).to_s
146
138
  end
147
139
 
148
140
  def test_fetch_size_bad_uri
@@ -157,7 +149,7 @@ gems:
157
149
 
158
150
  def test_fetch_size_socket_error
159
151
  fetcher = Gem::RemoteFetcher.new nil
160
- def fetcher.connection_for(uri)
152
+ def fetcher.request(uri, request_class, last_modified = nil)
161
153
  raise SocketError, "tarded"
162
154
  end
163
155
 
@@ -177,60 +169,15 @@ gems:
177
169
  end
178
170
 
179
171
  def test_api_endpoint
180
- uri = URI.parse "http://example.com/foo"
181
- target = MiniTest::Mock.new
182
- target.expect :target, "gems.example.com"
183
-
184
- dns = MiniTest::Mock.new
185
- dns.expect :getresource, target, [String, Object]
186
-
187
- fetch = Gem::RemoteFetcher.new nil, dns
188
- assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
189
-
190
- target.verify
191
- dns.verify
192
- end
193
-
194
- def test_api_endpoint_ignores_trans_domain_values
195
172
  uri = URI.parse "http://gems.example.com/foo"
196
173
  target = MiniTest::Mock.new
197
- target.expect :target, "blah.com"
198
-
199
- dns = MiniTest::Mock.new
200
- dns.expect :getresource, target, [String, Object]
201
-
202
- fetch = Gem::RemoteFetcher.new nil, dns
203
- assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
204
-
205
- target.verify
206
- dns.verify
207
- end
208
-
209
- def test_api_endpoint_ignores_trans_domain_values_that_starts_with_original
210
- uri = URI.parse "http://example.com/foo"
211
- target = MiniTest::Mock.new
212
- target.expect :target, "example.combadguy.com"
213
-
214
- dns = MiniTest::Mock.new
215
- dns.expect :getresource, target, [String, Object]
216
-
217
- fetch = Gem::RemoteFetcher.new nil, dns
218
- assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
219
-
220
- target.verify
221
- dns.verify
222
- end
223
-
224
- def test_api_endpoint_ignores_trans_domain_values_that_end_with_original
225
- uri = URI.parse "http://example.com/foo"
226
- target = MiniTest::Mock.new
227
- target.expect :target, "badexample.com"
174
+ target.expect :target, "http://blah.com"
228
175
 
229
176
  dns = MiniTest::Mock.new
230
177
  dns.expect :getresource, target, [String, Object]
231
178
 
232
179
  fetch = Gem::RemoteFetcher.new nil, dns
233
- assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
180
+ assert_equal URI.parse("http://blah.com/foo"), fetch.api_endpoint(uri)
234
181
 
235
182
  target.verify
236
183
  dns.verify
@@ -461,81 +408,6 @@ gems:
461
408
  assert_equal @a2.file_name, File.basename(gem)
462
409
  end
463
410
 
464
- def test_explicit_proxy
465
- use_ui @ui do
466
- fetcher = Gem::RemoteFetcher.new @proxy_uri
467
- assert_equal PROXY_DATA.size, fetcher.fetch_size(@server_uri)
468
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
469
- end
470
- end
471
-
472
- def test_explicit_proxy_with_user_auth
473
- use_ui @ui do
474
- uri = URI.parse @proxy_uri
475
- uri.user, uri.password = 'foo', 'bar'
476
- fetcher = Gem::RemoteFetcher.new uri.to_s
477
- proxy = fetcher.instance_variable_get("@proxy_uri")
478
- assert_equal 'foo', proxy.user
479
- assert_equal 'bar', proxy.password
480
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
481
- end
482
-
483
- use_ui @ui do
484
- uri = URI.parse @proxy_uri
485
- uri.user, uri.password = 'domain%5Cuser', 'bar'
486
- fetcher = Gem::RemoteFetcher.new uri.to_s
487
- proxy = fetcher.instance_variable_get("@proxy_uri")
488
- assert_equal 'domain\user', fetcher.unescape_auth_info(proxy.user)
489
- assert_equal 'bar', proxy.password
490
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
491
- end
492
-
493
- use_ui @ui do
494
- uri = URI.parse @proxy_uri
495
- uri.user, uri.password = 'user', 'my%20pass'
496
- fetcher = Gem::RemoteFetcher.new uri.to_s
497
- proxy = fetcher.instance_variable_get("@proxy_uri")
498
- assert_equal 'user', proxy.user
499
- assert_equal 'my pass', fetcher.unescape_auth_info(proxy.password)
500
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
501
- end
502
- end
503
-
504
- def test_explicit_proxy_with_user_auth_in_env
505
- use_ui @ui do
506
- ENV['http_proxy'] = @proxy_uri
507
- ENV['http_proxy_user'] = 'foo'
508
- ENV['http_proxy_pass'] = 'bar'
509
- fetcher = Gem::RemoteFetcher.new nil
510
- proxy = fetcher.instance_variable_get("@proxy_uri")
511
- assert_equal 'foo', proxy.user
512
- assert_equal 'bar', proxy.password
513
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
514
- end
515
-
516
- use_ui @ui do
517
- ENV['http_proxy'] = @proxy_uri
518
- ENV['http_proxy_user'] = 'foo\user'
519
- ENV['http_proxy_pass'] = 'my bar'
520
- fetcher = Gem::RemoteFetcher.new nil
521
- proxy = fetcher.instance_variable_get("@proxy_uri")
522
- assert_equal 'foo\user', fetcher.unescape_auth_info(proxy.user)
523
- assert_equal 'my bar', fetcher.unescape_auth_info(proxy.password)
524
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
525
- end
526
-
527
- use_ui @ui do
528
- ENV['http_proxy'] = @proxy_uri
529
- ENV['http_proxy_user'] = 'foo@user'
530
- ENV['http_proxy_pass'] = 'my@bar'
531
- fetcher = Gem::RemoteFetcher.new nil
532
- proxy = fetcher.instance_variable_get("@proxy_uri")
533
- assert_equal 'foo@user', fetcher.unescape_auth_info(proxy.user)
534
- assert_equal 'my@bar', fetcher.unescape_auth_info(proxy.password)
535
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
536
- end
537
- end
538
-
539
411
  def test_fetch_path_gzip
540
412
  fetcher = Gem::RemoteFetcher.new nil
541
413
 
@@ -618,22 +490,6 @@ gems:
618
490
  assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
619
491
  end
620
492
 
621
- def test_get_proxy_from_env_auto_normalizes
622
- fetcher = Gem::RemoteFetcher.new(nil)
623
- ENV['HTTP_PROXY'] = 'fakeurl:12345'
624
-
625
- assert_equal('http://fakeurl:12345', fetcher.get_proxy_from_env.to_s)
626
- end
627
-
628
- def test_get_proxy_from_env_empty
629
- ENV['HTTP_PROXY'] = ''
630
- ENV.delete 'http_proxy'
631
-
632
- fetcher = Gem::RemoteFetcher.new nil
633
-
634
- assert_equal nil, fetcher.send(:get_proxy_from_env)
635
- end
636
-
637
493
  def test_implicit_no_proxy
638
494
  use_ui @ui do
639
495
  ENV['http_proxy'] = 'http://fakeurl:12345'
@@ -669,9 +525,7 @@ gems:
669
525
  fetcher = Gem::RemoteFetcher.new nil
670
526
  url = 'http://gems.example.com/redirect'
671
527
 
672
- conn = Object.new
673
- def conn.started?() true end
674
- def conn.request(req)
528
+ def fetcher.request(uri, request_class, last_modified = nil)
675
529
  url = 'http://gems.example.com/redirect'
676
530
  unless defined? @requested then
677
531
  @requested = true
@@ -685,9 +539,6 @@ gems:
685
539
  end
686
540
  end
687
541
 
688
- conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
689
- fetcher.instance_variable_set :@connections, conn
690
-
691
542
  data = fetcher.fetch_http URI.parse(url)
692
543
 
693
544
  assert_equal 'real_path', data
@@ -697,18 +548,13 @@ gems:
697
548
  fetcher = Gem::RemoteFetcher.new nil
698
549
  url = 'http://gems.example.com/redirect'
699
550
 
700
- conn = Object.new
701
- def conn.started?() true end
702
- def conn.request(req)
551
+ def fetcher.request(uri, request_class, last_modified = nil)
703
552
  url = 'http://gems.example.com/redirect'
704
553
  res = Net::HTTPMovedPermanently.new nil, 301, nil
705
554
  res.add_field 'Location', url
706
555
  res
707
556
  end
708
557
 
709
- conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
710
- fetcher.instance_variable_set :@connections, conn
711
-
712
558
  e = assert_raises Gem::RemoteFetcher::FetchError do
713
559
  fetcher.fetch_http URI.parse(url)
714
560
  end
@@ -716,14 +562,6 @@ gems:
716
562
  assert_equal "too many redirects (#{url})", e.message
717
563
  end
718
564
 
719
- def test_normalize_uri
720
- assert_equal 'FILE://example/', @fetcher.normalize_uri('FILE://example/')
721
- assert_equal 'FTP://example/', @fetcher.normalize_uri('FTP://example/')
722
- assert_equal 'HTTP://example/', @fetcher.normalize_uri('HTTP://example/')
723
- assert_equal 'HTTPS://example/', @fetcher.normalize_uri('HTTPS://example/')
724
- assert_equal 'http://example/', @fetcher.normalize_uri('example/')
725
- end
726
-
727
565
  def test_observe_no_proxy_env_single_host
728
566
  use_ui @ui do
729
567
  ENV["http_proxy"] = @proxy_uri
@@ -742,115 +580,15 @@ gems:
742
580
  end
743
581
  end
744
582
 
745
- def test_request
746
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
747
- util_stub_connection_for :body => :junk, :code => 200
748
-
749
- response = @fetcher.request uri, Net::HTTP::Get
750
-
751
- assert_equal 200, response.code
752
- assert_equal :junk, response.body
753
- end
754
-
755
- def test_request_head
756
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
757
- util_stub_connection_for :body => '', :code => 200
758
- response = @fetcher.request uri, Net::HTTP::Head
759
-
760
- assert_equal 200, response.code
761
- assert_equal '', response.body
762
- end
763
-
764
- def test_request_unmodified
765
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
766
- conn = util_stub_connection_for :body => '', :code => 304
767
-
768
- t = Time.now
769
- response = @fetcher.request uri, Net::HTTP::Head, t
770
-
771
- assert_equal 304, response.code
772
- assert_equal '', response.body
773
-
774
- assert_equal t.rfc2822, conn.payload['if-modified-since']
775
- end
776
-
777
- def test_user_agent
778
- ua = @fetcher.user_agent
779
-
780
- assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua
781
- assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua
782
- assert_match %r% #{Regexp.escape Gem::Platform.local.to_s} %, ua
783
- assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}%, ua
784
- assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE} %, ua
785
- end
786
-
787
- def test_user_agent_engine
788
- util_save_version
789
-
790
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
791
- Object.send :const_set, :RUBY_ENGINE, 'vroom'
792
-
793
- ua = @fetcher.user_agent
794
-
795
- assert_match %r%\) vroom%, ua
796
- ensure
797
- util_restore_version
798
- end
799
-
800
- def test_user_agent_engine_ruby
801
- util_save_version
802
-
803
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
804
- Object.send :const_set, :RUBY_ENGINE, 'ruby'
805
-
806
- ua = @fetcher.user_agent
807
-
808
- assert_match %r%\)%, ua
809
- ensure
810
- util_restore_version
811
- end
812
-
813
- def test_user_agent_patchlevel
814
- util_save_version
815
-
816
- Object.send :remove_const, :RUBY_PATCHLEVEL
817
- Object.send :const_set, :RUBY_PATCHLEVEL, 5
818
-
819
- ua = @fetcher.user_agent
820
-
821
- assert_match %r% patchlevel 5\)%, ua
822
- ensure
823
- util_restore_version
824
- end
825
-
826
- def test_user_agent_revision
827
- util_save_version
828
-
829
- Object.send :remove_const, :RUBY_PATCHLEVEL
830
- Object.send :const_set, :RUBY_PATCHLEVEL, -1
831
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
832
- Object.send :const_set, :RUBY_REVISION, 6
833
-
834
- ua = @fetcher.user_agent
835
-
836
- assert_match %r% revision 6\)%, ua
837
- assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua
838
- ensure
839
- util_restore_version
840
- end
841
-
842
- def test_user_agent_revision_missing
843
- util_save_version
844
-
845
- Object.send :remove_const, :RUBY_PATCHLEVEL
846
- Object.send :const_set, :RUBY_PATCHLEVEL, -1
847
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
848
-
849
- ua = @fetcher.user_agent
583
+ def test_request_block
584
+ fetcher = Gem::RemoteFetcher.new nil
850
585
 
851
- assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua
852
- ensure
853
- util_restore_version
586
+ assert_throws :block_called do
587
+ fetcher.request URI('http://example'), Net::HTTP::Get do |req|
588
+ assert_kind_of Net::HTTPGenericRequest, req
589
+ throw :block_called
590
+ end
591
+ end
854
592
  end
855
593
 
856
594
  def test_yaml_error_on_size
@@ -869,6 +607,42 @@ gems:
869
607
  end
870
608
  end
871
609
 
610
+ def test_ssl_client_cert_auth_connection
611
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
612
+
613
+ ssl_server = self.class.start_ssl_server({
614
+ :SSLVerifyClient =>
615
+ OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})
616
+
617
+ temp_ca_cert = File.join(DIR, 'ca_cert.pem')
618
+ temp_client_cert = File.join(DIR, 'client.pem')
619
+
620
+ with_configured_fetcher(
621
+ ":ssl_ca_cert: #{temp_ca_cert}\n" +
622
+ ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher|
623
+ fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
624
+ end
625
+ end
626
+
627
+ def test_do_not_allow_invalid_client_cert_auth_connection
628
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
629
+
630
+ ssl_server = self.class.start_ssl_server({
631
+ :SSLVerifyClient =>
632
+ OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})
633
+
634
+ temp_ca_cert = File.join(DIR, 'ca_cert.pem')
635
+ temp_client_cert = File.join(DIR, 'invalid_client.pem')
636
+
637
+ with_configured_fetcher(
638
+ ":ssl_ca_cert: #{temp_ca_cert}\n" +
639
+ ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher|
640
+ assert_raises Gem::RemoteFetcher::FetchError do
641
+ fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
642
+ end
643
+ end
644
+ end
645
+
872
646
  def test_do_not_allow_insecure_ssl_connection_by_default
873
647
  ssl_server = self.class.start_ssl_server
874
648
  with_configured_fetcher do |fetcher|
@@ -908,18 +682,6 @@ gems:
908
682
  Gem.configuration = nil
909
683
  end
910
684
 
911
- def util_stub_connection_for hash
912
- def @fetcher.connection= conn
913
- @conn = conn
914
- end
915
-
916
- def @fetcher.connection_for uri
917
- @conn
918
- end
919
-
920
- @fetcher.connection = Conn.new OpenStruct.new(hash)
921
- end
922
-
923
685
  def assert_error(exception_class=Exception)
924
686
  got_exception = false
925
687
 
@@ -940,20 +702,6 @@ gems:
940
702
  assert_match(/0\.4\.2/, data, "Data is not from proxy")
941
703
  end
942
704
 
943
- class Conn
944
- attr_accessor :payload
945
-
946
- def initialize(response)
947
- @response = response
948
- self.payload = nil
949
- end
950
-
951
- def request(req)
952
- self.payload = req
953
- @response
954
- end
955
- end
956
-
957
705
  class NilLog < WEBrick::Log
958
706
  def log(level, data) #Do nothing
959
707
  end
@@ -964,24 +712,18 @@ gems:
964
712
  attr_accessor :enable_zip, :enable_yaml
965
713
 
966
714
  def start_servers
967
- @normal_server ||= start_server(SERVER_DATA)
968
- @proxy_server ||= start_server(PROXY_DATA)
715
+ @normal_server ||= start_server(SERVER_PORT, SERVER_DATA)
716
+ @proxy_server ||= start_server(PROXY_PORT, PROXY_DATA)
969
717
  @enable_yaml = true
970
718
  @enable_zip = false
971
719
  end
972
720
 
973
- def normal_server_port
974
- @normal_server[:server].config[:Port]
975
- end
976
-
977
- def proxy_server_port
978
- @proxy_server[:server].config[:Port]
979
- end
980
-
981
721
  DIR = File.expand_path(File.dirname(__FILE__))
982
- DH_PARAM = OpenSSL::PKey::DH.new(128)
983
722
 
984
723
  def start_ssl_server(config = {})
724
+ raise MiniTest::Skip, 'openssl not installed' unless
725
+ defined?(OpenSSL::SSL)
726
+
985
727
  null_logger = NilLog.new
986
728
  server = WEBrick::HTTPServer.new({
987
729
  :Port => 0,
@@ -1000,7 +742,7 @@ gems:
1000
742
  server.mount_proc("/insecure_redirect") { |req, res|
1001
743
  res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query['to'])
1002
744
  }
1003
- server.ssl_context.tmp_dh_callback = proc { DH_PARAM }
745
+ server.ssl_context.tmp_dh_callback = proc { OpenSSL::PKey::DH.new 128 }
1004
746
  t = Thread.new do
1005
747
  begin
1006
748
  server.start
@@ -1019,49 +761,47 @@ gems:
1019
761
  server
1020
762
  end
1021
763
 
1022
-
1023
-
1024
764
  private
1025
765
 
1026
- def start_server(data)
1027
- null_logger = NilLog.new
1028
- s = WEBrick::HTTPServer.new(
1029
- :Port => 0,
1030
- :DocumentRoot => nil,
1031
- :Logger => null_logger,
1032
- :AccessLog => null_logger
1033
- )
1034
- s.mount_proc("/kill") { |req, res| s.shutdown }
1035
- s.mount_proc("/yaml") { |req, res|
1036
- if @enable_yaml
1037
- res.body = data
1038
- res['Content-Type'] = 'text/plain'
1039
- res['content-length'] = data.size
1040
- else
1041
- res.status = "404"
1042
- res.body = "<h1>NOT FOUND</h1>"
1043
- res['Content-Type'] = 'text/html'
1044
- end
1045
- }
1046
- s.mount_proc("/yaml.Z") { |req, res|
1047
- if @enable_zip
1048
- res.body = Zlib::Deflate.deflate(data)
1049
- res['Content-Type'] = 'text/plain'
1050
- else
1051
- res.status = "404"
1052
- res.body = "<h1>NOT FOUND</h1>"
1053
- res['Content-Type'] = 'text/html'
1054
- end
1055
- }
1056
- th = Thread.new do
766
+ def start_server(port, data)
767
+ Thread.new do
1057
768
  begin
769
+ null_logger = NilLog.new
770
+ s = WEBrick::HTTPServer.new(
771
+ :Port => port,
772
+ :DocumentRoot => nil,
773
+ :Logger => null_logger,
774
+ :AccessLog => null_logger
775
+ )
776
+ s.mount_proc("/kill") { |req, res| s.shutdown }
777
+ s.mount_proc("/yaml") { |req, res|
778
+ if @enable_yaml
779
+ res.body = data
780
+ res['Content-Type'] = 'text/plain'
781
+ res['content-length'] = data.size
782
+ else
783
+ res.status = "404"
784
+ res.body = "<h1>NOT FOUND</h1>"
785
+ res['Content-Type'] = 'text/html'
786
+ end
787
+ }
788
+ s.mount_proc("/yaml.Z") { |req, res|
789
+ if @enable_zip
790
+ res.body = Zlib::Deflate.deflate(data)
791
+ res['Content-Type'] = 'text/plain'
792
+ else
793
+ res.status = "404"
794
+ res.body = "<h1>NOT FOUND</h1>"
795
+ res['Content-Type'] = 'text/html'
796
+ end
797
+ }
1058
798
  s.start
1059
799
  rescue Exception => ex
1060
- abort "ERROR during server thread: #{ex.message}"
800
+ abort ex.message
801
+ puts "ERROR during server thread: #{ex.message}"
1061
802
  end
1062
803
  end
1063
- th[:server] = s
1064
- th
804
+ sleep 0.2 # Give the servers time to startup
1065
805
  end
1066
806
 
1067
807
  def cert(filename)
@@ -1081,24 +821,5 @@ gems:
1081
821
  assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path)
1082
822
  end
1083
823
 
1084
- def util_save_version
1085
- @orig_RUBY_ENGINE = RUBY_ENGINE if defined? RUBY_ENGINE
1086
- @orig_RUBY_PATCHLEVEL = RUBY_PATCHLEVEL
1087
- @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION
1088
- end
1089
-
1090
- def util_restore_version
1091
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
1092
- Object.send :const_set, :RUBY_ENGINE, @orig_RUBY_ENGINE if
1093
- defined?(@orig_RUBY_ENGINE)
1094
-
1095
- Object.send :remove_const, :RUBY_PATCHLEVEL
1096
- Object.send :const_set, :RUBY_PATCHLEVEL, @orig_RUBY_PATCHLEVEL
1097
-
1098
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
1099
- Object.send :const_set, :RUBY_REVISION, @orig_RUBY_REVISION if
1100
- defined?(@orig_RUBY_REVISION)
1101
- end
1102
-
1103
824
  end
1104
825