glogin 0.16.1 → 0.16.3

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: 6960c45e5d074619ac8a5b4997f5fca734f445ffbf2ea203bf6264436af521ff
4
- data.tar.gz: 6718628c2085dca6a4dae18a3eea5e0de734dfe99676530d7fc70d3dea166bf3
3
+ metadata.gz: eda8e66e30f5f90d9a125ca84f104c5bddaf38f9b0ac2381935ee9dac92aff70
4
+ data.tar.gz: 74d58b5818dbd3f0809336de8895866aa8d9f1a01aa326ba1f1d73fc1383ebab
5
5
  SHA512:
6
- metadata.gz: fe27db59e34f29a75550a21641710a6f199bf9be582c065d0dd94aca1448a0193e2f481aeae5d642e29202e077355b684f5a3cc5e2a7639ba2f276edb475468b
7
- data.tar.gz: ef9537ee5ec99726b5e02658a12905f35b411cc5aeaa139ca4a15902645e823504f24ffdd0ce1fe1cbbf35d60feb36ce686ba1bf94b8e4f98455cf09f7add689
6
+ metadata.gz: 63ec19df364df3d7db038e71798dff21713df174ecbddb3ef8e26de8a0a76d2c39efaed520809252bf42f0bbf077fd3628f65e006126a56e64ba8fe19700233d
7
+ data.tar.gz: 280d55cd553045833c0fb23e58918db97659a7f270efa1837223f2d02b781a5e9a60b7db5b96f86aaf9eb4b6fa897d147de5f258c0ecf55c9e4b545fd40a235f
data/Gemfile CHANGED
@@ -29,6 +29,6 @@ gem 'rake', '13.2.1', require: false
29
29
  gem 'rdoc', '6.7.0', require: false
30
30
  gem 'rspec-rails', '6.1.3', require: false
31
31
  gem 'rubocop', '1.65.0', require: false
32
- gem 'rubocop-rspec', '3.0.2', require: false
32
+ gem 'rubocop-rspec', '3.0.3', require: false
33
33
  gem 'simplecov', '0.22.0', require: false
34
34
  gem 'webmock', '3.23.1', require: false
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)
data/lib/glogin/cookie.rb CHANGED
@@ -92,9 +92,9 @@ module GLogin
92
92
  raise 'JSON can\'t be nil' if json.nil?
93
93
  raise 'JSON must contain "id" key' if json['id'].nil?
94
94
  json.each do |k, v|
95
- raise "Key #{k} is not a string" unless k.is_a?(String)
96
- raise "Key #{k} is not allowed" unless %w[id login avatar_url bearer].include?(k)
97
- raise "Value #{v} is not a string" unless v.is_a?(String)
95
+ raise "The key #{k} is not a string" unless k.is_a?(String)
96
+ raise "The key #{k} is not allowed" unless %w[id login avatar_url bearer].include?(k)
97
+ raise "The value '#{v}' of #{k} is not String or Integer" unless v.is_a?(String) || v.is_a?(Integer)
98
98
  end
99
99
  @id = json['id']
100
100
  @login = json['login'] || ''
@@ -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.3'
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
@@ -30,7 +30,7 @@ class TestCookie < Minitest::Test
30
30
  user = GLogin::Cookie::Closed.new(
31
31
  GLogin::Cookie::Open.new(
32
32
  JSON.parse(
33
- "{\"id\":\"123\",
33
+ "{\"id\":123,
34
34
  \"login\":\"yegor256\",
35
35
  \"avatar_url\":\"https://avatars1.githubusercontent.com/u/526301\"}"
36
36
  ),
metadata CHANGED
@@ -1,14 +1,14 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58