rubygems-update 3.3.22 → 3.3.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Manifest.txt +1 -0
  4. data/POLICIES.md +38 -5
  5. data/bundler/CHANGELOG.md +18 -0
  6. data/bundler/lib/bundler/build_metadata.rb +2 -2
  7. data/bundler/lib/bundler/cli/init.rb +5 -1
  8. data/bundler/lib/bundler/definition.rb +2 -12
  9. data/bundler/lib/bundler/dsl.rb +0 -1
  10. data/bundler/lib/bundler/gem_version_promoter.rb +6 -7
  11. data/bundler/lib/bundler/index.rb +3 -26
  12. data/bundler/lib/bundler/resolver.rb +7 -11
  13. data/bundler/lib/bundler/rubygems_ext.rb +12 -1
  14. data/bundler/lib/bundler/spec_set.rb +1 -1
  15. data/bundler/lib/bundler/templates/newgem/gitlab-ci.yml.tt +5 -4
  16. data/bundler/lib/bundler/version.rb +1 -1
  17. data/lib/rubygems/gemcutter_utilities.rb +8 -1
  18. data/lib/rubygems/package.rb +9 -4
  19. data/lib/rubygems/platform.rb +17 -1
  20. data/lib/rubygems/resolver.rb +1 -1
  21. data/lib/rubygems.rb +1 -1
  22. data/rubygems-update.gemspec +1 -1
  23. data/test/rubygems/helper.rb +23 -17
  24. data/test/rubygems/packages/Bluebie-legs-0.6.2.gem +0 -0
  25. data/test/rubygems/test_gem.rb +254 -212
  26. data/test/rubygems/test_gem_commands_owner_command.rb +105 -24
  27. data/test/rubygems/test_gem_commands_push_command.rb +44 -23
  28. data/test/rubygems/test_gem_commands_signin_command.rb +28 -3
  29. data/test/rubygems/test_gem_commands_yank_command.rb +9 -9
  30. data/test/rubygems/test_gem_gemcutter_utilities.rb +16 -12
  31. data/test/rubygems/test_gem_package.rb +15 -0
  32. data/test/rubygems/test_gem_platform.rb +35 -0
  33. data/test/rubygems/test_gem_resolver.rb +33 -0
  34. data/test/rubygems/test_require.rb +5 -5
  35. data/test/rubygems/utilities.rb +36 -14
  36. metadata +4 -3
@@ -36,7 +36,7 @@ class TestGemCommandsOwnerCommand < Gem::TestCase
36
36
  - id: 4
37
37
  EOF
38
38
 
39
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
39
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
40
40
 
41
41
  use_ui @stub_ui do
42
42
  @cmd.show_owners("freewill")
@@ -66,7 +66,7 @@ EOF
66
66
  - id: 4
67
67
  EOF
68
68
 
69
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
69
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
70
70
 
71
71
  assert_raise Psych::DisallowedClass do
72
72
  use_ui @ui do
@@ -80,7 +80,7 @@ EOF
80
80
  host = "http://rubygems.example"
81
81
  ENV["RUBYGEMS_HOST"] = host
82
82
 
83
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
83
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
84
84
 
85
85
  use_ui @stub_ui do
86
86
  @cmd.show_owners("freewill")
@@ -95,7 +95,7 @@ EOF
95
95
  host = "http://rubygems.example"
96
96
  @cmd.host = host
97
97
 
98
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
98
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
99
99
 
100
100
  use_ui @stub_ui do
101
101
  @cmd.show_owners("freewill")
@@ -107,7 +107,7 @@ EOF
107
107
 
108
108
  def test_show_owners_denied
109
109
  response = "You don't have permission to push to this gem"
110
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, "Forbidden"]
110
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
111
111
 
112
112
  assert_raise Gem::MockGemUi::TermError do
113
113
  use_ui @stub_ui do
@@ -118,9 +118,32 @@ EOF
118
118
  assert_match response, @stub_ui.output
119
119
  end
120
120
 
121
+ def test_show_owners_permanent_redirect
122
+ host = "http://rubygems.example"
123
+ ENV["RUBYGEMS_HOST"] = host
124
+ path = "/api/v1/gems/freewill/owners.yaml"
125
+ redirected_uri = "https://rubygems.example#{path}"
126
+
127
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
128
+ body: "",
129
+ code: "301",
130
+ msg: "Moved Permanently",
131
+ headers: { "location" => redirected_uri }
132
+ )
133
+
134
+ assert_raise Gem::MockGemUi::TermError do
135
+ use_ui @stub_ui do
136
+ @cmd.show_owners("freewill")
137
+ end
138
+ end
139
+
140
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
141
+ assert_match response, @stub_ui.output
142
+ end
143
+
121
144
  def test_show_owners_key
122
145
  response = "- email: user1@example.com\n"
123
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
146
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
124
147
  File.open Gem.configuration.credentials_path, "a" do |f|
125
148
  f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
126
149
  end
@@ -134,7 +157,7 @@ EOF
134
157
 
135
158
  def test_add_owners
136
159
  response = "Owner added successfully."
137
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
160
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
138
161
 
139
162
  use_ui @stub_ui do
140
163
  @cmd.add_owners("freewill", ["user-new1@example.com"])
@@ -149,12 +172,33 @@ EOF
149
172
 
150
173
  def test_add_owners_denied
151
174
  response = "You don't have permission to push to this gem"
152
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
175
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
176
+
177
+ use_ui @stub_ui do
178
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
179
+ end
180
+
181
+ assert_match response, @stub_ui.output
182
+ end
183
+
184
+ def test_add_owners_permanent_redirect
185
+ host = "http://rubygems.example"
186
+ ENV["RUBYGEMS_HOST"] = host
187
+ path = "/api/v1/gems/freewill/owners"
188
+ redirected_uri = "https://rubygems.example#{path}"
189
+
190
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
191
+ body: "",
192
+ code: "308",
193
+ msg: "Permanent Redirect",
194
+ headers: { "location" => redirected_uri }
195
+ )
153
196
 
154
197
  use_ui @stub_ui do
155
198
  @cmd.add_owners("freewill", ["user-new1@example.com"])
156
199
  end
157
200
 
201
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
158
202
  assert_match response, @stub_ui.output
159
203
  end
160
204
 
@@ -162,8 +206,8 @@ EOF
162
206
  host = "http://rubygems.example"
163
207
  add_owner_response = "Owner added successfully."
164
208
  show_owners_response = "- email: user1@example.com\n"
165
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, "OK"]
166
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, "OK"]
209
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: add_owner_response, code: 200, msg: "OK")
210
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: show_owners_response, code: 200, msg: "OK")
167
211
 
