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 +4 -4
- data/lib/glogin/auth.rb +5 -2
- data/lib/glogin/version.rb +1 -1
- data/test/glogin/test_auth.rb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7add4a0060296c5a54d007c99c6aa47d66ca034412e742a8cff753b27929510e
|
4
|
+
data.tar.gz: 99c4ab32611b03ad386803d71c623efbfcdc7c1cb6e7256aec9b03ba119e8a3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
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
|
-
'*' * (
|
108
|
+
'*' * (txt.length - prefix),
|
106
109
|
'"'
|
107
110
|
].join
|
108
111
|
end
|
data/lib/glogin/version.rb
CHANGED
data/test/glogin/test_auth.rb
CHANGED
@@ -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
|