jruby-openssl vs mri openssl - Socket Closed - ruby-on-rails

Issue: Net::HTTP calls failing when using jruby with a OpenSSL::SSLError Socket Closed, but working fine using MRI.
Side Note: Calls to many servers work, however this app is calling to a cisco sensor. Again, it works via MRI but not Jruby. I've tried a number of different things to no avail. I've tried jruby 1.6.7, 1.7, and the recently released 1.7.1.dev. I've also tried jruby-openssl-0.7.4, 0.7.7, and 0.8.0.pre3. I've even tried running the script with from Ruby 1.8, and 1.9.
Failing At https://github.com/jruby/jruby/blob/master/src/org/jruby/ext/openssl/SSLSocket.java#L404 ?
Similar Issue in research: http://jira.codehaus.org/browse/JRUBY-6346
Small Back Trace Excerpt
org/jruby/ext/openssl/Utils.java:79:in newError'
org/jruby/ext/openssl/SSL.java:92:innewSSLError'
org/jruby/ext/openssl/SSLSocket.java:192:in connectCommon'
org/jruby/ext/openssl/SSLSocket.java:162:inconnect'
org/jruby/runtime/callsite/CachingCallSite.java:306:in cacheAndCall'
org/jruby/runtime/callsite/CachingCallSite.java:136:incall'
org/jruby/ast/CallNoArgNode.java:64:in interpret'
org/jruby/ast/NewlineNode.java:105:ininterpret'
I have scoured google with no luck. Any help would be greatly appreciated.
It should also be noted that I am running OSX Mountain Lion 10.8.2.
[UPDATE]
I have ran out of time to debug this and used the following workaround:
Gemfile
gem 'typhoeus'
Test method
def send_post(url, body)
response = Typhoeus::Request.post(url,
:method => :post,
:disable_ssl_host_verification => true,
:disable_ssl_peer_verification => true,
:username => #auth[:username],
:password => #auth[:password],
:headers => {
'Accept' => 'text/xml',
'Content-type' => 'application/binary',
'Connection' => 'keepalive',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Pragma' => 'no-cache',
'Cache-Control' => 'no-cache',
},
:body => body
)
response
end

Related

How to expose ActiveSupport instrumentation metrics as HTTP response headers in Rails?

(78.3ms) ItemsController -- Completed #active -- { :view_runtime => 10.46, :db_runtime => 6.76, :controller => "ItemsController", :action => "active", :format => "*/*", :method => "GET", :path => "/active", :status => 200, :status_message => "OK" }
I'm wondering if there is any simple method of exposing these ActiveSupport Instrumentation metrics(view_runtime, db_runtime) as HTTP response headers.
My use case is the following:
staging/beta environment that's a bit annoying to get into(VPN + ssh + cat/grep/tail) + it is used pretty heavily so it's not very easy to spot the messages I'm looking for.
But if it was accessible in Web inspector for AJAX requests, then it is better visibility.
Just to be clear, I'm aware of New Relic but this would be an overkill for such a simple task.
Ok, view_runtime might be harder to get in a controller but db_runtime seems to be pretty straightforward if there aren't any queries triggered from templates.
db_runtime = ActiveRecord::LogSubscriber.runtime
response.headers['db_runtime'] = ("ActiveRecord: %.1fms" % db_runtime.to_f) if db_runtime

Issue with opening the generated file in MS Excel using axlsx_rails

I am using axlsx_rails in my Rails project to generate an excel file with validations and dropdowns. After generating the File, I tried to open the file in MS Excel and it said that it needs to repair the file and all the validations and dropdowns are cleared off.
Versions
axlsx_rails - 0.1.5
axlsx - 1.3.6
rubyzip - 1.2.0
rails - 4.1.2
ruby - 2.2.2
Code
#excel = Axlsx::Package.new
#excel.workbook.add_worksheet(name: "Samples") do |ws|
ws.add_row #field_names
sheet.add_data_validation("G2:G1000", {
:type => :list,
:formula1 => '"Jim", "Tom", "Jack"',
:showDropDown => false,
:showErrorMessage => true,
:errorTitle => '',
:error => 'Please use the dropdown selector to choose the value',
:errorStyle => :stop,
:showInputMessage => true,
:prompt => 'Choose the value from the dropdown'})
end
#excel.serialize "tmp/SampleTemplate.xlsx"
Sending the file using
send_file "tmp/SampleTemplate.xlsx"
The generated file is working in LibreOffice but not in MSExcel
Please help
Solved. The issue is in the line,
:formula_1 => '"Jim", "Tom","Jack"'
I've changed it to,
:formula_1 => '"Jim, Tom, Jack"'

