无效的盐值 (BCrypt::Errors::InvalidSalt)

4
自从升级到 Ruby 2.2.0 后,我的测试中出现了以下消息:
invalid salt (BCrypt::Errors::InvalidSalt)

我没有找到任何升级通知来帮助我理解问题。我正在使用Rails 4.1.8和Sorcery 0.8.6。
还有其他人遇到这个问题吗?
更多细节:
我正在使用Sorcery而不是Devise。加密数据是密码。 一切都始于Cucumber测试,在两种情况下: 当我过去把@user发送给邮件程序员为邮件准备数据时。这里是代码:
UserMailer.passphrase_reset_notification(@user).deliver 它生成了一个异常,并显示了我在最初消息中写的消息。作为解决方法,我发送了所需的字段,它起作用了。这是新代码:
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:in `create' ./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 `And I press "Sign up"'
我删除了用户表中“salt”字段的“null:false”,如社区成员在一个更或多或少类似的问题的帖子中建议的,但它也没有帮助。
我的主要问题仍然是相同的:Ruby新版本(2.2.0)与此有何关系?如果我升级生产环境,可能会有哪些其他惊喜?

你是在使用Devise宝石还是你想要加密什么? - MZaragoza
3
堆栈跟踪有助于缩小范围。 - tadman
3个回答

3
我刚刚修复了这个问题。结果发现是使用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)

异常发生在“保存”调用时。当我跟踪代码时,它立即引发异常!不起作用。谢谢。 - Reza
我正在使用DelayedJob...但这也是我的解决方法。删除对象(@user),只传递id,然后在邮件发送方法中稍后获取对象。 - hellion
相当恶心的 bug... 你的修复救了我的一天! - Renaud Kern

2

我曾经遇到过类似的问题。调查后得出结论是 bcrypt 与 Psych(Ruby 系统库,用于生成和解析 YAML)不兼容。

现在有一个开放的 bcrypt 问题。等待 gem 作者修复。


很好发现,Oleg。让我们等待BCrypt团队的修复。 - Reza

2

**已解决** 问题已经解决,至少我的问题是这样的。我刚刚将bcrypt宝石从3.1.9升级到了3.1.10,就解决了!感谢Oleg在bcrypt账户上创建了一个问题。


立即升级 gem 对我也起作用了。谢谢! - nfriend21

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接