googleauth 0.5.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +5 -4
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +36 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  5. data/.github/ISSUE_TEMPLATE/support_request.md +7 -0
  6. data/.kokoro/build.bat +16 -0
  7. data/.kokoro/build.sh +4 -0
  8. data/.kokoro/continuous/common.cfg +24 -0
  9. data/.kokoro/continuous/linux.cfg +25 -0
  10. data/.kokoro/continuous/osx.cfg +8 -0
  11. data/.kokoro/continuous/post.cfg +30 -0
  12. data/.kokoro/continuous/windows.cfg +29 -0
  13. data/.kokoro/osx.sh +4 -0
  14. data/.kokoro/presubmit/common.cfg +24 -0
  15. data/.kokoro/presubmit/linux.cfg +24 -0
  16. data/.kokoro/presubmit/osx.cfg +8 -0
  17. data/.kokoro/presubmit/windows.cfg +29 -0
  18. data/.kokoro/release.cfg +94 -0
  19. data/.kokoro/trampoline.bat +10 -0
  20. data/.kokoro/trampoline.sh +4 -0
  21. data/.repo-metadata.json +5 -0
  22. data/.rubocop.yml +17 -1
  23. data/CHANGELOG.md +90 -19
  24. data/CODE_OF_CONDUCT.md +43 -0
  25. data/Gemfile +16 -13
  26. data/README.md +58 -18
  27. data/Rakefile +106 -10
  28. data/googleauth.gemspec +27 -25
  29. data/lib/googleauth/application_default.rb +81 -0
  30. data/lib/googleauth/client_id.rb +21 -19
  31. data/lib/googleauth/compute_engine.rb +40 -43
  32. data/lib/googleauth/credentials.rb +375 -0
  33. data/lib/googleauth/credentials_loader.rb +117 -43
  34. data/lib/googleauth/default_credentials.rb +93 -0
  35. data/lib/googleauth/iam.rb +11 -11
  36. data/lib/googleauth/json_key_reader.rb +46 -0
  37. data/lib/googleauth/scope_util.rb +12 -12
  38. data/lib/googleauth/service_account.rb +64 -62
  39. data/lib/googleauth/signet.rb +53 -12
  40. data/lib/googleauth/stores/file_token_store.rb +8 -8
  41. data/lib/googleauth/stores/redis_token_store.rb +22 -22
  42. data/lib/googleauth/token_store.rb +6 -6
  43. data/lib/googleauth/user_authorizer.rb +80 -68
  44. data/lib/googleauth/user_refresh.rb +44 -35
  45. data/lib/googleauth/version.rb +1 -1
  46. data/lib/googleauth/web_user_authorizer.rb +77 -68
  47. data/lib/googleauth.rb +6 -96
  48. data/rakelib/devsite_builder.rb +45 -0
  49. data/rakelib/link_checker.rb +64 -0
  50. data/rakelib/repo_metadata.rb +59 -0
  51. data/spec/googleauth/apply_auth_examples.rb +47 -46
  52. data/spec/googleauth/client_id_spec.rb +75 -55
  53. data/spec/googleauth/compute_engine_spec.rb +60 -43
  54. data/spec/googleauth/credentials_spec.rb +467 -0
  55. data/spec/googleauth/get_application_default_spec.rb +149 -111
  56. data/spec/googleauth/iam_spec.rb +25 -25
  57. data/spec/googleauth/scope_util_spec.rb +26 -24
  58. data/spec/googleauth/service_account_spec.rb +261 -143
  59. data/spec/googleauth/signet_spec.rb +93 -30
  60. data/spec/googleauth/stores/file_token_store_spec.rb +12 -13
  61. data/spec/googleauth/stores/redis_token_store_spec.rb +11 -11
  62. data/spec/googleauth/stores/store_examples.rb +16 -16
  63. data/spec/googleauth/user_authorizer_spec.rb +153 -124
  64. data/spec/googleauth/user_refresh_spec.rb +186 -121
  65. data/spec/googleauth/web_user_authorizer_spec.rb +82 -69
  66. data/spec/spec_helper.rb +21 -19
  67. metadata +75 -32
  68. data/.rubocop_todo.yml +0 -32
  69. data/.travis.yml +0 -37
