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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.md +113 -21
  4. data/README.md +13 -15
  5. data/SECURITY.md +7 -0
  6. data/lib/googleauth/application_default.rb +9 -9
  7. data/lib/googleauth/compute_engine.rb +55 -30
  8. data/lib/googleauth/credentials.rb +253 -64
  9. data/lib/googleauth/credentials_loader.rb +15 -16
  10. data/lib/googleauth/iam.rb +1 -1
  11. data/{spec/googleauth/stores/store_examples.rb → lib/googleauth/id_tokens/errors.rb} +36 -23
  12. data/lib/googleauth/id_tokens/key_sources.rb +396 -0
  13. data/lib/googleauth/id_tokens/verifier.rb +142 -0
  14. data/lib/googleauth/id_tokens.rb +233 -0
  15. data/lib/googleauth/json_key_reader.rb +6 -2
  16. data/lib/googleauth/scope_util.rb +1 -1
  17. data/lib/googleauth/service_account.rb +61 -36
  18. data/lib/googleauth/signet.rb +9 -7
  19. data/lib/googleauth/stores/file_token_store.rb +1 -0
  20. data/lib/googleauth/stores/redis_token_store.rb +1 -0
  21. data/lib/googleauth/user_authorizer.rb +8 -3
  22. data/lib/googleauth/user_refresh.rb +1 -1
  23. data/lib/googleauth/version.rb +1 -1
  24. data/lib/googleauth/web_user_authorizer.rb +5 -8
  25. data/lib/googleauth.rb +1 -0
  26. metadata +33 -76
  27. data/.github/CONTRIBUTING.md +0 -74
  28. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -36
  29. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -21
  30. data/.github/ISSUE_TEMPLATE/support_request.md +0 -7
  31. data/.gitignore +0 -36
  32. data/.kokoro/build.bat +0 -16
  33. data/.kokoro/build.sh +0 -4
  34. data/.kokoro/continuous/common.cfg +0 -24
  35. data/.kokoro/continuous/linux.cfg +0 -15
  36. data/.kokoro/continuous/osx.cfg +0 -3
  37. data/.kokoro/continuous/windows.cfg +0 -19
  38. data/.kokoro/osx.sh +0 -4
  39. data/.kokoro/presubmit/common.cfg +0 -24
  40. data/.kokoro/presubmit/linux.cfg +0 -14
  41. data/.kokoro/presubmit/osx.cfg +0 -3
  42. data/.kokoro/presubmit/windows.cfg +0 -19
  43. data/.kokoro/release.cfg +0 -53
  44. data/.kokoro/trampoline.bat +0 -10
  45. data/.kokoro/trampoline.sh +0 -4
  46. data/.rspec +0 -2
  47. data/.rubocop.yml +0 -42
  48. data/Gemfile +0 -25
  49. data/Rakefile +0 -89
  50. data/googleauth.gemspec +0 -35
  51. data/spec/googleauth/apply_auth_examples.rb +0 -148
  52. data/spec/googleauth/client_id_spec.rb +0 -160
  53. data/spec/googleauth/compute_engine_spec.rb +0 -122
  54. data/spec/googleauth/credentials_spec.rb +0 -459
  55. data/spec/googleauth/get_application_default_spec.rb +0 -286
  56. data/spec/googleauth/iam_spec.rb +0 -80
  57. data/spec/googleauth/scope_util_spec.rb +0 -77
  58. data/spec/googleauth/service_account_spec.rb +0 -482
  59. data/spec/googleauth/signet_spec.rb +0 -134
  60. data/spec/googleauth/stores/file_token_store_spec.rb +0 -57
  61. data/spec/googleauth/stores/redis_token_store_spec.rb +0 -50
  62. data/spec/googleauth/user_authorizer_spec.rb +0 -323
  63. data/spec/googleauth/user_refresh_spec.rb +0 -359
  64. data/spec/googleauth/web_user_authorizer_spec.rb +0 -172
  65. data/spec/spec_helper.rb +0 -92
  66. /data/{COPYING → LICENSE} +0 -0
