Update '.gitea/issue_template/bug.yml'
[akkoma] / test / pleroma / password / pbkdf2_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Password.Pbkdf2Test do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Password.Pbkdf2, as: Password
9
10 test "it generates the same hash as pbkd2_elixir" do
11 # hash = Pbkdf2.hash_pwd_salt("password")
12 hash =
13 "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
14
15 # Use the same randomly generated salt
16 salt = Password.decode64("QJpEYw8iBKcnY.4Rm0eCVw")
17
18 assert hash == Password.hash_pwd_salt("password", salt: salt)
19 end
20
21 @tag skip: "Works when Pbkd2 is present. Source: trust me bro"
22 test "Pbkdf2 can verify passwords generated with it" do
23 # Commented to prevent warnings.
24 # hash = Password.hash_pwd_salt("password")
25 # assert Pbkdf2.verify_pass("password", hash)
26 end
27
28 test "it verifies pbkdf2_elixir hashes" do
29 # hash = Pbkdf2.hash_pwd_salt("password")
30 hash =
31 "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
32
33 assert Password.verify_pass("password", hash)
34 end
35 end