rb-net_http-client 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/client/client.rb +10 -14
- data/lib/client/ext.rb +39 -31
- data/lib/client/schema.rb +21 -8
- data/lib/core/core.rb +16 -5
- data/lib/core/utilities.rb +57 -37
- data/lib/request/request.rb +51 -24
- data/lib/request/schema.rb +7 -0
- data/lib/response/response.rb +48 -30
- data/lib/version.rb +1 -1
- data/spec/unit/client/client_spec.rb +47 -0
- data/spec/unit/client/ext_spec.rb +90 -0
- data/spec/unit/core/core_spec.rb +47 -0
- data/spec/unit/core/utilities_spec.rb +230 -0
- data/spec/unit/request/request_spec.rb +275 -0
- data/spec/unit/response/response_spec.rb +39 -0
- data/spec/{integration/net_http → unit}/version_spec.rb +1 -1
- metadata +9 -17
- data/lib/response/schema.rb +0 -11
- data/spec/integration/net_http/client/client_ext_spec.rb +0 -7
- data/spec/integration/net_http/client/client_spec.rb +0 -7
- data/spec/integration/net_http/net_http_core_spec.rb +0 -18
- data/spec/integration/net_http/request/request_ext_spec.rb +0 -342
- data/spec/integration/net_http/response/response_ext_spec.rb +0 -7
- data/spec/unit/net_http/client/client_ext_spec.rb +0 -7
- data/spec/unit/net_http/client/client_schema_spec.rb +0 -8
- data/spec/unit/net_http/client/client_spec.rb +0 -232
- data/spec/unit/net_http/net_http_core_spec.rb +0 -433
- data/spec/unit/net_http/request/request_ext_spec.rb +0 -603
- data/spec/unit/net_http/request/request_schema_spec.rb +0 -8
- data/spec/unit/net_http/response/response_ext_spec.rb +0 -97
- data/spec/unit/net_http/version_spec.rb +0 -10
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'webmock/rspec'
|
2
|
-
require_relative '../../../spec_helper'
|
3
|
-
|
4
|
-
describe NetHTTP::Response::Ext do
|
5
|
-
it 'performs a POST request for a valid oAuth token from ESG' do
|
6
|
-
stub_request(:post, 'https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner').
|
7
|
-
with(body: successful_post_request_token_req_body,
|
8
|
-
headers: { 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' }).
|
9
|
-
to_return(status: 200,
|
10
|
-
body: successful_post_request_token_resp_body,
|
11
|
-
headers: { 'date' => ['Thu, 10 Aug 2017 14:09:19 GMT'],
|
12
|
-
'server' => [''],
|
13
|
-
'connection' => ['close'],
|
14
|
-
'x-correlationid' => ['Id-0f698c59b97c8df3c572145c 0'],
|
15
|
-
'accept' => ['*/*'],
|
16
|
-
'host' => ['esg-qa-oauth2-internal.fmr.com'],
|
17
|
-
'user-agent' => ['Ruby'],
|
18
|
-
'cache-control' => ['no-store'],
|
19
|
-
'content-type' => ['application/json'],
|
20
|
-
'pragma' => ['no-cache'] })
|
21
|
-
|
22
|
-
client = NetHTTP.client(post_request_token_client_opts)
|
23
|
-
resp = client.call_web_service(post_request_token_req_opts)
|
24
|
-
|
25
|
-
expect(resp.methods.include?(:logger)).to eq(true)
|
26
|
-
expect(resp.methods.include?(:resp_body)).to eq(true)
|
27
|
-
expect(resp.methods.include?(:resp_code)).to eq(true)
|
28
|
-
expect(resp.methods.include?(:headers)).to eq(true)
|
29
|
-
expect(resp.methods.include?(:headers_hash)).to eq(true)
|
30
|
-
expect(resp.methods.include?(:body_hash)).to eq(true)
|
31
|
-
expect(resp.methods.include?(:valid_json?)).to eq(true)
|
32
|
-
expect(resp.methods.include?(:valid_xml?)).to eq(true)
|
33
|
-
expect(resp.methods.include?(:valid_html?)).to eq(true)
|
34
|
-
expect(resp.methods.include?(:resp_headers)).to eq(true)
|
35
|
-
expect(resp.methods.include?(:resp_headers_hash)).to eq(true)
|
36
|
-
expect(resp.methods.include?(:resp_body_hash)).to eq(true)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'the logger object is maintained from client to core object' do
|
40
|
-
stub_request(:post, 'https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner').
|
41
|
-
with(body: successful_post_request_token_req_body,
|
42
|
-
headers: { 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' }).
|
43
|
-
to_return(status: 200,
|
44
|
-
body: successful_post_request_token_resp_body,
|
45
|
-
headers: { 'date' => ['Thu, 10 Aug 2017 14:09:19 GMT'],
|
46
|
-
'server' => [''],
|
47
|
-
'connection' => ['close'],
|
48
|
-
'x-correlationid' => ['Id-0f698c59b97c8df3c572145c 0'],
|
49
|
-
'accept' => ['*/*'],
|
50
|
-
'host' => ['esg-qa-oauth2-internal.fmr.com'],
|
51
|
-
'user-agent' => ['Ruby'],
|
52
|
-
'cache-control' => ['no-store'],
|
53
|
-
'content-type' => ['application/json'],
|
54
|
-
'pragma' => ['no-cache'] })
|
55
|
-
|
56
|
-
client = NetHTTP.client(post_request_token_client_opts)
|
57
|
-
resp = client.call_web_service(post_request_token_req_opts)
|
58
|
-
|
59
|
-
expect(client.logger == resp.logger).to eq(false)
|
60
|
-
expect(client.logger.class).to eq(Logger)
|
61
|
-
expect(resp.logger.class).to eq(Logger)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
# post
|
67
|
-
def post_request_token_client_opts
|
68
|
-
opts = {}
|
69
|
-
opts[:uri] = 'https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner'
|
70
|
-
opts
|
71
|
-
end
|
72
|
-
|
73
|
-
def post_request_token_req_opts
|
74
|
-
opts = {}
|
75
|
-
|
76
|
-
user_id = ENV['USER_ID']
|
77
|
-
password = ENV['PASSWORD']
|
78
|
-
client_id = 'd6bcd5e1-29d7-4ec0-9b96-215b3a317fd6'
|
79
|
-
client_secret = 'e391e6aa-4d60-4470-b351-0f84f11495a8'
|
80
|
-
grant_type = 'password'
|
81
|
-
scope = 'AppIdClaimsTrust'
|
82
|
-
|
83
|
-
opts[:req_method] = 'post'
|
84
|
-
opts[:req_headers] = { 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' }
|
85
|
-
opts[:req_body] = "username=#{user_id}&password=#{password}&client_id=#{client_id}&client_secret=#{client_secret}&grant_type=#{grant_type}&scope=#{scope}"
|
86
|
-
opts[:req_path] = '/as/resourceOwner'
|
87
|
-
opts
|
88
|
-
end
|
89
|
-
|
90
|
-
def successful_post_request_token_req_body
|
91
|
-
"username=#{ENV['USER_ID']}&password=#{ENV['PASSWORD']}&client_id=d6bcd5e1-29d7-4ec0-9b96-215b3a317fd6&client_secret=e391e6aa-4d60-4470-b351-0f84f11495a8&grant_type=password&scope=AppIdClaimsTrust"
|
92
|
-
end
|
93
|
-
|
94
|
-
def successful_post_request_token_resp_body
|
95
|
-
'{"access_token":"l3k0QJfU3k6L0XXyfe5MJBjy5672hgau6aJA1BMAwYDwmVkeK00M7h","token_type":"Bearer","expires_in":43201,"refresh_token":"x9gvXcGF1zKD4ZpwYA6T9n9vHdc5CB1xednEPPIqU6yWic","scope":"AppIdClaimsTrust","Environment":"QA","secondLvlAuthzId":"","webAuthAppID":"AP118499"}'
|
96
|
-
end
|
97
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
describe NetHTTP::VERSION do
|
4
|
-
it 'should have a valid version' do
|
5
|
-
expect(NetHTTP::VERSION.nil?).to eq(false)
|
6
|
-
expect(NetHTTP::VERSION.empty?).to eq(false)
|
7
|
-
expect(NetHTTP::VERSION.class).to eq(String)
|
8
|
-
expect(NetHTTP::VERSION.frozen?).to eq(true)
|
9
|
-
end
|
10
|
-
end
|