googleauth 0.9.0 → 0.17.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/.yardopts +11 -0
- data/CHANGELOG.md +113 -21
- data/README.md +13 -15
- data/SECURITY.md +7 -0
- data/lib/googleauth/application_default.rb +9 -9
- data/lib/googleauth/compute_engine.rb +55 -30
- data/lib/googleauth/credentials.rb +253 -64
- data/lib/googleauth/credentials_loader.rb +15 -16
- data/lib/googleauth/iam.rb +1 -1
- data/{spec/googleauth/stores/store_examples.rb → lib/googleauth/id_tokens/errors.rb} +36 -23
- data/lib/googleauth/id_tokens/key_sources.rb +396 -0
- data/lib/googleauth/id_tokens/verifier.rb +142 -0
- data/lib/googleauth/id_tokens.rb +233 -0
- data/lib/googleauth/json_key_reader.rb +6 -2
- data/lib/googleauth/scope_util.rb +1 -1
- data/lib/googleauth/service_account.rb +61 -36
- data/lib/googleauth/signet.rb +9 -7
- data/lib/googleauth/stores/file_token_store.rb +1 -0
- data/lib/googleauth/stores/redis_token_store.rb +1 -0
- data/lib/googleauth/user_authorizer.rb +8 -3
- data/lib/googleauth/user_refresh.rb +1 -1
- data/lib/googleauth/version.rb +1 -1
- data/lib/googleauth/web_user_authorizer.rb +5 -8
- data/lib/googleauth.rb +1 -0
- metadata +33 -76
- data/.github/CONTRIBUTING.md +0 -74
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -36
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -21
- data/.github/ISSUE_TEMPLATE/support_request.md +0 -7
- data/.gitignore +0 -36
- data/.kokoro/build.bat +0 -16
- data/.kokoro/build.sh +0 -4
- data/.kokoro/continuous/common.cfg +0 -24
- data/.kokoro/continuous/linux.cfg +0 -15
- data/.kokoro/continuous/osx.cfg +0 -3
- data/.kokoro/continuous/windows.cfg +0 -19
- data/.kokoro/osx.sh +0 -4
- data/.kokoro/presubmit/common.cfg +0 -24
- data/.kokoro/presubmit/linux.cfg +0 -14
- data/.kokoro/presubmit/osx.cfg +0 -3
- data/.kokoro/presubmit/windows.cfg +0 -19
- data/.kokoro/release.cfg +0 -53
- data/.kokoro/trampoline.bat +0 -10
- data/.kokoro/trampoline.sh +0 -4
- data/.rspec +0 -2
- data/.rubocop.yml +0 -42
- data/Gemfile +0 -25
- data/Rakefile +0 -89
- data/googleauth.gemspec +0 -35
- data/spec/googleauth/apply_auth_examples.rb +0 -148
- data/spec/googleauth/client_id_spec.rb +0 -160
- data/spec/googleauth/compute_engine_spec.rb +0 -122
- data/spec/googleauth/credentials_spec.rb +0 -459
- data/spec/googleauth/get_application_default_spec.rb +0 -286
- data/spec/googleauth/iam_spec.rb +0 -80
- data/spec/googleauth/scope_util_spec.rb +0 -77
- data/spec/googleauth/service_account_spec.rb +0 -482
- data/spec/googleauth/signet_spec.rb +0 -134
- data/spec/googleauth/stores/file_token_store_spec.rb +0 -57
- data/spec/googleauth/stores/redis_token_store_spec.rb +0 -50
- data/spec/googleauth/user_authorizer_spec.rb +0 -323
- data/spec/googleauth/user_refresh_spec.rb +0 -359
- data/spec/googleauth/web_user_authorizer_spec.rb +0 -172
- data/spec/spec_helper.rb +0 -92
- /data/{COPYING → LICENSE} +0 -0
@@ -1,459 +0,0 @@
|
|
1
|
-
# Copyright 2017, Google Inc.
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are
|
6
|
-
# met:
|
7
|
-
#
|
8
|
-
# * Redistributions of source code must retain the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer.
|
10
|
-
# * Redistributions in binary form must reproduce the above
|
11
|
-
# copyright notice, this list of conditions and the following disclaimer
|
12
|
-
# in the documentation and/or other materials provided with the
|
13
|
-
# distribution.
|
14
|
-
# * Neither the name of Google Inc. nor the names of its
|
15
|
-
# contributors may be used to endorse or promote products derived from
|
16
|
-
# this software without specific prior written permission.
|
17
|
-
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
require "googleauth"
|
31
|
-
|
32
|
-
|
33
|
-
# This test is testing the private class Google::Auth::Credentials. We want to
|
34
|
-
# make sure that the passed in scope propogates to the Signet object. This means
|
35
|
-
# testing the private API, which is generally frowned on.
|
36
|
-
describe Google::Auth::Credentials, :private do
|
37
|
-
let :default_keyfile_hash do
|
38
|
-
{
|
39
|
-
"private_key_id" => "testabc1234567890xyz",
|
40
|
-
"private_key" => "-----BEGIN RSA PRIVATE KEY-----\nMIIBOwIBAAJBAOyi0Hy1l4Ym2m2o71Q0TF4O9E81isZEsX0bb+Bqz1SXEaSxLiXM\nUZE8wu0eEXivXuZg6QVCW/5l+f2+9UPrdNUCAwEAAQJAJkqubA/Chj3RSL92guy3\nktzeodarLyw8gF8pOmpuRGSiEo/OLTeRUMKKD1/kX4f9sxf3qDhB4e7dulXR1co/\nIQIhAPx8kMW4XTTL6lJYd2K5GrH8uBMp8qL5ya3/XHrBgw3dAiEA7+3Iw3ULTn2I\n1J34WlJ2D5fbzMzB4FAHUNEV7Ys3f1kCIQDtUahCMChrl7+H5t9QS+xrn77lRGhs\nB50pjvy95WXpgQIhAI2joW6JzTfz8fAapb+kiJ/h9Vcs1ZN3iyoRlNFb61JZAiA8\nNy5NyNrMVwtB/lfJf1dAK/p/Bwd8LZLtgM6PapRfgw==\n-----END RSA PRIVATE KEY-----\n",
|
41
|
-
"client_email" => "credz-testabc1234567890xyz@developer.gserviceaccount.com",
|
42
|
-
"client_id" => "credz-testabc1234567890xyz.apps.googleusercontent.com",
|
43
|
-
"type" => "service_account",
|
44
|
-
"project_id" => "a_project_id"
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
it "uses a default scope" do
|
49
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
50
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
51
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
52
|
-
allow(mocked_signet).to receive(:client_id)
|
53
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
54
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
55
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
56
|
-
expect(options[:scope]).to eq([])
|
57
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
58
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
59
|
-
|
60
|
-
mocked_signet
|
61
|
-
end
|
62
|
-
|
63
|
-
Google::Auth::Credentials.new default_keyfile_hash
|
64
|
-
end
|
65
|
-
|
66
|
-
it "uses a custom scope" do
|
67
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
68
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
69
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
70
|
-
allow(mocked_signet).to receive(:client_id)
|
71
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
72
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
73
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
74
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
75
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
76
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
77
|
-
|
78
|
-
mocked_signet
|
79
|
-
end
|
80
|
-
|
81
|
-
Google::Auth::Credentials.new default_keyfile_hash, scope: "http://example.com/scope"
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "using CONSTANTS" do
|
85
|
-
it "can be subclassed to pass in other env paths" do
|
86
|
-
test_path_env_val = "/unknown/path/to/file.txt".freeze
|
87
|
-
test_json_env_val = JSON.generate default_keyfile_hash
|
88
|
-
|
89
|
-
ENV["TEST_PATH"] = test_path_env_val
|
90
|
-
ENV["TEST_JSON_VARS"] = test_json_env_val
|
91
|
-
|
92
|
-
class TestCredentials1 < Google::Auth::Credentials
|
93
|
-
TOKEN_CREDENTIAL_URI = "https://example.com/token".freeze
|
94
|
-
AUDIENCE = "https://example.com/audience".freeze
|
95
|
-
SCOPE = "http://example.com/scope".freeze
|
96
|
-
PATH_ENV_VARS = ["TEST_PATH"].freeze
|
97
|
-
JSON_ENV_VARS = ["TEST_JSON_VARS"].freeze
|
98
|
-
end
|
99
|
-
|
100
|
-
allow(::File).to receive(:file?).with(test_path_env_val) { false }
|
101
|
-
allow(::File).to receive(:file?).with(test_json_env_val) { false }
|
102
|
-
|
103
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
104
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
105
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
106
|
-
allow(mocked_signet).to receive(:client_id)
|
107
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
108
|
-
expect(options[:token_credential_uri]).to eq("https://example.com/token")
|
109
|
-
expect(options[:audience]).to eq("https://example.com/audience")
|
110
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
111
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
112
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
113
|
-
|
114
|
-
mocked_signet
|
115
|
-
end
|
116
|
-
|
117
|
-
creds = TestCredentials1.default
|
118
|
-
expect(creds).to be_a_kind_of(TestCredentials1)
|
119
|
-
expect(creds.client).to eq(mocked_signet)
|
120
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
121
|
-
end
|
122
|
-
|
123
|
-
it "subclasses can use PATH_ENV_VARS to get keyfile path" do
|
124
|
-
class TestCredentials2 < Google::Auth::Credentials
|
125
|
-
SCOPE = "http://example.com/scope".freeze
|
126
|
-
PATH_ENV_VARS = %w[PATH_ENV_DUMMY PATH_ENV_TEST].freeze
|
127
|
-
JSON_ENV_VARS = ["JSON_ENV_DUMMY"].freeze
|
128
|
-
DEFAULT_PATHS = ["~/default/path/to/file.txt"].freeze
|
129
|
-
end
|
130
|
-
|
131
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
132
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
133
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_TEST") { "/unknown/path/to/file.txt" }
|
134
|
-
allow(::File).to receive(:file?).with("/unknown/path/to/file.txt") { true }
|
135
|
-
allow(::File).to receive(:read).with("/unknown/path/to/file.txt") { JSON.generate default_keyfile_hash }
|
136
|
-
|
137
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
138
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
139
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
140
|
-
allow(mocked_signet).to receive(:client_id)
|
141
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
142
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
143
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
144
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
145
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
146
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
147
|
-
|
148
|
-
mocked_signet
|
149
|
-
end
|
150
|
-
|
151
|
-
creds = TestCredentials2.default
|
152
|
-
expect(creds).to be_a_kind_of(TestCredentials2)
|
153
|
-
expect(creds.client).to eq(mocked_signet)
|
154
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
155
|
-
end
|
156
|
-
|
157
|
-
it "subclasses can use JSON_ENV_VARS to get keyfile contents" do
|
158
|
-
test_json_env_val = JSON.generate default_keyfile_hash
|
159
|
-
|
160
|
-
class TestCredentials3 < Google::Auth::Credentials
|
161
|
-
SCOPE = "http://example.com/scope".freeze
|
162
|
-
PATH_ENV_VARS = ["PATH_ENV_DUMMY"].freeze
|
163
|
-
JSON_ENV_VARS = %w[JSON_ENV_DUMMY JSON_ENV_TEST].freeze
|
164
|
-
DEFAULT_PATHS = ["~/default/path/to/file.txt"].freeze
|
165
|
-
end
|
166
|
-
|
167
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
168
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
169
|
-
allow(::File).to receive(:file?).with(test_json_env_val) { false }
|
170
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
171
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_TEST") { test_json_env_val }
|
172
|
-
|
173
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
174
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
175
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
176
|
-
allow(mocked_signet).to receive(:client_id)
|
177
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
178
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
179
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
180
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
181
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
182
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
183
|
-
|
184
|
-
mocked_signet
|
185
|
-
end
|
186
|
-
|
187
|
-
creds = TestCredentials3.default
|
188
|
-
expect(creds).to be_a_kind_of(TestCredentials3)
|
189
|
-
expect(creds.client).to eq(mocked_signet)
|
190
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
191
|
-
end
|
192
|
-
|
193
|
-
it "subclasses can use DEFAULT_PATHS to get keyfile path" do
|
194
|
-
class TestCredentials4 < Google::Auth::Credentials
|
195
|
-
SCOPE = "http://example.com/scope".freeze
|
196
|
-
PATH_ENV_VARS = ["PATH_ENV_DUMMY"].freeze
|
197
|
-
JSON_ENV_VARS = ["JSON_ENV_DUMMY"].freeze
|
198
|
-
DEFAULT_PATHS = ["~/default/path/to/file.txt"].freeze
|
199
|
-
end
|
200
|
-
|
201
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
202
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
203
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
204
|
-
allow(::File).to receive(:file?).with("~/default/path/to/file.txt") { true }
|
205
|
-
allow(::File).to receive(:read).with("~/default/path/to/file.txt") { JSON.generate default_keyfile_hash }
|
206
|
-
|
207
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
208
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
209
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
210
|
-
allow(mocked_signet).to receive(:client_id)
|
211
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
212
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
213
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
214
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
215
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
216
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
217
|
-
|
218
|
-
mocked_signet
|
219
|
-
end
|
220
|
-
|
221
|
-
creds = TestCredentials4.default
|
222
|
-
expect(creds).to be_a_kind_of(TestCredentials4)
|
223
|
-
expect(creds.client).to eq(mocked_signet)
|
224
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
225
|
-
end
|
226
|
-
|
227
|
-
it "subclasses that find no matches default to Google::Auth.get_application_default" do
|
228
|
-
class TestCredentials5 < Google::Auth::Credentials
|
229
|
-
SCOPE = "http://example.com/scope".freeze
|
230
|
-
PATH_ENV_VARS = ["PATH_ENV_DUMMY"].freeze
|
231
|
-
JSON_ENV_VARS = ["JSON_ENV_DUMMY"].freeze
|
232
|
-
DEFAULT_PATHS = ["~/default/path/to/file.txt"].freeze
|
233
|
-
end
|
234
|
-
|
235
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
236
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
237
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
238
|
-
allow(::File).to receive(:file?).with("~/default/path/to/file.txt") { false }
|
239
|
-
|
240
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
241
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
242
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
243
|
-
allow(mocked_signet).to receive(:client_id)
|
244
|
-
allow(Google::Auth).to receive(:get_application_default) do |scope|
|
245
|
-
expect(scope).to eq([TestCredentials5::SCOPE])
|
246
|
-
|
247
|
-
# This should really be a Signet::OAuth2::Client object,
|
248
|
-
# but mocking is making that difficult, so return a valid hash instead.
|
249
|
-
default_keyfile_hash
|
250
|
-
end
|
251
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
252
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
253
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
254
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
255
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
256
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
257
|
-
|
258
|
-
mocked_signet
|
259
|
-
end
|
260
|
-
|
261
|
-
creds = TestCredentials5.default
|
262
|
-
expect(creds).to be_a_kind_of(TestCredentials5)
|
263
|
-
expect(creds.client).to eq(mocked_signet)
|
264
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
describe "using class methods" do
|
269
|
-
it "can be subclassed to pass in other env paths" do
|
270
|
-
test_path_env_val = "/unknown/path/to/file.txt".freeze
|
271
|
-
test_json_env_val = JSON.generate default_keyfile_hash
|
272
|
-
|
273
|
-
ENV["TEST_PATH"] = test_path_env_val
|
274
|
-
ENV["TEST_JSON_VARS"] = test_json_env_val
|
275
|
-
|
276
|
-
class TestCredentials11 < Google::Auth::Credentials
|
277
|
-
self.token_credential_uri = "https://example.com/token"
|
278
|
-
self.audience = "https://example.com/audience"
|
279
|
-
self.scope = "http://example.com/scope"
|
280
|
-
self.env_vars = ["TEST_PATH", "TEST_JSON_VARS"]
|
281
|
-
end
|
282
|
-
|
283
|
-
allow(::File).to receive(:file?).with(test_path_env_val) { false }
|
284
|
-
allow(::File).to receive(:file?).with(test_json_env_val) { false }
|
285
|
-
|
286
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
287
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
288
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
289
|
-
allow(mocked_signet).to receive(:client_id)
|
290
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
291
|
-
expect(options[:token_credential_uri]).to eq("https://example.com/token")
|
292
|
-
expect(options[:audience]).to eq("https://example.com/audience")
|
293
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
294
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
295
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
296
|
-
|
297
|
-
mocked_signet
|
298
|
-
end
|
299
|
-
|
300
|
-
creds = TestCredentials11.default
|
301
|
-
expect(creds).to be_a_kind_of(TestCredentials11)
|
302
|
-
expect(creds.client).to eq(mocked_signet)
|
303
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
304
|
-
end
|
305
|
-
|
306
|
-
it "subclasses can use PATH_ENV_VARS to get keyfile path" do
|
307
|
-
class TestCredentials12 < Google::Auth::Credentials
|
308
|
-
self.scope = "http://example.com/scope"
|
309
|
-
self.env_vars = %w[PATH_ENV_DUMMY PATH_ENV_TEST JSON_ENV_DUMMY]
|
310
|
-
self.paths = ["~/default/path/to/file.txt"]
|
311
|
-
end
|
312
|
-
|
313
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
314
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
315
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_TEST") { "/unknown/path/to/file.txt" }
|
316
|
-
allow(::File).to receive(:file?).with("/unknown/path/to/file.txt") { true }
|
317
|
-
allow(::File).to receive(:read).with("/unknown/path/to/file.txt") { JSON.generate default_keyfile_hash }
|
318
|
-
|
319
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
320
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
321
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
322
|
-
allow(mocked_signet).to receive(:client_id)
|
323
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
324
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
325
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
326
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
327
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
328
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
329
|
-
|
330
|
-
mocked_signet
|
331
|
-
end
|
332
|
-
|
333
|
-
creds = TestCredentials12.default
|
334
|
-
expect(creds).to be_a_kind_of(TestCredentials12)
|
335
|
-
expect(creds.client).to eq(mocked_signet)
|
336
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
337
|
-
end
|
338
|
-
|
339
|
-
it "subclasses can use JSON_ENV_VARS to get keyfile contents" do
|
340
|
-
test_json_env_val = JSON.generate default_keyfile_hash
|
341
|
-
|
342
|
-
class TestCredentials13 < Google::Auth::Credentials
|
343
|
-
self.scope = "http://example.com/scope"
|
344
|
-
self.env_vars = %w[PATH_ENV_DUMMY JSON_ENV_DUMMY JSON_ENV_TEST]
|
345
|
-
self.paths = ["~/default/path/to/file.txt"]
|
346
|
-
end
|
347
|
-
|
348
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
349
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
350
|
-
allow(::File).to receive(:file?).with(test_json_env_val) { false }
|
351
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
352
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_TEST") { test_json_env_val }
|
353
|
-
|
354
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
355
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
356
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
357
|
-
allow(mocked_signet).to receive(:client_id)
|
358
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
359
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
360
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
361
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
362
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
363
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
364
|
-
|
365
|
-
mocked_signet
|
366
|
-
end
|
367
|
-
|
368
|
-
creds = TestCredentials13.default
|
369
|
-
expect(creds).to be_a_kind_of(TestCredentials13)
|
370
|
-
expect(creds.client).to eq(mocked_signet)
|
371
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
372
|
-
end
|
373
|
-
|
374
|
-
it "subclasses can use DEFAULT_PATHS to get keyfile path" do
|
375
|
-
class TestCredentials14 < Google::Auth::Credentials
|
376
|
-
self.scope = "http://example.com/scope"
|
377
|
-
self.env_vars = %w[PATH_ENV_DUMMY JSON_ENV_DUMMY]
|
378
|
-
self.paths = ["~/default/path/to/file.txt"]
|
379
|
-
end
|
380
|
-
|
381
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
382
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
383
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
384
|
-
allow(::File).to receive(:file?).with("~/default/path/to/file.txt") { true }
|
385
|
-
allow(::File).to receive(:read).with("~/default/path/to/file.txt") { JSON.generate default_keyfile_hash }
|
386
|
-
|
387
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
388
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
389
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
390
|
-
allow(mocked_signet).to receive(:client_id)
|
391
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
392
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
393
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
394
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
395
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
396
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
397
|
-
|
398
|
-
mocked_signet
|
399
|
-
end
|
400
|
-
|
401
|
-
creds = TestCredentials14.default
|
402
|
-
expect(creds).to be_a_kind_of(TestCredentials14)
|
403
|
-
expect(creds.client).to eq(mocked_signet)
|
404
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
405
|
-
end
|
406
|
-
|
407
|
-
it "subclasses that find no matches default to Google::Auth.get_application_default" do
|
408
|
-
class TestCredentials15 < Google::Auth::Credentials
|
409
|
-
self.scope = "http://example.com/scope"
|
410
|
-
self.env_vars = %w[PATH_ENV_DUMMY JSON_ENV_DUMMY]
|
411
|
-
self.paths = ["~/default/path/to/file.txt"]
|
412
|
-
end
|
413
|
-
|
414
|
-
allow(::ENV).to receive(:[]).with("PATH_ENV_DUMMY") { "/fake/path/to/file.txt" }
|
415
|
-
allow(::File).to receive(:file?).with("/fake/path/to/file.txt") { false }
|
416
|
-
allow(::ENV).to receive(:[]).with("JSON_ENV_DUMMY") { nil }
|
417
|
-
allow(::File).to receive(:file?).with("~/default/path/to/file.txt") { false }
|
418
|
-
|
419
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
420
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
421
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
422
|
-
allow(mocked_signet).to receive(:client_id)
|
423
|
-
allow(Google::Auth).to receive(:get_application_default) do |scope|
|
424
|
-
expect(scope).to eq(TestCredentials15.scope)
|
425
|
-
|
426
|
-
# This should really be a Signet::OAuth2::Client object,
|
427
|
-
# but mocking is making that difficult, so return a valid hash instead.
|
428
|
-
default_keyfile_hash
|
429
|
-
end
|
430
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |options|
|
431
|
-
expect(options[:token_credential_uri]).to eq("https://oauth2.googleapis.com/token")
|
432
|
-
expect(options[:audience]).to eq("https://oauth2.googleapis.com/token")
|
433
|
-
expect(options[:scope]).to eq(["http://example.com/scope"])
|
434
|
-
expect(options[:issuer]).to eq(default_keyfile_hash["client_email"])
|
435
|
-
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
|
436
|
-
|
437
|
-
mocked_signet
|
438
|
-
end
|
439
|
-
|
440
|
-
creds = TestCredentials15.default
|
441
|
-
expect(creds).to be_a_kind_of(TestCredentials15)
|
442
|
-
expect(creds.client).to eq(mocked_signet)
|
443
|
-
expect(creds.project_id).to eq(default_keyfile_hash["project_id"])
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
it "warns when cloud sdk credentials are used" do
|
448
|
-
mocked_signet = double "Signet::OAuth2::Client"
|
449
|
-
allow(mocked_signet).to receive(:configure_connection).and_return(mocked_signet)
|
450
|
-
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
|
451
|
-
allow(Signet::OAuth2::Client).to receive(:new) do |_options|
|
452
|
-
mocked_signet
|
453
|
-
end
|
454
|
-
allow(mocked_signet).to receive(:client_id).and_return(Google::Auth::CredentialsLoader::CLOUD_SDK_CLIENT_ID)
|
455
|
-
expect { Google::Auth::Credentials.new default_keyfile_hash }.to output(
|
456
|
-
Google::Auth::CredentialsLoader::CLOUD_SDK_CREDENTIALS_WARNING + "\n"
|
457
|
-
).to_stderr
|
458
|
-
end
|
459
|
-
end
|