manticore 0.7.0-java → 0.9.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -8
- data/CHANGELOG.md +23 -1
- data/Gemfile +9 -7
- data/README.md +18 -5
- data/Rakefile +2 -0
- data/lib/commons-codec/commons-codec/1.15/commons-codec-1.15.jar +0 -0
- data/lib/manticore/client/trust_strategies.rb +119 -0
- data/lib/manticore/client.rb +115 -50
- data/lib/manticore/response.rb +12 -12
- data/lib/manticore/version.rb +1 -1
- data/lib/manticore.rb +27 -2
- data/lib/manticore_jars.rb +16 -6
- data/lib/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar +0 -0
- data/lib/org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar +0 -0
- data/lib/org/apache/httpcomponents/httpmime/4.5.13/httpmime-4.5.13.jar +0 -0
- data/lib/org/manticore/manticore-ext.jar +0 -0
- data/manticore.gemspec +5 -5
- data/spec/manticore/client_spec.rb +73 -16
- data/spec/manticore/client_trust_strategies_spec.rb +168 -0
- data/spec/manticore/response_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +16 -41
- data/lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar +0 -0
- data/lib/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar +0 -0
- data/lib/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.jar +0 -0
- data/lib/org/apache/httpcomponents/httpmime/4.5.2/httpmime-4.5.2.jar +0 -0
data/lib/manticore/version.rb
CHANGED
data/lib/manticore.rb
CHANGED
@@ -5,7 +5,11 @@ require "cgi"
|
|
5
5
|
require_relative "./manticore_jars.rb"
|
6
6
|
require_relative "./org/manticore/manticore-ext"
|
7
7
|
|
8
|
-
|
8
|
+
if defined? JRuby::Util.load_ext
|
9
|
+
JRuby::Util.load_ext 'org.manticore.Manticore'
|
10
|
+
else
|
11
|
+
org.manticore.Manticore.new.load(JRuby.runtime, false)
|
12
|
+
end
|
9
13
|
|
10
14
|
require_relative "./manticore/version"
|
11
15
|
|
@@ -13,7 +17,27 @@ require_relative "./manticore/version"
|
|
13
17
|
# with the beauty of Ruby.
|
14
18
|
module Manticore
|
15
19
|
# General base class for all Manticore exceptions
|
16
|
-
class ManticoreException < StandardError
|
20
|
+
class ManticoreException < StandardError
|
21
|
+
def initialize(arg = nil)
|
22
|
+
case arg
|
23
|
+
when nil
|
24
|
+
@_cause = nil
|
25
|
+
super()
|
26
|
+
when java.lang.Throwable
|
27
|
+
@_cause = arg
|
28
|
+
super(arg.message)
|
29
|
+
else
|
30
|
+
@_cause = nil
|
31
|
+
super(arg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return cause which is likely to be a Java exception
|
36
|
+
# @overload Exception#cause
|
37
|
+
def cause
|
38
|
+
@_cause || super
|
39
|
+
end
|
40
|
+
end
|
17
41
|
|
18
42
|
# Exception thrown if you attempt to read from a closed Response stream
|
19
43
|
class StreamClosedException < ManticoreException; end
|
@@ -43,6 +67,7 @@ module Manticore
|
|
43
67
|
|
44
68
|
require_relative "./manticore/java_extensions"
|
45
69
|
require_relative "./manticore/client/proxies"
|
70
|
+
require_relative "./manticore/client/trust_strategies"
|
46
71
|
require_relative "./manticore/client"
|
47
72
|
require_relative "./manticore/response"
|
48
73
|
require_relative "./manticore/stubbed_response"
|
data/lib/manticore_jars.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
# this is a generated file, to avoid over-writing it just delete this comment
|
2
|
-
|
2
|
+
begin
|
3
|
+
require 'jar_dependencies'
|
4
|
+
rescue LoadError
|
5
|
+
require 'commons-logging/commons-logging/1.2/commons-logging-1.2.jar'
|
6
|
+
require 'commons-codec/commons-codec/1.15/commons-codec-1.15.jar'
|
7
|
+
require 'org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar'
|
8
|
+
require 'org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar'
|
9
|
+
require 'org/apache/httpcomponents/httpmime/4.5.13/httpmime-4.5.13.jar'
|
10
|
+
end
|
3
11
|
|
4
|
-
|
5
|
-
require_jar
|
6
|
-
require_jar
|
7
|
-
require_jar
|
8
|
-
require_jar
|
12
|
+
if defined? Jars
|
13
|
+
require_jar 'commons-logging', 'commons-logging', '1.2'
|
14
|
+
require_jar 'commons-codec', 'commons-codec', '1.15'
|
15
|
+
require_jar 'org.apache.httpcomponents', 'httpcore', '4.4.14'
|
16
|
+
require_jar 'org.apache.httpcomponents', 'httpclient', '4.5.13'
|
17
|
+
require_jar 'org.apache.httpcomponents', 'httpmime', '4.5.13'
|
18
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/manticore.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 2.3' # JRuby >= 9.1
|
23
|
+
|
22
24
|
private_key = File.expand_path("~/.gemcert/gem-private_key.pem")
|
23
25
|
if File.exists? private_key
|
24
26
|
spec.signing_key = private_key
|
@@ -27,13 +29,11 @@ Gem::Specification.new do |spec|
|
|
27
29
|
|
28
30
|
spec.add_dependency "openssl_pkcs8_pure"
|
29
31
|
|
30
|
-
spec.add_development_dependency "bundler"
|
31
|
-
spec.add_development_dependency "rake"
|
32
32
|
spec.add_development_dependency "jar-dependencies", "~> 0.4.1"
|
33
33
|
|
34
|
-
spec.requirements << "jar org.apache.httpcomponents:httpclient, '~> 4.5.
|
35
|
-
spec.requirements << "jar org.apache.httpcomponents:httpmime, '~> 4.5.
|
34
|
+
spec.requirements << "jar org.apache.httpcomponents:httpclient, '~> 4.5.13'"
|
35
|
+
spec.requirements << "jar org.apache.httpcomponents:httpmime, '~> 4.5.13'"
|
36
36
|
spec.requirements << "jar commons-logging:commons-logging, '~> 1.2'"
|
37
37
|
spec.requirements << "jar commons-codec:commons-codec, '~> 1.9'"
|
38
|
-
spec.requirements << "jar org.apache.httpcomponents:httpcore, '~> 4.4.
|
38
|
+
spec.requirements << "jar org.apache.httpcomponents:httpcore, '~> 4.4.14'"
|
39
39
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
|
-
java_import "org.apache.http.entity.mime.MultipartEntityBuilder"
|
5
|
-
java_import "org.apache.http.entity.ContentType"
|
6
|
-
|
7
4
|
describe Manticore::Client do
|
8
5
|
let(:client) { Manticore::Client.new }
|
9
6
|
|
7
|
+
after { client.close }
|
8
|
+
|
10
9
|
it "fetches a URL and return a response" do
|
11
10
|
expect(client.get(local_server)).to be_a Manticore::Response
|
12
11
|
end
|
@@ -96,7 +95,7 @@ describe Manticore::Client do
|
|
96
95
|
|
97
96
|
describe "ignore_ssl_validation (deprecated option)" do
|
98
97
|
context "when on" do
|
99
|
-
let(:client) { Manticore::Client.new ssl: {verify: false} }
|
98
|
+
let(:client) { Manticore::Client.new ssl: { verify: false } }
|
100
99
|
|
101
100
|
it "does not break on SSL validation errors" do
|
102
101
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
@@ -104,7 +103,7 @@ describe Manticore::Client do
|
|
104
103
|
end
|
105
104
|
|
106
105
|
context "when off" do
|
107
|
-
let(:client) { Manticore::Client.new ssl: {verify: true} }
|
106
|
+
let(:client) { Manticore::Client.new ssl: { verify: true } }
|
108
107
|
|
109
108
|
it "breaks on SSL validation errors" do
|
110
109
|
expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
|
@@ -130,7 +129,13 @@ describe Manticore::Client do
|
|
130
129
|
let(:client) { Manticore::Client.new :ssl => {:verify => :strict} }
|
131
130
|
|
132
131
|
it "breaks on SSL validation errors" do
|
133
|
-
|
132
|
+
begin
|
133
|
+
client.get("https://localhost:55445/").body
|
134
|
+
rescue Manticore::ClientProtocolException => e
|
135
|
+
expect( e.cause ).to be_a javax.net.ssl.SSLHandshakeException
|
136
|
+
else
|
137
|
+
fail "exception not raised"
|
138
|
+
end
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
@@ -142,6 +147,29 @@ describe Manticore::Client do
|
|
142
147
|
end
|
143
148
|
end
|
144
149
|
|
150
|
+
context "when on and custom trust strategy is given" do
|
151
|
+
# let(:custom_trust_strategy) { Proc.new {|chain,type| true } }
|
152
|
+
let(:client) { Manticore::Client.new :ssl => {:verify => :strict, :trust_strategy => custom_trust_strategy} }
|
153
|
+
context 'and trust strategy approves the cert chain' do
|
154
|
+
let(:custom_trust_strategy) { Proc.new { |chain,type| true } }
|
155
|
+
it "verifies the request and succeed" do
|
156
|
+
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
157
|
+
end
|
158
|
+
end
|
159
|
+
context 'and trust strategy does not approve the cert chain' do
|
160
|
+
let(:custom_trust_strategy) { Proc.new { |chain,type| false } }
|
161
|
+
it "breaks on SSL validation errors" do
|
162
|
+
begin
|
163
|
+
client.get("https://localhost:55445/").body
|
164
|
+
rescue Manticore::ClientProtocolException => e
|
165
|
+
expect( e.cause ).to be_a javax.net.ssl.SSLHandshakeException
|
166
|
+
else
|
167
|
+
fail "exception not raised"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
145
173
|
context "when the client specifies a protocol list" do
|
146
174
|
let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "test123", protocols: ["TLSv1", "TLSv1.1", "TLSv1.2"]} }
|
147
175
|
|
@@ -151,10 +179,10 @@ describe Manticore::Client do
|
|
151
179
|
end
|
152
180
|
|
153
181
|
context "when on and custom trust store is given with the wrong password" do
|
154
|
-
let(:
|
182
|
+
let(:ssl_opts) { { verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "wrongpass" } }
|
155
183
|
|
156
184
|
it "fails to load the keystore" do
|
157
|
-
expect {
|
185
|
+
expect { Manticore::Client.new(:ssl => ssl_opts) }.to raise_exception(Java::JavaIo::IOException)
|
158
186
|
end
|
159
187
|
end
|
160
188
|
|
@@ -187,7 +215,7 @@ describe Manticore::Client do
|
|
187
215
|
let(:client) {
|
188
216
|
Manticore::Client.new(
|
189
217
|
:ssl => {
|
190
|
-
verify: :
|
218
|
+
verify: :default,
|
191
219
|
ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__),
|
192
220
|
client_cert: OpenSSL::X509::Certificate.new(File.read(File.expand_path("../../ssl/client.crt", __FILE__))),
|
193
221
|
client_key: OpenSSL::PKey::RSA.new(File.read(File.expand_path("../../ssl/client.key", __FILE__))),
|
@@ -204,7 +232,7 @@ describe Manticore::Client do
|
|
204
232
|
let(:client) {
|
205
233
|
Manticore::Client.new(
|
206
234
|
:ssl => {
|
207
|
-
verify: :
|
235
|
+
verify: :default,
|
208
236
|
ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__),
|
209
237
|
client_cert: File.read(File.expand_path("../../ssl/client.crt", __FILE__)),
|
210
238
|
client_key: File.read(File.expand_path("../../ssl/client.key", __FILE__)),
|
@@ -227,6 +255,27 @@ describe Manticore::Client do
|
|
227
255
|
it "does not break on expired SSL certificates" do
|
228
256
|
expect { client.get("https://localhost:55446/").body }.to_not raise_exception
|
229
257
|
end
|
258
|
+
|
259
|
+
it "does not break on untrusted certificates" do
|
260
|
+
expect { client.get("https://localhost:55447/").body }.to_not raise_exception
|
261
|
+
end
|
262
|
+
|
263
|
+
context "when custom trust strategy is given" do
|
264
|
+
# let(:custom_trust_strategy) { Proc.new {|chain,type| true } }
|
265
|
+
let(:client) { Manticore::Client.new :ssl => {:verify => :disable, :trust_strategy => custom_trust_strategy} }
|
266
|
+
context 'and trust strategy approves the cert chain' do
|
267
|
+
let(:custom_trust_strategy) { Proc.new { |chain,type| true } }
|
268
|
+
it "verifies the request and succeed" do
|
269
|
+
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
270
|
+
end
|
271
|
+
end
|
272
|
+
context 'and trust strategy does not approve the cert chain' do
|
273
|
+
let(:custom_trust_strategy) { Proc.new { |chain,type| false } }
|
274
|
+
it "verifies the request and succeed" do
|
275
|
+
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
230
279
|
end
|
231
280
|
|
232
281
|
context "against a server that verifies clients" do
|
@@ -266,11 +315,11 @@ describe Manticore::Client do
|
|
266
315
|
end
|
267
316
|
|
268
317
|
describe ":cipher_suites" do
|
269
|
-
skip
|
318
|
+
skip 'TODO: someone should write the spec'
|
270
319
|
end
|
271
320
|
|
272
321
|
describe ":protocols" do
|
273
|
-
skip
|
322
|
+
skip 'TODO: someone should write the spec'
|
274
323
|
end
|
275
324
|
end
|
276
325
|
|
@@ -525,7 +574,9 @@ describe Manticore::Client do
|
|
525
574
|
|
526
575
|
it "sends an arbitrary entity" do
|
527
576
|
f = open(File.expand_path(File.join(__FILE__, "..", "..", "spec_helper.rb")), "r").to_inputstream
|
528
|
-
multipart_entity = MultipartEntityBuilder.create.
|
577
|
+
multipart_entity = org.apache.http.entity.mime.MultipartEntityBuilder.create.
|
578
|
+
add_text_body("foo", "bar").
|
579
|
+
add_binary_body("whatever", f, org.apache.http.entity.ContentType::TEXT_PLAIN, __FILE__)
|
529
580
|
response = client.post(local_server, entity: multipart_entity.build)
|
530
581
|
expect(response.body).to match "RSpec.configure"
|
531
582
|
end
|
@@ -736,14 +787,13 @@ describe Manticore::Client do
|
|
736
787
|
context "with a misbehaving endpoint" do
|
737
788
|
let(:port) do
|
738
789
|
p = 4000
|
739
|
-
server = nil
|
740
790
|
begin
|
741
791
|
server = TCPServer.new p
|
742
792
|
rescue Errno::EADDRINUSE
|
743
793
|
p += 1
|
744
794
|
retry
|
745
795
|
ensure
|
746
|
-
server
|
796
|
+
server&.close
|
747
797
|
end
|
748
798
|
p
|
749
799
|
end
|
@@ -764,6 +814,7 @@ describe Manticore::Client do
|
|
764
814
|
].join("\n"))
|
765
815
|
client.close
|
766
816
|
rescue IOError => e
|
817
|
+
warn "caught an error: #{e.inspect}"
|
767
818
|
break
|
768
819
|
end
|
769
820
|
end
|
@@ -830,7 +881,13 @@ describe Manticore::Client do
|
|
830
881
|
let(:client) { Manticore::Client.new request_timeout: 1, connect_timeout: 1, socket_timeout: 1 }
|
831
882
|
|
832
883
|
it "times out" do
|
833
|
-
|
884
|
+
begin
|
885
|
+
client.get(local_server "/?sleep=2").body
|
886
|
+
rescue Manticore::SocketTimeout => e
|
887
|
+
expect( e.cause ).to be_a java.net.SocketTimeoutException
|
888
|
+
else
|
889
|
+
fail "exception not raised"
|
890
|
+
end
|
834
891
|
end
|
835
892
|
|
836
893
|
it "times out when custom request options are passed" do
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
describe Manticore::Client::TrustStrategies do
|
4
|
+
describe '#coerce' do
|
5
|
+
subject(:coerced) { described_class.coerce(input) }
|
6
|
+
context 'with a nil value' do
|
7
|
+
let(:input) { nil }
|
8
|
+
it 'returns the value unchanged' do
|
9
|
+
expect(coerced).to be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context 'with an implementation of org.apache.http.conn.ssl.TrustStrategy' do
|
13
|
+
let(:input) { org.apache.http.conn.ssl.TrustAllStrategy::INSTANCE }
|
14
|
+
it 'returns the value unchanged' do
|
15
|
+
expect(coerced).to be input
|
16
|
+
end
|
17
|
+
end
|
18
|
+
context 'with a Proc' do
|
19
|
+
let(:input) { ->(chain, type) { true } }
|
20
|
+
it 'wraps the proc in a `CustomTrustStrategy`' do
|
21
|
+
expect(Manticore::Client::CustomTrustStrategy).to receive(:new).with(input).and_call_original
|
22
|
+
expect(described_class.coerce(input)).to be_a_kind_of Manticore::Client::CustomTrustStrategy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#combine' do
|
28
|
+
context 'when left-hand value is nil' do
|
29
|
+
let(:left_hand_strategy) { nil }
|
30
|
+
let(:right_hand_strategy) { described_class.coerce(->(chain,type){ true }) }
|
31
|
+
it 'returns the right-hand value coerced' do
|
32
|
+
expect(described_class).to receive(:coerce).with(right_hand_strategy).and_call_original
|
33
|
+
expect(described_class.combine(left_hand_strategy, right_hand_strategy)).to be right_hand_strategy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context 'when the right-hand value is nil' do
|
37
|
+
let(:left_hand_strategy) { described_class.coerce(->(chain,type){ true }) }
|
38
|
+
let(:right_hand_strategy) { nil }
|
39
|
+
it 'returns the left-hand value coerced' do
|
40
|
+
expect(described_class).to receive(:coerce).with(left_hand_strategy).and_call_original
|
41
|
+
expect(described_class.combine(left_hand_strategy, right_hand_strategy)).to be left_hand_strategy
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'when neither value is nil' do
|
45
|
+
let(:left_hand_strategy) { described_class.coerce(->(chain,type){ true }) }
|
46
|
+
let(:right_hand_strategy) { described_class.coerce(->(chain,type){ true }) }
|
47
|
+
|
48
|
+
it 'returns a CombinedTrustStrategy' do
|
49
|
+
expect(Manticore::Client::CombinedTrustStrategy)
|
50
|
+
.to receive(:new).with(left_hand_strategy, right_hand_strategy).and_call_original
|
51
|
+
|
52
|
+
# ensures that the values are coerced.
|
53
|
+
expect(described_class).to receive(:coerce).with(left_hand_strategy).and_call_original
|
54
|
+
expect(described_class).to receive(:coerce).with(right_hand_strategy).and_call_original
|
55
|
+
|
56
|
+
combined = described_class.combine(left_hand_strategy, right_hand_strategy)
|
57
|
+
expect(combined).to be_a_kind_of Manticore::Client::CombinedTrustStrategy
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'when both values are nil' do
|
61
|
+
let(:left_hand_strategy) { nil }
|
62
|
+
let(:right_hand_strategy) { nil }
|
63
|
+
|
64
|
+
it 'returns nil' do
|
65
|
+
expect(described_class.combine(left_hand_strategy, right_hand_strategy)).to be nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Manticore::Client::CustomTrustStrategy do
|
72
|
+
|
73
|
+
subject(:custom_trust_strategy) { described_class.new(trust_strategy_proc) }
|
74
|
+
|
75
|
+
context 'when called via Java interface' do
|
76
|
+
def load_java_cert(file_path)
|
77
|
+
pem_contents = File.read(file_path)
|
78
|
+
cf = java.security.cert.CertificateFactory::getInstance("X.509")
|
79
|
+
is = java.io.ByteArrayInputStream.new(pem_contents.to_java_bytes)
|
80
|
+
cf.generateCertificate(is)
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:java_host_cert) { load_java_cert(File.expand_path("../../ssl/host.crt", __FILE__)) }
|
84
|
+
let(:java_root_cert) { load_java_cert(File.expand_path("../../ssl/root-ca.crt", __FILE__)) }
|
85
|
+
let(:java_chain) { [java_host_cert, java_root_cert].to_java(java.security.cert.X509Certificate) }
|
86
|
+
let(:java_type) { java.lang.String.new("my_type".to_java_bytes) }
|
87
|
+
|
88
|
+
subject(:java_trust_strategy) { custom_trust_strategy.to_java(org.apache.http.conn.ssl.TrustStrategy) }
|
89
|
+
|
90
|
+
context 'when called with Java Certs and a Java String' do
|
91
|
+
let(:trust_strategy_proc) { ->(chain,type) { true } }
|
92
|
+
it 'yields an enum of equivalent Ruby certs and an equivalent Ruby String' do
|
93
|
+
expect(trust_strategy_proc).to receive(:call) do |chain, type|
|
94
|
+
expect(chain.to_a.length).to eq java_chain.length
|
95
|
+
chain.each_with_index do |cert, idx|
|
96
|
+
expect(cert).to be_a_kind_of OpenSSL::X509::Certificate
|
97
|
+
expect(cert.to_der).to eq String.from_java_bytes(java_chain[idx].encoded)
|
98
|
+
end
|
99
|
+
expect(type).to be_a_kind_of String
|
100
|
+
expect(type).to eq String.from_java_bytes(java_type.bytes)
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(java_trust_strategy.isTrusted(java_chain, java_type)).to be true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when the ruby block returns false' do
|
108
|
+
let(:trust_strategy_proc) { ->(chain,type) { false } }
|
109
|
+
it 'returns false' do
|
110
|
+
expect(java_trust_strategy.isTrusted(java_chain, java_type)).to be false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when the ruby block returns true' do
|
115
|
+
let(:trust_strategy_proc) { ->(chain,type) { true } }
|
116
|
+
it 'returns true' do
|
117
|
+
expect(java_trust_strategy.isTrusted(java_chain, java_type)).to be true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when the ruby block raises an exception' do
|
122
|
+
let(:trust_strategy_proc) { ->(chain, type) { fail(OpenSSL::X509::CertificateError, 'intentional') } }
|
123
|
+
it 'throws a CertificateException' do
|
124
|
+
expect {
|
125
|
+
java_trust_strategy.isTrusted(java_chain, java_type)
|
126
|
+
}.to raise_exception(java.security.cert.CertificateException)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe Manticore::Client::CombinedTrustStrategy do
|
133
|
+
let(:always_trust_strategy) { ->(chain,type) { true } }
|
134
|
+
let(:never_trust_strategy) { ->(chain,type) { false } }
|
135
|
+
|
136
|
+
subject(:combined_trust_strategy) { Manticore::Client::TrustStrategies.combine(left_hand_strategy, right_hand_strategy) }
|
137
|
+
|
138
|
+
context 'when left-hand strategy trusts' do
|
139
|
+
let(:left_hand_strategy) { always_trust_strategy }
|
140
|
+
context 'when right-hand strategy trusts' do
|
141
|
+
let(:right_hand_strategy) { always_trust_strategy }
|
142
|
+
it 'trusts' do
|
143
|
+
expect(combined_trust_strategy.trusted?([],'ignored')).to be true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
context 'when right-hand strategy does not trust' do
|
147
|
+
let(:right_hand_strategy) { never_trust_strategy }
|
148
|
+
it 'trusts' do
|
149
|
+
expect(combined_trust_strategy.trusted?([],'ignored')).to be true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
context 'when left-hand strategy does not trust' do
|
154
|
+
let(:left_hand_strategy) { never_trust_strategy }
|
155
|
+
context 'when right-hand strategy trusts' do
|
156
|
+
let(:right_hand_strategy) { always_trust_strategy }
|
157
|
+
it 'trusts' do
|
158
|
+
expect(combined_trust_strategy.trusted?([],'ignored')).to be true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
context 'when right-hand strategy does not trust' do
|
162
|
+
let(:right_hand_strategy) { never_trust_strategy }
|
163
|
+
it 'does not trust' do
|
164
|
+
expect(combined_trust_strategy.trusted?([],'ignored')).to be false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -6,7 +6,7 @@ describe Manticore::Response do
|
|
6
6
|
|
7
7
|
its(:headers) { is_expected.to be_a Hash }
|
8
8
|
its(:body) { is_expected.to be_a String }
|
9
|
-
its(:length) { is_expected.to be_a
|
9
|
+
its(:length) { is_expected.to be_a Integer }
|
10
10
|
|
11
11
|
it "provides response header lookup via #[]" do
|
12
12
|
expect(subject["Content-Type"]).to eq "application/json"
|
data/spec/spec_helper.rb
CHANGED
@@ -151,6 +151,7 @@ RSpec.configure do |c|
|
|
151
151
|
start_ssl_server 55444
|
152
152
|
start_ssl_server 55445, :SSLVerifyClient => OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT, :SSLCACertificateFile => File.expand_path("../ssl/root-ca.crt", __FILE__)
|
153
153
|
start_ssl_server 55446, cert: File.expand_path("../ssl/host-expired.crt", __FILE__)
|
154
|
+
start_ssl_server 55447, cert: File.expand_path("../ssl/host-untrusted.crt", __FILE__), SSLCACertificateFile: File.expand_path("../ssl/root-untrusted-ca.crt", __FILE__)
|
154
155
|
|
155
156
|
Manticore.disable_httpcomponents_logging!
|
156
157
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manticore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Chris Heald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,36 +17,8 @@ dependencies:
|
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '0'
|
19
19
|
name: openssl_pkcs8_pure
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
29
|
-
requirements:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
33
|
-
name: bundler
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
name: rake
|
48
|
-
type: :development
|
49
20
|
prerelease: false
|
21
|
+
type: :runtime
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
24
|
- - ">="
|
@@ -59,8 +31,8 @@ dependencies:
|
|
59
31
|
- !ruby/object:Gem::Version
|
60
32
|
version: 0.4.1
|
61
33
|
name: jar-dependencies
|
62
|
-
type: :development
|
63
34
|
prerelease: false
|
35
|
+
type: :development
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - "~>"
|
@@ -86,12 +58,13 @@ files:
|
|
86
58
|
- ext/manticore/org/manticore/HttpGetWithEntity.java
|
87
59
|
- ext/manticore/org/manticore/Manticore.java
|
88
60
|
- gem-public_cert.pem
|
89
|
-
- lib/commons-codec/commons-codec/1.
|
61
|
+
- lib/commons-codec/commons-codec/1.15/commons-codec-1.15.jar
|
90
62
|
- lib/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
|
91
63
|
- lib/faraday/adapter/manticore.rb
|
92
64
|
- lib/manticore.rb
|
93
65
|
- lib/manticore/client.rb
|
94
66
|
- lib/manticore/client/proxies.rb
|
67
|
+
- lib/manticore/client/trust_strategies.rb
|
95
68
|
- lib/manticore/cookie.rb
|
96
69
|
- lib/manticore/facade.rb
|
97
70
|
- lib/manticore/java_extensions.rb
|
@@ -99,13 +72,14 @@ files:
|
|
99
72
|
- lib/manticore/stubbed_response.rb
|
100
73
|
- lib/manticore/version.rb
|
101
74
|
- lib/manticore_jars.rb
|
102
|
-
- lib/org/apache/httpcomponents/httpclient/4.5.
|
103
|
-
- lib/org/apache/httpcomponents/httpcore/4.4.
|
104
|
-
- lib/org/apache/httpcomponents/httpmime/4.5.
|
75
|
+
- lib/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar
|
76
|
+
- lib/org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar
|
77
|
+
- lib/org/apache/httpcomponents/httpmime/4.5.13/httpmime-4.5.13.jar
|
105
78
|
- lib/org/manticore/manticore-ext.jar
|
106
79
|
- manticore.gemspec
|
107
80
|
- spec/manticore/client_proxy_spec.rb
|
108
81
|
- spec/manticore/client_spec.rb
|
82
|
+
- spec/manticore/client_trust_strategies_spec.rb
|
109
83
|
- spec/manticore/cookie_spec.rb
|
110
84
|
- spec/manticore/facade_spec.rb
|
111
85
|
- spec/manticore/response_spec.rb
|
@@ -124,25 +98,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
98
|
requirements:
|
125
99
|
- - ">="
|
126
100
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
101
|
+
version: '2.3'
|
128
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
103
|
requirements:
|
130
104
|
- - ">="
|
131
105
|
- !ruby/object:Gem::Version
|
132
106
|
version: '0'
|
133
107
|
requirements:
|
134
|
-
- jar org.apache.httpcomponents:httpclient, '~> 4.5.
|
135
|
-
- jar org.apache.httpcomponents:httpmime, '~> 4.5.
|
108
|
+
- jar org.apache.httpcomponents:httpclient, '~> 4.5.13'
|
109
|
+
- jar org.apache.httpcomponents:httpmime, '~> 4.5.13'
|
136
110
|
- jar commons-logging:commons-logging, '~> 1.2'
|
137
111
|
- jar commons-codec:commons-codec, '~> 1.9'
|
138
|
-
- jar org.apache.httpcomponents:httpcore, '~> 4.4.
|
139
|
-
rubygems_version: 3.
|
112
|
+
- jar org.apache.httpcomponents:httpcore, '~> 4.4.14'
|
113
|
+
rubygems_version: 3.2.29
|
140
114
|
signing_key:
|
141
115
|
specification_version: 4
|
142
116
|
summary: Manticore is an HTTP client built on the Apache HttpCore components
|
143
117
|
test_files:
|
144
118
|
- spec/manticore/client_proxy_spec.rb
|
145
119
|
- spec/manticore/client_spec.rb
|
120
|
+
- spec/manticore/client_trust_strategies_spec.rb
|
146
121
|
- spec/manticore/cookie_spec.rb
|
147
122
|
- spec/manticore/facade_spec.rb
|
148
123
|
- spec/manticore/response_spec.rb
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|