Digest::MD5 in Ruby 1.9.3
Asked Answered
U

2

8

I'm running into something weird here. I have an "authenticator" that relies on ND5 to hash a certain string we match as password. The problem when I run my tests is this:

NoMethodError: undefined method `md5' for #<CASServer::Authenticators::Billing:0x007fd8e6c906a0>
./models/authenticators/billing.rb:63:in `validate'
./routes/login.rb:166:in `block (2 levels) in <class:Server>'
./routes/login.rb:158:in `each'
./routes/login.rb:158:in `block in <class:Server>'
(eval):2:in `click_button'
./features/step_definitions/when_steps.rb:32:in `/^I enter "(.*)" as username and the generated username password and log in$/'
./features/rubycas.login.feature:14:in `When I enter "username" as username and the generated username password and log in'

So basically he does not recognize the MD5 as part of the Digest library. This problem occurs when running the tests in the IDE, as well as in the IRB console:

1.9.3-p125 :001 > require "digest/md5" and Digest::MD5("test")
NoMethodError: undefined method `MD5' for Digest:Module

However, when I run the following:

[root@DCUDEV01 /home/morn/rubycas/current]# ruby
require "digest/md5" and Digest::MD5("test")

I receive no errors, dumps or exceptions. Ruby just accepts it. What am I missing in order to get this MD5 stuff working?

Unattached answered 23/8, 2012 at 10:38 Comment(0)
C
34

Digest::MD5 is not a method but a module. Try

Digest::MD5.digest("test")
Cybil answered 23/8, 2012 at 10:48 Comment(2)
Could you provide a link to the documentation of the method, please?Radiochemical
Documentation here. Somehow I can't find the official documentation for Digest::MD5Meteorology
C
0

I found it confusing, it doesn't seem like .digest is correct. I can't say it is wrong either...

Commenter @reconbot got it right, IMO, but I saw the comment only after coming back to improve this QA, I think a comment isn't visible enough.

http://ruby-doc.org/stdlib-2.4.0/libdoc/digest/rdoc/Digest/MD5.html

Below is an example usage for md5 hasing for gibbon usage, the mailchimp gem.

md5_hashed_email_address = Digest::MD5.hexdigest("[email protected]")
Corduroy answered 2/2, 2018 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.