@@ -27,124 +27,148 @@
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(File.join(File.dirname(__FILE__)))
31
- $LOAD_PATH.unshift(spec_dir)
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 'faraday'
35
- require 'fakefs/safe'
36
- require 'googleauth'
37
- require 'spec_helper'
34
+ require "faraday"
35
+ require "fakefs/safe"
36
+ require "googleauth"
37
+ require "spec_helper"
38
+ require "os"
38
39
 
39
- describe '#get_application_default' do
40
+ describe "#get_application_default" do
40
41
  # Pass unique options each time to bypass memoization
41
42
  let(:options) { |example| { dememoize: example } }
42
43
 
43
- before(:example) do
44
- @key = OpenSSL::PKey::RSA.new(2048)
44
+ before :example do
45
+ @key = OpenSSL::PKey::RSA.new 2048
45
46
  @var_name = ENV_VAR
46
47
  @credential_vars = [
47
48
  ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, CLIENT_ID_VAR,
48
- CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR, ACCOUNT_TYPE_VAR]
49
+ CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR, ACCOUNT_TYPE_VAR
50
+ ]
49
51
  @original_env_vals = {}
50
52
  @credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
51
- @home = ENV['HOME']
52
- @scope = 'https://www.googleapis.com/auth/userinfo.profile'
53
+ @home = ENV["HOME"]
54
+ @app_data = ENV["APPDATA"]
55
+ @program_data = ENV["ProgramData"]
56
+ @scope = "https://www.googleapis.com/auth/userinfo.profile"
53
57
  end
54
58
 
55
- after(:example) do
59
+ after :example do
56
60
  @credential_vars.each { |var| ENV[var] = @original_env_vals[var] }
57
- ENV['HOME'] = @home unless @home == ENV['HOME']
61
+ ENV["HOME"] = @home unless @home == ENV["HOME"]
62
+ ENV["APPDATA"] = @app_data unless @app_data == ENV["APPDATA"]
63
+ ENV["ProgramData"] = @program_data unless @program_data == ENV["ProgramData"]
58
64
  end
59
65
 
60
- shared_examples 'it cannot load misconfigured credentials' do
61
- it 'fails if the GOOGLE_APPLICATION_CREDENTIALS path does not exist' do
66
+ shared_examples "it cannot load misconfigured credentials" do
67
+ it "fails if the GOOGLE_APPLICATION_CREDENTIALS path does not exist" do
62
68
  Dir.mktmpdir do |dir|
63
- key_path = File.join(dir, 'does-not-exist')
69
+ key_path = File.join dir, "does-not-exist"
64
70
  ENV[@var_name] = key_path
65
- expect { Google::Auth.get_application_default(@scope, options) }
71
+ expect { Google::Auth.get_application_default @scope, options }
66
72
  .to raise_error RuntimeError
67
73
  end
68
74
  end
69
75
 
70
- it 'fails without default file or env if not on compute engine' do
71
- stub = stub_request(:get, 'http://169.254.169.254')
72
- .to_return(status: 404,
73
- headers: { 'Metadata-Flavor' => 'NotGoogle' })
76
+ it "fails without default file or env if not on compute engine" do
77
+ stub = stub_request(:get, "http://169.254.169.254")
78
+ .to_return(status: 404,
79
+ headers: { "Metadata-Flavor" => "NotGoogle" })
74
80
  Dir.mktmpdir do |dir|
75
- ENV.delete(@var_name) unless ENV[@var_name].nil? # no env var
76
- ENV['HOME'] = dir # no config present in this tmp dir
77
- blk = proc do
78
- Google::Auth.get_application_default(@scope, options)
79
- end
80
- expect(&blk).to raise_error RuntimeError
81
+ ENV.delete @var_name unless ENV[@var_name].nil? # no env var
82
+ ENV["HOME"] = dir # no config present in this tmp dir
83
+ expect do
84
+ Google::Auth.get_application_default @scope, options
85
+ end.to raise_error RuntimeError
81
86
  end
