glogin 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6960c45e5d074619ac8a5b4997f5fca734f445ffbf2ea203bf6264436af521ff
4
- data.tar.gz: 6718628c2085dca6a4dae18a3eea5e0de734dfe99676530d7fc70d3dea166bf3
3
+ metadata.gz: 7add4a0060296c5a54d007c99c6aa47d66ca034412e742a8cff753b27929510e
4
+ data.tar.gz: 99c4ab32611b03ad386803d71c623efbfcdc7c1cb6e7256aec9b03ba119e8a3f
5
5
  SHA512:
6
- metadata.gz: fe27db59e34f29a75550a21641710a6f199bf9be582c065d0dd94aca1448a0193e2f481aeae5d642e29202e077355b684f5a3cc5e2a7639ba2f276edb475468b
7
- data.tar.gz: ef9537ee5ec99726b5e02658a12905f35b411cc5aeaa139ca4a15902645e823504f24ffdd0ce1fe1cbbf35d60feb36ce686ba1bf94b8e4f98455cf09f7add689
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)
@@ -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.1'
29
+ VERSION = '0.16.2'
30
30
  end
@@ -65,4 +65,18 @@ class TestAuth < Minitest::Test
65
65
  e = assert_raises { auth.user('437849732894732') }
66
66
  assert(e.message.include?('with code "43784***'))
67
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
68
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.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko