aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems/test_gem_gemcutter_utilities.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-01 11:01:00 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-01 11:01:00 +0000
commit7a46a3b94121339cbead211c4497142bee82fddb (patch)
treebc6e9f11a1b60f8c4258e4780b18f952b0a8ec35 /test/rubygems/test_gem_gemcutter_utilities.rb
parent5cae104e51be9cbf524b7d953b33d0909c46d006 (diff)
downloadruby-7a46a3b94121339cbead211c4497142bee82fddb.tar.gz
Merge rubygems-3.0.0.beta3.
* [GSoC] Multi-factor feature for RubyGems https://github.com/rubygems/rubygems/pull/2369 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_gemcutter_utilities.rb')
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb
index f0d2428391..4315090a3d 100644
--- a/test/rubygems/test_gem_gemcutter_utilities.rb
+++ b/test/rubygems/test_gem_gemcutter_utilities.rb
@@ -187,7 +187,35 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_match %r{Access Denied.}, @sign_in_ui.output
end
- def util_sign_in(response, host = nil, args = [])
+ def test_sign_in_with_correct_otp_code
+ api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
+ response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
+
+ util_sign_in(proc do
+ @call_count ||= 0
+ (@call_count += 1).odd? ? [response_fail, 401, 'Unauthorized'] : [api_key, 200, 'OK']
+ end, nil, [], "111111\n")
+
+ assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @sign_in_ui.output
+ assert_match 'Code: ', @sign_in_ui.output
+ assert_match 'Signed in.', @sign_in_ui.output
+ assert_equal '111111', @fetcher.last_request['OTP']
+ end
+
+ def test_sign_in_with_incorrect_otp_code
+ response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
+
+ assert_raises Gem::MockGemUi::TermError do
+ util_sign_in [response, 401, 'Unauthorized'], nil, [], "111111\n"
+ end
+
+ assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @sign_in_ui.output
+ assert_match 'Code: ', @sign_in_ui.output
+ assert_match response, @sign_in_ui.output
+ assert_equal '111111', @fetcher.last_request['OTP']
+ end
+
+ def util_sign_in(response, host = nil, args = [], extra_input = '')
email = 'you@example.com'
password = 'secret'
@@ -201,7 +229,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
@fetcher.data["#{host}/api/v1/api_key"] = response
Gem::RemoteFetcher.fetcher = @fetcher
- @sign_in_ui = Gem::MockGemUi.new "#{email}\n#{password}\n"
+ @sign_in_ui = Gem::MockGemUi.new("#{email}\n#{password}\n" + extra_input)
use_ui @sign_in_ui do
if args.length > 0