82
87
  expect(stub).to have_been_requested
83
88
  end
84
89
  end
85
90
 
86
- shared_examples 'it can successfully load credentials' do
87
- it 'succeeds if the GOOGLE_APPLICATION_CREDENTIALS file is valid' do
91
+ shared_examples "it can successfully load credentials" do
92
+ it "succeeds if the GOOGLE_APPLICATION_CREDENTIALS file is valid" do
88
93
  Dir.mktmpdir do |dir|
89
- key_path = File.join(dir, 'my_cert_file')
90
- FileUtils.mkdir_p(File.dirname(key_path))
91
- File.write(key_path, cred_json_text)
94
+ key_path = File.join dir, "my_cert_file"
95
+ FileUtils.mkdir_p File.dirname(key_path)
96
+ File.write key_path, cred_json_text
92
97
  ENV[@var_name] = key_path
93
98
  expect(Google::Auth.get_application_default(@scope, options))
94
99
  .to_not be_nil
95
100
  end
96
101
  end
97
102
 
98
- it 'succeeds with default file without GOOGLE_APPLICATION_CREDENTIALS' do
99
- ENV.delete(@var_name) unless ENV[@var_name].nil?
103
+ it "propagates default_connection option" do
100
104
  Dir.mktmpdir do |dir|
101
- key_path = File.join(dir, '.config', WELL_KNOWN_PATH)
102
- FileUtils.mkdir_p(File.dirname(key_path))
103
- File.write(key_path, cred_json_text)
104
- ENV['HOME'] = dir
105
+ key_path = File.join dir, "my_cert_file"
106
+ FileUtils.mkdir_p File.dirname(key_path)
107
+ File.write key_path, cred_json_text
108
+ ENV[@var_name] = key_path
109
+ connection = Faraday.new headers: { "User-Agent" => "hello" }
110
+ opts = options.merge default_connection: connection
111
+ creds = Google::Auth.get_application_default @scope, opts
112
+ expect(creds.build_default_connection).to be connection
113
+ end
114
+ end
115
+
116
+ it "succeeds with default file without GOOGLE_APPLICATION_CREDENTIALS" do
117
+ ENV.delete @var_name unless ENV[@var_name].nil?
118
+ Dir.mktmpdir do |dir|
119
+ key_path = File.join dir, ".config", WELL_KNOWN_PATH
120
+ key_path = File.join dir, WELL_KNOWN_PATH if OS.windows?
121
+ FileUtils.mkdir_p File.dirname(key_path)
122
+ File.write key_path, cred_json_text
123
+ ENV["HOME"] = dir
124
+ ENV["APPDATA"] = dir
105
125
  expect(Google::Auth.get_application_default(@scope, options))
106
126
  .to_not be_nil
107
127
  end
108
128
  end
109
129
 
110
- it 'succeeds with default file without a scope' do
111
- ENV.delete(@var_name) unless ENV[@var_name].nil?
130
+ it "succeeds with default file without a scope" do
131
+ ENV.delete @var_name unless ENV[@var_name].nil?
112
132
  Dir.mktmpdir do |dir|
113
- key_path = File.join(dir, '.config', WELL_KNOWN_PATH)
114
- FileUtils.mkdir_p(File.dirname(key_path))
115
- File.write(key_path, cred_json_text)
116
- ENV['HOME'] = dir
133
+ key_path = File.join dir, ".config", WELL_KNOWN_PATH
134
+ key_path = File.join dir, WELL_KNOWN_PATH if OS.windows?
135
+ FileUtils.mkdir_p File.dirname(key_path)
136
+ File.write key_path, cred_json_text
137
+ ENV["HOME"] = dir
138
+ ENV["APPDATA"] = dir
117
139
  expect(Google::Auth.get_application_default(nil, options)).to_not be_nil
118
140
  end
119
141
  end
120
142
 