WebMock stub_request not working

In my rails project, one of the initialisers requests and fetches certain data from S3.
S3.buckets[CONFIG['aws']['cdn_bucket']].objects['object_name'].read
This breaks the rspec test suite which uses webmock gem
WebMock.allow_net_connect!(:net_http_connect_on_start => true)
I get the following error when I try to run the test suite
WebMock::NetConnectNotAllowedError
You can stub this request with the following snippet:
stub_request(:get, "https://bucket.s3.amazonaws.com/object_name").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'', 'Authorization'=>'AWS AKxxxxxx:Hyxxxxxxxxxx', 'Content-Type'=>'', 'Date'=>'Thu, 14 Apr 2016 15:10:18 GMT', 'User-Agent'=>'aws-sdk-ruby/1.60.2 ruby/1.8.7 i686-darwin15.3.0'}).to_return(:status => 200, :body => "", :headers => {})
Adding this stub does not fix the error. Infact, adding any of the following does not seem to make any change:
WebMock.stub_request(:any, /.*amazonaws.*/).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'', 'Authorization'=>'AWS AKIxxxxxxxxxx:MSxxxxxxxx'}).to_return(:status => 200, :body => "stubbed response", :headers => {})
WebMock.stub_request(:any, /.*amazonaws.*/).to_return(:status => 200, :body => "stubbed response", :headers => {})
What is it that I am missing here? The detailed header in the error message does not seem to make sense here to allow all kinds of requests to S3
EDIT:
I just noticed that adding WebMock.disable! to the spec_helper also results in no change. Am I not adding the stub to the right place? Where should it be added if not in the spec_helper?
After sleeping over it, it was clear that the stub_request was being added to the wrong place. Adding it directly to the initialiser could have fixed this but that would have broken all other environments as the gem webmock is included for test env only.
Hence adding the following code snippet to the script fixed this
begin
require 'webmock'
WebMock.stub_request(:any, /testimonial/).to_return(:body => '')
rescue LoadError
end
S3.buckets[CONFIG['aws']['cdn_bucket']].objects['object_name'].read
This makes a stub_request if the gem is included else simply goes on as nothing happened.

Setting RestClient SSL version to SSLv3

Is there a way to force SSL version on a single RestClient connection?
I need to set it to 'SSLv3'.
I'm able to do that for ALL connections using:
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ssl_version] = 'SSLv3'
But that of course is too global.
When trying to pass parameters in the initialization, it doesn't work:
RestClient::Resource.new('https://example.com',:ssl_version => "SSLv3")
You can use an invocation like this:
RestClient::Request.execute(:url => 'https://example.com', :ssl_version => 'SSLv3', :method => 'get')
But note that older versions of rest-client would silently discard the :ssl_version option. You can test whether this is happening by using a bogus SSL version:
>> RestClient::Request.execute(:url => 'https://example.com', :ssl_version => 'blah', :method => 'get')
ArgumentError: unknown SSL method `blah'.
from /usr/lib/ruby/1.9.1/openssl/ssl-internal.rb:38:in `ssl_version='

Rails Mailer Ubuntu

In my rails application (running on a mac), I'm using a gem called pony. When I create a message through pony I get the following output (out of a rails console).
#<Mail::Message:2186559360, Multipart: false, Headers: <Date: Tue, 13 Dec 2011 00:15:14 -0500>, <From: you#me.com>, <To: myself#hotmail.com>, <Message-ID: <4ee6df6288e90_30b080443b3c8148e#My-Name-MacBook-Pro.local.mail>>, <Subject: nothing>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
This message sends without problem.
For a separate application, running on Ubuntu, pony throws me errors.
I didn't post the errors, because I switched to a gem called mail which gives the same output after sending a message (no errors, the console says it sent fine). But the problem is that no message get sent on the Ubuntu system.
I suspect it's because I've never set up a mailing system on the Ubuntu system (if that's an action that ever needs to be done in the programming world). If it is, I'm not sure how I should do this, so that my mail will get sent.
I'm using rails 3 and Ubuntu Oneiric Ocelot.
Instead of relying on the operating system to have a working local sendmail (which OS X does, but I guess your Ubuntu doesn't), you could use an external SMTP server.
For testing and development, your Gmail will work:
Pony.mail(:to => 'you#example.com', :via => :smtp, :via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'user',
:password => 'password',
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
})
If you're sending emails from a production app, you could use an inexpensive external SMTP server from http://sendgrid.com/.
Go to ubuntu software center. Search for
mail agent
(what you need is a mail transfer agent)
now something called 'mutt' should be there. Install it. (it worked for me when i had this problem)

Resources