ruby-on-rails - 无效盐 (BCrypt::Errors::InvalidSalt)

标签 ruby-on-rails ruby bcrypt sorcery

自升级到 Ruby 2.2.0 后,我在测试中收到以下消息:

invalid salt (BCrypt::Errors::InvalidSalt)

我没有找到任何升级通知来帮助我理解问题。我正在使用 Rails 4.1.8 和 Sorcery 0.8.6。

还有其他人遇到这个问题吗?

更多详情:

我使用的是 Sorcery 而不是 Devise。加密后的数据就是密码。 这一切都始于 Cucumber 测试,在 2 个案例中: 当我曾经将@user 发送给邮件程序以准备邮件数据时。这是代码:

UserMailer.passphrase_reset_notification(@user).deliver

它生成了我在初始消息中写入的消息的异常。作为一种解决方法,而不是发送@user,我发送了我需要的字段并且它起作用了。这是新代码:

UserMailer.passphrase_reset_notification(@user.name, @user.email).deliver

但第二种情况是注册。它在开发中失败了,我不得不将 :salt 添加到 user_params 来修复它。但它并没有解决测试环境中的问题。

没有堆栈跟踪,只有一条包含导致错误的场景行的衬里消息。

然后我按“注册” 无效盐 (BCrypt::Errors::InvalidSalt) ./app/controllers/users_controller.rb:66:in block in create' ./app/controllers/users_controller.rb:64:increate' ./app/controllers/application_controller.rb:120:in scope_current_tenant' ./features/step_definitions/web_steps.rb:53:in/^(?:|I )press "([^"]*)"$/' features/users/sign_up.feature:149:in `然后我按“注册”'

我删除了用户表中字段“salt”的“null: false”,正如一位社区成员在一篇关于或多或少类似问题的帖子中所建议的那样,它也没有帮助。

我的主要问题还是一样:Ruby 新版本 (2.2.0) 与此有什么关系?如果我升级产品,其他惊喜可能是什么?

最佳答案

我刚刚解决了这个问题。结果发现它与使用 has_secure_password(使用 bcrypt-ruby)

序列化一个对象有关

更具体地说,当 Sidekiq 试图将参数序列化为 Redis 队列的对象时,类似以下的内容导致了问题。

@user = User.new(
  :firstname => 'Scott',
  :lastname => 'Klein',
  :password => 'mypass',
  :password_confirmation => 'mypass'   
)
@user.save!

# broken
# note that @user.password can still be called here
# and sidekiq will attempt to serialize this whole object using YAML
# and this is the serialization issue that barfs (in the depths of YAML)
UserMailer.delay.new_user_signup(@user)

# fixed
# i just passed the id and then recalled the user record in the mailer class
UserMailer.delay.new_user_signup(@user.id)

关于ruby-on-rails - 无效盐 (BCrypt::Errors::InvalidSalt),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27762260/

相关文章:

jquery - 动态添加内容的事件绑定(bind)遇到问题

ruby-on-rails - 使用 Rails 获取 Web 应用程序页面的 FB Likes 总数

ruby-on-rails - Ruby - 如果请求是以 JSON 发送的帖子,如何获取参数

arrays - Ruby:将 int 和存储转换为数组

xcode - 在 yosemite 上使用 npm 安装 bcrypt 时出错

ruby-on-rails - 向现有模型添加更多字段

ruby-on-rails - :disabled field not working in fields_for

ruby-on-rails - CSS 类选择器不适用于 form.collection_select Rails 5

java - 使用 BCrypt 加载测试数据

javascript - 用户密码确认到位后如何将虚拟数据播种到 Mongoose 数据库