121
- it 'succeeds without default file or env if on compute engine' do
122
- stub = stub_request(:get, 'http://169.254.169.254')
123
- .to_return(status: 200,
124
- headers: { 'Metadata-Flavor' => 'Google' })
143
+ it "succeeds without default file or env if on compute engine" do
144
+ stub = stub_request(:get, "http://169.254.169.254")
145
+ .to_return(status: 200,
146
+ headers: { "Metadata-Flavor" => "Google" })
125
147
  Dir.mktmpdir do |dir|
126
- ENV.delete(@var_name) unless ENV[@var_name].nil? # no env var
127
- ENV['HOME'] = dir # no config present in this tmp dir
128
- creds = Google::Auth.get_application_default(@scope, options)
148
+ ENV.delete @var_name unless ENV[@var_name].nil? # no env var
149
+ ENV["HOME"] = dir # no config present in this tmp dir
150
+ creds = Google::Auth.get_application_default @scope, options
129
151
  expect(creds).to_not be_nil
130
152
  end
131
153
  expect(stub).to have_been_requested
132
154
  end
133
155
 
134
- it 'succeeds with system default file' do
135
- ENV.delete(@var_name) unless ENV[@var_name].nil?
156
+ it "succeeds with system default file" do
157
+ ENV.delete @var_name unless ENV[@var_name].nil?
136
158
  FakeFS do
137
- key_path = File.join('/etc/google/auth/', CREDENTIALS_FILE_NAME)
138
- FileUtils.mkdir_p(File.dirname(key_path))
139
- File.write(key_path, cred_json_text)
159
+ ENV["ProgramData"] = "/etc"
160
+ prefix = OS.windows? ? "/etc/Google/Auth/" : "/etc/google/auth/"
161
+ key_path = File.join prefix, CREDENTIALS_FILE_NAME
162
+ FileUtils.mkdir_p File.dirname(key_path)
163
+ File.write key_path, cred_json_text
140
164
  expect(Google::Auth.get_application_default(@scope, options))
141
165
  .to_not be_nil
142
- File.delete(key_path)
166
+ File.delete key_path
143
167
  end
144
168
  end
145
169
 
146
- it 'succeeds if environment vars are valid' do
147
- ENV.delete(@var_name) unless ENV[@var_name].nil? # no env var
170
+ it "succeeds if environment vars are valid" do
171
+ ENV.delete @var_name unless ENV[@var_name].nil? # no env var
148
172
  ENV[PRIVATE_KEY_VAR] = cred_json[:private_key]
149
173
  ENV[CLIENT_EMAIL_VAR] = cred_json[:client_email]
150
174
  ENV[CLIENT_ID_VAR] = cred_json[:client_id]
@@ -154,95 +178,109 @@ describe '#get_application_default' do
154
178
  expect(Google::Auth.get_application_default(@scope, options))
155
179
  .to_not be_nil
156
180
  end
181
+
182
+ it "warns when using cloud sdk credentials" do
183
+ ENV.delete @var_name unless ENV[@var_name].nil? # no env var
184
+ ENV[PRIVATE_KEY_VAR] = cred_json[:private_key]
185
+ ENV[CLIENT_EMAIL_VAR] = cred_json[:client_email]
186
+ ENV[CLIENT_ID_VAR] = Google::Auth::CredentialsLoader::CLOUD_SDK_CLIENT_ID
187
+ ENV[CLIENT_SECRET_VAR] = cred_json[:client_secret]
188
+ ENV[REFRESH_TOKEN_VAR] = cred_json[:refresh_token]
189
+ ENV[ACCOUNT_TYPE_VAR] = cred_json[:type]
190
+ ENV[PROJECT_ID_VAR] = "a_project_id"
191
+ expect { Google::Auth.get_application_default @scope, options }.to output(
192
+ Google::Auth::CredentialsLoader::CLOUD_SDK_CREDENTIALS_WARNING + "\n"
193
+ ).to_stderr
194
+ end
157
195
  end
158
196
 