168
212
  @cmd.handle_options %W[--host #{host} --add user-new1@example.com freewill]
169
213
 
@@ -178,7 +222,7 @@ EOF
178
222
 
179
223
  def test_add_owners_key
180
224
  response = "Owner added successfully."
181
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
225
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
182
226
  File.open Gem.configuration.credentials_path, "a" do |f|
183
227
  f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
184
228
  end
@@ -192,7 +236,7 @@ EOF
192
236
 
193
237
  def test_remove_owners
194
238
  response = "Owner removed successfully."
195
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
239
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
196
240
 
197
241
  use_ui @stub_ui do
198
242
  @cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -207,7 +251,7 @@ EOF
207
251
 
208
252
  def test_remove_owners_denied
209
253
  response = "You don't have permission to push to this gem"
210
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
254
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
211
255
 
212
256
  use_ui @stub_ui do
213
257
  @cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -216,9 +260,46 @@ EOF
216
260
  assert_match response, @stub_ui.output
217
261
  end
218
262
 
263
+ def test_remove_owners_permanent_redirect
264
+ host = "http://rubygems.example"
265
+ ENV["RUBYGEMS_HOST"] = host
266
+ path = "/api/v1/gems/freewill/owners"
267
+ redirected_uri = "https://rubygems.example#{path}"
268
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
269
+ body: "",
270
+ code: "308",
271
+ msg: "Permanent Redirect",
272
+ headers: { "location" => redirected_uri }
273
+ )
274
+
275
+ use_ui @stub_ui do
276
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
277
+ end
278
+
279
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
280
+ assert_match response, @stub_ui.output
281
+
282
+ path = "/api/v1/gems/freewill/owners"
283
+ redirected_uri = "https://rubygems.example#{path}"
284
+
285
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
286
+ body: "",
287
+ code: "308",
288
+ msg: "Permanent Redirect",
289
+ headers: { "location" => redirected_uri }
290
+ )
291
+
292
+ use_ui @stub_ui do
293
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
294
+ end
295
+
296
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
297
+ assert_match response, @stub_ui.output
298
+ end
299
+
219
300
  def test_remove_owners_key
220
301
  response = "Owner removed successfully."
221
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
302
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
222
303
  File.open Gem.configuration.credentials_path, "a" do |f|
223
304
  f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
224
305
  end
@@ -232,7 +313,7 @@ EOF
232
313
 
233
314
  def test_remove_owners_missing
234
315
  response = "Owner could not be found."
235
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 404, "Not Found"]
316
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 404, msg: "Not Found")
236
317
 
237
318
  use_ui @stub_ui do
238
319
  @cmd.remove_owners("freewill", ["missing@example"])
@@ -246,8 +327,8 @@ EOF
246
327
  response_success = "Owner added successfully."
247
328
 
248
329
  @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
249
- [response_fail, 401, "Unauthorized"],
250
- [response_success, 200, "OK"],
330
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
331
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
251
332
  ]
252
333
 
253
334
  @otp_ui = Gem::MockGemUi.new "111111\n"
@@ -263,7 +344,7 @@ EOF
263
344
 
264
345
  def test_otp_verified_failure
265
346
  response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
266
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 401, "Unauthorized"]
347
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
267
348
 
268
349
  @otp_ui = Gem::MockGemUi.new "111111\n"
269
350
  use_ui @otp_ui do
@@ -281,10 +362,10 @@ EOF
281
362
  response_success = "Owner removed successfully."
282
363
 
283
364
  @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
284
- [response_forbidden, 403, "Forbidden"],
285
- [response_success, 200, "OK"],
365
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
366
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
286
367
  ]
287
- @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
368
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
288
369
  @cmd.instance_variable_set :@scope, :remove_owner
289
370
 
290
371
  @stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
@@ -305,10 +386,10 @@ EOF
305
386
  response_success = "Owner added successfully."
306
387
 
307
388
  @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
308
- [response_forbidden, 403, "Forbidden"],
309
- [response_success, 200, "OK"],
389
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
390
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
310
391
  ]
311
- @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
392
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
312
393
  @cmd.instance_variable_set :@scope, :add_owner
313
394
 
314
395
  @stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
@@ -68,7 +68,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
68
68
 
69
69
  def test_execute
70
70
  @response = "Successfully registered gem: freewill (1.0.0)"
71
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, "OK"]
71
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
72
72
 
73
73
  @cmd.options[:args] = [@path]
74
74
 
@@ -84,7 +84,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
84
84
  host = "https://other.example"
85
85
 
86
86
  @response = "Successfully registered gem: freewill (1.0.0)"
