SMTP error with Rails Exception Notifier plugin - ruby-on-rails

Working on OS X, trying to get Rails Exception Notifier plugin to send out emails. I have verified the following:
I can successfully send email from my app
I am creating a test error (1/0 in one of my actions).
Current plugin installed...
script/plugin install git://github.com/rails/exception_notification.git
In ApplicationController...
include ExceptionNotifiable
local_addresses.clear
In environment.rb...
Rails::Initializer.run do |config|
# ...
config.after_initialize do
ExceptionNotifier.exception_recipients = %w(abc#gmail.com abc#abc.gov)
ExceptionNotifier.sender_address = %("Contact DB error" <abc#abc.gov>)
ExceptionNotifier.email_prefix = "[Contact DB error] "
end
end
In addition to the intentionally-created test error, I'm seeing this error on the console...
Processing ApplicationController#index (for 127.0.0.1 at 2009-10-02 14:40:55) [GET]
Net::SMTPFatalError (555 5.5.2 Syntax error. 3sm30577fge.12
):
/usr/local/lib/ruby/1.8/net/smtp.rb:680:in `check_response'
/usr/local/lib/ruby/1.8/net/smtp.rb:653:in `getok'
/usr/local/lib/ruby/1.8/net/smtp.rb:631:in `mailfrom'
/usr/local/lib/ruby/1.8/net/smtp.rb:544:in `send0'
/usr/local/lib/ruby/1.8/net/smtp.rb:472:in `sendmail'
/usr/local/lib/ruby/1.8/net/smtp.rb:379:in `start'
haml (2.2.6) rails/./lib/sass/plugin/rails.rb:19:in `process'
Then it tries to send an exception notification for the SMTP error...
Subject: [Contact DB error] application#index (Net::SMTPFatalError) "555 5.5.2 Syntax error. 3sm30577fge.12\n"

This page seems to indicate it is related to your from address. Try changing it to just abc#abc.gov.

Related

How to setup error 404 page in Ruby on Rails system testing

Rails 5.1 introduced system testing that uses Capybara with Selenium to test the UI of Rails application.
I'm wondering to how to use this system testing to test the UI of error pages.
For standard controller tests, we can do something like below to assert response to be 404.
test 'should get not_found' do
get errors_not_found_url
assert_response :not_found
end
But for system tests, if I go to a 404 page, exception will be thrown in controller level and tests terminate immediately without rendering the page.
test '404 page should render with the correct title' do
# act.
visit NOT_FOUND_URL
# assert.
assert_equal("#{APP_NAME} - #{TITLE_404}", page.title)
end
Exception is thrown in controller level.
$ rails test test/system/error/error_page_test.rb
Run options: --seed 30076
# Running:
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:55237
Use Ctrl-C to stop
2017-07-09 11:10:45 +1200: Rack app error handling request { GET /books/12345678 }
#<ActionController::RoutingError: Could not find book '12345678' by id or name>
/myapp/app/controllers/books_controller.rb:7:in `index'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/abstract_controller/base.rb:186:in `process_action'
...
Under development/test environment, config.consider_all_requests_local can be set to false in order to show error page instead of stracktrace. But this doesn't swallow exception during system tests.
If you don't want Capybara to re-raise server exceptions in the tests you can set Capybara.raise_server_errors = false.
Secondly, you should check your Gemfile and make sure any gems like web-console,better-errrors, etc are only loaded in the development environment (not in the test environment)
Finally, you shouldn't be using assert_equal with title, you should be using the Capybara provided assert_title which includes waiting/retrying behavior and will reduce potential flakiness in tests.
assert_title("#{APP_NAME} - #{TITLE_404}")

Neo4j.rb (8.0.11) + Resque : Input/output error # io_write - <STDOUT>

I have recently upgraded neo4j and I am getting issue in resque workers,
Exception
Errno::EIO
Error
Input/output error # io_write - <STDOUT>
I am getting this issue and backtrace says its related to neo4j.rb puts
Errno::EIO: Input/output error - <STDOUT>
/home/ubuntu/staycircles-backend/shared/bundle/ruby/2.3.0/gems/neo4j-8.0.11/lib/neo4j/session_manager.rb:60:in `write'
/home/ubuntu/staycircles-backend/shared/bundle/ruby/2.3.0/gems/neo4j-8.0.11/lib/neo4j/session_manager.rb:60:in `puts'
/home/ubuntu/staycircles-backend/shared/bundle/ruby/2.3.0/gems/neo4j-8.0.11/lib/neo4j/session_manager.rb:60:in `puts'
/home/ubuntu/staycircles-backend/shared/bundle/ruby/2.3.0/gems/neo4j-8.0.11/lib/neo4j/session_manager.rb:60:in `block in wait_for_value'
My current configration is
neo4j version - 3.xx
neo4j.rb - 8.0.11
Could you try updating to 8.0.13 of the neo4j gem?
The gem maintainers have released v 8.0.13, which removes the puts statements. Want to see if it fixes the issue on your end?
https://github.com/neo4jrb/neo4j/releases/tag/v8.0.13

NoMethodError: undefined method `bindings' for java.lang.NullPointerException

we're working on a ruby on rails (4.2.8) application which is running on jruby-1.7.25. It really is time to update this mummy to the latest version 9.1.7.0. We did that and for most of my colleagues it works out fine. But - guess what - not for me. Before posting my question here, I made sure that:
I have the same setup
Same DB content
The exactly same code
as the others, but I still get that stupid error which is
java.lang.NullPointerException and that's really all, the app is spitting out on any request.
I was digging for the last hours and found out, that the real issue is getting lost in the depth of logging. Finally I found, that I will see the real cause if I add a puts in the file vendor/jruby/2.3.0/gems/actionpack-4.2.8/lib/action_dispatch/middleware/show_exceptions.rb like:
class ShowExceptions
FAILSAFE_RESPONSE = [500, { 'Content-Type' => 'text/plain' },
["500 Internal Server Error\n" \
"If you are the administrator of this website, then please read this web " \
"application's log file and/or the web server's log file to find out what " \
"went wrong."]]
def initialize(app, exceptions_app)
#app = app
#exceptions_app = exceptions_app
end
def call(env)
#app.call(env)
rescue Exception => exception
puts "EXCEPTION: #{exception.inspect}\n#app: #{#app.inspect}\nENV: #{env.inspect}"
if env['action_dispatch.show_exceptions'] == false
raise exception
else
render_exception(env, exception)
end
end
The output is:
EXCEPTION: #<NoMethodError: undefined method `bindings' for java.lang.NullPointerException:Java::JavaLang::NullPointerException
#app and env print out kilobytes of data which probably do not help. Honestly, I'm kind of stuck here. How can it work on other machines while it fails on mine? Has anyone of you had a similar issue or any idea what causes this trouble?
Ah, some version infos
Puma: * Version 3.7.1 (jruby 9.1.7.0 - ruby 2.3.1), codename: Snowy Sagebrush
jruby: jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 24.79-b02 on 1.7.0_79-b15 +jit [darwin-x86_64]
java: java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Mac OSX: 10.12.3 (16D32)
Thanks for any hints!

Rails rake rollbar:test didn't pass

I was trying to use rollbar gem to monitor error message.
I followed its document.
Add gem 'rollbar', and rails generate rollbar POST_SERVER_ITEM_ACCESS_TOKEN.
(I did changed the POST_SERVER_ITEM_ACCESS_TOKEN to my key)
But after I run rake rollbar:test, it only threw Test error from rollbar:test in dashboard.
Update
initializers/rollbar
Rollbar.configure do |config|
if Rails.env.test?
config.enabled = false
end
In console
rake rollbar:test 16:21:14
Testing manual report...
[Rollbar] Scheduling item
[Rollbar] Sending item
[Rollbar] Success
[Rollbar] Details: https://rollbar.com/instance/uuid?uuid=1f4c4e35-df5f-4606-916d-d97341b01dc7 (only available if report was successful)
Setting up the controller.
Processing...
Started GET "/verify" for at 2016-12-02 16:21:21 +0800
Check your rollbar config, probably it's disabled in development mode.
https://github.com/rollbar/rollbar-gem/blob/master/lib/generators/rollbar/templates/initializer.rb#L7

Script Kiddie attempts triggering Rails URI::InvalidURIError - how to filter?

I just launched a production Rails app (on Heroku) on a long-existing domain and, of course, now that it's facing the wide open web, I'm picking up all the flotsam and jetsam of the attempted script kiddies.
I have any exceptions that get thrown emailed to me and I've managed to catch (rescue_from) all the standard errors, but this keeps coming through a few times a day:
An URI::InvalidURIError occurred in #:
bad URI(is not URI?): http://www.myapp.com/assets/,data:n,complete:function(e,t)
{r&&u.each(r,o||[e.responseText,t,e])}}).done(function(e){o=arguments,u
vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:176:in `split'
-------------------------------
Request:
-------------------------------
* URL : http://myapp.com/assets/,data:n,complete:function(e,t)
{r&&u.each(r,o||[e.responseText,t,e])}}).done(function(e){o=arguments,u.html(i?v(
* IP address: 195.241.58.105
* Parameters: {"v("=>nil, "path"=>"assets/,data:n,complete:function(e,t){r&&u.each(r,o||
[e.responseText,t,e])}}).done(function(e){o=arguments,u", "format"=>"html(i"}
* Rails root: /app
* Timestamp : 2013-02-26 16:53:51 UTC
So from my untrained eye, this looks like script kiddies attempting to try for some sort of vulnerability (or?)
My questions:
1) This is one area where I'm not sure how far the "rails magic" goes -- do I need to do anything? I don't really like that outside forces are able to cause an exception in my app just from the request. Should I be rescuing the URI::InvalidURIError exception and just throwing a 404? Is there anything more I should be doing? Does this happen to everyone?
2) Is something misconfigured or is this just standard "stock production" behavior for an app? I'm running Rails 3.2.12 (latest patched version as of this posting).
Thanks in advance for any advice!
EDIT: Adding some more details about the requests, as Christian pointed out below, might not be script kiddies? Either way, I'm curious.
2nd request:
An URI::InvalidURIError occurred in #:
bad URI(is not URI?): http://www.myapp.com/assets/&&!yt.test(e)&&
(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt
vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:176:in `split'
-------------------------------
Request:
-------------------------------
* URL : http://myapp.com/assets/&&!yt.test(e)&&
(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||[
* IP address: 217.16.182.42
* Parameters: {"path"=>"assets/&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt", "format"=>"exec(e)||["}
* Rails root: /app
* Timestamp : 2013-02-27 18:37:20 UTC
3rd request:
An URI::InvalidURIError occurred in #:
bad URI(is not URI?): http://www.myapp.com/assets/&&!yt.test(e)&&
(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt
vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:176:in `split'
-------------------------------
Request:
-------------------------------
* URL : http://myapp.com/assets/&&!yt.test(e)&&
(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||[
* IP address: 62.141.42.107
* Parameters: {"path"=>"assets/&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&
(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt", "format"=>"exec(e)||["}
* Rails root: /app
* Timestamp : 2013-02-27 20:56:25 UTC
I just found that code in my production.log
GET "/assets/&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||["
Rails 3.2.13 dealt with it with Completed 406 Not Acceptable
I found the same in my logs but in november 2012:
ActionController::RoutingError (No route matches [GET] "/assets/&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||["):

Resources