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 +4 -4
- data/lib/glogin/auth.rb +4 -1
- data/lib/glogin/version.rb +1 -1
- data/test/glogin/test_auth.rb +14 -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)
|
data/lib/glogin/version.rb
CHANGED
data/test/glogin/test_auth.rb
CHANGED
@@ -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
|