Pow: Speedup tests by reducing password hashing rounds

Created on 15 Feb 2020  路  7Comments  路  Source: danschultzer/pow

When using pbkdf2_elixir (https://github.com/riverrun/pbkdf2_elixir) there is a way to speed up testing by adding the following line to config/test.exs:

config :pbkdf2_elixir, :rounds, 1

Is there a way to similarly reduce the hashing rounds during tests with Pow? I have done a cursory check of the documentation, open issues, and closed issues but did not find any indication that there is a way to do this.

Most helpful comment

That was exactly what needed to be done! For those who may run into this down the road...

Add the following to _your project's_ config/test.exs:

config :pow, Pow.Ecto.Schema.Password, iterations: 1

Just because Pow's internal tests are configured this way does not mean your project's tests are! Thanks @Schultzer, closing the issue now.

All 7 comments

Ah indeed. Is this a default behavior then? The only reason I ask is that my tests are running quite slowly. Considering they are fairly basic, I figured it likely had to do with password hashing seeing as I create a user for the tests.

I cannot answer your question. I have no idea how your environment or tests are setup.

You could try adding that line in your test config and tweak the iteration to see if it changes anything.

That was exactly what needed to be done! For those who may run into this down the road...

Add the following to _your project's_ config/test.exs:

config :pow, Pow.Ecto.Schema.Password, iterations: 1

Just because Pow's internal tests are configured this way does not mean your project's tests are! Thanks @Schultzer, closing the issue now.

@jmpressman this works when I add it in config.exs but not when in test.exs

ok sorry - I added it to test but seeded in dev. Works fine when added to dev

I'm using bcrypt_elixir instead of the default pbkdf2_elixir and tried adding

config :pow, Pow.Ecto.Schema.Password, iterations: 1

to config/test.exs and it didn't work.

However, adding

config :bcrypt_elixir, :log_rounds, 4

from Step 3 in https://github.com/riverrun/bcrypt_elixir#installation works.

Hopefully this helps someone, but I'm assuming @danschultzer that config :pow, Pow.Ecto.Schema.Password, iterations: 1 only works when using Pow's default pbkdf?

@miXwui Correct, that config only applies to the default password hashing module in Pow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danschultzer picture danschultzer  路  6Comments

jung-hunsoo picture jung-hunsoo  路  3Comments

blatyo picture blatyo  路  4Comments

joepstender picture joepstender  路  6Comments

danschultzer picture danschultzer  路  3Comments