rubygems-update 2.2.5 → 2.3.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.autotest +4 -1
- data/CONTRIBUTING +20 -0
- data/History.txt +117 -14
- data/Manifest.txt +11 -2
- data/README.rdoc +1 -1
- data/Rakefile +0 -3
- data/lib/rubygems.rb +31 -11
- data/lib/rubygems/available_set.rb +1 -1
- data/lib/rubygems/basic_specification.rb +20 -10
- data/lib/rubygems/command.rb +4 -1
- data/lib/rubygems/commands/cert_command.rb +11 -13
- data/lib/rubygems/commands/cleanup_command.rb +2 -2
- data/lib/rubygems/commands/dependency_command.rb +2 -2
- data/lib/rubygems/commands/environment_command.rb +5 -2
- data/lib/rubygems/commands/help_command.rb +199 -20
- data/lib/rubygems/commands/install_command.rb +40 -10
- data/lib/rubygems/commands/list_command.rb +2 -2
- data/lib/rubygems/commands/open_command.rb +81 -0
- data/lib/rubygems/commands/search_command.rb +5 -5
- data/lib/rubygems/commands/setup_command.rb +1 -1
- data/lib/rubygems/commands/update_command.rb +8 -5
- data/lib/rubygems/commands/yank_command.rb +8 -13
- data/lib/rubygems/config_file.rb +13 -2
- data/lib/rubygems/dependency.rb +29 -16
- data/lib/rubygems/dependency_installer.rb +44 -10
- data/lib/rubygems/doctor.rb +1 -1
- data/lib/rubygems/errors.rb +30 -0
- data/lib/rubygems/exceptions.rb +20 -0
- data/lib/rubygems/ext/builder.rb +1 -1
- data/lib/rubygems/gemcutter_utilities.rb +1 -1
- data/lib/rubygems/installer.rb +4 -4
- data/lib/rubygems/name_tuple.rb +3 -1
- data/lib/rubygems/package.rb +27 -14
- data/lib/rubygems/package/file_source.rb +33 -0
- data/lib/rubygems/package/io_source.rb +45 -0
- data/lib/rubygems/package/old.rb +5 -5
- data/lib/rubygems/package/source.rb +3 -0
- data/lib/rubygems/platform.rb +2 -1
- data/lib/rubygems/rdoc.rb +1 -1
- data/lib/rubygems/remote_fetcher.rb +59 -18
- data/lib/rubygems/request.rb +71 -101
- data/lib/rubygems/request/connection_pools.rb +77 -0
- data/lib/rubygems/request/http_pool.rb +38 -0
- data/lib/rubygems/request/https_pool.rb +10 -0
- data/lib/rubygems/request_set.rb +65 -20
- data/lib/rubygems/request_set/gem_dependency_api.rb +234 -14
- data/lib/rubygems/request_set/lockfile.rb +65 -22
- data/lib/rubygems/requirement.rb +3 -0
- data/lib/rubygems/resolver.rb +33 -16
- data/lib/rubygems/resolver/activation_request.rb +7 -0
- data/lib/rubygems/resolver/api_set.rb +12 -2
- data/lib/rubygems/resolver/api_specification.rb +6 -0
- data/lib/rubygems/resolver/composed_set.rb +4 -0
- data/lib/rubygems/resolver/dependency_request.rb +20 -1
- data/lib/rubygems/resolver/git_set.rb +1 -1
- data/lib/rubygems/resolver/git_specification.rb +1 -1
- data/lib/rubygems/resolver/index_set.rb +3 -1
- data/lib/rubygems/resolver/installed_specification.rb +19 -1
- data/lib/rubygems/resolver/installer_set.rb +84 -4
- data/lib/rubygems/resolver/local_specification.rb +25 -0
- data/lib/rubygems/resolver/lock_set.rb +13 -9
- data/lib/rubygems/resolver/lock_specification.rb +1 -1
- data/lib/rubygems/resolver/set.rb +6 -0
- data/lib/rubygems/resolver/spec_specification.rb +0 -2
- data/lib/rubygems/resolver/specification.rb +23 -2
- data/lib/rubygems/resolver/vendor_set.rb +1 -1
- data/lib/rubygems/resolver/vendor_specification.rb +1 -1
- data/lib/rubygems/security/policy.rb +1 -0
- data/lib/rubygems/server.rb +36 -1
- data/lib/rubygems/source.rb +6 -2
- data/lib/rubygems/source/git.rb +1 -1
- data/lib/rubygems/source/installed.rb +4 -0
- data/lib/rubygems/source/specific_file.rb +6 -1
- data/lib/rubygems/spec_fetcher.rb +6 -13
- data/lib/rubygems/specification.rb +91 -63
- data/lib/rubygems/stub_specification.rb +9 -0
- data/lib/rubygems/test_case.rb +4 -2
- data/lib/rubygems/text.rb +15 -5
- data/lib/rubygems/uninstaller.rb +4 -1
- data/lib/rubygems/user_interaction.rb +8 -0
- data/lib/rubygems/version.rb +5 -1
- data/test/rubygems/test_gem.rb +88 -2
- data/test/rubygems/test_gem_available_set.rb +11 -8
- data/test/rubygems/test_gem_command.rb +55 -0
- data/test/rubygems/test_gem_commands_cert_command.rb +1 -0
- data/test/rubygems/test_gem_commands_environment_command.rb +1 -0
- data/test/rubygems/test_gem_commands_help_command.rb +7 -0
- data/test/rubygems/test_gem_commands_install_command.rb +71 -4
- data/test/rubygems/test_gem_commands_open_command.rb +46 -0
- data/test/rubygems/test_gem_commands_setup_command.rb +9 -0
- data/test/rubygems/test_gem_commands_update_command.rb +48 -0
- data/test/rubygems/test_gem_commands_yank_command.rb +2 -2
- data/test/rubygems/test_gem_config_file.rb +19 -7
- data/test/rubygems/test_gem_dependency.rb +86 -2
- data/test/rubygems/test_gem_dependency_installer.rb +36 -164
- data/test/rubygems/test_gem_gemcutter_utilities.rb +9 -0
- data/test/rubygems/test_gem_installer.rb +6 -1
- data/test/rubygems/test_gem_name_tuple.rb +7 -0
- data/test/rubygems/test_gem_package.rb +17 -0
- data/test/rubygems/test_gem_remote_fetcher.rb +65 -46
- data/test/rubygems/test_gem_request.rb +75 -61
- data/test/rubygems/test_gem_request_connection_pools.rb +83 -0
- data/test/rubygems/test_gem_request_set.rb +156 -1
- data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +72 -27
- data/test/rubygems/test_gem_request_set_lockfile.rb +335 -0
- data/test/rubygems/test_gem_requirement.rb +5 -0
- data/test/rubygems/test_gem_resolver.rb +91 -2
- data/test/rubygems/test_gem_resolver_activation_request.rb +10 -0
- data/test/rubygems/test_gem_resolver_api_set.rb +2 -2
- data/test/rubygems/test_gem_resolver_api_specification.rb +40 -0
- data/test/rubygems/test_gem_resolver_composed_set.rb +14 -0
- data/test/rubygems/test_gem_resolver_dependency_request.rb +55 -0
- data/test/rubygems/test_gem_resolver_git_set.rb +26 -0
- data/test/rubygems/test_gem_resolver_index_set.rb +28 -2
- data/test/rubygems/test_gem_resolver_installer_set.rb +143 -0
- data/test/rubygems/test_gem_resolver_lock_set.rb +12 -6
- data/test/rubygems/test_gem_resolver_lock_specification.rb +1 -1
- data/test/rubygems/test_gem_resolver_specification.rb +32 -0
- data/test/rubygems/test_gem_resolver_vendor_set.rb +14 -0
- data/test/rubygems/test_gem_security_policy.rb +2 -2
- data/test/rubygems/test_gem_server.rb +69 -4
- data/test/rubygems/test_gem_source.rb +4 -1
- data/test/rubygems/test_gem_source_git.rb +15 -0
- data/test/rubygems/test_gem_source_specific_file.rb +4 -0
- data/test/rubygems/test_gem_specification.rb +82 -27
- data/test/rubygems/test_gem_stub_specification.rb +61 -23
- data/test/rubygems/test_gem_uninstaller.rb +23 -0
- data/test/rubygems/test_gem_unsatisfiable_dependency_error.rb +32 -0
- metadata +187 -33
- metadata.gz.sig +0 -0
- data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
- data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +0 -32
@@ -148,6 +148,15 @@ class TestGemGemcutterUtilities < Gem::TestCase
|
|
148
148
|
assert_equal "", @sign_in_ui.output
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_sign_in_skips_with_key_override
|
152
|
+
api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
|
153
|
+
Gem.configuration.api_keys[:KEY] = 'other'
|
154
|
+
@cmd.options[:key] = :KEY
|
155
|
+
util_sign_in [api_key, 200, 'OK']
|
156
|
+
|
157
|
+
assert_equal "", @sign_in_ui.output
|
158
|
+
end
|
159
|
+
|
151
160
|
def test_sign_in_with_other_credentials_doesnt_overwrite_other_keys
|
152
161
|
api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
|
153
162
|
other_api_key = 'f46dbb18bb6a9c97cdc61b5b85c186a17403cdcbf'
|
@@ -574,6 +574,9 @@ gem 'other', version
|
|
574
574
|
def test_generate_bin_symlink_win32
|
575
575
|
old_win_platform = Gem.win_platform?
|
576
576
|
Gem.win_platform = true
|
577
|
+
old_alt_separator = File::ALT_SEPARATOR
|
578
|
+
File.__send__(:remove_const, :ALT_SEPARATOR)
|
579
|
+
File.const_set(:ALT_SEPARATOR, '\\')
|
577
580
|
@installer.wrappers = false
|
578
581
|
util_make_exec
|
579
582
|
@installer.gem_dir = util_gem_dir
|
@@ -592,6 +595,8 @@ gem 'other', version
|
|
592
595
|
wrapper = File.read installed_exec
|
593
596
|
assert_match(/generated by RubyGems/, wrapper)
|
594
597
|
ensure
|
598
|
+
File.__send__(:remove_const, :ALT_SEPARATOR)
|
599
|
+
File.const_set(:ALT_SEPARATOR, old_alt_separator)
|
595
600
|
Gem.win_platform = old_win_platform
|
596
601
|
end
|
597
602
|
|
@@ -1053,7 +1058,7 @@ gem 'other', version
|
|
1053
1058
|
|
1054
1059
|
path = File.join(@gemhome, 'gems', 'a-2', 'gem_make.out')
|
1055
1060
|
|
1056
|
-
if File.
|
1061
|
+
if File.exist?(path)
|
1057
1062
|
puts File.read(path)
|
1058
1063
|
puts '-' * 78
|
1059
1064
|
end
|
@@ -33,5 +33,12 @@ class TestGemNameTuple < Gem::TestCase
|
|
33
33
|
assert_equal "a-0.gemspec", n.spec_name
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_spaceship
|
37
|
+
a = Gem::NameTuple.new 'a', Gem::Version.new(0), Gem::Platform::RUBY
|
38
|
+
a_p = Gem::NameTuple.new 'a', Gem::Version.new(0), Gem::Platform.local
|
39
|
+
|
40
|
+
assert_equal 1, a_p.<=>(a)
|
41
|
+
end
|
42
|
+
|
36
43
|
end
|
37
44
|
|
@@ -778,6 +778,23 @@ class TestGemPackage < Gem::Package::TarTestCase
|
|
778
778
|
assert_equal @spec, package.spec
|
779
779
|
end
|
780
780
|
|
781
|
+
def test_spec_from_io
|
782
|
+
# This functionality is used by rubygems.org to extract spec data from an
|
783
|
+
# uploaded gem before it is written to storage.
|
784
|
+
io = StringIO.new Gem.read_binary @gem
|
785
|
+
package = Gem::Package.new io
|
786
|
+
|
787
|
+
assert_equal @spec, package.spec
|
788
|
+
end
|
789
|
+
|
790
|
+
def test_spec_from_io_raises_gem_error_for_io_not_at_start
|
791
|
+
io = StringIO.new Gem.read_binary @gem
|
792
|
+
io.read(1)
|
793
|
+
assert_raises(Gem::Package::Error) do
|
794
|
+
Gem::Package.new io
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
781
798
|
def util_tar
|
782
799
|
tar_io = StringIO.new
|
783
800
|
|
@@ -163,21 +163,6 @@ gems:
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def test_api_endpoint
|
166
|
-
uri = URI.parse "http://example.com/foo"
|
167
|
-
target = MiniTest::Mock.new
|
168
|
-
target.expect :target, "gems.example.com"
|
169
|
-
|
170
|
-
dns = MiniTest::Mock.new
|
171
|
-
dns.expect :getresource, target, [String, Object]
|
172
|
-
|
173
|
-
fetch = Gem::RemoteFetcher.new nil, dns
|
174
|
-
assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
|
175
|
-
|
176
|
-
target.verify
|
177
|
-
dns.verify
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_api_endpoint_ignores_trans_domain_values
|
181
166
|
uri = URI.parse "http://gems.example.com/foo"
|
182
167
|
target = MiniTest::Mock.new
|
183
168
|
target.expect :target, "blah.com"
|
@@ -186,37 +171,7 @@ gems:
|
|
186
171
|
dns.expect :getresource, target, [String, Object]
|
187
172
|
|
188
173
|
fetch = Gem::RemoteFetcher.new nil, dns
|
189
|
-
assert_equal URI.parse("http://
|
190
|
-
|
191
|
-
target.verify
|
192
|
-
dns.verify
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_api_endpoint_ignores_trans_domain_values_that_starts_with_original
|
196
|
-
uri = URI.parse "http://example.com/foo"
|
197
|
-
target = MiniTest::Mock.new
|
198
|
-
target.expect :target, "example.combadguy.com"
|
199
|
-
|
200
|
-
dns = MiniTest::Mock.new
|
201
|
-
dns.expect :getresource, target, [String, Object]
|
202
|
-
|
203
|
-
fetch = Gem::RemoteFetcher.new nil, dns
|
204
|
-
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
|
205
|
-
|
206
|
-
target.verify
|
207
|
-
dns.verify
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_api_endpoint_ignores_trans_domain_values_that_end_with_original
|
211
|
-
uri = URI.parse "http://example.com/foo"
|
212
|
-
target = MiniTest::Mock.new
|
213
|
-
target.expect :target, "badexample.com"
|
214
|
-
|
215
|
-
dns = MiniTest::Mock.new
|
216
|
-
dns.expect :getresource, target, [String, Object]
|
217
|
-
|
218
|
-
fetch = Gem::RemoteFetcher.new nil, dns
|
219
|
-
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
|
174
|
+
assert_equal URI.parse("http://blah.com/foo"), fetch.api_endpoint(uri)
|
220
175
|
|
221
176
|
target.verify
|
222
177
|
dns.verify
|
@@ -288,6 +243,36 @@ gems:
|
|
288
243
|
assert File.exist?(a1_cache_gem)
|
289
244
|
end
|
290
245
|
|
246
|
+
def test_download_with_auth
|
247
|
+
a1_data = nil
|
248
|
+
File.open @a1_gem, 'rb' do |fp|
|
249
|
+
a1_data = fp.read
|
250
|
+
end
|
251
|
+
|
252
|
+
fetcher = util_fuck_with_fetcher a1_data
|
253
|
+
|
254
|
+
a1_cache_gem = @a1.cache_file
|
255
|
+
assert_equal a1_cache_gem, fetcher.download(@a1, 'http://user:password@gems.example.com')
|
256
|
+
assert_equal("http://user:password@gems.example.com/gems/a-1.gem",
|
257
|
+
fetcher.instance_variable_get(:@test_arg).to_s)
|
258
|
+
assert File.exist?(a1_cache_gem)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_download_with_encoded_auth
|
262
|
+
a1_data = nil
|
263
|
+
File.open @a1_gem, 'rb' do |fp|
|
264
|
+
a1_data = fp.read
|
265
|
+
end
|
266
|
+
|
267
|
+
fetcher = util_fuck_with_fetcher a1_data
|
268
|
+
|
269
|
+
a1_cache_gem = @a1.cache_file
|
270
|
+
assert_equal a1_cache_gem, fetcher.download(@a1, 'http://user:%25pas%25sword@gems.example.com')
|
271
|
+
assert_equal("http://user:%25pas%25sword@gems.example.com/gems/a-1.gem",
|
272
|
+
fetcher.instance_variable_get(:@test_arg).to_s)
|
273
|
+
assert File.exist?(a1_cache_gem)
|
274
|
+
end
|
275
|
+
|
291
276
|
def test_download_cached
|
292
277
|
FileUtils.mv @a1_gem, @cache_dir
|
293
278
|
|
@@ -601,6 +586,40 @@ gems:
|
|
601
586
|
assert_equal "too many redirects (#{url})", e.message
|
602
587
|
end
|
603
588
|
|
589
|
+
def test_fetch_s3
|
590
|
+
fetcher = Gem::RemoteFetcher.new nil
|
591
|
+
url = 's3://testuser:testpass@my-bucket/gems/specs.4.8.gz'
|
592
|
+
$fetched_uri = nil
|
593
|
+
|
594
|
+
def fetcher.request(uri, request_class, last_modified = nil)
|
595
|
+
$fetched_uri = uri
|
596
|
+
res = Net::HTTPOK.new nil, 200, nil
|
597
|
+
def res.body() 'success' end
|
598
|
+
res
|
599
|
+
end
|
600
|
+
|
601
|
+
def fetcher.s3_expiration
|
602
|
+
1395098371
|
603
|
+
end
|
604
|
+
|
605
|
+
data = fetcher.fetch_s3 URI.parse(url)
|
606
|
+
|
607
|
+
assert_equal 'https://my-bucket.s3.amazonaws.com/gems/specs.4.8.gz?AWSAccessKeyId=testuser&Expires=1395098371&Signature=eUTr7NkpZEet%2BJySE%2BfH6qukroI%3D', $fetched_uri.to_s
|
608
|
+
assert_equal 'success', data
|
609
|
+
ensure
|
610
|
+
$fetched_uri = nil
|
611
|
+
end
|
612
|
+
|
613
|
+
def test_fetch_s3_no_creds
|
614
|
+
fetcher = Gem::RemoteFetcher.new nil
|
615
|
+
url = 's3://my-bucket/gems/specs.4.8.gz'
|
616
|
+
e = assert_raises Gem::RemoteFetcher::FetchError do
|
617
|
+
fetcher.fetch_s3 URI.parse(url)
|
618
|
+
end
|
619
|
+
|
620
|
+
assert_match "credentials needed", e.message
|
621
|
+
end
|
622
|
+
|
604
623
|
def test_observe_no_proxy_env_single_host
|
605
624
|
use_ui @ui do
|
606
625
|
ENV["http_proxy"] = @proxy_uri
|
@@ -11,6 +11,10 @@ class TestGemRequest < Gem::TestCase
|
|
11
11
|
PUBLIC_CERT_FILE = cert_path 'public'
|
12
12
|
SSL_CERT = load_cert 'ssl'
|
13
13
|
|
14
|
+
def make_request uri, request_class, last_modified, proxy
|
15
|
+
Gem::Request.create_with_proxy uri, request_class, last_modified, proxy
|
16
|
+
end
|
17
|
+
|
14
18
|
def setup
|
15
19
|
@proxies = %w[http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
|
16
20
|
@old_proxies = @proxies.map {|k| ENV[k] }
|
@@ -21,7 +25,7 @@ class TestGemRequest < Gem::TestCase
|
|
21
25
|
@proxy_uri = "http://localhost:1234"
|
22
26
|
@uri = URI('http://example')
|
23
27
|
|
24
|
-
@request =
|
28
|
+
@request = make_request @uri, nil, nil, nil
|
25
29
|
end
|
26
30
|
|
27
31
|
def teardown
|
@@ -33,7 +37,7 @@ class TestGemRequest < Gem::TestCase
|
|
33
37
|
def test_initialize_proxy
|
34
38
|
proxy_uri = 'http://proxy.example.com'
|
35
39
|
|
36
|
-
request =
|
40
|
+
request = make_request @uri, nil, nil, proxy_uri
|
37
41
|
|
38
42
|
assert_equal proxy_uri, request.proxy_uri.to_s
|
39
43
|
end
|
@@ -41,7 +45,7 @@ class TestGemRequest < Gem::TestCase
|
|
41
45
|
def test_initialize_proxy_URI
|
42
46
|
proxy_uri = 'http://proxy.example.com'
|
43
47
|
|
44
|
-
request =
|
48
|
+
request = make_request @uri, nil, nil, URI(proxy_uri)
|
45
49
|
|
46
50
|
assert_equal proxy_uri, request.proxy_uri.to_s
|
47
51
|
end
|
@@ -51,7 +55,7 @@ class TestGemRequest < Gem::TestCase
|
|
51
55
|
ENV['http_proxy_user'] = 'foo'
|
52
56
|
ENV['http_proxy_pass'] = 'bar'
|
53
57
|
|
54
|
-
request =
|
58
|
+
request = make_request @uri, nil, nil, nil
|
55
59
|
|
56
60
|
proxy = request.proxy_uri
|
57
61
|
|
@@ -62,7 +66,7 @@ class TestGemRequest < Gem::TestCase
|
|
62
66
|
def test_initialize_proxy_ENV_https
|
63
67
|
ENV['https_proxy'] = @proxy_uri
|
64
68
|
|
65
|
-
request =
|
69
|
+
request = make_request URI('https://example'), nil, nil, nil
|
66
70
|
|
67
71
|
proxy = request.proxy_uri
|
68
72
|
|
@@ -72,13 +76,13 @@ class TestGemRequest < Gem::TestCase
|
|
72
76
|
def test_configure_connection_for_https
|
73
77
|
connection = Net::HTTP.new 'localhost', 443
|
74
78
|
|
75
|
-
request = Gem::Request
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
request = Class.new(Gem::Request) {
|
80
|
+
def self.get_cert_files
|
81
|
+
[TestGemRequest::PUBLIC_CERT_FILE]
|
82
|
+
end
|
83
|
+
}.create_with_proxy URI('https://example'), nil, nil, nil
|
80
84
|
|
81
|
-
|
85
|
+
Gem::Request.configure_connection_for_https connection, request.cert_files
|
82
86
|
|
83
87
|
cert_store = connection.cert_store
|
84
88
|
|
@@ -91,13 +95,13 @@ class TestGemRequest < Gem::TestCase
|
|
91
95
|
|
92
96
|
connection = Net::HTTP.new 'localhost', 443
|
93
97
|
|
94
|
-
request = Gem::Request
|
98
|
+
request = Class.new(Gem::Request) {
|
99
|
+
def self.get_cert_files
|
100
|
+
[TestGemRequest::PUBLIC_CERT_FILE]
|
101
|
+
end
|
102
|
+
}.create_with_proxy URI('https://example'), nil, nil, nil
|
95
103
|
|
96
|
-
|
97
|
-
store.add_cert TestGemRequest::PUBLIC_CERT
|
98
|
-
end
|
99
|
-
|
100
|
-
request.configure_connection_for_https connection
|
104
|
+
Gem::Request.configure_connection_for_https connection, request.cert_files
|
101
105
|
|
102
106
|
cert_store = connection.cert_store
|
103
107
|
|
@@ -109,16 +113,18 @@ class TestGemRequest < Gem::TestCase
|
|
109
113
|
|
110
114
|
def test_get_proxy_from_env_fallback
|
111
115
|
ENV['http_proxy'] = @proxy_uri
|
112
|
-
|
113
|
-
proxy =
|
116
|
+
request = make_request @uri, nil, nil, nil
|
117
|
+
proxy = request.proxy_uri
|
114
118
|
|
115
119
|
assert_equal URI(@proxy_uri), proxy
|
116
120
|
end
|
117
121
|
|
118
122
|
def test_get_proxy_from_env_https
|
119
123
|
ENV['https_proxy'] = @proxy_uri
|
124
|
+
uri = URI('https://example')
|
125
|
+
request = make_request uri, nil, nil, nil
|
120
126
|
|
121
|
-
proxy =
|
127
|
+
proxy = request.proxy_uri
|
122
128
|
|
123
129
|
assert_equal URI(@proxy_uri), proxy
|
124
130
|
end
|
@@ -127,8 +133,9 @@ class TestGemRequest < Gem::TestCase
|
|
127
133
|
ENV['http_proxy'] = @proxy_uri
|
128
134
|
ENV['http_proxy_user'] = 'foo\user'
|
129
135
|
ENV['http_proxy_pass'] = 'my bar'
|
136
|
+
request = make_request @uri, nil, nil, nil
|
130
137
|
|
131
|
-
proxy =
|
138
|
+
proxy = request.proxy_uri
|
132
139
|
|
133
140
|
assert_equal 'foo\user', Gem::UriFormatter.new(proxy.user).unescape
|
134
141
|
assert_equal 'my bar', Gem::UriFormatter.new(proxy.password).unescape
|
@@ -138,8 +145,9 @@ class TestGemRequest < Gem::TestCase
|
|
138
145
|
ENV['http_proxy'] = @proxy_uri
|
139
146
|
ENV['http_proxy_user'] = 'foo@user'
|
140
147
|
ENV['http_proxy_pass'] = 'my@bar'
|
148
|
+
request = make_request @uri, nil, nil, nil
|
141
149
|
|
142
|
-
proxy =
|
150
|
+
proxy = request.proxy_uri
|
143
151
|
|
144
152
|
assert_equal 'foo%40user', proxy.user
|
145
153
|
assert_equal 'my%40bar', proxy.password
|
@@ -147,23 +155,26 @@ class TestGemRequest < Gem::TestCase
|
|
147
155
|
|
148
156
|
def test_get_proxy_from_env_normalize
|
149
157
|
ENV['HTTP_PROXY'] = 'fakeurl:12345'
|
158
|
+
request = make_request @uri, nil, nil, nil
|
150
159
|
|
151
|
-
assert_equal 'http://fakeurl:12345',
|
160
|
+
assert_equal 'http://fakeurl:12345', request.proxy_uri.to_s
|
152
161
|
end
|
153
162
|
|
154
163
|
def test_get_proxy_from_env_empty
|
155
164
|
ENV['HTTP_PROXY'] = ''
|
156
165
|
ENV.delete 'http_proxy'
|
166
|
+
request = make_request @uri, nil, nil, nil
|
157
167
|
|
158
|
-
assert_nil
|
168
|
+
assert_nil request.proxy_uri
|
159
169
|
end
|
160
170
|
|
161
171
|
def test_fetch
|
162
172
|
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
|
163
|
-
|
164
|
-
|
173
|
+
response = util_stub_net_http(:body => :junk, :code => 200) do
|
174
|
+
@request = make_request(uri, Net::HTTP::Get, nil, nil)
|
165
175
|
|
166
|
-
|
176
|
+
@request.fetch
|
177
|
+
end
|
167
178
|
|
168
179
|
assert_equal 200, response.code
|
169
180
|
assert_equal :junk, response.body
|
@@ -171,34 +182,34 @@ class TestGemRequest < Gem::TestCase
|
|
171
182
|
|
172
183
|
def test_fetch_basic_auth
|
173
184
|
uri = URI.parse "https://user:pass@example.rubygems/specs.#{Gem.marshal_version}"
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
185
|
+
conn = util_stub_net_http(:body => :junk, :code => 200) do |c|
|
186
|
+
@request = make_request(uri, Net::HTTP::Get, nil, nil)
|
187
|
+
@request.fetch
|
188
|
+
c
|
189
|
+
end
|
178
190
|
|
179
191
|
auth_header = conn.payload['Authorization']
|
180
|
-
|
181
192
|
assert_equal "Basic #{Base64.encode64('user:pass')}".strip, auth_header
|
182
193
|
end
|
183
194
|
|
184
195
|
def test_fetch_basic_auth_encoded
|
185
196
|
uri = URI.parse "https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}"
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
197
|
+
conn = util_stub_net_http(:body => :junk, :code => 200) do |c|
|
198
|
+
@request = make_request(uri, Net::HTTP::Get, nil, nil)
|
199
|
+
@request.fetch
|
200
|
+
c
|
201
|
+
end
|
190
202
|
|
191
203
|
auth_header = conn.payload['Authorization']
|
192
|
-
|
193
204
|
assert_equal "Basic #{Base64.encode64('user:{DEScede}pass')}".strip, auth_header
|
194
205
|
end
|
195
206
|
|
196
207
|
def test_fetch_head
|
197
208
|
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
209
|
+
response = util_stub_net_http(:body => '', :code => 200) do |conn|
|
210
|
+
@request = make_request(uri, Net::HTTP::Get, nil, nil)
|
211
|
+
@request.fetch
|
212
|
+
end
|
202
213
|
|
203
214
|
assert_equal 200, response.code
|
204
215
|
assert_equal '', response.body
|
@@ -207,10 +218,10 @@ class TestGemRequest < Gem::TestCase
|
|
207
218
|
def test_fetch_unmodified
|
208
219
|
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
|
209
220
|
t = Time.utc(2013, 1, 2, 3, 4, 5)
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
221
|
+
conn, response = util_stub_net_http(:body => '', :code => 304) do |c|
|
222
|
+
@request = make_request(uri, Net::HTTP::Get, t, nil)
|
223
|
+
[c, @request.fetch]
|
224
|
+
end
|
214
225
|
|
215
226
|
assert_equal 304, response.code
|
216
227
|
assert_equal '', response.body
|
@@ -221,7 +232,7 @@ class TestGemRequest < Gem::TestCase
|
|
221
232
|
end
|
222
233
|
|
223
234
|
def test_user_agent
|
224
|
-
ua =
|
235
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
225
236
|
|
226
237
|
assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua
|
227
238
|
assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua
|
@@ -236,7 +247,7 @@ class TestGemRequest < Gem::TestCase
|
|
236
247
|
Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
|
237
248
|
Object.send :const_set, :RUBY_ENGINE, 'vroom'
|
238
249
|
|
239
|
-
ua =
|
250
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
240
251
|
|
241
252
|
assert_match %r%\) vroom%, ua
|
242
253
|
ensure
|
@@ -249,7 +260,7 @@ class TestGemRequest < Gem::TestCase
|
|
249
260
|
Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
|
250
261
|
Object.send :const_set, :RUBY_ENGINE, 'ruby'
|
251
262
|
|
252
|
-
ua =
|
263
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
253
264
|
|
254
265
|
assert_match %r%\)%, ua
|
255
266
|
ensure
|
@@ -262,7 +273,7 @@ class TestGemRequest < Gem::TestCase
|
|
262
273
|
Object.send :remove_const, :RUBY_PATCHLEVEL
|
263
274
|
Object.send :const_set, :RUBY_PATCHLEVEL, 5
|
264
275
|
|
265
|
-
ua =
|
276
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
266
277
|
|
267
278
|
assert_match %r% patchlevel 5\)%, ua
|
268
279
|
ensure
|
@@ -277,7 +288,7 @@ class TestGemRequest < Gem::TestCase
|
|
277
288
|
Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
|
278
289
|
Object.send :const_set, :RUBY_REVISION, 6
|
279
290
|
|
280
|
-
ua =
|
291
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
281
292
|
|
282
293
|
assert_match %r% revision 6\)%, ua
|
283
294
|
assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua
|
@@ -292,7 +303,7 @@ class TestGemRequest < Gem::TestCase
|
|
292
303
|
Object.send :const_set, :RUBY_PATCHLEVEL, -1
|
293
304
|
Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
|
294
305
|
|
295
|
-
ua =
|
306
|
+
ua = make_request(@uri, nil, nil, nil).user_agent
|
296
307
|
|
297
308
|
assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua
|
298
309
|
ensure
|
@@ -318,21 +329,24 @@ class TestGemRequest < Gem::TestCase
|
|
318
329
|
@orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION
|
319
330
|
end
|
320
331
|
|
321
|
-
def
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
end
|
329
|
-
|
330
|
-
@request.connection = Conn.new OpenStruct.new(hash)
|
332
|
+
def util_stub_net_http hash
|
333
|
+
old_client = Gem::Request::ConnectionPools.client
|
334
|
+
conn = Conn.new OpenStruct.new(hash)
|
335
|
+
Gem::Request::ConnectionPools.client = conn
|
336
|
+
yield conn
|
337
|
+
ensure
|
338
|
+
Gem::Request::ConnectionPools.client = old_client
|
331
339
|
end
|
332
340
|
|
333
341
|
class Conn
|
334
342
|
attr_accessor :payload
|
335
343
|
|
344
|
+
def new *args; self; end
|
345
|
+
def use_ssl=(bool); end
|
346
|
+
def verify_mode=(setting); end
|
347
|
+
def cert_store=(setting); end
|
348
|
+
def start; end
|
349
|
+
|
336
350
|
def initialize(response)
|
337
351
|
@response = response
|
338
352
|
self.payload = nil
|