googleauth 0.8.0 → 0.8.1
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/.kokoro/build.sh +2 -34
- data/.kokoro/continuous/common.cfg +5 -0
- data/.kokoro/continuous/linux.cfg +1 -1
- data/.kokoro/osx.sh +2 -33
- data/.kokoro/presubmit/common.cfg +5 -0
- data/.kokoro/presubmit/linux.cfg +1 -1
- data/.kokoro/release.cfg +53 -0
- data/.kokoro/trampoline.sh +3 -23
- data/.kokoro/windows.sh +2 -30
- data/.rubocop.yml +7 -24
- data/CHANGELOG.md +24 -39
- data/Gemfile +14 -14
- data/README.md +21 -1
- data/Rakefile +84 -10
- data/googleauth.gemspec +23 -23
- data/lib/googleauth.rb +6 -6
- data/lib/googleauth/application_default.rb +11 -11
- data/lib/googleauth/client_id.rb +16 -16
- data/lib/googleauth/compute_engine.rb +27 -27
- data/lib/googleauth/credentials.rb +35 -37
- data/lib/googleauth/credentials_loader.rb +64 -67
- data/lib/googleauth/default_credentials.rb +18 -18
- data/lib/googleauth/iam.rb +9 -9
- data/lib/googleauth/json_key_reader.rb +6 -6
- data/lib/googleauth/scope_util.rb +11 -11
- data/lib/googleauth/service_account.rb +42 -42
- data/lib/googleauth/signet.rb +15 -17
- data/lib/googleauth/stores/file_token_store.rb +8 -8
- data/lib/googleauth/stores/redis_token_store.rb +17 -17
- data/lib/googleauth/token_store.rb +6 -6
- data/lib/googleauth/user_authorizer.rb +55 -59
- data/lib/googleauth/user_refresh.rb +27 -27
- data/lib/googleauth/version.rb +1 -1
- data/lib/googleauth/web_user_authorizer.rb +55 -56
- data/spec/googleauth/apply_auth_examples.rb +46 -46
- data/spec/googleauth/client_id_spec.rb +54 -54
- data/spec/googleauth/compute_engine_spec.rb +41 -41
- data/spec/googleauth/credentials_spec.rb +97 -97
- data/spec/googleauth/get_application_default_spec.rb +114 -114
- data/spec/googleauth/iam_spec.rb +25 -25
- data/spec/googleauth/scope_util_spec.rb +24 -24
- data/spec/googleauth/service_account_spec.rb +204 -194
- data/spec/googleauth/signet_spec.rb +37 -38
- data/spec/googleauth/stores/file_token_store_spec.rb +12 -12
- data/spec/googleauth/stores/redis_token_store_spec.rb +11 -11
- data/spec/googleauth/stores/store_examples.rb +16 -16
- data/spec/googleauth/user_authorizer_spec.rb +120 -121
- data/spec/googleauth/user_refresh_spec.rb +151 -146
- data/spec/googleauth/web_user_authorizer_spec.rb +66 -66
- data/spec/spec_helper.rb +19 -19
- metadata +4 -6
- data/.kokoro/common.cfg +0 -22
- data/.travis.yml +0 -40
|
@@ -27,64 +27,64 @@
|
|
|
27
27
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
28
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
29
|
|
|
30
|
-
spec_dir = File.expand_path
|
|
31
|
-
$LOAD_PATH.unshift
|
|
30
|
+
spec_dir = File.expand_path File.join(File.dirname(__FILE__))
|
|
31
|
+
$LOAD_PATH.unshift spec_dir
|
|
32
32
|
$LOAD_PATH.uniq!
|
|
33
33
|
|
|
34
|
-
require
|
|
35
|
-
require
|
|
36
|
-
require
|
|
37
|
-
require
|
|
38
|
-
require
|
|
39
|
-
require
|
|
40
|
-
require
|
|
41
|
-
require
|
|
42
|
-
require
|
|
43
|
-
require
|
|
34
|
+
require "apply_auth_examples"
|
|
35
|
+
require "fakefs/safe"
|
|
36
|
+
require "fileutils"
|
|
37
|
+
require "googleauth/user_refresh"
|
|
38
|
+
require "jwt"
|
|
39
|
+
require "multi_json"
|
|
40
|
+
require "openssl"
|
|
41
|
+
require "spec_helper"
|
|
42
|
+
require "tmpdir"
|
|
43
|
+
require "os"
|
|
44
44
|
|
|
45
45
|
include Google::Auth::CredentialsLoader
|
|
46
46
|
|
|
47
47
|
describe Google::Auth::UserRefreshCredentials do
|
|
48
48
|
UserRefreshCredentials = Google::Auth::UserRefreshCredentials
|
|
49
49
|
|
|
50
|
-
let
|
|
50
|
+
let :cred_json do
|
|
51
51
|
{
|
|
52
|
-
client_secret:
|
|
53
|
-
client_id:
|
|
54
|
-
refresh_token:
|
|
55
|
-
type:
|
|
52
|
+
client_secret: "privatekey",
|
|
53
|
+
client_id: "client123",
|
|
54
|
+
refresh_token: "refreshtoken",
|
|
55
|
+
type: "authorized_user"
|
|
56
56
|
}
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
before
|
|
60
|
-
@key = OpenSSL::PKey::RSA.new
|
|
59
|
+
before :example do
|
|
60
|
+
@key = OpenSSL::PKey::RSA.new 2048
|
|
61
61
|
@client = UserRefreshCredentials.make_creds(
|
|
62
62
|
json_key_io: StringIO.new(cred_json_text),
|
|
63
|
-
scope:
|
|
63
|
+
scope: "https://www.googleapis.com/auth/userinfo.profile"
|
|
64
64
|
)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def make_auth_stubs
|
|
68
|
-
access_token = opts[:access_token] ||
|
|
69
|
-
body = MultiJson.dump(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
stub_request(:post,
|
|
73
|
-
.with(body: hash_including(
|
|
74
|
-
.to_return(body:
|
|
75
|
-
status:
|
|
76
|
-
headers: {
|
|
67
|
+
def make_auth_stubs opts = {}
|
|
68
|
+
access_token = opts[:access_token] || ""
|
|
69
|
+
body = MultiJson.dump("access_token" => access_token,
|
|
70
|
+
"token_type" => "Bearer",
|
|
71
|
+
"expires_in" => 3600)
|
|
72
|
+
stub_request(:post, "https://oauth2.googleapis.com/token")
|
|
73
|
+
.with(body: hash_including("grant_type" => "refresh_token"))
|
|
74
|
+
.to_return(body: body,
|
|
75
|
+
status: 200,
|
|
76
|
+
headers: { "Content-Type" => "application/json" })
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
def cred_json_text
|
|
80
|
-
cred_json.delete
|
|
81
|
-
MultiJson.dump
|
|
79
|
+
def cred_json_text missing = nil
|
|
80
|
+
cred_json.delete missing.to_sym unless missing.nil?
|
|
81
|
+
MultiJson.dump cred_json
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
it_behaves_like
|
|
84
|
+
it_behaves_like "apply/apply! are OK"
|
|
85
85
|
|
|
86
|
-
describe
|
|
87
|
-
before
|
|
86
|
+
describe "#from_env" do
|
|
87
|
+
before :example do
|
|
88
88
|
@var_name = ENV_VAR
|
|
89
89
|
@credential_vars = [
|
|
90
90
|
ENV_VAR, CLIENT_ID_VAR, CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR,
|
|
@@ -92,243 +92,248 @@ describe Google::Auth::UserRefreshCredentials do
|
|
|
92
92
|
]
|
|
93
93
|
@original_env_vals = {}
|
|
94
94
|
@credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
|
|
95
|
-
@scope =
|
|
95
|
+
@scope = "https://www.googleapis.com/auth/userinfo.profile"
|
|
96
96
|
@clz = UserRefreshCredentials
|
|
97
|
-
@project_id =
|
|
97
|
+
@project_id = "a_project_id"
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
after
|
|
100
|
+
after :example do
|
|
101
101
|
@credential_vars.each { |var| ENV[var] = @original_env_vals[var] }
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
it
|
|
105
|
-
ENV.delete
|
|
104
|
+
it "returns nil if the GOOGLE_APPLICATION_CREDENTIALS is unset" do
|
|
105
|
+
ENV.delete @var_name unless ENV[@var_name].nil?
|
|
106
106
|
expect(UserRefreshCredentials.from_env(@scope)).to be_nil
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
it
|
|
110
|
-
ENV
|
|
109
|
+
it "returns nil if the GOOGLE_APPLICATION_CREDENTIALS is empty" do
|
|
110
|
+
ENV[@var_name] = ""
|
|
111
|
+
expect(UserRefreshCredentials.from_env(@scope)).to be_nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "fails if the GOOGLE_APPLICATION_CREDENTIALS path does not exist" do
|
|
115
|
+
ENV.delete @var_name unless ENV[@var_name].nil?
|
|
111
116
|
expect(UserRefreshCredentials.from_env(@scope)).to be_nil
|
|
112
117
|
Dir.mktmpdir do |dir|
|
|
113
|
-
key_path = File.join
|
|
118
|
+
key_path = File.join dir, "does-not-exist"
|
|
114
119
|
ENV[@var_name] = key_path
|
|
115
|
-
expect { @clz.from_env
|
|
120
|
+
expect { @clz.from_env @scope }.to raise_error RuntimeError
|
|
116
121
|
end
|
|
117
122
|
end
|
|
118
123
|
|
|
119
|
-
it
|
|
120
|
-
needed = %w
|
|
124
|
+
it "fails if the GOOGLE_APPLICATION_CREDENTIALS path file is invalid" do
|
|
125
|
+
needed = %w[client_id client_secret refresh_token]
|
|
121
126
|
needed.each do |missing|
|
|
122
127
|
Dir.mktmpdir do |dir|
|
|
123
|
-
key_path = File.join
|
|
124
|
-
FileUtils.mkdir_p
|
|
125
|
-
File.write
|
|
128
|
+
key_path = File.join dir, "my_cert_file"
|
|
129
|
+
FileUtils.mkdir_p File.dirname(key_path)
|
|
130
|
+
File.write key_path, cred_json_text(missing)
|
|
126
131
|
ENV[@var_name] = key_path
|
|
127
|
-
expect { @clz.from_env
|
|
132
|
+
expect { @clz.from_env @scope }.to raise_error RuntimeError
|
|
128
133
|
end
|
|
129
134
|
end
|
|
130
135
|
end
|
|
131
136
|
|
|
132
|
-
it
|
|
137
|
+
it "succeeds when the GOOGLE_APPLICATION_CREDENTIALS file is valid" do
|
|
133
138
|
Dir.mktmpdir do |dir|
|
|
134
|
-
key_path = File.join
|
|
135
|
-
FileUtils.mkdir_p
|
|
136
|
-
File.write
|
|
139
|
+
key_path = File.join dir, "my_cert_file"
|
|
140
|
+
FileUtils.mkdir_p File.dirname(key_path)
|
|
141
|
+
File.write key_path, cred_json_text
|
|
137
142
|
ENV[@var_name] = key_path
|
|
138
143
|
expect(@clz.from_env(@scope)).to_not be_nil
|
|
139
144
|
end
|
|
140
145
|
end
|
|
141
146
|
|
|
142
|
-
it
|
|
143
|
-
|
|
147
|
+
it "succeeds when GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and "\
|
|
148
|
+
"GOOGLE_REFRESH_TOKEN env vars are valid" do
|
|
144
149
|
ENV[ENV_VAR] = nil
|
|
145
150
|
ENV[CLIENT_ID_VAR] = cred_json[:client_id]
|
|
146
151
|
ENV[CLIENT_SECRET_VAR] = cred_json[:client_secret]
|
|
147
152
|
ENV[REFRESH_TOKEN_VAR] = cred_json[:refresh_token]
|
|
148
153
|
ENV[ACCOUNT_TYPE_VAR] = cred_json[:type]
|
|
149
|
-
creds = @clz.from_env
|
|
154
|
+
creds = @clz.from_env @scope
|
|
150
155
|
expect(creds).to_not be_nil
|
|
151
156
|
expect(creds.client_id).to eq(cred_json[:client_id])
|
|
152
157
|
expect(creds.client_secret).to eq(cred_json[:client_secret])
|
|
153
158
|
expect(creds.refresh_token).to eq(cred_json[:refresh_token])
|
|
154
159
|
end
|
|
155
160
|
|
|
156
|
-
it
|
|
161
|
+
it "sets project_id when the PROJECT_ID_VAR env var is set" do
|
|
157
162
|
ENV[ENV_VAR] = nil
|
|
158
163
|
ENV[CLIENT_ID_VAR] = cred_json[:client_id]
|
|
159
164
|
ENV[CLIENT_SECRET_VAR] = cred_json[:client_secret]
|
|
160
165
|
ENV[REFRESH_TOKEN_VAR] = cred_json[:refresh_token]
|
|
161
166
|
ENV[ACCOUNT_TYPE_VAR] = cred_json[:type]
|
|
162
167
|
ENV[PROJECT_ID_VAR] = @project_id
|
|
163
|
-
creds = @clz.from_env
|
|
168
|
+
creds = @clz.from_env @scope
|
|
164
169
|
expect(creds.project_id).to eq(@project_id)
|
|
165
170
|
end
|
|
166
171
|
end
|
|
167
172
|
|
|
168
|
-
describe
|
|
169
|
-
before
|
|
170
|
-
@home = ENV[
|
|
171
|
-
@app_data = ENV[
|
|
172
|
-
@scope =
|
|
173
|
+
describe "#from_well_known_path" do
|
|
174
|
+
before :example do
|
|
175
|
+
@home = ENV["HOME"]
|
|
176
|
+
@app_data = ENV["APPDATA"]
|
|
177
|
+
@scope = "https://www.googleapis.com/auth/userinfo.profile"
|
|
173
178
|
@known_path = WELL_KNOWN_PATH
|
|
174
179
|
@clz = UserRefreshCredentials
|
|
175
180
|
end
|
|
176
181
|
|
|
177
|
-
after
|
|
178
|
-
ENV[
|
|
179
|
-
ENV[
|
|
182
|
+
after :example do
|
|
183
|
+
ENV["HOME"] = @home unless @home == ENV["HOME"]
|
|
184
|
+
ENV["APPDATA"] = @app_data unless @app_data == ENV["APPDATA"]
|
|
180
185
|
end
|
|
181
186
|
|
|
182
|
-
it
|
|
183
|
-
ENV[
|
|
187
|
+
it "is nil if no file exists" do
|
|
188
|
+
ENV["HOME"] = File.dirname __FILE__
|
|
184
189
|
expect(UserRefreshCredentials.from_well_known_path(@scope)).to be_nil
|
|
185
190
|
end
|
|
186
191
|
|
|
187
|
-
it
|
|
188
|
-
needed = %w
|
|
192
|
+
it "fails if the file is invalid" do
|
|
193
|
+
needed = %w[client_id client_secret refresh_token]
|
|
189
194
|
needed.each do |missing|
|
|
190
195
|
Dir.mktmpdir do |dir|
|
|
191
|
-
key_path = File.join
|
|
192
|
-
key_path = File.join
|
|
193
|
-
FileUtils.mkdir_p
|
|
194
|
-
File.write
|
|
195
|
-
ENV[
|
|
196
|
-
ENV[
|
|
197
|
-
expect { @clz.from_well_known_path
|
|
196
|
+
key_path = File.join dir, ".config", @known_path
|
|
197
|
+
key_path = File.join dir, @known_path if OS.windows?
|
|
198
|
+
FileUtils.mkdir_p File.dirname(key_path)
|
|
199
|
+
File.write key_path, cred_json_text(missing)
|
|
200
|
+
ENV["HOME"] = dir
|
|
201
|
+
ENV["APPDATA"] = dir
|
|
202
|
+
expect { @clz.from_well_known_path @scope }
|
|
198
203
|
.to raise_error RuntimeError
|
|
199
204
|
end
|
|
200
205
|
end
|
|
201
206
|
end
|
|
202
207
|
|
|
203
|
-
it
|
|
208
|
+
it "successfully loads the file when it is present" do
|
|
204
209
|
Dir.mktmpdir do |dir|
|
|
205
|
-
key_path = File.join
|
|
206
|
-
key_path = File.join
|
|
207
|
-
FileUtils.mkdir_p
|
|
208
|
-
File.write
|
|
209
|
-
ENV[
|
|
210
|
-
ENV[
|
|
210
|
+
key_path = File.join dir, ".config", @known_path
|
|
211
|
+
key_path = File.join dir, @known_path if OS.windows?
|
|
212
|
+
FileUtils.mkdir_p File.dirname(key_path)
|
|
213
|
+
File.write key_path, cred_json_text
|
|
214
|
+
ENV["HOME"] = dir
|
|
215
|
+
ENV["APPDATA"] = dir
|
|
211
216
|
expect(@clz.from_well_known_path(@scope)).to_not be_nil
|
|
212
217
|
end
|
|
213
218
|
end
|
|
214
219
|
|
|
215
|
-
it
|
|
220
|
+
it "checks gcloud config for project_id if none was provided" do
|
|
216
221
|
Dir.mktmpdir do |dir|
|
|
217
|
-
key_path = File.join
|
|
218
|
-
key_path = File.join
|
|
219
|
-
FileUtils.mkdir_p
|
|
220
|
-
File.write
|
|
221
|
-
ENV[
|
|
222
|
-
ENV[
|
|
222
|
+
key_path = File.join dir, ".config", @known_path
|
|
223
|
+
key_path = File.join dir, @known_path if OS.windows?
|
|
224
|
+
FileUtils.mkdir_p File.dirname(key_path)
|
|
225
|
+
File.write key_path, cred_json_text
|
|
226
|
+
ENV["HOME"] = dir
|
|
227
|
+
ENV["APPDATA"] = dir
|
|
223
228
|
ENV[PROJECT_ID_VAR] = nil
|
|
224
229
|
expect(Google::Auth::CredentialsLoader).to receive(:load_gcloud_project_id).with(no_args)
|
|
225
|
-
@clz.from_well_known_path
|
|
230
|
+
@clz.from_well_known_path @scope
|
|
226
231
|
end
|
|
227
232
|
end
|
|
228
233
|
end
|
|
229
234
|
|
|
230
|
-
describe
|
|
231
|
-
before
|
|
232
|
-
@scope =
|
|
233
|
-
@prefix = OS.windows? ?
|
|
234
|
-
@path = File.join
|
|
235
|
-
@program_data = ENV[
|
|
235
|
+
describe "#from_system_default_path" do
|
|
236
|
+
before :example do
|
|
237
|
+
@scope = "https://www.googleapis.com/auth/userinfo.profile"
|
|
238
|
+
@prefix = OS.windows? ? "/etc/Google/Auth/" : "/etc/google/auth/"
|
|
239
|
+
@path = File.join @prefix, CREDENTIALS_FILE_NAME
|
|
240
|
+
@program_data = ENV["ProgramData"]
|
|
236
241
|
@clz = UserRefreshCredentials
|
|
237
242
|
end
|
|
238
243
|
|
|
239
|
-
after
|
|
240
|
-
ENV[
|
|
244
|
+
after :example do
|
|
245
|
+
ENV["ProgramData"] = @program_data
|
|
241
246
|
end
|
|
242
247
|
|
|
243
|
-
it
|
|
248
|
+
it "is nil if no file exists" do
|
|
244
249
|
FakeFS do
|
|
245
250
|
expect(UserRefreshCredentials.from_system_default_path(@scope))
|
|
246
251
|
.to be_nil
|
|
247
252
|
end
|
|
248
253
|
end
|
|
249
254
|
|
|
250
|
-
it
|
|
251
|
-
needed = %w
|
|
255
|
+
it "fails if the file is invalid" do
|
|
256
|
+
needed = %w[client_id client_secret refresh_token]
|
|
252
257
|
needed.each do |missing|
|
|
253
258
|
FakeFS do
|
|
254
|
-
ENV[
|
|
255
|
-
FileUtils.mkdir_p
|
|
256
|
-
File.write
|
|
257
|
-
expect { @clz.from_system_default_path
|
|
259
|
+
ENV["ProgramData"] = "/etc"
|
|
260
|
+
FileUtils.mkdir_p File.dirname(@path)
|
|
261
|
+
File.write @path, cred_json_text(missing)
|
|
262
|
+
expect { @clz.from_system_default_path @scope }
|
|
258
263
|
.to raise_error RuntimeError
|
|
259
|
-
File.delete
|
|
264
|
+
File.delete @path
|
|
260
265
|
end
|
|
261
266
|
end
|
|
262
267
|
end
|
|
263
268
|
|
|
264
|
-
it
|
|
269
|
+
it "successfully loads the file when it is present" do
|
|
265
270
|
FakeFS do
|
|
266
|
-
ENV[
|
|
267
|
-
FileUtils.mkdir_p
|
|
268
|
-
File.write
|
|
271
|
+
ENV["ProgramData"] = "/etc"
|
|
272
|
+
FileUtils.mkdir_p File.dirname(@path)
|
|
273
|
+
File.write @path, cred_json_text
|
|
269
274
|
expect(@clz.from_system_default_path(@scope)).to_not be_nil
|
|
270
|
-
File.delete
|
|
275
|
+
File.delete @path
|
|
271
276
|
end
|
|
272
277
|
end
|
|
273
278
|
end
|
|
274
279
|
|
|
275
|
-
shared_examples
|
|
276
|
-
it
|
|
280
|
+
shared_examples "revoked token" do
|
|
281
|
+
it "should nil the refresh token" do
|
|
277
282
|
expect(@client.refresh_token).to be_nil
|
|
278
283
|
end
|
|
279
284
|
|
|
280
|
-
it
|
|
285
|
+
it "should nil the access token" do
|
|
281
286
|
expect(@client.access_token).to be_nil
|
|
282
287
|
end
|
|
283
288
|
|
|
284
|
-
it
|
|
289
|
+
it "should mark the token as expired" do
|
|
285
290
|
expect(@client.expired?).to be_truthy
|
|
286
291
|
end
|
|
287
292
|
end
|
|
288
293
|
|
|
289
|
-
describe
|
|
290
|
-
let
|
|
291
|
-
stub_request(:post,
|
|
292
|
-
.with(body: hash_including(
|
|
293
|
-
.to_return(status:
|
|
294
|
-
headers: {
|
|
294
|
+
describe "when revoking a refresh token" do
|
|
295
|
+
let :stub do
|
|
296
|
+
stub_request(:post, "https://oauth2.googleapis.com/revoke")
|
|
297
|
+
.with(body: hash_including("token" => "refreshtoken"))
|
|
298
|
+
.to_return(status: 200,
|
|
299
|
+
headers: { "Content-Type" => "application/json" })
|
|
295
300
|
end
|
|
296
301
|
|
|
297
|
-
before
|
|
302
|
+
before :example do
|
|
298
303
|
stub
|
|
299
304
|
@client.revoke!
|
|
300
305
|
end
|
|
301
306
|
|
|
302
|
-
it_behaves_like
|
|
307
|
+
it_behaves_like "revoked token"
|
|
303
308
|
end
|
|
304
309
|
|
|
305
|
-
describe
|
|
306
|
-
let
|
|
307
|
-
stub_request(:post,
|
|
308
|
-
.with(body: hash_including(
|
|
309
|
-
.to_return(status:
|
|
310
|
-
headers: {
|
|
310
|
+
describe "when revoking an access token" do
|
|
311
|
+
let :stub do
|
|
312
|
+
stub_request(:post, "https://oauth2.googleapis.com/revoke")
|
|
313
|
+
.with(body: hash_including("token" => "accesstoken"))
|
|
314
|
+
.to_return(status: 200,
|
|
315
|
+
headers: { "Content-Type" => "application/json" })
|
|
311
316
|
end
|
|
312
317
|
|
|
313
|
-
before
|
|
318
|
+
before :example do
|
|
314
319
|
stub
|
|
315
320
|
@client.refresh_token = nil
|
|
316
|
-
@client.access_token =
|
|
321
|
+
@client.access_token = "accesstoken"
|
|
317
322
|
@client.revoke!
|
|
318
323
|
end
|
|
319
324
|
|
|
320
|
-
it_behaves_like
|
|
325
|
+
it_behaves_like "revoked token"
|
|
321
326
|
end
|
|
322
327
|
|
|
323
|
-
describe
|
|
324
|
-
let
|
|
325
|
-
stub_request(:post,
|
|
326
|
-
.with(body: hash_including(
|
|
327
|
-
.to_return(status:
|
|
328
|
-
headers: {
|
|
328
|
+
describe "when revoking an invalid token" do
|
|
329
|
+
let :stub do
|
|
330
|
+
stub_request(:post, "https://oauth2.googleapis.com/revoke")
|
|
331
|
+
.with(body: hash_including("token" => "refreshtoken"))
|
|
332
|
+
.to_return(status: 400,
|
|
333
|
+
headers: { "Content-Type" => "application/json" })
|
|
329
334
|
end
|
|
330
335
|
|
|
331
|
-
it
|
|
336
|
+
it "raises an authorization error" do
|
|
332
337
|
stub
|
|
333
338
|
expect { @client.revoke! }.to raise_error(
|
|
334
339
|
Signet::AuthorizationError
|
|
@@ -336,15 +341,15 @@ describe Google::Auth::UserRefreshCredentials do
|
|
|
336
341
|
end
|
|
337
342
|
end
|
|
338
343
|
|
|
339
|
-
describe
|
|
340
|
-
it
|
|
344
|
+
describe "when errors occurred with request" do
|
|
345
|
+
it "should fail with Signet::AuthorizationError if request times out" do
|
|
341
346
|
allow_any_instance_of(Faraday::Connection).to receive(:post)
|
|
342
347
|
.and_raise(Faraday::TimeoutError)
|
|
343
348
|
expect { @client.revoke! }
|
|
344
349
|
.to raise_error Signet::AuthorizationError
|
|
345
350
|
end
|
|
346
351
|
|
|
347
|
-
it
|
|
352
|
+
it "should fail with Signet::AuthorizationError if request fails" do
|
|
348
353
|
allow_any_instance_of(Faraday::Connection).to receive(:post)
|
|
349
354
|
.and_raise(Faraday::ConnectionFailed, nil)
|
|
350
355
|
expect { @client.revoke! }
|