159
- describe 'when credential type is service account' do
160
- let(:cred_json) do
197
+ describe "when credential type is service account" do
198
+ let :cred_json do
161
199
  {
162
- private_key_id: 'a_private_key_id',
163
- private_key: @key.to_pem,
164
- client_email: 'app@developer.gserviceaccount.com',
165
- client_id: 'app.apps.googleusercontent.com',
166
- type: 'service_account'
200
+ private_key_id: "a_private_key_id",
201
+ private_key: @key.to_pem,
202
+ client_email: "app@developer.gserviceaccount.com",
203
+ client_id: "app.apps.googleusercontent.com",
204
+ type: "service_account"
167
205
  }
168
206
  end
169
207
 
170
208
  def cred_json_text
171
- MultiJson.dump(cred_json)
209
+ MultiJson.dump cred_json
172
210
  end
173
211
 
174
- it_behaves_like 'it can successfully load credentials'
175
- it_behaves_like 'it cannot load misconfigured credentials'
212
+ it_behaves_like "it can successfully load credentials"
213
+ it_behaves_like "it cannot load misconfigured credentials"
176
214
  end
177
215
 
178
- describe 'when credential type is authorized_user' do
179
- let(:cred_json) do
216
+ describe "when credential type is authorized_user" do
217
+ let :cred_json do
180
218
  {
181
- client_secret: 'privatekey',
182
- refresh_token: 'refreshtoken',
183
- client_id: 'app.apps.googleusercontent.com',
184
- type: 'authorized_user'
219
+ client_secret: "privatekey",
220
+ refresh_token: "refreshtoken",
221
+ client_id: "app.apps.googleusercontent.com",
222
+ type: "authorized_user"
185
223
  }
186
224
  end
187
225
 
188
226
  def cred_json_text
189
- MultiJson.dump(cred_json)
227
+ MultiJson.dump cred_json
190
228
  end
191
229
 
192
- it_behaves_like 'it can successfully load credentials'
193
- it_behaves_like 'it cannot load misconfigured credentials'
230
+ it_behaves_like "it can successfully load credentials"
231
+ it_behaves_like "it cannot load misconfigured credentials"
194
232
  end
195
233
 
196
- describe 'when credential type is unknown' do
197
- let(:cred_json) do
234
+ describe "when credential type is unknown" do
235
+ let :cred_json do
198
236
  {
199
- client_secret: 'privatekey',
200
- refresh_token: 'refreshtoken',
201
- client_id: 'app.apps.googleusercontent.com',
202
- private_key: @key.to_pem,
203
- client_email: 'app@developer.gserviceaccount.com',
204
- type: 'not_known_type'
237
+ client_secret: "privatekey",
238
+ refresh_token: "refreshtoken",
239
+ client_id: "app.apps.googleusercontent.com",
240
+ private_key: @key.to_pem,
241
+ client_email: "app@developer.gserviceaccount.com",
242
+ type: "not_known_type"
205
243
  }
206
244
  end
207
245
 
208
246
  def cred_json_text
209
- MultiJson.dump(cred_json)
247
+ MultiJson.dump cred_json
210
248
  end
211
249
 
212
- it 'fails if the GOOGLE_APPLICATION_CREDENTIALS file contains the creds' do
250
+ it "fails if the GOOGLE_APPLICATION_CREDENTIALS file contains the creds" do
213
251
  Dir.mktmpdir do |dir|
214
- key_path = File.join(dir, 'my_cert_file')
215
- FileUtils.mkdir_p(File.dirname(key_path))
216
- File.write(key_path, cred_json_text)
252
+ key_path = File.join dir, "my_cert_file"
253
+ FileUtils.mkdir_p File.dirname(key_path)
254
+ File.write key_path, cred_json_text
217
255
  ENV[@var_name] = key_path
218
- blk = proc do
219
- Google::Auth.get_application_default(@scope, options)
220
- end
221
- expect(&blk).to raise_error RuntimeError
256
+ expect do
257
+ Google::Auth.get_application_default @scope, options
258
+ end.to raise_error RuntimeError
222
259
  end
223
260
  end
224
261
 
225
- it 'fails if the well known file contains the creds' do
226
- ENV.delete(@var_name) unless ENV[@var_name].nil?
262
+ it "fails if the well known file contains the creds" do
263
+ ENV.delete @var_name unless ENV[@var_name].nil?
227
264
  Dir.mktmpdir do |dir|
