southbridgeio / redmine_2fa

Two-factor (sms/telegram) authentication for Redmine
https://southbridge.io
MIT License
42 stars 17 forks source link

500 error with Google Auth, production.log - NoMethodError (undefined method `tr' for nil:NilClass #92

Closed KiYiul closed 3 years ago

KiYiul commented 3 years ago

Hi, I tried login with Google Authentication after upgrade gcc, install redis, redmine_sidekiq, redmine_bots, redmine_2fa. In installing redmine_sidekiq, I was modified sidekiq_sandbox_controller.rb from before_filter into before_action. And in installing redmine_bots, modified Gemfile from gem 'database_cleaner', '1.5.1' into gem 'database_cleaner'. And in installing redmine_2fa, I saw 500 error after log in by admin account and input Google Authentication code.

Here the Redmine production log as below.

Started POST "/redmine_2fa/otp_code/confirm" for xxx.xxx.xxx.xxx at 2020-09-14 18:46:37 +0900
Processing by AccountController#confirm_otp as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Fe/RpT8W0CX9tEofhV9J2XeVek411fWl1yuKumm+AFZkOBioPOh0D/PMiieyFcwxuV37eu4dYe+nP4aq29iYfw==", "otp_code"=>"355684", "login"=>"Login »"}
   (0.4ms)  SELECT MAX("settings"."updated_on") FROM "settings"
  AnonymousUser Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('AnonymousUser') AND "users"."lastname" = $1 LIMIT $2  [["lastname", "Anonymous"], ["LIMIT", 1]]
  Current user: anonymous
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
Completed 500 Internal Server Error in 6ms (ActiveRecord: 1.4ms)

NoMethodError (undefined method `tr' for nil:NilClass
Did you mean?  try):

plugins/redmine_2fa/lib/redmine_two_fa/patches/account_controller_patch/confirm_methods.rb:36:in `confirm_otp'
plugins/redmine_reporting/lib/redmine_reporting/sweeper.rb:23:in `around'
plugins/redmine_reporting/lib/redmine_reporting/sweeper.rb:23:in `around'
lib/redmine/sudo_mode.rb:65:in `sudo_mode'
plugins/redmine_dmsf/lib/redmine_dmsf/webdav/custom_middleware.rb:60:in `call'

I also tried install gem manually according to Gemfile, However that is not solution and same 500 error pop.

gem active_model_otp
gem rotp
gem rqrcode
gem shoulda
gem rails-controller-testing
KiYiul commented 3 years ago

Nevermind, I was fresh install Redmine and confirmed that the issue has been not occurred again.

keineahnung2345 commented 3 years ago

The problem also happens to me, after tracing lib/redmine_two_fa/patches/account_controller_patch/confirm_methods.rb, vendor/bundle/ruby/2.6.0/gems/rotp-4.0.2/lib/rotp/otp.rb, vendor/bundle/ruby/2.6.0/gems/rotp-4.0.2/lib/rotp/totp.rb and vendor/bundle/ruby/2.6.0/bundler/gems/active_model_otp-6ed9927ac245/lib/active_model/one_time_password.rb. I found that it is because that the following line is not executed when migration(I've checked the otp_secret_key column of users table, it is full of nil after migration): https://github.com/southbridgeio/redmine_2fa/blob/2312a2067ee3af3deb168edc7a224de28fe9bede/db/migrate/003_add_otp_secret_key_to_users.rb#L8

After migration, I have to manually run the line above in rails console to resolve this problem.

My environment:

Environment:
  Redmine version                4.1.1.stable
  Ruby version                   2.6.5-p114 (2019-10-01) [x86_64-linux]
  Rails version                  5.2.4.2
  Environment                    production
  Database adapter               PostgreSQL
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp

@funk-yourself Do you have any ideas?