Skip to content

Commit b000a7a

Browse files
committed
Disable cert verification in Ruby only if insecureSkipVerify is set
1 parent c003f65 commit b000a7a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/targets/ruby/native.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ module.exports = function (source, options) {
3434

3535
if (source.uriObj.protocol === 'https:') {
3636
code.push('http.use_ssl = true')
37-
.push('http.verify_mode = OpenSSL::SSL::VERIFY_NONE')
37+
38+
if (options.insecureSkipVerify) {
39+
code.push('http.verify_mode = OpenSSL::SSL::VERIFY_NONE')
40+
}
3841
}
3942

4043
code.blank()

test/fixtures/output/ruby/native/https.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
http = Net::HTTP.new(url.host, url.port)
88
http.use_ssl = true
9-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
109

1110
request = Net::HTTP::Get.new(url)
1211

test/targets/ruby/native.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
'use strict'
22

3-
module.exports = function (snippet, fixtures) {}
3+
module.exports = function (HTTPSnippet, fixtures) {
4+
it('should support insecureSkipVerify', function () {
5+
const result = new HTTPSnippet(fixtures.requests.https).convert('ruby', 'native', {
6+
insecureSkipVerify: true
7+
})
8+
9+
result.should.be.a.String()
10+
result.should.eql(`require 'uri'
11+
require 'net/http'
12+
require 'openssl'
13+
14+
url = URI("https://mockbin.com/har")
15+
16+
http = Net::HTTP.new(url.host, url.port)
17+
http.use_ssl = true
18+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
19+
20+
request = Net::HTTP::Get.new(url)
21+
22+
response = http.request(request)
23+
puts response.read_body`)
24+
})
25+
}

0 commit comments

Comments
 (0)