glogin 0.16.0 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f95b5783be06871b3fcc570c2c931aa4805df8d9eba5fd3e56efdc324b828947
4
- data.tar.gz: 59bad949654ddf467ee7c3c7e520cb885682227fd2b19e2f52131a299d69e0ec
3
+ metadata.gz: 7add4a0060296c5a54d007c99c6aa47d66ca034412e742a8cff753b27929510e
4
+ data.tar.gz: 99c4ab32611b03ad386803d71c623efbfcdc7c1cb6e7256aec9b03ba119e8a3f
5
5
  SHA512:
6
- metadata.gz: 22863efe1b00bb8fb9da9727d173e2b884986496f50be8d1c4f7fead6f16383ac0be0f2ee5c2acb66834d558e67e290a6855b622e94738f86c729e371abe609d
7
- data.tar.gz: 822e2f1c55dada3a6cb2dd5cfc15f77ebb6762bab9f7ad23d270612d94e6489c3352f92973c6491e009d02af955a9522a734419dc6dac1d26b7da9edc9e88c2f
6
+ metadata.gz: 4e904da86505aac96eef855769f5c97adab7be319c66205adb7147d26af49426982dd137da54809b19915808e65d6420bafb414dc7e586ebc77aafa827d5851e
7
+ data.tar.gz: 6ed925cd140812eb2b37ad87802d093a82c6c6545f1a77bf5b11e67c0f96e4bd30df2cc0eb903e2c3b10093645db426ffdfa4e56c64b839148afd5dac3668ead
data/lib/glogin/auth.rb CHANGED
@@ -94,7 +94,10 @@ module GLogin
94
94
  req['Accept'] = 'application/json'
95
95
  res = http.request(req)
96
96
  raise "HTTP error ##{res.code} with code #{escape(code)}: #{res.body}" unless res.code == '200'
97
- JSON.parse(res.body)['access_token']
97
+ json = JSON.parse(res.body)
98
+ token = json['access_token']
99
+ raise "There is no 'access_token' in JSON response from GitHub: #{res.body}" if token.nil?
100
+ token
98
101
  end
99
102
 
100
103
  def escape(txt)
@@ -102,7 +105,7 @@ module GLogin
102
105
  [
103
106
  '"',
104
107
  txt[0..prefix],
105
- '*' * (token.length - prefix),
108
+ '*' * (txt.length - prefix),
106
109
  '"'
107
110
  ].join
108
111
  end
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module GLogin
29
- VERSION = '0.16.0'
29
+ VERSION = '0.16.2'
30
30
  end
@@ -58,4 +58,25 @@ class TestAuth < Minitest::Test
58
58
  auth = GLogin::Auth.new('99999', '', 'http://www.example.com/github-oauth')
59
59
  assert_equal('yegor256', auth.user('1234567890')['login'])
60
60
  end
61
+
62
+ def test_failed_authentication
63
+ auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
64
+ stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(status: 401)
65
+ e = assert_raises { auth.user('437849732894732') }
66
+ assert(e.message.include?('with code "43784***'))
67
+ end
68
+
69
+ def test_broken_json
70
+ auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
71
+ stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: 'Hello!')
72
+ e = assert_raises { auth.user('47839893') }
73
+ assert(e.message.include?('unexpected token'), e)
74
+ end
75
+
76
+ def test_no_token_in_json
77
+ auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
78
+ stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: '{}')
79
+ e = assert_raises { auth.user('47839893') }
80
+ assert(e.message.include?('There is no \'access_token\''), e)
81
+ end
61
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko