gini-api 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gini-api/oauth.rb +35 -100
- data/lib/gini-api/version.rb +2 -1
- data/spec/gini-api/client_spec.rb +6 -6
- data/spec/gini-api/document/extraction_spec.rb +1 -1
- data/spec/gini-api/document_spec.rb +14 -14
- data/spec/gini-api/error_spec.rb +1 -1
- data/spec/gini-api/oauth_spec.rb +39 -103
- data/spec/integration/api_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1830e16b7d2607dd85bee598ba303c2e25de8c24
|
4
|
+
data.tar.gz: 5ce81f559626bfc77e3aae333a5083ec86fcbaf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 614d219b4965e33d0719df8e6404afca5b4454d5eda193bf43e20e322bc3535f1748602365f4d8893cdf8b1b81c6f9e2ce43fabffc28e0e99e9da21a93a0a970
|
7
|
+
data.tar.gz: 6109ca515471045161ab64a59ccef471dc43c65812fa5a38f1a5589c60924cf3366bc999b592841bfdd5ddf07aafa5d218253b2a7278abe78da2e2c80fd1e4cd
|
data/lib/gini-api/oauth.rb
CHANGED
@@ -25,33 +25,27 @@ module Gini
|
|
25
25
|
api.client_id,
|
26
26
|
api.client_secret,
|
27
27
|
site: api.oauth_site,
|
28
|
-
|
29
|
-
token_url: '/token',
|
28
|
+
token_url: '/oauth/token',
|
30
29
|
max_redirects: 0,
|
31
30
|
raise_errors: true,
|
32
31
|
)
|
33
32
|
|
34
|
-
# Verify opts. Prefered authorization methis is auth_code. If no auth_code is present a login from
|
35
|
-
#
|
36
|
-
|
33
|
+
# Verify opts. Prefered authorization methis is auth_code. If no auth_code is present a login from
|
34
|
+
# "Resource Owner Password Credentials Grant" flow.
|
35
|
+
# @token is a Oauth2::AccessToken object. Accesstoken is @token.token
|
36
|
+
@token =
|
37
37
|
if opts.key?(:auth_code) && !opts[:auth_code].empty?
|
38
|
-
|
38
|
+
# Exchange code for a token
|
39
|
+
exchange_code_for_token(api, client, opts[:auth_code])
|
39
40
|
else
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
opts[:username],
|
47
|
-
opts[:password])
|
48
|
-
extract_auth_code(location, csrf_token)
|
41
|
+
#
|
42
|
+
login_with_resource_owner_password_credentials(
|
43
|
+
client,
|
44
|
+
opts[:username],
|
45
|
+
opts[:password],
|
46
|
+
)
|
49
47
|
end
|
50
48
|
|
51
|
-
# Exchange code for a real token.
|
52
|
-
# @token is a Oauth2::AccessToken object. Accesstoken is @token.token
|
53
|
-
@token = exchange_code_for_token(api, client, auth_code)
|
54
|
-
|
55
49
|
# Override OAuth2::AccessToken#refresh! to update self instead of returnign a new object
|
56
50
|
# Inspired by https://github.com/intridea/oauth2/issues/116#issuecomment-8097675
|
57
51
|
#
|
@@ -82,20 +76,22 @@ module Gini
|
|
82
76
|
# Destroy token
|
83
77
|
#
|
84
78
|
def destroy
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
79
|
+
return "Not implemented yet. Come back later!"
|
80
|
+
|
81
|
+
# @token.refresh_token && @token.refresh!
|
82
|
+
# response = token.delete("/accessToken/#{@token.token}")
|
83
|
+
# unless response.status == 204
|
84
|
+
# fail_with_oauth_error(
|
85
|
+
# "Failed to destroy token /accessToken/#{@token.token} "\
|
86
|
+
# "(code=#{response.status})",
|
87
|
+
# response
|
88
|
+
# )
|
89
|
+
# end
|
90
|
+
# rescue OAuth2::Error => e
|
91
|
+
# fail_with_oauth_error(
|
92
|
+
# "Failed to destroy token (code=#{e.response.status})",
|
93
|
+
# e.response
|
94
|
+
# )
|
99
95
|
end
|
100
96
|
|
101
97
|
private
|
@@ -112,85 +108,24 @@ module Gini
|
|
112
108
|
)
|
113
109
|
end
|
114
110
|
|
115
|
-
#
|
111
|
+
# Login with resource owner password credentials
|
116
112
|
#
|
117
|
-
# @param [String] location Location URI containing the auth_code
|
118
|
-
# @param [String] csrf_token CSRF token to verify request
|
119
|
-
#
|
120
|
-
# @return [String] Collected authorization code
|
121
|
-
#
|
122
|
-
def extract_auth_code(location, csrf_token)
|
123
|
-
query_params = parse_location(location)
|
124
|
-
|
125
|
-
unless query_params['state'] == csrf_token
|
126
|
-
fail_with_oauth_error(
|
127
|
-
"CSRF token mismatch detected (should=#{csrf_token}, "\
|
128
|
-
"is=#{query_params['state']})"
|
129
|
-
)
|
130
|
-
end
|
131
|
-
|
132
|
-
unless query_params.key?('code') && !query_params['code'].empty?
|
133
|
-
fail_with_oauth_error(
|
134
|
-
"Failed to extract code from location #{location}"
|
135
|
-
)
|
136
|
-
end
|
137
|
-
|
138
|
-
query_params['code']
|
139
|
-
end
|
140
|
-
|
141
|
-
# Parse auth_code and state from URI
|
142
|
-
#
|
143
|
-
# @param [String] location Location URI with auth_code and state
|
144
|
-
#
|
145
|
-
# @return [Hash] Hash with auth_code and state
|
146
|
-
#
|
147
|
-
def parse_location(location)
|
148
|
-
# Parse the location header from the response and return hash
|
149
|
-
# {'code' => '123abc', 'state' => 'supersecret'}
|
150
|
-
q = URI.parse(location).query
|
151
|
-
Hash[*q.split(/\=|\&/)]
|
152
|
-
rescue => e
|
153
|
-
fail_with_oauth_error("Failed to parse location header: #{e.message}")
|
154
|
-
end
|
155
|
-
|
156
|
-
# Login with username/password
|
157
|
-
#
|
158
|
-
# @param [Gini::Api::Client] api API object
|
159
113
|
# @param [OAuth2::Client] client OAuth2 client object
|
160
|
-
# @param [String] csrf_token CSRF token to verify request
|
161
114
|
# @param [String] username API username
|
162
115
|
# @param [String] password API password
|
163
116
|
#
|
164
|
-
# @return [
|
117
|
+
# @return [OAuth2::AccessToken] AccessToken object
|
165
118
|
#
|
166
|
-
def
|
167
|
-
|
168
|
-
auth_uri = client.auth_code.authorize_url(
|
169
|
-
redirect_uri: api.oauth_redirect,
|
170
|
-
state: csrf_token
|
171
|
-
)
|
172
|
-
|
173
|
-
# Accquire auth code
|
174
|
-
response = client.request(
|
175
|
-
:post,
|
176
|
-
auth_uri,
|
177
|
-
body: { username: username, password: password }
|
178
|
-
)
|
179
|
-
unless response.status == 303
|
180
|
-
fail_with_oauth_error(
|
181
|
-
"API login failed (code=#{response.status})",
|
182
|
-
response
|
183
|
-
)
|
184
|
-
end
|
185
|
-
response.headers['location']
|
119
|
+
def login_with_resource_owner_password_credentials(client, username, password)
|
120
|
+
client.password.get_token(username, password)
|
186
121
|
rescue OAuth2::Error => e
|
187
122
|
fail_with_oauth_error(
|
188
|
-
"Failed to acquire
|
123
|
+
"Failed to acquire token with resource owner credentials (code=#{e.response.body})",
|
189
124
|
e.response
|
190
125
|
)
|
191
126
|
end
|
192
127
|
|
193
|
-
# Exchange auth_code for a
|
128
|
+
# Exchange auth_code for a access token
|
194
129
|
#
|
195
130
|
# @param [Gini::Api::Client] api API object
|
196
131
|
# @param [OAuth2::Client] client OAuth2 client object
|
data/lib/gini-api/version.rb
CHANGED
@@ -258,7 +258,7 @@ describe Gini::Api::Client do
|
|
258
258
|
allow(Gini::Api::Document).to \
|
259
259
|
receive(:new).with(api, 'LOC'
|
260
260
|
) { doc }
|
261
|
-
api.token.
|
261
|
+
allow(api.token).to receive(:token).and_return('abc-123')
|
262
262
|
stub_request(
|
263
263
|
:post,
|
264
264
|
%r{/documents}
|
@@ -320,7 +320,7 @@ describe Gini::Api::Client do
|
|
320
320
|
let(:status) { 203 }
|
321
321
|
|
322
322
|
it do
|
323
|
-
api.token.
|
323
|
+
allow(api.token).to receive(:delete).and_return(response)
|
324
324
|
expect { api.delete('abc-123') }.to \
|
325
325
|
raise_error(Gini::Api::DocumentError, /Deletion of docId abc-123 failed/)
|
326
326
|
end
|
@@ -332,8 +332,8 @@ describe Gini::Api::Client do
|
|
332
332
|
let(:status) { 204 }
|
333
333
|
|
334
334
|
it do
|
335
|
-
api.token.
|
336
|
-
expect(api.delete('abc-123')).to
|
335
|
+
allow(api.token).to receive(:delete).and_return(response)
|
336
|
+
expect(api.delete('abc-123').class).to be_truthy
|
337
337
|
end
|
338
338
|
|
339
339
|
end
|
@@ -366,7 +366,7 @@ describe Gini::Api::Client do
|
|
366
366
|
end
|
367
367
|
|
368
368
|
before do
|
369
|
-
api.token.
|
369
|
+
allow(api.token).to receive(:get).and_return(OAuth2::Response.new(response))
|
370
370
|
end
|
371
371
|
|
372
372
|
context 'with documents' do
|
@@ -428,7 +428,7 @@ describe Gini::Api::Client do
|
|
428
428
|
describe '#search' do
|
429
429
|
|
430
430
|
before do
|
431
|
-
api.token.
|
431
|
+
allow(api.token).to receive(:get).and_return(OAuth2::Response.new(response))
|
432
432
|
end
|
433
433
|
|
434
434
|
let(:status) { 200 }
|
@@ -7,7 +7,7 @@ describe Gini::Api::Document do
|
|
7
7
|
double('Gini::Api::OAuth', token: 'TOKEN', destroy: nil)
|
8
8
|
end
|
9
9
|
api.login(auth_code: '1234567890')
|
10
|
-
api.token.
|
10
|
+
allow(api.token).to receive(:get).with(
|
11
11
|
location,
|
12
12
|
{ headers: { accept: header } }
|
13
13
|
).and_return(OAuth2::Response.new(response))
|
@@ -116,7 +116,7 @@ describe Gini::Api::Document do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it do
|
119
|
-
expect(document.completed?).to
|
119
|
+
expect(document.completed?).to be_falsey
|
120
120
|
end
|
121
121
|
|
122
122
|
end
|
@@ -134,7 +134,7 @@ describe Gini::Api::Document do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
it do
|
137
|
-
expect(document.completed?).to
|
137
|
+
expect(document.completed?).to be_truthy
|
138
138
|
end
|
139
139
|
|
140
140
|
end
|
@@ -156,7 +156,7 @@ describe Gini::Api::Document do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it do
|
159
|
-
expect(document.successful?).to
|
159
|
+
expect(document.successful?).to be_truthy
|
160
160
|
end
|
161
161
|
|
162
162
|
end
|
@@ -174,7 +174,7 @@ describe Gini::Api::Document do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it do
|
177
|
-
expect(document.successful?).to
|
177
|
+
expect(document.successful?).to be_falsey
|
178
178
|
end
|
179
179
|
|
180
180
|
end
|
@@ -192,7 +192,7 @@ describe Gini::Api::Document do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
it do
|
195
|
-
api.token.
|
195
|
+
allow(api.token).to receive(:get).with(
|
196
196
|
"#{location}/processed",
|
197
197
|
{ headers: { accept: 'application/octet-stream' } }
|
198
198
|
).and_return(OAuth2::Response.new(pd_response))
|
@@ -211,7 +211,7 @@ describe Gini::Api::Document do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it do
|
214
|
-
api.token.
|
214
|
+
allow(api.token).to receive(:get).with(
|
215
215
|
"#{location}/processed",
|
216
216
|
{ headers: { accept: 'application/octet-stream' } }
|
217
217
|
).and_return(OAuth2::Response.new(pd_response))
|
@@ -236,7 +236,7 @@ describe Gini::Api::Document do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
it do
|
239
|
-
api.token.
|
239
|
+
allow(api.token).to receive(:get).with(
|
240
240
|
"#{location}/extractions",
|
241
241
|
{ headers: { accept: header } }
|
242
242
|
).and_return(OAuth2::Response.new(ex_response))
|
@@ -312,8 +312,8 @@ describe Gini::Api::Document do
|
|
312
312
|
let(:fb_response) { double('Response', status: 204) }
|
313
313
|
|
314
314
|
it do
|
315
|
-
document.
|
316
|
-
api.token.
|
315
|
+
allow(document).to receive(:extractions) { double('Extractions').as_null_object }
|
316
|
+
allow(api.token).to receive(:put).with(
|
317
317
|
"#{location}/extractions/bic",
|
318
318
|
{
|
319
319
|
headers: { 'content-type' => header },
|
@@ -331,8 +331,8 @@ describe Gini::Api::Document do
|
|
331
331
|
let(:fb_response) { double('Response', status: 204) }
|
332
332
|
|
333
333
|
it 'on invalid label' do
|
334
|
-
document.
|
335
|
-
api.token.
|
334
|
+
allow(document).to receive(:extractions) { double('Extractions', bic: nil) }
|
335
|
+
allow(api.token).to receive(:put).with(
|
336
336
|
"#{location}/extractions/bic",
|
337
337
|
{
|
338
338
|
headers: { 'content-type' => header },
|
@@ -351,8 +351,8 @@ describe Gini::Api::Document do
|
|
351
351
|
let(:fb_response) { double('Response', status: 404, body: {}, env: {}) }
|
352
352
|
|
353
353
|
it 'on invalid http code' do
|
354
|
-
document.
|
355
|
-
api.token.
|
354
|
+
allow(document).to receive(:extractions) { double('Extractions').as_null_object }
|
355
|
+
allow(api.token).to receive(:put).with(
|
356
356
|
"#{location}/extractions/bic",
|
357
357
|
{
|
358
358
|
headers: { 'content-type' => header },
|
data/spec/gini-api/error_spec.rb
CHANGED
data/spec/gini-api/oauth_spec.rb
CHANGED
@@ -5,15 +5,14 @@ describe Gini::Api::OAuth do
|
|
5
5
|
let(:user) { 'user@gini.net' }
|
6
6
|
let(:pass) { 'secret' }
|
7
7
|
let(:auth_code) { '1234567890' }
|
8
|
-
let(:state) { '1234567890' }
|
9
8
|
let(:code) { 'abcdefghij'}
|
10
9
|
let(:redirect) { 'http://localhost' }
|
11
10
|
let(:status) { 303 }
|
12
11
|
let(:token_status) { 200 }
|
13
12
|
let(:token_body) { 'client_id=cid&client_secret=sec&code=1234567890&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost' }
|
14
|
-
let(:header) { { 'location' => "https://api.gini.net?code=#{code}
|
13
|
+
let(:header) { { 'location' => "https://api.gini.net?code=#{code}" } }
|
15
14
|
let(:oauth_site) { 'https://user.gini.net' }
|
16
|
-
let(:
|
15
|
+
let(:token_uri) { "#{oauth_site}/oauth/token" }
|
17
16
|
let(:api) do
|
18
17
|
double('API',
|
19
18
|
client_id: 'cid',
|
@@ -28,21 +27,11 @@ describe Gini::Api::OAuth do
|
|
28
27
|
context 'login with username/password' do
|
29
28
|
|
30
29
|
before do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
stub_request(:post,
|
35
|
-
authorize_uri
|
30
|
+
stub_request(
|
31
|
+
:post,
|
32
|
+
token_uri
|
36
33
|
).to_return(
|
37
34
|
status: status,
|
38
|
-
headers: header,
|
39
|
-
body: {}
|
40
|
-
)
|
41
|
-
|
42
|
-
stub_request(:post,
|
43
|
-
"#{oauth_site}/token"
|
44
|
-
).to_return(
|
45
|
-
status: token_status,
|
46
35
|
headers: {
|
47
36
|
'content-type' => 'application/json'
|
48
37
|
},
|
@@ -68,83 +57,9 @@ describe Gini::Api::OAuth do
|
|
68
57
|
expect(oauth.token.token).to eql('123-456')
|
69
58
|
end
|
70
59
|
|
71
|
-
context 'with invalid credentials' do
|
72
|
-
|
73
|
-
let(:status) { 500 }
|
74
|
-
|
75
|
-
it do
|
76
|
-
expect {
|
77
|
-
Gini::Api::OAuth.new(
|
78
|
-
api,
|
79
|
-
username: user,
|
80
|
-
password: pass
|
81
|
-
) }.to raise_error(Gini::Api::OAuthError, /Failed to acquire auth_code/)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'with non-redirect status code' do
|
87
|
-
|
88
|
-
let(:status) { 200 }
|
89
|
-
|
90
|
-
it do
|
91
|
-
expect {
|
92
|
-
Gini::Api::OAuth.new(
|
93
|
-
api,
|
94
|
-
username: user,
|
95
|
-
password: pass
|
96
|
-
) }.to raise_error(Gini::Api::OAuthError, /API login failed/)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'with invalid location header' do
|
101
|
-
|
102
|
-
let(:header) { { location: 'https://api.gini.net' } }
|
103
|
-
|
104
|
-
it do
|
105
|
-
expect {
|
106
|
-
Gini::Api::OAuth.new(
|
107
|
-
api,
|
108
|
-
username: user,
|
109
|
-
password: pass
|
110
|
-
) }.to raise_error(Gini::Api::OAuthError, /Failed to parse location header/)
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'with CSRF token mismatch' do
|
116
|
-
|
117
|
-
let(:header) { { location: "https://rspec.gini.net?code=#{code}&state=hacked"} }
|
118
|
-
|
119
|
-
it do
|
120
|
-
expect {
|
121
|
-
Gini::Api::OAuth.new(
|
122
|
-
api,
|
123
|
-
username: user,
|
124
|
-
password: pass
|
125
|
-
) }.to raise_error(Gini::Api::OAuthError, /CSRF token mismatch detected/)
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'without code' do
|
131
|
-
|
132
|
-
let(:header) { { location: "https://api.gini.net?state=#{state}"} }
|
133
|
-
|
134
|
-
it do
|
135
|
-
expect {
|
136
|
-
Gini::Api::OAuth.new(
|
137
|
-
api,
|
138
|
-
username: user,
|
139
|
-
password: pass
|
140
|
-
) }.to raise_error(Gini::Api::OAuthError, /Failed to extract code from location/)
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
60
|
context 'with invalid client credentials' do
|
146
61
|
|
147
|
-
let(:
|
62
|
+
let(:status) { 401 }
|
148
63
|
|
149
64
|
it do
|
150
65
|
expect {
|
@@ -152,7 +67,7 @@ describe Gini::Api::OAuth do
|
|
152
67
|
api,
|
153
68
|
username: user,
|
154
69
|
password: pass
|
155
|
-
) }.to raise_error(Gini::Api::OAuthError, /Failed to
|
70
|
+
) }.to raise_error(Gini::Api::OAuthError, /Failed to acquire token/)
|
156
71
|
end
|
157
72
|
|
158
73
|
end
|
@@ -162,8 +77,9 @@ describe Gini::Api::OAuth do
|
|
162
77
|
context 'login with auth_code' do
|
163
78
|
|
164
79
|
before do
|
165
|
-
stub_request(
|
166
|
-
|
80
|
+
stub_request(
|
81
|
+
:post,
|
82
|
+
token_uri
|
167
83
|
).with(
|
168
84
|
body: 'client_id=cid&client_secret=sec&code=1234567890&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost'
|
169
85
|
).to_return(
|
@@ -186,6 +102,20 @@ describe Gini::Api::OAuth do
|
|
186
102
|
expect(oauth.token.token).to eql('123-456')
|
187
103
|
end
|
188
104
|
|
105
|
+
context 'with invalid auth_code' do
|
106
|
+
|
107
|
+
let(:token_status) { 400 }
|
108
|
+
|
109
|
+
it do
|
110
|
+
expect {
|
111
|
+
Gini::Api::OAuth.new(
|
112
|
+
api,
|
113
|
+
auth_code: auth_code
|
114
|
+
) }.to raise_error(Gini::Api::OAuthError, /Failed to exchange auth_code/)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
189
119
|
context 'overrides #refresh!' do
|
190
120
|
|
191
121
|
it do
|
@@ -212,8 +142,9 @@ describe Gini::Api::OAuth do
|
|
212
142
|
let(:refresh_token) { false }
|
213
143
|
|
214
144
|
before do
|
215
|
-
stub_request(
|
216
|
-
|
145
|
+
stub_request(
|
146
|
+
:post,
|
147
|
+
token_uri
|
217
148
|
).with(
|
218
149
|
body: 'client_id=cid&client_secret=sec&code=1234567890&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost'
|
219
150
|
).to_return(
|
@@ -234,7 +165,7 @@ describe Gini::Api::OAuth do
|
|
234
165
|
%r{/accessToken/123-456}
|
235
166
|
).to_return(status: status)
|
236
167
|
|
237
|
-
oauth.token.
|
168
|
+
allow(oauth.token).to receive(:refresh_token).and_return(refresh_token)
|
238
169
|
end
|
239
170
|
|
240
171
|
subject(:oauth) { Gini::Api::OAuth.new(api, auth_code: auth_code) }
|
@@ -244,6 +175,7 @@ describe Gini::Api::OAuth do
|
|
244
175
|
let(:refresh_token) { true }
|
245
176
|
|
246
177
|
it 'does a refresh first' do
|
178
|
+
pending "not implemented yet"
|
247
179
|
expect(oauth.token).to receive(:refresh_token)
|
248
180
|
expect(oauth.token).to receive(:refresh!)
|
249
181
|
expect(oauth.destroy).to be_nil
|
@@ -254,6 +186,7 @@ describe Gini::Api::OAuth do
|
|
254
186
|
context 'without refresh token' do
|
255
187
|
|
256
188
|
it 'destroys token directly' do
|
189
|
+
pending "not implemented yet"
|
257
190
|
expect(oauth.token).to receive(:refresh_token)
|
258
191
|
expect(oauth.token).not_to receive(:refresh!)
|
259
192
|
expect(oauth.destroy).to be_nil
|
@@ -265,6 +198,7 @@ describe Gini::Api::OAuth do
|
|
265
198
|
let(:status) { 404 }
|
266
199
|
|
267
200
|
it do
|
201
|
+
pending "not implemented yet"
|
268
202
|
expect{oauth.destroy}.to raise_error Gini::Api::OAuthError, /Failed to destroy token/
|
269
203
|
end
|
270
204
|
end
|
@@ -274,6 +208,7 @@ describe Gini::Api::OAuth do
|
|
274
208
|
let(:status) { 200 }
|
275
209
|
|
276
210
|
it do
|
211
|
+
pending "not implemented yet"
|
277
212
|
expect{oauth.destroy}.to raise_error Gini::Api::OAuthError, /Failed to destroy token/
|
278
213
|
end
|
279
214
|
end
|
@@ -282,8 +217,9 @@ describe Gini::Api::OAuth do
|
|
282
217
|
describe 'overridden AccessToken#refresh!' do
|
283
218
|
|
284
219
|
before do
|
285
|
-
stub_request(
|
286
|
-
|
220
|
+
stub_request(
|
221
|
+
:post,
|
222
|
+
token_uri
|
287
223
|
).with(
|
288
224
|
body: 'client_id=cid&client_secret=sec&code=1234567890&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost'
|
289
225
|
).to_return(
|
@@ -308,7 +244,7 @@ describe Gini::Api::OAuth do
|
|
308
244
|
|
309
245
|
stub_request(
|
310
246
|
:post,
|
311
|
-
|
247
|
+
token_uri
|
312
248
|
).to_return(
|
313
249
|
status: 200,
|
314
250
|
headers: {
|
@@ -332,7 +268,7 @@ describe Gini::Api::OAuth do
|
|
332
268
|
|
333
269
|
before do
|
334
270
|
stub_request(:post,
|
335
|
-
|
271
|
+
token_uri
|
336
272
|
).with(
|
337
273
|
body: 'client_id=cid&client_secret=sec&code=1234567890&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost'
|
338
274
|
).to_return(
|
@@ -358,7 +294,7 @@ describe Gini::Api::OAuth do
|
|
358
294
|
stub_request(:get, "https://user.gini.net/a")
|
359
295
|
stub_request(
|
360
296
|
:post,
|
361
|
-
|
297
|
+
token_uri
|
362
298
|
).to_return(
|
363
299
|
status: 200,
|
364
300
|
headers: {
|
@@ -385,7 +321,7 @@ describe Gini::Api::OAuth do
|
|
385
321
|
stub_request(:get, "https://user.gini.net/a")
|
386
322
|
stub_request(
|
387
323
|
:post,
|
388
|
-
|
324
|
+
token_uri
|
389
325
|
).to_return(
|
390
326
|
status: 200,
|
391
327
|
headers: {
|
@@ -34,7 +34,7 @@ describe 'Gini::Api integration test' do
|
|
34
34
|
|
35
35
|
it '#login sets token' do
|
36
36
|
expect(@api.token.token).to match(/\w+-\w+/)
|
37
|
-
expect(@api.token.expired?).to
|
37
|
+
expect(@api.token.expired?).to be_falsey
|
38
38
|
@api.logout
|
39
39
|
end
|
40
40
|
|
@@ -76,7 +76,7 @@ describe 'Gini::Api integration test' do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it '#delete returns true' do
|
79
|
-
expect(@api.delete(@doc.id)).to
|
79
|
+
expect(@api.delete(@doc.id)).to be_truthy
|
80
80
|
expect { @api.get(@doc.id) }.to raise_error(Gini::Api::RequestError)
|
81
81
|
@api.logout
|
82
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gini-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|