data/Rakefile DELETED
@@ -1,89 +0,0 @@
1
- # -*- ruby -*-
2
- require "bundler/gem_tasks"
3
-
4
- task :ci do
5
- header "Using Ruby - #{RUBY_VERSION}"
6
- sh "bundle exec rubocop"
7
- sh "bundle exec rspec"
8
- end
9
-
10
- task :release, :tag do |_t, args|
11
- tag = args[:tag]
12
- raise "You must provide a tag to release." if tag.nil?
13
-
14
- # Verify the tag format "vVERSION"
15
- m = tag.match(/v(?<version>\S*)/)
16
- raise "Tag #{tag} does not match the expected format." if m.nil?
17
-
18
- version = m[:version]
19
- raise "You must provide a version." if version.nil?
20
-
21
- api_token = ENV["RUBYGEMS_API_TOKEN"]
22
-
23
- require "gems"
24
- if api_token
25
- ::Gems.configure do |config|
26
- config.key = api_token
27
- end
28
- end
29
-
30
- Bundler.with_clean_env do
31
- sh "rm -rf pkg"
32
- sh "bundle update"
33
- sh "bundle exec rake build"
34
- end
35
-
36
- path_to_be_pushed = "pkg/#{version}.gem"
37
- if File.file? path_to_be_pushed
38
- begin
39
- ::Gems.push File.new(path_to_be_pushed)
40
- puts "Successfully built and pushed googleauth for version #{version}"
41
- rescue StandardError => e
42
- puts "Error while releasing googleauth version #{version}: #{e.message}"
43
- end
44
- else
45
- raise "Cannot build googleauth for version #{version}"
46
- end
47
- end
48
-
49
- namespace :kokoro do
50
- task :load_env_vars do
51
- service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
52
- ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
53
- filename = "#{ENV['KOKORO_GFILE_DIR']}/env_vars.json"
54
- env_vars = JSON.parse File.read(filename)
55
- env_vars.each { |k, v| ENV[k] = v }
56
- end
57
-
58
- task :presubmit do
59
- Rake::Task["ci"].invoke
60
- end
61
-
62
- task :continuous do
63
- Rake::Task["ci"].invoke
64
- end
65
-
66
- task :nightly do
67
- Rake::Task["ci"].invoke
68
- end
69
-
70
- task :release do
71
- version = "0.1.0"
72
- Bundler.with_clean_env do
73
- version = `bundle exec gem list`
74
- .split("\n").select { |line| line.include? "googleauth" }
75
- .first.split("(").last.split(")").first || "0.1.0"
76
- end
77
- Rake::Task["kokoro:load_env_vars"].invoke
78
- Rake::Task["release"].invoke "v/#{version}"
79
- end
80
- end
81
-
82
- def header str, token = "#"
83
- line_length = str.length + 8
84
- puts ""
85
- puts token * line_length
86
- puts "#{token * 3} #{str} #{token * 3}"
87
- puts token * line_length
88
- puts ""
89
- end
data/googleauth.gemspec DELETED
@@ -1,35 +0,0 @@
1
- # -*- ruby -*-
2
- # encoding: utf-8
3
-
4
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
5
- require "googleauth/version"
6
-
7
- Gem::Specification.new do |gem|
8
- gem.name = "googleauth"
9
- gem.version = Google::Auth::VERSION
10
- gem.authors = ["Tim Emiola"]
11
- gem.email = "temiola@google.com"
12
- gem.homepage = "https://github.com/google/google-auth-library-ruby"
13
- gem.summary = "Google Auth Library for Ruby"
14
- gem.license = "Apache-2.0"
15
- gem.description = <<-DESCRIPTION
16
- Allows simple authorization for accessing Google APIs.
17
- Provide support for Application Default Credentials, as described at
18
- https://developers.google.com/accounts/docs/application-default-credentials
19
- DESCRIPTION
20
-
21
- gem.files = `git ls-files`.split "\n"
22
- gem.test_files = `git ls-files -- spec/*`.split "\n"
23
- gem.executables = `git ls-files -- bin/*.rb`.split("\n").map do |f|
24
- File.basename f
25
- end
26
- gem.require_paths = ["lib"]
27
- gem.platform = Gem::Platform::RUBY
28
-
29
- gem.add_dependency "faraday", "~> 0.12"
30
- gem.add_dependency "jwt", ">= 1.4", "< 3.0"
31
- gem.add_dependency "memoist", "~> 0.16"
32
- gem.add_dependency "multi_json", "~> 1.11"
33
- gem.add_dependency "os", ">= 0.9", "< 2.0"
34
- gem.add_dependency "signet", "~> 0.7"
35
- end
@@ -1,148 +0,0 @@
1
- # Copyright 2015, 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
- spec_dir = File.expand_path File.join(File.dirname(__FILE__))
31
- $LOAD_PATH.unshift spec_dir
32
- $LOAD_PATH.uniq!
33
-
34
- require "faraday"
35
- require "spec_helper"
36
-
37
- shared_examples "apply/apply! are OK" do
38
- let(:auth_key) { :authorization }
39
-
40
- # tests that use these examples need to define
41
- #
42
- # @client which should be an auth client
43
- #
44
- # @make_auth_stubs, which should stub out the expected http behaviour of the
45
- # auth client
46
- describe "#fetch_access_token" do
47
- let(:token) { "1/abcdef1234567890" }
48
- let :stub do
49
- make_auth_stubs access_token: token
50
- end
51
-
52
- it "should set access_token to the fetched value" do
53
- stub
54
- @client.fetch_access_token!
55
- expect(@client.access_token).to eq(token)
56
- expect(stub).to have_been_requested
57
- end
58
-
59
- it "should notify refresh listeners after updating" do
60
- stub
61
- expect do |b|
62
- @client.on_refresh(&b)
63
- @client.fetch_access_token!
64
- end.to yield_with_args(have_attributes(
65
- access_token: "1/abcdef1234567890"
66
- ))
67
- expect(stub).to have_been_requested
68
- end
69
- end
70
-
71
- describe "#apply!" do
72
- it "should update the target hash with fetched access token" do
73
- token = "1/abcdef1234567890"
74
- stub = make_auth_stubs access_token: token
75
-
76
- md = { foo: "bar" }
77
- @client.apply! md
78
- want = { :foo => "bar", auth_key => "Bearer #{token}" }
79
- expect(md).to eq(want)
80
- expect(stub).to have_been_requested
81
- end
82
- end
83
-
84
- describe "updater_proc" do
85
- it "should provide a proc that updates a hash with the access token" do
86
- token = "1/abcdef1234567890"
87
- stub = make_auth_stubs access_token: token
88
- md = { foo: "bar" }
89
- the_proc = @client.updater_proc
90
- got = the_proc.call md
91
- want = { :foo => "bar", auth_key => "Bearer #{token}" }
92
- expect(got).to eq(want)
93
- expect(stub).to have_been_requested
94
- end
95
- end
96
-
97
- describe "#apply" do
98
- it "should not update the original hash with the access token" do
99
- token = "1/abcdef1234567890"
100
- stub = make_auth_stubs access_token: token
101
-
102
- md = { foo: "bar" }
103
- @client.apply md
104
- want = { foo: "bar" }
105
- expect(md).to eq(want)
106
- expect(stub).to have_been_requested
107
- end
108
-
109
- it "should add the token to the returned hash" do
110
- token = "1/abcdef1234567890"
111
- stub = make_auth_stubs access_token: token
112
-
113
- md = { foo: "bar" }
114
- got = @client.apply md
115
- want = { :foo => "bar", auth_key => "Bearer #{token}" }
116
- expect(got).to eq(want)
117
- expect(stub).to have_been_requested
118
- end
119
-
120
- it "should not fetch a new token if the current is not expired" do
121
- token = "1/abcdef1234567890"
122
- stub = make_auth_stubs access_token: token
123
-
124
- n = 5 # arbitrary
125
- n.times do |_t|
126
- md = { foo: "bar" }
127
- got = @client.apply md
128
- want = { :foo => "bar", auth_key => "Bearer #{token}" }
129
- expect(got).to eq(want)
130
- end
131
- expect(stub).to have_been_requested
132
- end
133
-
134
- it "should fetch a new token if the current one is expired" do
135
- token1 = "1/abcdef1234567890"
136
- token2 = "2/abcdef1234567891"
137
-
138
- [token1, token2].each do |t|
139
- make_auth_stubs access_token: t
140
- md = { foo: "bar" }
141
- got = @client.apply md
142
- want = { :foo => "bar", auth_key => "Bearer #{t}" }
143
- expect(got).to eq(want)
144
- @client.expires_at -= 3601 # default is to expire in 1hr
145
- end
146
- end
147
- end
148
- end
@@ -1,160 +0,0 @@
1
- # Copyright 2015, 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
- spec_dir = File.expand_path File.join(File.dirname(__FILE__))
31
- $LOAD_PATH.unshift spec_dir
32
- $LOAD_PATH.uniq!
33
-
34
- require "spec_helper"
35
- require "fakefs/safe"
36
- require "googleauth"
37
-
38
- describe Google::Auth::ClientId do
39
- shared_examples "it has a valid config" do
40
- it "should include a valid id" do
41
- expect(client_id.id).to eql "abc@example.com"
42
- end
43
-
44
- it "should include a valid secret" do
45
- expect(client_id.secret).to eql "notasecret"
46
- end
47
- end
48
-
49
- shared_examples "it can successfully load client_id" do
50
- context "loaded from hash" do
51
- let(:client_id) { Google::Auth::ClientId.from_hash config }
52
-
53
- it_behaves_like "it has a valid config"
54
- end
55
-
56
- context "loaded from file" do
57
- file_path = "/client_secrets.json"
58
-
59
- let :client_id do
60
- FakeFS do
61
- content = MultiJson.dump config
62
- File.write file_path, content
63
- Google::Auth::ClientId.from_file file_path
64
- end
65
- end
66
-
67
- it_behaves_like "it has a valid config"
68
- end
69
- end
70
-
71
- describe "with web config" do
72
- let :config do
73
- {
74
- "web" => {
75
- "client_id" => "abc@example.com",
76
- "client_secret" => "notasecret"
77
- }
78
- }
79
- end
80
- it_behaves_like "it can successfully load client_id"
81
- end
82
-
83
- describe "with installed app config" do
84
- let :config do
85
- {
86
- "installed" => {
87
- "client_id" => "abc@example.com",
88
- "client_secret" => "notasecret"
89
- }
90
- }
91
- end
92
- it_behaves_like "it can successfully load client_id"
93
- end
94
-
95
- context "with missing top level property" do
96
- let :config do
97
- {
98
- "notvalid" => {
99
- "client_id" => "abc@example.com",
100
- "client_secret" => "notasecret"
101
- }
102
- }
103
- end
104
-
105
- it "should raise error" do
106
- expect { Google::Auth::ClientId.from_hash config }.to raise_error(
107
- /Expected top level property/
108
- )
109
- end
110
- end
111
-
112
- context "with missing client id" do
113
- let :config do
114
- {
115
- "web" => {
116
- "client_secret" => "notasecret"
117
- }
118
- }
119
- end
120
-
121
- it "should raise error" do
122
- expect { Google::Auth::ClientId.from_hash config }.to raise_error(
123
- /Client id can not be nil/
124
- )
125
- end
126
- end
127
-
128
- context "with missing client secret" do
129
- let :config do
130
- {
131
- "web" => {
132
- "client_id" => "abc@example.com"
133
- }
134
- }
135
- end
136
-
137
- it "should raise error" do
138
- expect { Google::Auth::ClientId.from_hash config }.to raise_error(
139
- /Client secret can not be nil/
140
- )
141
- end
142
- end
143
-
144
- context "with cloud sdk credentials" do
145
- let :config do
146
- {
147
- "web" => {
148
- "client_id" => Google::Auth::CredentialsLoader::CLOUD_SDK_CLIENT_ID,
149
- "client_secret" => "notasecret"
150
- }
151
- }
152
- end
153
-
154
- it "should raise warning" do
155
- expect { Google::Auth::ClientId.from_hash config }.to output(
156
- Google::Auth::CredentialsLoader::CLOUD_SDK_CREDENTIALS_WARNING + "\n"
157
- ).to_stderr
158
- end
159
- end
160
- end
@@ -1,122 +0,0 @@
1
- # Copyright 2015, 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
- spec_dir = File.expand_path File.join(File.dirname(__FILE__))
31
- $LOAD_PATH.unshift spec_dir
32
- $LOAD_PATH.uniq!
33
-
34
- require "apply_auth_examples"
35
- require "faraday"
36
- require "googleauth/compute_engine"
37
- require "spec_helper"
38
-
39
- describe Google::Auth::GCECredentials do
40
- MD_URI = "http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token".freeze
41
- GCECredentials = Google::Auth::GCECredentials
42
-
43
- before :example do
44
- @client = GCECredentials.new
45
- end
46
-
47
- def make_auth_stubs opts = {}
48
- access_token = opts[:access_token] || ""
49
- body = MultiJson.dump("access_token" => access_token,
50
- "token_type" => "Bearer",
51
- "expires_in" => 3600)
52
- stub_request(:get, MD_URI)
53
- .with(headers: { "Metadata-Flavor" => "Google" })
54
- .to_return(body: body,
55
- status: 200,
56
- headers: { "Content-Type" => "application/json" })
57
- end
58
-
59
- it_behaves_like "apply/apply! are OK"
60
-
61
- context "metadata is unavailable" do
62
- describe "#fetch_access_token" do
63
- it "should fail if the metadata request returns a 404" do
64
- stub = stub_request(:get, MD_URI)
65
- .to_return(status: 404,
66
- headers: { "Metadata-Flavor" => "Google" })
67
- expect { @client.fetch_access_token! }
68
- .to raise_error Signet::AuthorizationError
69
- expect(stub).to have_been_requested
70
- end
71
-
72
- it "should fail if the metadata request returns an unexpected code" do
73
- stub = stub_request(:get, MD_URI)
74
- .to_return(status: 503,
75
- headers: { "Metadata-Flavor" => "Google" })
76
- expect { @client.fetch_access_token! }
77
- .to raise_error Signet::AuthorizationError
78
- expect(stub).to have_been_requested
79
- end
80
-
81
- it "should fail with Signet::AuthorizationError if request times out" do
82
- allow_any_instance_of(Faraday::Connection).to receive(:get)
83
- .and_raise(Faraday::TimeoutError)
84
- expect { @client.fetch_access_token! }
85
- .to raise_error Signet::AuthorizationError
86
- end
87
-
88
- it "should fail with Signet::AuthorizationError if request fails" do
89
- allow_any_instance_of(Faraday::Connection).to receive(:get)
90
- .and_raise(Faraday::ConnectionFailed, nil)
91
- expect { @client.fetch_access_token! }
92
- .to raise_error Signet::AuthorizationError
93
- end
94
- end
95
- end
96
-
97
- describe "#on_gce?" do
98
- it "should be true when Metadata-Flavor is Google" do
99
- stub = stub_request(:get, "http://169.254.169.254")
100
- .to_return(status: 200,
101
- headers: { "Metadata-Flavor" => "Google" })
102
- expect(GCECredentials.on_gce?({}, true)).to eq(true)
103
- expect(stub).to have_been_requested
104
- end
105
-
106
- it "should be false when Metadata-Flavor is not Google" do
107
- stub = stub_request(:get, "http://169.254.169.254")
108
- .to_return(status: 200,
109
- headers: { "Metadata-Flavor" => "NotGoogle" })
110
- expect(GCECredentials.on_gce?({}, true)).to eq(false)
111
- expect(stub).to have_been_requested
112
- end
113
-
114
- it "should be false if the response is not 200" do
115
- stub = stub_request(:get, "http://169.254.169.254")
116
- .to_return(status: 404,
117
- headers: { "Metadata-Flavor" => "NotGoogle" })
118
- expect(GCECredentials.on_gce?({}, true)).to eq(false)
119
- expect(stub).to have_been_requested
120
- end
121
- end
122
- end