228
- key_path = File.join(dir, '.config', WELL_KNOWN_PATH)
229
- FileUtils.mkdir_p(File.dirname(key_path))
230
- File.write(key_path, cred_json_text)
231
- ENV['HOME'] = dir
232
- blk = proc do
233
- Google::Auth.get_application_default(@scope, options)
234
- end
235
- expect(&blk).to raise_error RuntimeError
265
+ key_path = File.join dir, ".config", WELL_KNOWN_PATH
266
+ key_path = File.join dir, WELL_KNOWN_PATH if OS.windows?
267
+ FileUtils.mkdir_p File.dirname(key_path)
268
+ File.write key_path, cred_json_text
269
+ ENV["HOME"] = dir
270
+ ENV["APPDATA"] = dir
271
+ expect do
272
+ Google::Auth.get_application_default @scope, options
273
+ end.to raise_error RuntimeError
236
274
  end
237
275
  end
238
276
 
239
- it 'fails if env vars are set' do
277
+ it "fails if env vars are set" do
278
+ ENV[ENV_VAR] = nil
240
279
  ENV[PRIVATE_KEY_VAR] = cred_json[:private_key]
241
280
  ENV[CLIENT_EMAIL_VAR] = cred_json[:client_email]
242
- blk = proc do
243
- Google::Auth.get_application_default(@scope, options)
244
- end
245
- expect(&blk).to raise_error RuntimeError
281
+ expect do
282
+ Google::Auth.get_application_default @scope, options
283
+ end.to raise_error RuntimeError
246
284
  end
247
285
  end
248
286
  end
@@ -27,54 +27,54 @@
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(File.join(File.dirname(__FILE__)))
31
- $LOAD_PATH.unshift(spec_dir)
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 'googleauth/iam'
34
+ require "googleauth/iam"
35
35
 
36
36
  describe Google::Auth::IAMCredentials do
37
37
  IAMCredentials = Google::Auth::IAMCredentials
38
- let(:test_selector) { 'the-test-selector' }
39
- let(:test_token) { 'the-test-token' }
40
- let(:test_creds) { IAMCredentials.new(test_selector, test_token) }
38
+ let(:test_selector) { "the-test-selector" }
39
+ let(:test_token) { "the-test-token" }
40
+ let(:test_creds) { IAMCredentials.new test_selector, test_token }
41
41
 
42
- describe '#apply!' do
43
- it 'should update the target hash with the iam values' do
44
- md = { foo: 'bar' }
45
- test_creds.apply!(md)
42
+ describe "#apply!" do
43
+ it "should update the target hash with the iam values" do
44
+ md = { foo: "bar" }
45
+ test_creds.apply! md
46
46
  expect(md[IAMCredentials::SELECTOR_KEY]).to eq test_selector
47
47
  expect(md[IAMCredentials::TOKEN_KEY]).to eq test_token
48
- expect(md[:foo]).to eq 'bar'
48
+ expect(md[:foo]).to eq "bar"
49
49
  end
50
50
  end
51
51
 
52
- describe 'updater_proc' do
53
- it 'should provide a proc that updates a hash with the iam values' do
54
- md = { foo: 'bar' }
52
+ describe "updater_proc" do
53
+ it "should provide a proc that updates a hash with the iam values" do
54
+ md = { foo: "bar" }
55
55
  the_proc = test_creds.updater_proc
56
- got = the_proc.call(md)
56
+ got = the_proc.call md
57
57
  expect(got[IAMCredentials::SELECTOR_KEY]).to eq test_selector
58
58
  expect(got[IAMCredentials::TOKEN_KEY]).to eq test_token
59
- expect(got[:foo]).to eq 'bar'
59
+ expect(got[:foo]).to eq "bar"
60
60
  end
61
61
  end
62
62
 
