rb-net_http-client 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/client/client.rb +51 -0
- data/lib/client/ext.rb +120 -0
- data/lib/client/schema.rb +38 -0
- data/lib/core/core.rb +75 -0
- data/lib/core/utilities.rb +243 -0
- data/lib/rb-net_http-client.rb +4 -0
- data/lib/request/ext.rb +87 -0
- data/lib/request/schema.rb +20 -0
- data/lib/response/ext.rb +111 -0
- data/lib/version.rb +5 -0
- data/spec/integration/net_http/client/client_ext_spec.rb +7 -0
- data/spec/integration/net_http/client/client_spec.rb +7 -0
- data/spec/integration/net_http/net_http_core_spec.rb +18 -0
- data/spec/integration/net_http/request/request_ext_spec.rb +342 -0
- data/spec/integration/net_http/response/response_ext_spec.rb +7 -0
- data/spec/integration/net_http/version_spec.rb +10 -0
- data/spec/unit/net_http/client/client_ext_spec.rb +7 -0
- data/spec/unit/net_http/client/client_schema_spec.rb +8 -0
- data/spec/unit/net_http/client/client_spec.rb +232 -0
- data/spec/unit/net_http/net_http_core_spec.rb +433 -0
- data/spec/unit/net_http/request/request_ext_spec.rb +603 -0
- data/spec/unit/net_http/request/request_schema_spec.rb +8 -0
- data/spec/unit/net_http/response/response_ext_spec.rb +97 -0
- data/spec/unit/net_http/version_spec.rb +10 -0
- metadata +252 -0
data/lib/request/ext.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../core/core'
|
4
|
+
require_relative 'schema'
|
5
|
+
|
6
|
+
module NetHTTP
|
7
|
+
module Request
|
8
|
+
module Ext
|
9
|
+
def call_web_service(opts = {})
|
10
|
+
logger = Core.assign_logger(self.logger ||= opts[:logger])
|
11
|
+
|
12
|
+
Core.schema_validation(opts, NetHTTP::Request::Schema, logger) unless opts[:enforce_schema_validation] == false
|
13
|
+
|
14
|
+
method = (opts[:method] ||= opts[:req_method] ||= opts[:request_method] ||= 'post').to_s.upcase
|
15
|
+
uri = Core.parse_uri(opts[:uri] ||= opts[:url] ||= self.uri)
|
16
|
+
path = opts[:path] ||= opts[:req_path] ||= opts[:request_path] ||= opts[:path] ||= uri.path ||= self.path
|
17
|
+
path = (path + '?' + uri.query) unless uri.query.nil? || path.include?('?')
|
18
|
+
headers = opts[:headers] ||= opts[:req_headers] ||= opts[:request_headers] ||= {}
|
19
|
+
body = opts[:body] ||= opts[:req_body] ||= opts[:request_body] ||= nil
|
20
|
+
|
21
|
+
resp = case method
|
22
|
+
when 'DELETE'
|
23
|
+
logger.debug('Request Method => ' + method)
|
24
|
+
logger.debug('Request Host => ' + uri.host.to_s)
|
25
|
+
logger.debug('Request Path => ' + path)
|
26
|
+
delete(path)
|
27
|
+
when 'GET'
|
28
|
+
logger.debug('Request Method => ' + method)
|
29
|
+
logger.debug('Request Host => ' + uri.host.to_s)
|
30
|
+
logger.debug('Request Path => ' + path)
|
31
|
+
logger.debug('Request Headers =>')
|
32
|
+
logger.debug(headers)
|
33
|
+
get(path, headers)
|
34
|
+
when 'POST'
|
35
|
+
logger.debug('Request Method => ' + method)
|
36
|
+
logger.debug('Request Host => ' + uri.host.to_s)
|
37
|
+
logger.debug('Request Path => ' + path)
|
38
|
+
logger.debug('Request Headers =>')
|
39
|
+
logger.debug(headers)
|
40
|
+
logger.debug('Request Body =>')
|
41
|
+
logger.debug(body)
|
42
|
+
post(path, body, headers)
|
43
|
+
when 'POST_FORM', 'POST_FORM_DATA'
|
44
|
+
logger.debug('Request Method => ' + method)
|
45
|
+
logger.debug('Request Host => ' + uri.host.to_s)
|
46
|
+
logger.debug('Request Path => ' + path)
|
47
|
+
logger.debug('Request Headers =>')
|
48
|
+
logger.debug(headers)
|
49
|
+
logger.debug('Request Body =>')
|
50
|
+
logger.debug(URI.encode_www_form(body))
|
51
|
+
post(uri, URI.encode_www_form(body), headers)
|
52
|
+
when 'PUT'
|
53
|
+
logger.debug('Request Method => ' + method)
|
54
|
+
logger.debug('Request Host => ' + uri.host.to_s)
|
55
|
+
logger.debug('Request Path => ' + path)
|
56
|
+
logger.debug('Request Headers =>')
|
57
|
+
logger.debug(headers)
|
58
|
+
logger.debug('Request Body =>')
|
59
|
+
logger.debug(body)
|
60
|
+
put(path, body, headers)
|
61
|
+
else
|
62
|
+
logger.debug("Request method => '#{method}' not yet supported.")
|
63
|
+
raise "Request method => '#{method}' not yet supported."
|
64
|
+
end
|
65
|
+
logger.debug('Response Code => ' + resp.code)
|
66
|
+
logger.debug('Response Headers => ')
|
67
|
+
logger.debug(resp.headers)
|
68
|
+
logger.debug('Response Body => ')
|
69
|
+
logger.debug(resp.body)
|
70
|
+
resp
|
71
|
+
end
|
72
|
+
|
73
|
+
alias call_api call_web_service
|
74
|
+
alias call_service call_web_service
|
75
|
+
alias execute_request call_web_service
|
76
|
+
alias send_request call_web_service
|
77
|
+
alias submit_request call_web_service
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Net
|
83
|
+
class HTTP
|
84
|
+
include NetHTTP::Core
|
85
|
+
include NetHTTP::Request::Ext
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-validation'
|
4
|
+
|
5
|
+
module NetHTTP
|
6
|
+
module Request
|
7
|
+
Schema = Dry::Validation.Schema do
|
8
|
+
optional(:req_method).filled(type?: String)
|
9
|
+
optional(:method).filled(type?: String)
|
10
|
+
optional(:req_headers).maybe(type?: Hash)
|
11
|
+
optional(:headers).maybe(type?: Hash)
|
12
|
+
optional(:req_body).maybe
|
13
|
+
optional(:body).maybe
|
14
|
+
|
15
|
+
rule(if_url_and_uri_are_nil_must_provide_path: [:uri, :url, :path]) do |uri, url, path|
|
16
|
+
uri.empty?.then(url.empty?.then(path.filled?))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/response/ext.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'ostruct'
|
6
|
+
require_relative '../core/core'
|
7
|
+
require_relative '../core/utilities'
|
8
|
+
|
9
|
+
module NetHTTP
|
10
|
+
module Response
|
11
|
+
module Ext
|
12
|
+
def resp_code
|
13
|
+
code
|
14
|
+
end
|
15
|
+
|
16
|
+
alias response_code resp_code
|
17
|
+
|
18
|
+
def headers
|
19
|
+
resp_headers = {}
|
20
|
+
headers = to_hash
|
21
|
+
headers.each do |key, value|
|
22
|
+
resp_headers[key] = value.flatten[0].to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
alias resp_headers headers
|
27
|
+
alias response_headers headers
|
28
|
+
|
29
|
+
def headers_hash
|
30
|
+
NetHTTP::Core::Utilities.convert_hash_keys(
|
31
|
+
object: headers,
|
32
|
+
format: 'snake',
|
33
|
+
type: 'symbol'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
alias resp_headers_hash headers_hash
|
38
|
+
alias response_headers_hash headers_hash
|
39
|
+
|
40
|
+
def headers_os
|
41
|
+
JSON.parse(headers_hash.to_json, object_class: OpenStruct)
|
42
|
+
end
|
43
|
+
|
44
|
+
alias resp_headers_os headers_os
|
45
|
+
alias response_headers_os headers_os
|
46
|
+
alias headers_open_struct headers_os
|
47
|
+
alias resp_headers_struct headers_os
|
48
|
+
alias response_headers_open_struct headers_os
|
49
|
+
|
50
|
+
def resp_body
|
51
|
+
body
|
52
|
+
end
|
53
|
+
|
54
|
+
alias response_body resp_body
|
55
|
+
|
56
|
+
def body_hash
|
57
|
+
begin
|
58
|
+
return NetHTTP::Core::Utilities.json_2_hash(body, 'symbol', logger) if valid_json?
|
59
|
+
rescue JSON::ParserError => err
|
60
|
+
logger.debug(err)
|
61
|
+
end
|
62
|
+
begin
|
63
|
+
return NetHTTP::Core::Utilities.xml_2_hash(body, 'symbol', logger) if valid_xml?
|
64
|
+
rescue Nokogiri::XML::SyntaxError => err
|
65
|
+
logger.debug(err)
|
66
|
+
end
|
67
|
+
begin
|
68
|
+
# TODO: update this to work if necessary
|
69
|
+
# probably makes more sense to parse HTML using nokogiri
|
70
|
+
return NetHTTP::Core::Utilities.xml_2_hash(body, 'symbol', logger) if valid_html?
|
71
|
+
rescue Nokogiri::XML::SyntaxError => err
|
72
|
+
logger.debug(err)
|
73
|
+
end
|
74
|
+
|
75
|
+
{}
|
76
|
+
end
|
77
|
+
|
78
|
+
alias resp_body_hash body_hash
|
79
|
+
alias response_body_hash body_hash
|
80
|
+
|
81
|
+
def body_os
|
82
|
+
JSON.parse(body_hash.to_json, object_class: OpenStruct)
|
83
|
+
end
|
84
|
+
|
85
|
+
alias resp_body_os body_os
|
86
|
+
alias response_body_os body_os
|
87
|
+
alias body_open_struct body_os
|
88
|
+
alias resp_body_open_struct body_os
|
89
|
+
alias response_body_open_struct body_os
|
90
|
+
|
91
|
+
def valid_json?
|
92
|
+
NetHTTP::Core::Utilities.valid_json?(body, logger)
|
93
|
+
end
|
94
|
+
|
95
|
+
def valid_xml?
|
96
|
+
NetHTTP::Core::Utilities.valid_xml?(body, logger)
|
97
|
+
end
|
98
|
+
|
99
|
+
def valid_html?
|
100
|
+
NetHTTP::Core::Utilities.valid_html?(body, logger)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
module Net
|
107
|
+
class HTTPResponse
|
108
|
+
include NetHTTP::Core
|
109
|
+
include NetHTTP::Response::Ext
|
110
|
+
end
|
111
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe NetHTTP::Core do
|
4
|
+
it 'returns schema validation errors when invalid options are used to instantiate a NetHTTP client' do
|
5
|
+
client_opts = {}
|
6
|
+
|
7
|
+
expect { NetHTTP.client(client_opts) } .to raise_error('NetHTTP::Core::Error - schema input validation failed.')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns schema validation errors when invalid options are used to instantiate a NetHTTP client with logger' do
|
11
|
+
client_opts = {}
|
12
|
+
logger = Logger.new(STDOUT)
|
13
|
+
logger.level = Logger::INFO
|
14
|
+
client_opts[:logger] = logger
|
15
|
+
|
16
|
+
expect { NetHTTP.client(client_opts) } .to raise_error('NetHTTP::Core::Error - schema input validation failed.')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
describe 'NetHTTP::Request::Ext.call_web_service' do
|
3
|
+
it 'performs a GET request from http://eelslap.com/' do
|
4
|
+
client_opts = {}
|
5
|
+
client_opts[:uri] = 'http://eelslap.com/'
|
6
|
+
client_opts[:use_ssl] = false
|
7
|
+
|
8
|
+
client = NetHTTP.client(client_opts)
|
9
|
+
|
10
|
+
request_opts = {}
|
11
|
+
request_opts[:req_headers] = {}
|
12
|
+
request_opts[:req_method] = 'get'
|
13
|
+
request_opts[:req_path] = '/'
|
14
|
+
|
15
|
+
resp = client.call_web_service(request_opts)
|
16
|
+
|
17
|
+
expect(resp.code).to eq('200')
|
18
|
+
expect(resp.resp_code).to eq('200')
|
19
|
+
expect(resp.headers.empty?).to eq(false)
|
20
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
21
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
22
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
23
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
24
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
25
|
+
expect(resp.valid_html?).to eq(true)
|
26
|
+
expect(NetHTTP::Core.valid_html?(resp.body, nil)).to eq(true)
|
27
|
+
expect(resp.body.empty?).to eq(false)
|
28
|
+
expect(resp.resp_body.empty?).to eq(false)
|
29
|
+
expect(resp.body_hash).to eq({})
|
30
|
+
expect(resp.body_hash.class).to eq(Hash)
|
31
|
+
expect(resp.resp_body_hash).to eq({})
|
32
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'performs a GET request from http://eelslap.com/ with logger' do
|
36
|
+
client_opts = {}
|
37
|
+
client_opts[:uri] = 'http://eelslap.com/'
|
38
|
+
client_opts[:use_ssl] = false
|
39
|
+
|
40
|
+
logger = Logger.new(STDOUT)
|
41
|
+
logger.level = Logger::DEBUG
|
42
|
+
client_opts[:logger] = logger
|
43
|
+
|
44
|
+
client = NetHTTP.client(client_opts)
|
45
|
+
|
46
|
+
request_opts = {}
|
47
|
+
request_opts[:logger] = client.logger
|
48
|
+
request_opts[:req_headers] = {}
|
49
|
+
request_opts[:req_method] = 'get'
|
50
|
+
request_opts[:req_path] = '/'
|
51
|
+
|
52
|
+
resp = client.call_web_service(request_opts)
|
53
|
+
|
54
|
+
expect(resp.code).to eq('200')
|
55
|
+
expect(resp.resp_code).to eq('200')
|
56
|
+
expect(resp.headers.empty?).to eq(false)
|
57
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
58
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
59
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
60
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
61
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
62
|
+
expect(resp.valid_html?).to eq(true)
|
63
|
+
expect(resp.body.empty?).to eq(false)
|
64
|
+
expect(resp.resp_body.empty?).to eq(false)
|
65
|
+
expect(resp.body_hash).to eq({})
|
66
|
+
expect(resp.body_hash.class).to eq(Hash)
|
67
|
+
expect(resp.resp_body_hash).to eq({})
|
68
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'performs a GET request from http://eelslap.com/ without uri' do
|
72
|
+
client_opts = {}
|
73
|
+
client_opts[:host] = 'eelslap.com'
|
74
|
+
client_opts[:port] = 80
|
75
|
+
client_opts[:path] = '/'
|
76
|
+
client_opts[:use_ssl] = false
|
77
|
+
|
78
|
+
logger = Logger.new(STDOUT)
|
79
|
+
logger.level = Logger::INFO
|
80
|
+
client_opts[:logger] = logger
|
81
|
+
|
82
|
+
client = NetHTTP.client(client_opts)
|
83
|
+
|
84
|
+
request_opts = {}
|
85
|
+
request_opts[:logger] = client.logger
|
86
|
+
request_opts[:req_headers] = {}
|
87
|
+
request_opts[:req_method] = 'get'
|
88
|
+
request_opts[:req_path] = '/'
|
89
|
+
|
90
|
+
resp = client.call_web_service(request_opts)
|
91
|
+
|
92
|
+
logger.debug('Response Code => ' + resp.code)
|
93
|
+
logger.debug('Response Headers =>')
|
94
|
+
logger.debug(resp.headers)
|
95
|
+
logger.debug('')
|
96
|
+
logger.debug('Response Body =>')
|
97
|
+
logger.debug(resp.body)
|
98
|
+
logger.debug('')
|
99
|
+
|
100
|
+
expect(resp.code).to eq('200')
|
101
|
+
expect(resp.resp_code).to eq('200')
|
102
|
+
expect(resp.headers.empty?).to eq(false)
|
103
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
104
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
105
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
106
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
107
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
108
|
+
expect(resp.valid_html?).to eq(true)
|
109
|
+
expect(resp.body.empty?).to eq(false)
|
110
|
+
expect(resp.resp_body.empty?).to eq(false)
|
111
|
+
expect(resp.body_hash).to eq({})
|
112
|
+
expect(resp.body_hash.class).to eq(Hash)
|
113
|
+
expect(resp.resp_body_hash).to eq({})
|
114
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'performs a POST request for a valid oAuth token from ESG' do
|
118
|
+
client_opts = {}
|
119
|
+
client_opts[:uri] = 'https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner'
|
120
|
+
client_opts[:use_ssl] = true
|
121
|
+
|
122
|
+
logger = Logger.new(STDOUT)
|
123
|
+
logger.level = Logger::INFO
|
124
|
+
client_opts[:logger] = logger
|
125
|
+
|
126
|
+
client = NetHTTP.client(client_opts)
|
127
|
+
|
128
|
+
request_opts = {}
|
129
|
+
request_opts[:logger] = client.logger
|
130
|
+
request_opts[:req_method] = 'post'
|
131
|
+
request_opts[:req_headers] = {'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'}
|
132
|
+
|
133
|
+
user_id = ENV['USER_ID']
|
134
|
+
password = ENV['PASSWORD']
|
135
|
+
client_id = 'd6bcd5e1-29d7-4ec0-9b96-215b3a317fd6'
|
136
|
+
client_secret = 'e391e6aa-4d60-4470-b351-0f84f11495a8'
|
137
|
+
grant_type = 'password'
|
138
|
+
scope = 'AppIdClaimsTrust'
|
139
|
+
request_opts[:req_body] = "username=#{user_id}&password=#{password}&client_id=#{client_id}&client_secret=#{client_secret}&grant_type=#{grant_type}&scope=#{scope}"
|
140
|
+
request_opts[:req_path] = '/as/resourceOwner'
|
141
|
+
|
142
|
+
resp = client.call_web_service(request_opts)
|
143
|
+
|
144
|
+
expect(resp.code).to eq('200')
|
145
|
+
expect(resp.resp_code).to eq('200')
|
146
|
+
expect(resp.headers.empty?).to eq(false)
|
147
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
148
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
149
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
150
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
151
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
152
|
+
expect(resp.valid_json?).to eq(true)
|
153
|
+
expect(resp.body.empty?).to eq(false)
|
154
|
+
expect(resp.resp_body.empty?).to eq(false)
|
155
|
+
expect(resp.body_hash.empty?).to eq(false)
|
156
|
+
expect(resp.body_hash.class).to eq(Hash)
|
157
|
+
expect(resp.resp_body_hash.empty?).to eq(false)
|
158
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'performs a POST request for a valid oAuth token from ESG with scheme without uri' do
|
162
|
+
client_opts = {}
|
163
|
+
client_opts[:use_ssl] = true
|
164
|
+
client_opts[:scheme] = 'https'
|
165
|
+
client_opts[:host] = 'esg-qa-oauth2-internal.fmr.com'
|
166
|
+
client_opts[:path] = '/as/resourceOwner'
|
167
|
+
|
168
|
+
logger = Logger.new(STDOUT)
|
169
|
+
logger.level = Logger::INFO
|
170
|
+
client_opts[:logger] = logger
|
171
|
+
|
172
|
+
client = NetHTTP.client(client_opts)
|
173
|
+
|
174
|
+
request_opts = {}
|
175
|
+
request_opts[:logger] = client.logger
|
176
|
+
request_opts[:req_method] = 'post'
|
177
|
+
request_opts[:req_headers] = {'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'}
|
178
|
+
|
179
|
+
user_id = ENV['USER_ID']
|
180
|
+
password = ENV['PASSWORD']
|
181
|
+
client_id = 'd6bcd5e1-29d7-4ec0-9b96-215b3a317fd6'
|
182
|
+
client_secret = 'e391e6aa-4d60-4470-b351-0f84f11495a8'
|
183
|
+
grant_type = 'password'
|
184
|
+
scope = 'AppIdClaimsTrust'
|
185
|
+
request_opts[:req_body] = "username=#{user_id}&password=#{password}&client_id=#{client_id}&client_secret=#{client_secret}&grant_type=#{grant_type}&scope=#{scope}"
|
186
|
+
request_opts[:req_path] = '/as/resourceOwner'
|
187
|
+
|
188
|
+
resp = client.call_web_service(request_opts)
|
189
|
+
|
190
|
+
expect(resp.code).to eq('200')
|
191
|
+
expect(resp.resp_code).to eq('200')
|
192
|
+
expect(resp.headers.empty?).to eq(false)
|
193
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
194
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
195
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
196
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
197
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
198
|
+
expect(resp.valid_json?).to eq(true)
|
199
|
+
expect(resp.body.empty?).to eq(false)
|
200
|
+
expect(resp.resp_body.empty?).to eq(false)
|
201
|
+
expect(resp.body_hash.empty?).to eq(false)
|
202
|
+
expect(resp.body_hash.class).to eq(Hash)
|
203
|
+
expect(resp.resp_body_hash.empty?).to eq(false)
|
204
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'performs a POST request for a valid oAuth token from ESG without scheme without uri' do
|
208
|
+
client_opts = {}
|
209
|
+
client_opts[:use_ssl] = true
|
210
|
+
client_opts[:host] = 'esg-qa-oauth2-internal.fmr.com'
|
211
|
+
client_opts[:port] = 443
|
212
|
+
client_opts[:path] = '/as/resourceOwner'
|
213
|
+
|
214
|
+
logger = Logger.new(STDOUT)
|
215
|
+
logger.level = Logger::INFO
|
216
|
+
client_opts[:logger] = logger
|
217
|
+
|
218
|
+
client = NetHTTP.client(client_opts)
|
219
|
+
|
220
|
+
request_opts = {}
|
221
|
+
request_opts[:logger] = client.logger
|
222
|
+
request_opts[:req_method] = 'post'
|
223
|
+
request_opts[:req_headers] = {'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'}
|
224
|
+
|
225
|
+
user_id = ENV['USER_ID']
|
226
|
+
password = ENV['PASSWORD']
|
227
|
+
client_id = 'd6bcd5e1-29d7-4ec0-9b96-215b3a317fd6'
|
228
|
+
client_secret = 'e391e6aa-4d60-4470-b351-0f84f11495a8'
|
229
|
+
grant_type = 'password'
|
230
|
+
scope = 'AppIdClaimsTrust'
|
231
|
+
request_opts[:req_body] = "username=#{user_id}&password=#{password}&client_id=#{client_id}&client_secret=#{client_secret}&grant_type=#{grant_type}&scope=#{scope}"
|
232
|
+
request_opts[:req_path] = '/as/resourceOwner'
|
233
|
+
|
234
|
+
resp = client.call_web_service(request_opts)
|
235
|
+
|
236
|
+
expect(resp.code).to eq('200')
|
237
|
+
expect(resp.resp_code).to eq('200')
|
238
|
+
expect(resp.headers.empty?).to eq(false)
|
239
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
240
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
241
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
242
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
243
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
244
|
+
expect(resp.valid_json?).to eq(true)
|
245
|
+
expect(resp.body.empty?).to eq(false)
|
246
|
+
expect(resp.resp_body.empty?).to eq(false)
|
247
|
+
expect(resp.body_hash.empty?).to eq(false)
|
248
|
+
expect(resp.body_hash.class).to eq(Hash)
|
249
|
+
expect(resp.resp_body_hash.empty?).to eq(false)
|
250
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'performs a POST request to MAUI to retrieve account users using ssl and cert' do
|
254
|
+
client_opts = {}
|
255
|
+
client_opts[:uri] = 'https://alpha-mmk.fmr.com:9980/XML_FEB_S_A'
|
256
|
+
client_opts[:ssl_path] = '/apps/security'
|
257
|
+
client_opts[:ca_file] = 'cacert.pem'
|
258
|
+
client_opts[:pkcs12_file] = 'dev-b2b-fidcom.p12'
|
259
|
+
client_opts[:pkcs12_passphrase] = ENV['PKCS12_PASSPHRASE']
|
260
|
+
client_opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
|
261
|
+
|
262
|
+
# logger = Logger.new(STDOUT)
|
263
|
+
# logger.level = Logger::DEBUG
|
264
|
+
# client_opts[:logger] = logger
|
265
|
+
|
266
|
+
client = NetHTTP.client(client_opts)
|
267
|
+
|
268
|
+
req_opts = {}
|
269
|
+
req_opts[:req_method] = 'post'
|
270
|
+
req_opts[:req_headers] = {'Content-Type' => 'application/xml'}
|
271
|
+
req_opts[:req_body] = '<?xml version="1.0" encoding="utf-16"?>
|
272
|
+
<DCLCUST0_REQUEST>
|
273
|
+
<PSL_VIEW>DCLCUST0.VIEW</PSL_VIEW>
|
274
|
+
<REQUESTOR_ID>024300218</REQUESTOR_ID>
|
275
|
+
<PRODUCT_ID>W</PRODUCT_ID>
|
276
|
+
<MESSAGE_TYPE>F</MESSAGE_TYPE>
|
277
|
+
<FUNCTION_INDICATOR>V</FUNCTION_INDICATOR>
|
278
|
+
<PARTITION_ID>RETAIL</PARTITION_ID>
|
279
|
+
<RELATIONSHIP_TYPE/>
|
280
|
+
<INCLUDE_4P_REL>Y</INCLUDE_4P_REL>
|
281
|
+
<PRM_KEY_TYPE>B</PRM_KEY_TYPE>
|
282
|
+
<PRIMARY_KEY>X01000833</PRIMARY_KEY>
|
283
|
+
<RETURN_PRODUCT_G_NBR_IND/>
|
284
|
+
<INPUT_VIEW>
|
285
|
+
<PAGING>
|
286
|
+
<PAGING_MAX_COUNT>All</PAGING_MAX_COUNT>
|
287
|
+
<PAGING_DIRECTION>F</PAGING_DIRECTION>
|
288
|
+
<PAGING_CONTINUATION_KEY/>
|
289
|
+
</PAGING>
|
290
|
+
</INPUT_VIEW>
|
291
|
+
</DCLCUST0_REQUEST>'
|
292
|
+
|
293
|
+
resp = client.call_web_service(req_opts)
|
294
|
+
|
295
|
+
expect(resp.code).to eq('200')
|
296
|
+
expect(resp.resp_code).to eq('200')
|
297
|
+
expect(resp.headers.empty?).to eq(false)
|
298
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
299
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
300
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
301
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
302
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
303
|
+
expect(resp.valid_xml?).to eq(true)
|
304
|
+
expect(resp.body.empty?).to eq(false)
|
305
|
+
expect(resp.resp_body.empty?).to eq(false)
|
306
|
+
expect(resp.body_hash.empty?).to eq(false)
|
307
|
+
expect(resp.body_hash.class).to eq(Hash)
|
308
|
+
expect(resp.resp_body_hash.empty?).to eq(false)
|
309
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
310
|
+
end
|
311
|
+
it 'performs a GET request from http://eelslap.com/ with query' do
|
312
|
+
client_opts = {}
|
313
|
+
client_opts[:uri] = 'http://eelslap.com/?req=aaaa'
|
314
|
+
client_opts[:use_ssl] = false
|
315
|
+
|
316
|
+
client = NetHTTP.client(client_opts)
|
317
|
+
|
318
|
+
request_opts = {}
|
319
|
+
request_opts[:req_headers] = {}
|
320
|
+
request_opts[:req_method] = 'get'
|
321
|
+
request_opts[:req_path] = '/?req=aaaa'
|
322
|
+
resp = client.call_web_service(request_opts)
|
323
|
+
|
324
|
+
expect(resp.code).to eq('200')
|
325
|
+
expect(resp.resp_code).to eq('200')
|
326
|
+
expect(resp.headers.empty?).to eq(false)
|
327
|
+
expect(resp.resp_headers.empty?).to eq(false)
|
328
|
+
expect(resp.headers_hash.empty?).to eq(false)
|
329
|
+
expect(resp.headers_hash.class).to eq(Hash)
|
330
|
+
expect(resp.resp_headers_hash.empty?).to eq(false)
|
331
|
+
expect(resp.resp_headers_hash.class).to eq(Hash)
|
332
|
+
expect(resp.valid_html?).to eq(true)
|
333
|
+
expect(NetHTTP::Core.valid_html?(resp.body, nil)).to eq(true)
|
334
|
+
expect(resp.body.empty?).to eq(false)
|
335
|
+
expect(resp.resp_body.empty?).to eq(false)
|
336
|
+
expect(resp.body_hash).to eq({})
|
337
|
+
expect(resp.body_hash.class).to eq(Hash)
|
338
|
+
expect(resp.resp_body_hash).to eq({})
|
339
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
340
|
+
expect(resp.resp_body_hash.class).to eq(Hash)
|
341
|
+
end
|
342
|
+
end
|