87
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
87
+ @fetcher.data["#{host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
88
88
  @fetcher.data["#{Gem.host}/api/v1/gems"] =
89
89
  ["fail", 500, "Internal Server Error"]
90
90
 
@@ -105,7 +105,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
105
105
  end
106
106
 
107
107
  @response = "Successfully registered gem: freewill (1.0.0)"
108
- @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = [@response, 200, "OK"]
108
+ @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
109
109
  @fetcher.data["#{Gem.host}/api/v1/gems"] =
110
110
  ["fail", 500, "Internal Server Error"]
111
111
 
@@ -136,7 +136,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
136
136
  ENV["RUBYGEMS_HOST"] = @host
137
137
  Gem.configuration.disable_default_gem_server = true
138
138
  @response = "Successfully registered gem: freewill (1.0.0)"
139
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
139
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
140
140
 
141
141
  send_battery
142
142
  end
@@ -163,14 +163,14 @@ class TestGemCommandsPushCommand < Gem::TestCase
163
163
  FileUtils.rm Gem.configuration.credentials_path
164
164
 
165
165
  @response = "Successfully registered gem: freebird (1.0.1)"
166
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
166
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
167
167
 
168
168
  send_battery
169
169
  end
170
170
 
171
171
  def test_sending_gem
172
172
  @response = "Successfully registered gem: freewill (1.0.0)"
173
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
173
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
174
174
 
175
175
  send_battery
176
176
  end
@@ -197,7 +197,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
197
197
  FileUtils.rm Gem.configuration.credentials_path
198
198
 
199
199
  @response = "Successfully registered gem: freebird (1.0.1)"
200
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
200
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
201
201
  send_battery
202
202
  end
203
203
 
@@ -212,7 +212,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
212
212
  ENV["GEM_HOST_API_KEY"] = "PRIVKEY"
213
213
 
214
214
  @response = "Successfully registered gem: freebird (1.0.1)"
215
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
215
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
216
216
  send_battery
217
217
  end
218
218
 
@@ -238,7 +238,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
238
238
  FileUtils.rm Gem.configuration.credentials_path
239
239
 
240
240
  @response = "Successfully registered gem: freebird (1.0.1)"
241
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
241
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
242
242
  send_battery
243
243
  end
244
244
 
@@ -309,7 +309,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
309
309
  FileUtils.rm Gem.configuration.credentials_path
310
310
 
311
311
  @response = "Successfully registered gem: freebird (1.0.1)"
312
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
312
+ @fetcher.data["#{host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
313
313
 
314
314
  # do not set @host
315
315
  use_ui(@ui) { @cmd.send_gem(@path) }
@@ -325,6 +325,27 @@ class TestGemCommandsPushCommand < Gem::TestCase
325
325
  assert_match @response, @ui.output
326
326
  end
327
327
 
328
+ def test_sending_gem_to_host_permanent_redirect
329
+ @host = "http://rubygems.example"
330
+ redirected_uri = "https://rubygems.example/api/v1/gems"
331
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(
332
+ body: "",
333
+ code: 308,
334
+ msg: "Permanent Redirect",
335
+ headers: { "Location" => redirected_uri }
336
+ )
337
+
338
+ assert_raise Gem::MockGemUi::TermError do
339
+ use_ui @ui do
340
+ @cmd.instance_variable_set :@host, @host
341
+ @cmd.send_gem(@path)
342
+ end
343
+ end
344
+
345
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
346
+ assert_match response, @ui.output
347
+ end
348
+
328
349
  def test_raises_error_with_no_arguments
329
350
  def @cmd.sign_in(*); end
330
351
  assert_raise Gem::CommandLineError do
@@ -334,7 +355,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
334
355
 
335
356
  def test_sending_gem_denied
336
357
  response = "You don't have permission to push to this gem"
337
- @fetcher.data["#{@host}/api/v1/gems"] = [response, 403, "Forbidden"]
358
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
338
359
  @cmd.instance_variable_set :@host, @host
339
360
 
340
361
  assert_raise Gem::MockGemUi::TermError do
@@ -348,7 +369,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
348
369
 
349
370
  def test_sending_gem_key
350
371
  @response = "Successfully registered gem: freewill (1.0.0)"
351
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
372
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
352
373
  File.open Gem.configuration.credentials_path, "a" do |f|
353
374
  f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
354
375
  end
@@ -367,8 +388,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
367
388
  response_success = "Successfully registered gem: freewill (1.0.0)"
368
389
 
369
390
  @fetcher.data["#{Gem.host}/api/v1/gems"] = [
370
- [response_fail, 401, "Unauthorized"],
371
- [response_success, 200, "OK"],
391
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
392
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
372
393
  ]
373
394
 
374
395
  @otp_ui = Gem::MockGemUi.new "111111\n"
@@ -384,7 +405,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
384
405
 
385
406
  def test_otp_verified_failure
386
407
  response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
387
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 401, "Unauthorized"]
408
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
388
409
 
389
410
  @otp_ui = Gem::MockGemUi.new "111111\n"
390
411
  assert_raise Gem::MockGemUi::TermError do
@@ -405,12 +426,12 @@ class TestGemCommandsPushCommand < Gem::TestCase
405
426
  response_success = "Successfully registered gem: freewill (1.0.0)"
406
427
 
407
428
  @fetcher.data["#{@host}/api/v1/gems"] = [
408
- [response_mfa_enabled, 401, "Unauthorized"],
409
- [response_forbidden, 403, "Forbidden"],
410
- [response_success, 200, "OK"],
429
+ HTTPResponseFactory.create(body: response_mfa_enabled, code: 401, msg: "Unauthorized"),
430
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
431
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
411
432
  ]
412
433
 
413
- @fetcher.data["#{@host}/api/v1/api_key"] = ["", 200, "OK"]
434
+ @fetcher.data["#{@host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
414
435
  @cmd.instance_variable_set :@host, @host
415
436
  @cmd.instance_variable_set :@scope, :push_rubygem
416
437
 
@@ -438,16 +459,16 @@ class TestGemCommandsPushCommand < Gem::TestCase
438
459
  response_profile = "mfa: disabled\n"
439
460
 
440
461
  @fetcher.data["#{@host}/api/v1/gems"] = [
441
- [response_success, 200, "OK"],
462
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
442
463
  ]
443
464
 
444
465
  @fetcher.data["#{@host}/api/v1/api_key"] = [
445
- [response_mfa_enabled, 401, "Unauthorized"],
446
- ["", 200, "OK"],
466
+ HTTPResponseFactory.create(body: response_mfa_enabled, code: 401, msg: "Unauthorized"),
467
+ HTTPResponseFactory.create(body: "", code: 200, msg: "OK"),
447
468
  ]
448
469
 
449
470
  @fetcher.data["#{@host}/api/v1/profile/me.yaml"] = [
450
- [response_profile, 200, "OK"],
471
+ HTTPResponseFactory.create(body: response_profile, code: 200, msg: "OK"),
451
472
  ]
452
473
 
453
474
  @cmd.instance_variable_set :@scope, :push_rubygem
@@ -71,6 +71,31 @@ class TestGemCommandsSigninCommand < Gem::TestCase
71
71
  assert_equal api_key, credentials[host]
72
72
  end
73
73
 
74
+ def test_execute_with_host_permanent_redirect
75
+ host = "http://rubygems.example/"
76
+ ENV["RUBYGEMS_HOST"] = host
77
+ path = "/api/v1/api_key"
78
+ redirected_uri = "http://rubygems.example#{path}"
79
+ fetcher = Gem::FakeFetcher.new
80
+ fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
81
+ body: "",
82
+ code: "308",
83
+ msg: "Permanent Redirect",
84
+ headers: { "location" => redirected_uri }
85
+ )
86
+ Gem::RemoteFetcher.fetcher = fetcher
87
+ ui = Gem::MockGemUi.new("you@example.com\nsecret\n\n\n\n\n\n\n\n\n")
88
+
89
+ assert_raise Gem::MockGemUi::TermError do
90
+ use_ui ui do
91
+ @cmd.execute
92
+ end
93
+ end
94
+
95
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
96
+ assert_match response, ui.output
97
+ end
98
+
74
99
  def test_execute_with_valid_creds_set_for_default_host
75
100
  util_capture { @cmd.execute }
76
101
 
@@ -186,7 +211,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase
186
211
  # Set the expected response for the Web-API supplied
187
212
  ENV["RUBYGEMS_HOST"] = host
188
213
  data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
189
- fetcher.data[data_key] = [api_key, 200, "OK"]
214
+ fetcher.data[data_key] = HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
190
215
 
191
216
  use_ui key_name_ui do
192
217
  @cmd.execute
@@ -209,8 +234,8 @@ class TestGemCommandsSigninCommand < Gem::TestCase
209
234
 
210
235
  def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled", warning = nil)
211
236
  api_key ||= "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
212
- response = [api_key, 200, "OK"]
213
- profile_response = [ "mfa: #{mfa_level}\nwarning: #{warning}" , 200, "OK"]
237
+ response = HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
238
+ profile_response = HTTPResponseFactory.create(body: "mfa: #{mfa_level}\nwarning: #{warning}", code: 200, msg: "OK")
214
239
  email = "you@example.com"
215
240
  password = "secret"
216
241
 
@@ -43,7 +43,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
43
43
 
44
44
  def test_execute
45
45
  yank_uri = "http://example/api/v1/gems/yank"
46
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
46
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
47
47
 
48
48
  @cmd.options[:args] = %w[a]
49
49
  @cmd.options[:added_platform] = true
@@ -69,8 +69,8 @@ class TestGemCommandsYankCommand < Gem::TestCase
69
69
  response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
70
70
  yank_uri = "http://example/api/v1/gems/yank"
71
71
  @fetcher.data[yank_uri] = [
72
- [response_fail, 401, "Unauthorized"],
73
- ["Successfully yanked", 200, "OK"],
72
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
73
+ HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK"),
74
74
  ]
75
75
 
76
76
  @cmd.options[:args] = %w[a]
@@ -92,7 +92,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
92
92
  def test_execute_with_otp_failure
93
93
  response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
94
94
  yank_uri = "http://example/api/v1/gems/yank"
95
- @fetcher.data[yank_uri] = [response, 401, "Unauthorized"]
95
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
96
96
 
97
97
  @cmd.options[:args] = %w[a]
98
98
  @cmd.options[:added_platform] = true
@@ -111,7 +111,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
111
111
 
112
112
  def test_execute_key
113
113
  yank_uri = "http://example/api/v1/gems/yank"
114
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
114
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
115
115
 
116
116
  @cmd.options[:args] = %w[a]
117
117
  @cmd.options[:version] = req("= 1.0")
@@ -129,7 +129,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
129
129
  def test_execute_host
130
130
  host = "https://other.example"
131
131
  yank_uri = "#{host}/api/v1/gems/yank"
132
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
132
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
133
133
 
134
134
  @cmd.options[:args] = %w[a]
135
135
  @cmd.options[:version] = req("= 1.0")
@@ -154,11 +154,11 @@ class TestGemCommandsYankCommand < Gem::TestCase
154
154
  host = "http://example"
155
155
 
156
156
  @fetcher.data["#{host}/api/v1/gems/yank"] = [
157
- [response_forbidden, 403, "Forbidden"],
158
- [response_success, 200, "OK"],
157
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
158
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
159
159
  ]
160
160
 
161
- @fetcher.data["#{host}/api/v1/api_key"] = ["", 200, "OK"]
161
+ @fetcher.data["#{host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
162
162
  @cmd.options[:args] = %w[a]
163
163
  @cmd.options[:added_platform] = true
164
164
  @cmd.options[:version] = req("= 1.0")