63
- describe '#apply' do
64
- it 'should not update the original hash with the iam values' do
65
- md = { foo: 'bar' }
66
- test_creds.apply(md)
63
+ describe "#apply" do
64
+ it "should not update the original hash with the iam values" do
65
+ md = { foo: "bar" }
66
+ test_creds.apply md
67
67
  expect(md[IAMCredentials::SELECTOR_KEY]).to be_nil
68
68
  expect(md[IAMCredentials::TOKEN_KEY]).to be_nil
69
- expect(md[:foo]).to eq 'bar'
69
+ expect(md[:foo]).to eq "bar"
70
70
  end
71
71
 
72
- it 'should return a with the iam values' do
73
- md = { foo: 'bar' }
74
- got = test_creds.apply(md)
72
+ it "should return a with the iam values" do
73
+ md = { foo: "bar" }
74
+ got = test_creds.apply md
75
75
  expect(got[IAMCredentials::SELECTOR_KEY]).to eq test_selector
76
76
  expect(got[IAMCredentials::TOKEN_KEY]).to eq test_token
77
- expect(got[:foo]).to eq 'bar'
77
+ expect(got[:foo]).to eq "bar"
78
78
  end
79
79
  end
80
80
  end
@@ -27,49 +27,51 @@
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(File.join(File.dirname(__FILE__)))
31
- $LOAD_PATH.unshift(spec_dir)
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 'googleauth/scope_util'
34
+ require "googleauth/scope_util"
35
35
 
36
36
  describe Google::Auth::ScopeUtil do
37
- shared_examples 'normalizes scopes' do
38
- let(:normalized) { Google::Auth::ScopeUtil.normalize(source) }
37
+ shared_examples "normalizes scopes" do
38
+ let(:normalized) { Google::Auth::ScopeUtil.normalize source }
39
39
 
40
- it 'normalizes the email scope' do
40
+ it "normalizes the email scope" do
41
41
  expect(normalized).to include(
42
- 'https://www.googleapis.com/auth/userinfo.email')
43
- expect(normalized).to_not include 'email'
42
+ "https://www.googleapis.com/auth/userinfo.email"
43
+ )
44
+ expect(normalized).to_not include "email"
44
45
  end
45
46
 
46
- it 'normalizes the profile scope' do
47
+ it "normalizes the profile scope" do
47
48
  expect(normalized).to include(
48
- 'https://www.googleapis.com/auth/userinfo.profile')
49
- expect(normalized).to_not include 'profile'
49
+ "https://www.googleapis.com/auth/userinfo.profile"
50
+ )
51
+ expect(normalized).to_not include "profile"
50
52
  end
51
53
 
52
- it 'normalizes the openid scope' do
53
- expect(normalized).to include 'https://www.googleapis.com/auth/plus.me'
54
- expect(normalized).to_not include 'openid'
54
+ it "normalizes the openid scope" do
55
+ expect(normalized).to include "https://www.googleapis.com/auth/plus.me"
56
+ expect(normalized).to_not include "openid"
55
57
  end
56
58
 
57
- it 'leaves other other scopes as-is' do
58
- expect(normalized).to include 'https://www.googleapis.com/auth/drive'
59
+ it "leaves other other scopes as-is" do
60
+ expect(normalized).to include "https://www.googleapis.com/auth/drive"
59
61
  end
60
62
  end
61
63
 
62
- context 'with scope as string' do
63
- let(:source) do
64
- 'email profile openid https://www.googleapis.com/auth/drive'
64
+ context "with scope as string" do
65
+ let :source do
66
+ "email profile openid https://www.googleapis.com/auth/drive"
65
67
  end
66
- it_behaves_like 'normalizes scopes'
68
+ it_behaves_like "normalizes scopes"
67
69
  end
68
70
 
69
- context 'with scope as Array' do
70
- let(:source) do
71
- %w(email profile openid https://www.googleapis.com/auth/drive)
71
+ context "with scope as Array" do
72
+ let :source do
73
+ %w[email profile openid https://www.googleapis.com/auth/drive]
72
74
  end
73
- it_behaves_like 'normalizes scopes'
75
+ it_behaves_like "normalizes scopes"
74
76
  end
75
77
  end