akkoma/test/pleroma/password/pbkdf2_test.exs

36 lines
1.2 KiB
Elixir
Raw Normal View History

2021-01-14 06:49:39 -07:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
2021-01-14 06:49:39 -07:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Password.Pbkdf2Test do
use Pleroma.DataCase, async: true
2021-01-14 07:06:16 -07:00
alias Pleroma.Password.Pbkdf2, as: Password
2021-01-14 06:49:39 -07:00
test "it generates the same hash as pbkd2_elixir" do
2021-01-14 07:06:16 -07:00
# hash = Pbkdf2.hash_pwd_salt("password")
2021-01-14 06:49:39 -07:00
hash =
"$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
# Use the same randomly generated salt
salt = Password.decode64("QJpEYw8iBKcnY.4Rm0eCVw")
assert hash == Password.hash_pwd_salt("password", salt: salt)
end
@tag skip: "Works when Pbkd2 is present. Source: trust me bro"
2021-01-14 07:06:16 -07:00
test "Pbkdf2 can verify passwords generated with it" do
# Commented to prevent warnings.
# hash = Password.hash_pwd_salt("password")
# assert Pbkdf2.verify_pass("password", hash)
2021-01-14 06:49:39 -07:00
end
test "it verifies pbkdf2_elixir hashes" do
2021-01-14 07:06:16 -07:00
# hash = Pbkdf2.hash_pwd_salt("password")
2021-01-14 06:49:39 -07:00
hash =
"$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
assert Password.verify_pass("password", hash)
end
end