4

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

invalid salt (BCrypt::Errors::InvalidSalt)

我没有发现任何升级通知可以帮助我理解问题。我正在使用 Rails 4.1.8 和 Sorcery 0.8.6。

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

更多细节:

我使用的是巫术而不是设计。加密的数据就是密码。这一切都始于 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 `然后我按 "Sign up"'

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

我的主要问题仍然相同:Ruby 新版本(2.2.0)与此有什么关系?如果我升级产品,还有什么其他惊喜?

4

3 回答 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)
于 2015-01-05T02:16:41.330 回答
2

我有类似的问题。调查使我得出结论,bcrypt 不能很好地与 Psych(这是用于生成和解析 YAML 的 Ruby 系统库)配合使用。

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

于 2015-01-09T05:15:02.833 回答
2

** 已修复 ** 至少我的问题已修复。我刚刚从 3.1 升级了 bcrypt gem。9 到 3.1.10,就是这样!感谢 Oleg 在 bcrypt 帐户上创建了一个问题。

于 2015-01-29T22:10:05.717 回答