ibm_cloud_sdk_core 1.1.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ibm_cloud_sdk_core/api_exception.rb +1 -0
- data/lib/ibm_cloud_sdk_core/authenticators/basic_authenticator.rb +3 -2
- data/lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb +3 -2
- data/lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory.rb +10 -9
- data/lib/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.rb +4 -3
- data/lib/ibm_cloud_sdk_core/authenticators/iam_authenticator.rb +4 -3
- data/lib/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.rb +1 -1
- data/lib/ibm_cloud_sdk_core/base_service.rb +6 -5
- data/lib/ibm_cloud_sdk_core/detailed_response.rb +1 -0
- data/lib/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.rb +1 -1
- data/lib/ibm_cloud_sdk_core/token_managers/iam_token_manager.rb +3 -3
- data/lib/ibm_cloud_sdk_core/token_managers/jwt_token_manager.rb +2 -2
- data/lib/ibm_cloud_sdk_core/utils.rb +3 -3
- data/lib/ibm_cloud_sdk_core/version.rb +1 -1
- data/lib/ibm_cloud_sdk_core.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/test_base_service.rb +11 -11
- data/test/unit/test_configure_http_proxy.rb +1 -1
- data/test/unit/test_cp4d_authenticator.rb +4 -4
- data/test/unit/test_cp4d_token_manager.rb +1 -1
- data/test/unit/test_detailed_response.rb +6 -2
- data/test/unit/test_iam_authenticator.rb +6 -6
- data/test/unit/test_iam_token_manager.rb +1 -1
- data/test/unit/test_jwt_token_manager.rb +2 -2
- data/test/unit/test_utils.rb +2 -2
- metadata +47 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08bd02341468ecb32993b19082783c0b646f88f5d7f538fa9343b24d5b2a595a'
|
4
|
+
data.tar.gz: 93173bbe7fa34e0d686092299a05a08665d400ac7d69057a2abcd7ca7557a3e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 113ace9041d72cb601693fc48a7c29c26ac4908f340b6c641a46bd8117e8bdc8fb1f0b5a06bc248f3044dace6d7471797b1ee95edb83e2a976c59ef2e846175d
|
7
|
+
data.tar.gz: cfa22645b5c9169a59691a248bfef3e846526f92687ac564deeb2d89ca462f20bedc1b8d480abe0bca220666ceab158367cba72336417e6fdad032e505e8a96b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.com/IBM/ruby-sdk-core.svg?branch=main)](https://travis-ci.com/IBM/ruby-sdk-core)
|
1
|
+
[![Build Status](https://app.travis-ci.com/IBM/ruby-sdk-core.svg?branch=main)](https://app.travis-ci.com/IBM/ruby-sdk-core)
|
2
2
|
[![codecov](https://codecov.io/gh/IBM/ruby-sdk-core/branch/main/graph/badge.svg)](https://codecov.io/gh/IBM/ruby-sdk-core)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ibm_cloud_sdk_core.svg)](https://rubygems.org/gems/ibm_cloud_sdk_core)
|
4
4
|
|
@@ -6,6 +6,7 @@ module IBMCloudSdkCore
|
|
6
6
|
# Custom exception class for errors returned from the APIs
|
7
7
|
class ApiException < StandardError
|
8
8
|
attr_reader :code, :error, :info, :transaction_id, :global_transaction_id
|
9
|
+
|
9
10
|
# :param HTTP::Response response: The response object from the API
|
10
11
|
def initialize(code: nil, error: nil, info: nil, transaction_id: nil, global_transaction_id: nil, response: nil)
|
11
12
|
if code.nil? || error.nil?
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require("json")
|
4
|
-
require_relative("./authenticator
|
5
|
-
require_relative("../utils
|
4
|
+
require_relative("./authenticator")
|
5
|
+
require_relative("../utils")
|
6
6
|
|
7
7
|
module IBMCloudSdkCore
|
8
8
|
# Basic Authenticator
|
9
9
|
class BasicAuthenticator < Authenticator
|
10
10
|
attr_accessor :username, :password, :authentication_type
|
11
|
+
|
11
12
|
def initialize(vars)
|
12
13
|
defaults = {
|
13
14
|
username: nil,
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require("json")
|
4
|
-
require_relative("./authenticator
|
5
|
-
require_relative("../utils
|
4
|
+
require_relative("./authenticator")
|
5
|
+
require_relative("../utils")
|
6
6
|
|
7
7
|
module IBMCloudSdkCore
|
8
8
|
# Basic Authenticator
|
9
9
|
class BearerTokenAuthenticator < Authenticator
|
10
10
|
attr_accessor :authentication_type
|
11
|
+
|
11
12
|
def initialize(vars)
|
12
13
|
defaults = {
|
13
14
|
bearer_token: nil
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require("json")
|
4
|
-
require_relative("./authenticator
|
5
|
-
require_relative("./basic_authenticator
|
6
|
-
require_relative("./bearer_token_authenticator
|
7
|
-
require_relative("./cp4d_authenticator
|
8
|
-
require_relative("./iam_authenticator
|
9
|
-
require_relative("./no_auth_authenticator
|
10
|
-
require_relative("../utils
|
4
|
+
require_relative("./authenticator")
|
5
|
+
require_relative("./basic_authenticator")
|
6
|
+
require_relative("./bearer_token_authenticator")
|
7
|
+
require_relative("./cp4d_authenticator")
|
8
|
+
require_relative("./iam_authenticator")
|
9
|
+
require_relative("./no_auth_authenticator")
|
10
|
+
require_relative("../utils")
|
11
11
|
|
12
12
|
module IBMCloudSdkCore
|
13
13
|
# Authenticator
|
@@ -17,7 +17,7 @@ module IBMCloudSdkCore
|
|
17
17
|
# :return: the authenticator
|
18
18
|
def get_authenticator(service_name:)
|
19
19
|
config = get_service_properties(service_name)
|
20
|
-
|
20
|
+
construct_authenticator(config) unless config.nil? || config.empty?
|
21
21
|
end
|
22
22
|
|
23
23
|
def construct_authenticator(config)
|
@@ -32,7 +32,8 @@ module IBMCloudSdkCore
|
|
32
32
|
return BearerTokenAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_BEARER_TOKEN).zero?
|
33
33
|
return CloudPakForDataAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_CP4D).zero?
|
34
34
|
return IamAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_IAM).zero?
|
35
|
-
|
35
|
+
|
36
|
+
NoAuthAuthenticator.new if auth_type.casecmp(AUTH_TYPE_NO_AUTH).zero?
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require("json")
|
4
|
-
require_relative("./authenticator
|
5
|
-
require_relative("../token_managers/cp4d_token_manager
|
6
|
-
require_relative("../utils
|
4
|
+
require_relative("./authenticator")
|
5
|
+
require_relative("../token_managers/cp4d_token_manager")
|
6
|
+
require_relative("../utils")
|
7
7
|
|
8
8
|
module IBMCloudSdkCore
|
9
9
|
# Basic Authenticator
|
10
10
|
class CloudPakForDataAuthenticator < Authenticator
|
11
11
|
attr_accessor :authentication_type, :disable_ssl_verification
|
12
|
+
|
12
13
|
def initialize(vars)
|
13
14
|
defaults = {
|
14
15
|
username: nil,
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require("json")
|
4
|
-
require_relative("./authenticator
|
5
|
-
require_relative("../token_managers/iam_token_manager
|
6
|
-
require_relative("../utils
|
4
|
+
require_relative("./authenticator")
|
5
|
+
require_relative("../token_managers/iam_token_manager")
|
6
|
+
require_relative("../utils")
|
7
7
|
|
8
8
|
module IBMCloudSdkCore
|
9
9
|
# Basic Authenticator
|
10
10
|
class IamAuthenticator < Authenticator
|
11
11
|
attr_accessor :authentication_type, :disable_ssl_verification, :client_id, :client_secret
|
12
|
+
|
12
13
|
def initialize(vars)
|
13
14
|
defaults = {
|
14
15
|
url: nil,
|
@@ -4,10 +4,10 @@ require("http")
|
|
4
4
|
require("rbconfig")
|
5
5
|
require("stringio")
|
6
6
|
require("json")
|
7
|
-
require_relative("./version
|
8
|
-
require_relative("./detailed_response
|
9
|
-
require_relative("./api_exception
|
10
|
-
require_relative("./utils
|
7
|
+
require_relative("./version")
|
8
|
+
require_relative("./detailed_response")
|
9
|
+
require_relative("./api_exception")
|
10
|
+
require_relative("./utils")
|
11
11
|
require_relative("./authenticators/authenticator")
|
12
12
|
require_relative("./authenticators/basic_authenticator")
|
13
13
|
require_relative("./authenticators/bearer_token_authenticator")
|
@@ -25,6 +25,7 @@ module IBMCloudSdkCore
|
|
25
25
|
class BaseService
|
26
26
|
attr_accessor :service_name, :service_url
|
27
27
|
attr_reader :conn, :authenticator, :disable_ssl_verification
|
28
|
+
|
28
29
|
def initialize(vars)
|
29
30
|
defaults = {
|
30
31
|
authenticator: nil,
|
@@ -148,7 +149,7 @@ module IBMCloudSdkCore
|
|
148
149
|
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
149
150
|
@conn.default_options = { ssl_context: ssl_context }
|
150
151
|
end
|
151
|
-
add_proxy(proxy) unless proxy.empty? || !proxy
|
152
|
+
add_proxy(proxy) unless proxy.empty? || !proxy[:address].is_a?(String) || !proxy[:port].is_a?(Integer)
|
152
153
|
add_timeout(timeout) unless timeout.empty? || (!timeout.key?(:per_operation) && !timeout.key?(:global))
|
153
154
|
end
|
154
155
|
|
@@ -6,6 +6,7 @@ module IBMCloudSdkCore
|
|
6
6
|
# Custom class for objects returned from API calls
|
7
7
|
class DetailedResponse
|
8
8
|
attr_reader :status, :headers, :result
|
9
|
+
|
9
10
|
def initialize(status: nil, headers: nil, body: nil, response: nil)
|
10
11
|
if status.nil? || headers.nil? || body.nil?
|
11
12
|
@status = response.code
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require("http")
|
4
4
|
require("json")
|
5
5
|
require("rbconfig")
|
6
|
-
require_relative("./../version
|
6
|
+
require_relative("./../version")
|
7
7
|
require_relative("./jwt_token_manager")
|
8
8
|
|
9
9
|
module IBMCloudSdkCore
|
@@ -17,6 +17,7 @@ module IBMCloudSdkCore
|
|
17
17
|
TOKEN_NAME = "access_token"
|
18
18
|
|
19
19
|
attr_accessor :token_info, :token_name, :client_id, :client_secret
|
20
|
+
|
20
21
|
def initialize(
|
21
22
|
apikey: nil,
|
22
23
|
url: nil,
|
@@ -51,7 +52,7 @@ module IBMCloudSdkCore
|
|
51
52
|
"response_type" => REQUEST_TOKEN_RESPONSE_TYPE
|
52
53
|
}
|
53
54
|
# @headers.add
|
54
|
-
|
55
|
+
request(
|
55
56
|
method: "POST",
|
56
57
|
url: @url,
|
57
58
|
headers: headers,
|
@@ -59,7 +60,6 @@ module IBMCloudSdkCore
|
|
59
60
|
username: @client_id,
|
60
61
|
password: @client_secret
|
61
62
|
)
|
62
|
-
response
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -4,7 +4,7 @@ require("http")
|
|
4
4
|
require("json")
|
5
5
|
require("jwt")
|
6
6
|
require("rbconfig")
|
7
|
-
require_relative("./../version
|
7
|
+
require_relative("./../version")
|
8
8
|
|
9
9
|
module IBMCloudSdkCore
|
10
10
|
# Class to manage JWT Token Authentication
|
@@ -84,7 +84,7 @@ module IBMCloudSdkCore
|
|
84
84
|
end
|
85
85
|
return JSON.parse(response.body.to_s) if (200..299).cover?(response.code)
|
86
86
|
|
87
|
-
require_relative("./../api_exception
|
87
|
+
require_relative("./../api_exception")
|
88
88
|
raise ApiException.new(response: response)
|
89
89
|
end
|
90
90
|
end
|
@@ -13,7 +13,7 @@ def get_service_properties(service_name)
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_bad_first_or_last_char(str)
|
16
|
-
|
16
|
+
str.start_with?("{", "\"") || str.end_with?("}", "\"") unless str.nil?
|
17
17
|
end
|
18
18
|
|
19
19
|
# checks if the provided value is truthy
|
@@ -29,13 +29,13 @@ def load_from_credential_file(service_name, separator = "=")
|
|
29
29
|
|
30
30
|
# Top-level directory of the project
|
31
31
|
if credential_file_path.nil?
|
32
|
-
file_path = File.join(File.dirname(__FILE__), "
|
32
|
+
file_path = File.join(File.dirname(__FILE__), "/../../#{DEFAULT_CREDENTIALS_FILE_NAME}")
|
33
33
|
credential_file_path = file_path if File.exist?(file_path)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Home directory
|
37
37
|
if credential_file_path.nil?
|
38
|
-
file_path = ENV["HOME"]
|
38
|
+
file_path = "#{ENV["HOME"]}/#{DEFAULT_CREDENTIALS_FILE_NAME}"
|
39
39
|
credential_file_path = file_path if File.exist?(file_path)
|
40
40
|
end
|
41
41
|
|
data/lib/ibm_cloud_sdk_core.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require("json")
|
4
4
|
require("jwt")
|
5
|
-
require_relative("./../test_helper
|
5
|
+
require_relative("./../test_helper")
|
6
6
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/basic_authenticator")
|
7
7
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory")
|
8
8
|
require("webmock/minitest")
|
@@ -113,7 +113,7 @@ class BaseServiceTest < Minitest::Test
|
|
113
113
|
headers: {
|
114
114
|
"Connection" => "close",
|
115
115
|
"Host" => "iam.cloud.ibm.com",
|
116
|
-
"User-Agent" => "http.rb
|
116
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
117
117
|
}
|
118
118
|
)
|
119
119
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -135,7 +135,7 @@ class BaseServiceTest < Minitest::Test
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def test_vcap_services
|
138
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
138
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
139
139
|
authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
|
140
140
|
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator)
|
141
141
|
assert_equal(authenticator.username, "mo")
|
@@ -144,7 +144,7 @@ class BaseServiceTest < Minitest::Test
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def test_dummy_request
|
147
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
147
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
148
148
|
stub_request(:get, "https://we.the.best/music")
|
149
149
|
.with(
|
150
150
|
headers: {
|
@@ -167,7 +167,7 @@ class BaseServiceTest < Minitest::Test
|
|
167
167
|
)
|
168
168
|
service.service_url = "https://gateway.watsonplatform.net/assistant/api/"
|
169
169
|
form_data = {}
|
170
|
-
file = File.open(Dir.getwd
|
170
|
+
file = File.open("#{Dir.getwd}/resources/cnc_test.pdf")
|
171
171
|
filename = file.path if filename.nil? && file.respond_to?(:path)
|
172
172
|
form_data[:file] = HTTP::FormData::File.new(file, content_type: "application/octet-stream", filename: filename)
|
173
173
|
|
@@ -185,7 +185,7 @@ class BaseServiceTest < Minitest::Test
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def test_dummy_request_fails
|
188
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
188
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
189
189
|
response = {
|
190
190
|
"code" => "500",
|
191
191
|
"error" => "Oh no"
|
@@ -262,7 +262,7 @@ class BaseServiceTest < Minitest::Test
|
|
262
262
|
authenticator: authenticator,
|
263
263
|
service_name: "key_to_service_entry_1"
|
264
264
|
)
|
265
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
265
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
266
266
|
service.configure_service("key_to_service_entry_1")
|
267
267
|
|
268
268
|
assert_equal("https://on.the.toolchainplatform.net/devops-insights/api", service.service_url)
|
@@ -278,7 +278,7 @@ class BaseServiceTest < Minitest::Test
|
|
278
278
|
authenticator: authenticator,
|
279
279
|
service_name: "devops_insights"
|
280
280
|
)
|
281
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
281
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
282
282
|
service.configure_service("devops_insights")
|
283
283
|
|
284
284
|
assert_equal("https://ibmtesturl.net/devops_insights/api", service.service_url)
|
@@ -294,7 +294,7 @@ class BaseServiceTest < Minitest::Test
|
|
294
294
|
authenticator: authenticator,
|
295
295
|
service_name: "different_name_two"
|
296
296
|
)
|
297
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
297
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
298
298
|
service.configure_service("different_name_two")
|
299
299
|
|
300
300
|
assert_equal("https://gateway.watsonplatform.net/different-name-two/api", service.service_url)
|
@@ -310,7 +310,7 @@ class BaseServiceTest < Minitest::Test
|
|
310
310
|
authenticator: authenticator,
|
311
311
|
service_name: "empty_service"
|
312
312
|
)
|
313
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
313
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
314
314
|
service.configure_service("empty_service")
|
315
315
|
|
316
316
|
assert_nil(service.service_url)
|
@@ -326,7 +326,7 @@ class BaseServiceTest < Minitest::Test
|
|
326
326
|
authenticator: authenticator,
|
327
327
|
service_name: "no-creds-service-two"
|
328
328
|
)
|
329
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
329
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
330
330
|
service.configure_service("no-creds-service-two")
|
331
331
|
|
332
332
|
assert_nil(service.service_url)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require("json")
|
4
4
|
require("jwt")
|
5
|
-
require_relative("./../test_helper
|
5
|
+
require_relative("./../test_helper")
|
6
6
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/basic_authenticator")
|
7
7
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory")
|
8
8
|
require("webmock/minitest")
|
@@ -37,7 +37,7 @@ class Cp4dAuthenticatorTest < Minitest::Test
|
|
37
37
|
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
38
38
|
"Connection" => "close",
|
39
39
|
"Host" => "icp.com",
|
40
|
-
"User-Agent" => "http.rb
|
40
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
41
41
|
}
|
42
42
|
)
|
43
43
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -77,7 +77,7 @@ class Cp4dAuthenticatorTest < Minitest::Test
|
|
77
77
|
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
78
78
|
"Connection" => "close",
|
79
79
|
"Host" => "icp.com",
|
80
|
-
"User-Agent" => "http.rb
|
80
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
81
81
|
}
|
82
82
|
)
|
83
83
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -90,7 +90,7 @@ class Cp4dAuthenticatorTest < Minitest::Test
|
|
90
90
|
refute_nil(authenticator)
|
91
91
|
assert_equal(authenticator.instance_variable_get(:@token_manager).access_token, token)
|
92
92
|
headers = {}
|
93
|
-
authenticated_headers = { "Authorization" => "Bearer "
|
93
|
+
authenticated_headers = { "Authorization" => "Bearer #{token}" }
|
94
94
|
authenticator.authenticate(headers)
|
95
95
|
assert_equal(headers, authenticated_headers)
|
96
96
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative("./../test_helper
|
3
|
+
require_relative("./../test_helper")
|
4
4
|
require("webmock/minitest")
|
5
5
|
require("http")
|
6
6
|
|
@@ -8,6 +8,10 @@ WebMock.disable_net_connect!(allow_localhost: true)
|
|
8
8
|
|
9
9
|
# Unit tests for the IAM Token Manager
|
10
10
|
class DetailedResponseTest < Minitest::Test
|
11
|
+
def example_request
|
12
|
+
HTTP::Request.new({ uri: "http://example.com", verb: :get })
|
13
|
+
end
|
14
|
+
|
11
15
|
def test_detailed_response
|
12
16
|
res = IBMCloudSdkCore::DetailedResponse.new(status: 200, headers: {}, body: {}, response: { code: 401 })
|
13
17
|
assert_equal(res.status, 200)
|
@@ -20,7 +24,7 @@ class DetailedResponseTest < Minitest::Test
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def test_detailed_response_when_only_response
|
23
|
-
response = IBMCloudSdkCore::DetailedResponse.new(response: HTTP::Response.new(status: 401, version: 1, body: {}))
|
27
|
+
response = IBMCloudSdkCore::DetailedResponse.new(response: HTTP::Response.new({ request: example_request, status: 401, version: 1, body: {} }))
|
24
28
|
assert_equal(response.status, 401)
|
25
29
|
end
|
26
30
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require("json")
|
4
4
|
require("jwt")
|
5
|
-
require_relative("./../test_helper
|
5
|
+
require_relative("./../test_helper")
|
6
6
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/basic_authenticator")
|
7
7
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory")
|
8
8
|
require("webmock/minitest")
|
@@ -41,7 +41,7 @@ class IamAuthenticatorTest < Minitest::Test
|
|
41
41
|
headers: {
|
42
42
|
"Connection" => "close",
|
43
43
|
"Host" => "iam.cloud.ibm.com",
|
44
|
-
"User-Agent" => "http.rb
|
44
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
45
45
|
}
|
46
46
|
)
|
47
47
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -83,7 +83,7 @@ class IamAuthenticatorTest < Minitest::Test
|
|
83
83
|
"Connection" => "close",
|
84
84
|
"Authorization" => "Basic Yng6Yng=",
|
85
85
|
"Host" => "iam.cloud.ibm.com",
|
86
|
-
"User-Agent" => "http.rb
|
86
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
87
87
|
}
|
88
88
|
)
|
89
89
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -126,7 +126,7 @@ class IamAuthenticatorTest < Minitest::Test
|
|
126
126
|
headers: {
|
127
127
|
"Connection" => "close",
|
128
128
|
"Host" => "iam.cloud.ibm.com",
|
129
|
-
"User-Agent" => "http.rb
|
129
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
130
130
|
}
|
131
131
|
)
|
132
132
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -136,7 +136,7 @@ class IamAuthenticatorTest < Minitest::Test
|
|
136
136
|
refute_nil(authenticator)
|
137
137
|
assert_equal(authenticator.instance_variable_get(:@token_manager).access_token, token)
|
138
138
|
headers = {}
|
139
|
-
authenticated_headers = { "Authorization" => "Bearer "
|
139
|
+
authenticated_headers = { "Authorization" => "Bearer #{token}" }
|
140
140
|
authenticator.authenticate(headers)
|
141
141
|
assert_equal(headers, authenticated_headers)
|
142
142
|
end
|
@@ -173,7 +173,7 @@ class IamAuthenticatorTest < Minitest::Test
|
|
173
173
|
headers: {
|
174
174
|
"Connection" => "close",
|
175
175
|
"Host" => "my.link",
|
176
|
-
"User-Agent" => "http.rb
|
176
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
177
177
|
}
|
178
178
|
)
|
179
179
|
.to_return(status: 200, body: response.to_json, headers: {})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative("./../test_helper
|
3
|
+
require_relative("./../test_helper")
|
4
4
|
require("jwt")
|
5
5
|
require("webmock/minitest")
|
6
6
|
|
@@ -114,7 +114,7 @@ class JWTTokenManagerTest < Minitest::Test
|
|
114
114
|
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
115
115
|
"Connection" => "close",
|
116
116
|
"Host" => "icp.com",
|
117
|
-
"User-Agent" => "http.rb
|
117
|
+
"User-Agent" => "http.rb/#{HTTP::VERSION}"
|
118
118
|
}
|
119
119
|
)
|
120
120
|
.to_return(status: 200, body: response.to_json, headers: {})
|
data/test/unit/test_utils.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require("json")
|
4
4
|
require("jwt")
|
5
|
-
require_relative("./../test_helper
|
5
|
+
require_relative("./../test_helper")
|
6
6
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/basic_authenticator")
|
7
7
|
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory")
|
8
8
|
require("webmock/minitest")
|
@@ -93,7 +93,7 @@ class UtilsTest < Minitest::Test
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_get_configuration_from_vcap
|
96
|
-
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd
|
96
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read("#{Dir.getwd}/resources/vcap-testing.json")).to_json
|
97
97
|
# get properties
|
98
98
|
config = get_service_properties("equals-sign-test")
|
99
99
|
auth_type = config[:auth_type] unless config.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_cloud_sdk_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mamoon Raja
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '5.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '5.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: jwt
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.2
|
47
|
+
version: '2.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.2
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: codecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,16 +182,44 @@ dependencies:
|
|
182
182
|
name: rubocop
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '1.40'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '1.40'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-performance
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rubocop-rails
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
195
223
|
- !ruby/object:Gem::Dependency
|
196
224
|
name: simplecov
|
197
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,8 +248,8 @@ dependencies:
|
|
220
248
|
- - "~>"
|
221
249
|
- !ruby/object:Gem::Version
|
222
250
|
version: '3.4'
|
223
|
-
description:
|
224
|
-
email:
|
251
|
+
description:
|
252
|
+
email:
|
225
253
|
executables: []
|
226
254
|
extensions: []
|
227
255
|
extra_rdoc_files: []
|
@@ -261,7 +289,7 @@ metadata:
|
|
261
289
|
allowed_push_host: https://rubygems.org
|
262
290
|
source_code_uri: https://github.com/IBM/ruby-sdk-core
|
263
291
|
documentation_uri: https://github.com/IBM/ruby-sdk-core
|
264
|
-
post_install_message:
|
292
|
+
post_install_message:
|
265
293
|
rdoc_options: []
|
266
294
|
require_paths:
|
267
295
|
- lib
|
@@ -269,15 +297,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
269
297
|
requirements:
|
270
298
|
- - ">="
|
271
299
|
- !ruby/object:Gem::Version
|
272
|
-
version: '2.
|
300
|
+
version: '2.7'
|
273
301
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
302
|
requirements:
|
275
303
|
- - ">="
|
276
304
|
- !ruby/object:Gem::Version
|
277
305
|
version: '0'
|
278
306
|
requirements: []
|
279
|
-
rubygems_version: 3.
|
280
|
-
signing_key:
|
307
|
+
rubygems_version: 3.4.20
|
308
|
+
signing_key:
|
281
309
|
specification_version: 4
|
282
310
|
summary: Official IBM Cloud SDK core library
|
283
311
|
test_files: []
|