google-ads-common 0.14.0 → 1.0.3
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 +5 -5
- data/COPYING +0 -0
- data/ChangeLog +22 -0
- data/README.md +1 -1
- data/lib/ads_common/api.rb +11 -21
- data/lib/ads_common/api_config.rb +10 -38
- data/lib/ads_common/auth/base_handler.rb +0 -0
- data/lib/ads_common/auth/oauth2_handler.rb +4 -0
- data/lib/ads_common/auth/oauth2_service_account_handler.rb +0 -0
- data/lib/ads_common/build/savon_abstract_generator.rb +0 -0
- data/lib/ads_common/build/savon_generator.rb +0 -0
- data/lib/ads_common/build/savon_registry.rb +19 -0
- data/lib/ads_common/build/savon_registry_generator.rb +0 -0
- data/lib/ads_common/build/savon_service_generator.rb +0 -0
- data/lib/ads_common/config.rb +0 -0
- data/lib/ads_common/credential_handler.rb +0 -0
- data/lib/ads_common/env_check.rb +0 -0
- data/lib/ads_common/errors.rb +0 -0
- data/lib/ads_common/http.rb +4 -0
- data/lib/ads_common/parameters_validator.rb +0 -0
- data/lib/ads_common/results_extractor.rb +0 -0
- data/lib/ads_common/savon_headers/base_header_handler.rb +0 -0
- data/lib/ads_common/savon_headers/oauth_header_handler.rb +0 -0
- data/lib/ads_common/savon_service.rb +12 -11
- data/lib/ads_common/utils.rb +1 -2
- data/lib/ads_common/version.rb +1 -1
- metadata +76 -29
- data/test/coverage.rb +0 -33
- data/test/suite_unittests.rb +0 -28
- data/test/test_config.rb +0 -96
- data/test/test_config.yml +0 -11
- data/test/test_credential_handler.rb +0 -125
- data/test/test_env.rb +0 -43
- data/test/test_oauth2_handler.rb +0 -84
- data/test/test_oauth2_service_account_handler.rb +0 -61
- data/test/test_parameters_validator.rb +0 -153
- data/test/test_results_extractor.rb +0 -250
- data/test/test_savon_service.rb +0 -125
- data/test/test_utils.rb +0 -111
data/test/coverage.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Runs test with coverage tool.
|
20
|
-
|
21
|
-
require 'simplecov'
|
22
|
-
|
23
|
-
SimpleCov.start
|
24
|
-
|
25
|
-
$:.unshift File.expand_path('../../', __FILE__)
|
26
|
-
require File.join(File.dirname(__FILE__), 'suite_unittests.rb')
|
27
|
-
|
28
|
-
# Now loading all files in the library to make sure we hit all untested files.
|
29
|
-
lib_base_path = File.expand_path('../../lib', __FILE__)
|
30
|
-
$:.unshift lib_base_path
|
31
|
-
|
32
|
-
code_files_mask = File.join(lib_base_path, '**/*.rb')
|
33
|
-
Dir.glob(code_files_mask).each {|file| require file}
|
data/test/suite_unittests.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Test suite for unit tests.
|
20
|
-
|
21
|
-
require 'test/unit'
|
22
|
-
|
23
|
-
$:.unshift File.expand_path('../../lib/', __FILE__)
|
24
|
-
$:.unshift File.expand_path('../../', __FILE__)
|
25
|
-
|
26
|
-
# Ads Common units tests.
|
27
|
-
test_files_mask = File.join(File.dirname(__FILE__), 'test_*.rb')
|
28
|
-
Dir.glob(test_files_mask).each {|file| require file}
|
data/test/test_config.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests the array replies from services.
|
20
|
-
|
21
|
-
require 'test/unit'
|
22
|
-
|
23
|
-
require 'ads_common/config'
|
24
|
-
|
25
|
-
class TestConfig < Test::Unit::TestCase
|
26
|
-
DEFAULT_CONFIG_HASH = {
|
27
|
-
:service => {:use_ruby_names => false,
|
28
|
-
:environment => 'sandbox'},
|
29
|
-
:authentication => {:method => 'ClientLogin',
|
30
|
-
:email => 'root@example.com'}
|
31
|
-
}
|
32
|
-
|
33
|
-
DEFAULT_CONFIG_FILENAME = 'test/test_config.yml'
|
34
|
-
|
35
|
-
# Test initializer with no arguments.
|
36
|
-
def test_initialize_nil
|
37
|
-
assert_nothing_raised do
|
38
|
-
config = AdsCommon::Config.new
|
39
|
-
assert_nil(config.read('service.use_ruby_names'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Test initializer with hash argument.
|
44
|
-
def test_initialize_hash
|
45
|
-
config = AdsCommon::Config.new(DEFAULT_CONFIG_HASH)
|
46
|
-
assert_equal(false, config.read('service.use_ruby_names'))
|
47
|
-
assert_equal('sandbox', config.read('service.environment'))
|
48
|
-
assert_equal('ClientLogin', config.read('authentication.method'))
|
49
|
-
assert_equal('root@example.com', config.read('authentication.email'))
|
50
|
-
assert_nil(config.read('unexisting.entry'))
|
51
|
-
end
|
52
|
-
|
53
|
-
# Test initializer with filename argument.
|
54
|
-
def test_initialize_filename_correct
|
55
|
-
config = AdsCommon::Config.new(DEFAULT_CONFIG_FILENAME)
|
56
|
-
assert_equal(false, config.read('service.use_ruby_names'))
|
57
|
-
assert_equal('sandbox', config.read('service.environment'))
|
58
|
-
assert_equal('ClientLogin', config.read('authentication.method'))
|
59
|
-
assert_equal('root@example.com', config.read('authentication.email'))
|
60
|
-
assert_nil(config.read('unexisting.entry'))
|
61
|
-
end
|
62
|
-
|
63
|
-
# Test initializer with an incorrect existing file.
|
64
|
-
def test_initialize_filename_incorrect
|
65
|
-
assert_raises (AdsCommon::Errors::Error) do
|
66
|
-
AdsCommon::Config.new('/dev/null')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Test default result.
|
71
|
-
def test_read_default_result
|
72
|
-
config = AdsCommon::Config.new(DEFAULT_CONFIG_HASH)
|
73
|
-
assert_nil(config.read('unexisting.entry'))
|
74
|
-
assert_equal('default', config.read('unexisting.entry', 'default'))
|
75
|
-
assert_equal('sandbox', config.read('service.environment', 'production'))
|
76
|
-
end
|
77
|
-
|
78
|
-
# Test setter.
|
79
|
-
def test_set
|
80
|
-
config = AdsCommon::Config.new(DEFAULT_CONFIG_HASH)
|
81
|
-
assert_equal('sandbox', config.read('service.environment'))
|
82
|
-
assert_nil(config.read('unexisting.entry'))
|
83
|
-
config.set('unexisting.entry', 'foobar')
|
84
|
-
assert_equal('sandbox', config.read('service.environment'))
|
85
|
-
assert_equal('foobar', config.read('unexisting.entry'))
|
86
|
-
end
|
87
|
-
|
88
|
-
# Test subhash.
|
89
|
-
def test_get_hash
|
90
|
-
config = AdsCommon::Config.new(DEFAULT_CONFIG_HASH)
|
91
|
-
result = config.read('service')
|
92
|
-
assert_instance_of(Hash, result)
|
93
|
-
assert_equal('sandbox', result[:environment])
|
94
|
-
assert_equal(false, result[:use_ruby_names])
|
95
|
-
end
|
96
|
-
end
|
data/test/test_config.yml
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
---
|
2
|
-
# This is a test configuration file for Ads Common library.
|
3
|
-
:authentication:
|
4
|
-
:method: ClientLogin
|
5
|
-
:application_name: ruby_test_suit
|
6
|
-
:password: mySecretPassword
|
7
|
-
:email: root@example.com
|
8
|
-
:network_code: 1234567
|
9
|
-
:service:
|
10
|
-
:environment: sandbox
|
11
|
-
:use_ruby_names: false
|
@@ -1,125 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests credential handler methods.
|
20
|
-
|
21
|
-
require 'logger'
|
22
|
-
require 'minitest/mock'
|
23
|
-
require 'test/unit'
|
24
|
-
|
25
|
-
require 'ads_common/config'
|
26
|
-
require 'ads_common/credential_handler'
|
27
|
-
|
28
|
-
class TestCredentialHandler < Test::Unit::TestCase
|
29
|
-
|
30
|
-
def setup()
|
31
|
-
logger = Logger.new(STDERR)
|
32
|
-
@default_credentials = {:client_customer_id => '1234567890', :foo => 'bar'}
|
33
|
-
config = AdsCommon::Config.new({
|
34
|
-
:library => {:logger => logger},
|
35
|
-
:authentication => @default_credentials
|
36
|
-
})
|
37
|
-
@handler = AdsCommon::CredentialHandler.new(config)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_credentials_simple()
|
41
|
-
credentials = @handler.credentials()
|
42
|
-
assert_equal(@default_credentials, credentials)
|
43
|
-
assert_not_same(@default_credentials, credentials)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_credentials_override()
|
47
|
-
@override = {:client_customer_id => 42}
|
48
|
-
credentials = @handler.credentials(@override)
|
49
|
-
assert_not_equal(@default_credentials, credentials)
|
50
|
-
assert_not_same(@default_credentials, credentials)
|
51
|
-
assert_equal(42, credentials[:client_customer_id])
|
52
|
-
assert_equal('bar', credentials[:foo])
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_generate_user_agent_simple()
|
56
|
-
result1 = @handler.generate_user_agent()
|
57
|
-
assert_kind_of(String, result1)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_generate_user_agent_chained()
|
61
|
-
test_str = 'Tester/0.2.0'
|
62
|
-
result1 = @handler.generate_user_agent([test_str])
|
63
|
-
assert_kind_of(String, result1)
|
64
|
-
assert_match(/#{Regexp.escape(test_str)}/, result1)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_generate_user_agent_include_simple()
|
68
|
-
test_str = 'Tester'
|
69
|
-
@handler.include_in_user_agent(test_str)
|
70
|
-
result1 = @handler.generate_user_agent()
|
71
|
-
assert_kind_of(String, result1)
|
72
|
-
assert_match(/#{Regexp.escape(test_str)}/, result1)
|
73
|
-
result2 = @handler.generate_user_agent()
|
74
|
-
assert_kind_of(String, result2)
|
75
|
-
assert_no_match(/#{Regexp.escape(test_str)}/, result2)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_generate_user_agent_include_version()
|
79
|
-
test_str = 'Tester/0.2.0'
|
80
|
-
argument1 = 'Tester'
|
81
|
-
argument2 = '0.2.0'
|
82
|
-
@handler.include_in_user_agent(argument1, argument2)
|
83
|
-
result1 = @handler.generate_user_agent()
|
84
|
-
assert_kind_of(String, result1)
|
85
|
-
assert_match(/#{Regexp.escape(test_str)}/, result1)
|
86
|
-
result2 = @handler.generate_user_agent()
|
87
|
-
assert_kind_of(String, result2)
|
88
|
-
assert_no_match(/#{Regexp.escape(test_str)}/, result2)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_auth_handler_callback_once()
|
92
|
-
mock = Minitest::Mock.new()
|
93
|
-
mock.expect(:property_changed, nil, [:foo, 'bar'])
|
94
|
-
@handler.set_auth_handler(mock)
|
95
|
-
@handler.set_credential(:foo, 'bar')
|
96
|
-
assert(mock.verify)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_auth_handler_callback_compare()
|
100
|
-
credentials = @handler.credentials
|
101
|
-
|
102
|
-
credentials[:foo] = 'bar'
|
103
|
-
credentials[:baz] = 42
|
104
|
-
mock1 = Minitest::Mock.new()
|
105
|
-
mock1.expect(:property_changed, nil, [:baz, 42])
|
106
|
-
@handler.set_auth_handler(mock1)
|
107
|
-
@handler.credentials = credentials
|
108
|
-
assert(mock1.verify)
|
109
|
-
|
110
|
-
credentials.delete(:baz)
|
111
|
-
mock2 = Minitest::Mock.new()
|
112
|
-
mock2.expect(:property_changed, nil, [:baz, nil])
|
113
|
-
@handler.set_auth_handler(mock2)
|
114
|
-
@handler.credentials = credentials
|
115
|
-
assert(mock2.verify)
|
116
|
-
|
117
|
-
credentials[:foo] = nil
|
118
|
-
mock3 = Minitest::Mock.new()
|
119
|
-
mock3.expect(:property_changed, nil, [:foo, nil])
|
120
|
-
mock3.expect(:property_changed, nil, [:baz, nil])
|
121
|
-
@handler.set_auth_handler(mock3)
|
122
|
-
@handler.credentials = credentials
|
123
|
-
assert(mock3.verify)
|
124
|
-
end
|
125
|
-
end
|
data/test/test_env.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2016, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Tests environment is correct.
|
20
|
-
|
21
|
-
require 'openssl'
|
22
|
-
require 'test/unit'
|
23
|
-
|
24
|
-
class TestEnv < Test::Unit::TestCase
|
25
|
-
|
26
|
-
# Output ruby interpreter version to the tests log.
|
27
|
-
def test_ruby_version
|
28
|
-
puts "\nRunning tests with %s-%s-%s.\n" %
|
29
|
-
[RUBY_ENGINE, RUBY_VERSION, RUBY_PATCHLEVEL]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Output SSL version to the tests log. There is a known issue with this
|
33
|
-
# required property not defined in some JRuby implementations.
|
34
|
-
def test_openssl_version
|
35
|
-
puts "\nUsing OpenSSL %s with %d methods.\n" %
|
36
|
-
[OpenSSL::OPENSSL_VERSION, OpenSSL::SSL::SSLContext::METHODS.count]
|
37
|
-
end
|
38
|
-
|
39
|
-
# Output rake version to the tests log.
|
40
|
-
def test_rake_version
|
41
|
-
puts "\nRunning with rake %s.\n" % Rake::VERSION if defined?(Rake)
|
42
|
-
end
|
43
|
-
end
|
data/test/test_oauth2_handler.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2015, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Test OAuth2 authentication.
|
20
|
-
|
21
|
-
require 'time'
|
22
|
-
|
23
|
-
require 'ads_common/auth/oauth2_handler'
|
24
|
-
require 'ads_common/config'
|
25
|
-
require 'webmock/test_unit'
|
26
|
-
|
27
|
-
module AdsCommon
|
28
|
-
module Auth
|
29
|
-
class OAuth2Handler
|
30
|
-
attr_reader :scopes
|
31
|
-
|
32
|
-
def client()
|
33
|
-
@client
|
34
|
-
end
|
35
|
-
|
36
|
-
# Overrides to ensure @client stores issued_at as a string, to test
|
37
|
-
# converting it back.
|
38
|
-
def setup_client()
|
39
|
-
@client = Signet::OAuth2::Client.new({
|
40
|
-
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
|
41
|
-
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
|
42
|
-
:client_id => 'client_id123',
|
43
|
-
:client_secret => 'client_secret123',
|
44
|
-
:scope => 'https://www.googleapis.com/auth/adwords'
|
45
|
-
})
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class TestOAuth < Test::Unit::TestCase
|
52
|
-
def setup()
|
53
|
-
stub_request(:post, 'https://accounts.google.com/o/oauth2/auth').to_return(
|
54
|
-
:status => 200,
|
55
|
-
:body => '{"access_token":"access_token123",' +
|
56
|
-
'"token_type":"Bearer","expires_in":"3600"}\n',
|
57
|
-
:headers => {}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_string_issued_at()
|
62
|
-
handler = AdsCommon::Auth::OAuth2Handler.new(AdsCommon::Config.new(), nil)
|
63
|
-
|
64
|
-
# Modify @client in the handler to get around a full setup.
|
65
|
-
handler.setup_client()
|
66
|
-
assert_not_nil(handler.client)
|
67
|
-
handler.client.issued_at = Time.now.to_s
|
68
|
-
assert_equal(Time, handler.client.issued_at.class)
|
69
|
-
|
70
|
-
# Make sure that we are still able to refresh the token.
|
71
|
-
assert_nothing_raised do
|
72
|
-
handler.refresh_token!();
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_additional_scopes()
|
77
|
-
config = AdsCommon::Config.new()
|
78
|
-
config.set('authentication.oauth2_extra_scopes', ['extra-scope'])
|
79
|
-
handler = AdsCommon::Auth::OAuth2Handler.new(config, 'base-scope')
|
80
|
-
scopes = handler.scopes
|
81
|
-
assert(scopes.include?('base-scope'), 'Missing base scope.')
|
82
|
-
assert(scopes.include?('extra-scope'), 'Missing extra scope.')
|
83
|
-
end
|
84
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: utf-8
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright 2016, Google Inc. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
# Test OAuth2 service account authentication.
|
20
|
-
|
21
|
-
require 'tempfile'
|
22
|
-
|
23
|
-
require 'ads_common/auth/oauth2_service_account_handler'
|
24
|
-
require 'ads_common/config'
|
25
|
-
|
26
|
-
module AdsCommon
|
27
|
-
module Auth
|
28
|
-
class OAuth2ServiceAccountHandler
|
29
|
-
public :validate_credentials
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class TestOAuthServiceAccount < Test::Unit::TestCase
|
35
|
-
def test_file_extension_check()
|
36
|
-
assert_nothing_raised do
|
37
|
-
validate_credentials(['test', '.json'])
|
38
|
-
end
|
39
|
-
assert_raise(AdsCommon::Errors::AuthError) do
|
40
|
-
validate_credentials(['test', '.p12'])
|
41
|
-
end
|
42
|
-
assert_raises(AdsCommon::Errors::AuthError) do
|
43
|
-
validate_credentials(['test', '.other'])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def validate_credentials(filename)
|
48
|
-
file = Tempfile.new(filename)
|
49
|
-
credentials = {
|
50
|
-
:method => 'OAUTH2_SERVICE_ACCOUNT',
|
51
|
-
:oauth2_keyfile => file.path,
|
52
|
-
:oauth2_issuer => 'issuer',
|
53
|
-
:oauth2_secret => 'secret'
|
54
|
-
}
|
55
|
-
handler = AdsCommon::Auth::OAuth2ServiceAccountHandler.new(
|
56
|
-
AdsCommon::Config.new(), 'https://www.googleapis.com/auth/adwords')
|
57
|
-
handler.validate_credentials(credentials)
|
58
|
-
file.close
|
59
|
-
file.unlink
|
60
|
-
end
|
61
|
-
end
|