Decrypting a phoney value breaks when testing
suprafly opened this issue · 2 comments
suprafly commented
A simple test:
test "decrypt something phoney" do
{resp, _} = Cipher.decrypt("nonsense")
assert resp == :error
end
Returns this error:
** (ArgumentError) argument error
stacktrace:
(crypto) :crypto.aes_cbc_crypt("f501bc2316ae38b1", "33G<I0WWJiEn1{;Y", <<158, 137, 236, 122, 123, 30>>, false)
lib/cipher.ex:39: Cipher.decrypt/1
I suspect that during testing, the helper functions to retrieve the :keyphrase and :ivphrase are not working correctly: https://github.com/rubencaro/cipher/blob/master/lib/cipher/helpers.ex
You can see this by extracting the definition and trying it in a test. When I add this line to my test:
IO.inspect Application.get_env(Mix.Project.get!.project[:app], :keyphrase, nil)
...the outut is: nil
rubencaro commented
That's something else I think. See:
iex(1)> Cipher.decrypt("random")
{:error, "Could not decode crypted string 'random'"}
iex(2)> Cipher.decrypt("nonsense")
** (ArgumentError) argument error
(crypto) :crypto.aes_cbc_crypt("1c538c5bcef14695", "testieivphrasefo", <<158, 137, 236, 122, 123, 30>>, false)
(cipher) lib/cipher.ex:39: Cipher.decrypt/1
I'm on it now.
rubencaro commented
Just released 1.0.2 including this!