diff options
author | Lain Soykaf <lain@lain.com> | 2021-01-14 15:06:16 +0100 |
---|---|---|
committer | Lain Soykaf <lain@lain.com> | 2021-01-14 15:06:16 +0100 |
commit | 39f3683a06aea3d6aed85c611b0db0f6ea21052a (patch) | |
tree | 51277de69d6a9fe99a664c9d47f2e41bbb670611 /test | |
parent | 87a31c5c9b903517ec0317d2a331be36f2ea5051 (diff) | |
download | pleroma-39f3683a06aea3d6aed85c611b0db0f6ea21052a.tar.gz |
Pbkdf2: Use it everywhere.
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/mfa_test.exs | 4 | ||||
-rw-r--r-- | test/pleroma/password/pbkdf2_test.exs | 14 | ||||
-rw-r--r-- | test/pleroma/password_test.exs | 35 | ||||
-rw-r--r-- | test/pleroma/web/auth/basic_auth_test.exs | 2 | ||||
-rw-r--r-- | test/pleroma/web/auth/pleroma_authenticator_test.exs | 2 | ||||
-rw-r--r-- | test/pleroma/web/auth/totp_authenticator_test.exs | 2 | ||||
-rw-r--r-- | test/pleroma/web/mongoose_im_controller_test.exs | 4 | ||||
-rw-r--r-- | test/pleroma/web/o_auth/ldap_authorization_test.exs | 4 | ||||
-rw-r--r-- | test/pleroma/web/o_auth/mfa_controller_test.exs | 4 | ||||
-rw-r--r-- | test/pleroma/web/o_auth/o_auth_controller_test.exs | 18 | ||||
-rw-r--r-- | test/pleroma/web/plugs/authentication_plug_test.exs | 2 | ||||
-rw-r--r-- | test/pleroma/web/twitter_api/password_controller_test.exs | 2 | ||||
-rw-r--r-- | test/pleroma/web/twitter_api/util_controller_test.exs | 2 | ||||
-rw-r--r-- | test/support/builders/user_builder.ex | 2 | ||||
-rw-r--r-- | test/support/factory.ex | 2 |
15 files changed, 32 insertions, 67 deletions
diff --git a/test/pleroma/mfa_test.exs b/test/pleroma/mfa_test.exs index db68fc1ca..76ba1a99d 100644 --- a/test/pleroma/mfa_test.exs +++ b/test/pleroma/mfa_test.exs @@ -30,8 +30,8 @@ defmodule Pleroma.MFATest do {:ok, [code1, code2]} = MFA.generate_backup_codes(user) updated_user = refresh_record(user) [hash1, hash2] = updated_user.multi_factor_authentication_settings.backup_codes - assert Pleroma.Password.verify_pass(code1, hash1) - assert Pleroma.Password.verify_pass(code2, hash2) + assert Pleroma.Password.Pbkdf2.verify_pass(code1, hash1) + assert Pleroma.Password.Pbkdf2.verify_pass(code2, hash2) end end diff --git a/test/pleroma/password/pbkdf2_test.exs b/test/pleroma/password/pbkdf2_test.exs index 4acbda939..e55348f9a 100644 --- a/test/pleroma/password/pbkdf2_test.exs +++ b/test/pleroma/password/pbkdf2_test.exs @@ -5,10 +5,10 @@ defmodule Pleroma.Password.Pbkdf2Test do use Pleroma.DataCase, async: true - alias Pleroma.Password.Pbkdf2 + alias Pleroma.Password.Pbkdf2, as: Password test "it generates the same hash as pbkd2_elixir" do - # hash = Pleroma.Password.Pbkdf2.hash_pwd_salt("password") + # hash = Pbkdf2.hash_pwd_salt("password") hash = "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g" @@ -19,14 +19,14 @@ defmodule Pleroma.Password.Pbkdf2Test do end @tag skip: "Works when Pbkd2 is present. Source: trust me bro" - test "Pleroma.Password.Pbkdf2 can verify passwords generated with it" do - hash = Password.hash_pwd_salt("password") - - assert Pleroma.Password.Pbkdf2.verify_pass("password", hash) + 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) end test "it verifies pbkdf2_elixir hashes" do - # hash = Pleroma.Password.Pbkdf2.hash_pwd_salt("password") + # hash = Pbkdf2.hash_pwd_salt("password") hash = "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g" diff --git a/test/pleroma/password_test.exs b/test/pleroma/password_test.exs deleted file mode 100644 index 6ed0ca826..000000000 --- a/test/pleroma/password_test.exs +++ /dev/null @@ -1,35 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.PasswordTest do - use Pleroma.DataCase, async: true - - alias Pleroma.Password - - test "it generates the same hash as pbkd2_elixir" do - # hash = Pleroma.Password.hash_pwd_salt("password") - 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" - test "Pleroma.Password can verify passwords generated with it" do - hash = Password.hash_pwd_salt("password") - - assert Pleroma.Password.verify_pass("password", hash) - end - - test "it verifies pbkdf2_elixir hashes" do - # hash = Pleroma.Password.hash_pwd_salt("password") - hash = - "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g" - - assert Password.verify_pass("password", hash) - end -end diff --git a/test/pleroma/web/auth/basic_auth_test.exs b/test/pleroma/web/auth/basic_auth_test.exs index b74516dd6..2816aae4c 100644 --- a/test/pleroma/web/auth/basic_auth_test.exs +++ b/test/pleroma/web/auth/basic_auth_test.exs @@ -11,7 +11,7 @@ defmodule Pleroma.Web.Auth.BasicAuthTest do conn: conn } do user = insert(:user) - assert Pleroma.Password.verify_pass("test", user.password_hash) + assert Pleroma.Password.Pbkdf2.verify_pass("test", user.password_hash) basic_auth_contents = (URI.encode_www_form(user.nickname) <> ":" <> URI.encode_www_form("test")) diff --git a/test/pleroma/web/auth/pleroma_authenticator_test.exs b/test/pleroma/web/auth/pleroma_authenticator_test.exs index ec63e2d41..edaf9eecb 100644 --- a/test/pleroma/web/auth/pleroma_authenticator_test.exs +++ b/test/pleroma/web/auth/pleroma_authenticator_test.exs @@ -11,7 +11,7 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do setup do password = "testpassword" name = "AgentSmith" - user = insert(:user, nickname: name, password_hash: Pleroma.Password.hash_pwd_salt(password)) + user = insert(:user, nickname: name, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)) {:ok, [user: user, name: name, password: password]} end diff --git a/test/pleroma/web/auth/totp_authenticator_test.exs b/test/pleroma/web/auth/totp_authenticator_test.exs index 6d2646b61..ac4209f2d 100644 --- a/test/pleroma/web/auth/totp_authenticator_test.exs +++ b/test/pleroma/web/auth/totp_authenticator_test.exs @@ -34,7 +34,7 @@ defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do hashed_codes = backup_codes - |> Enum.map(&Pleroma.Password.hash_pwd_salt(&1)) + |> Enum.map(&Pleroma.Password.Pbkdf2.hash_pwd_salt(&1)) user = insert(:user, diff --git a/test/pleroma/web/mongoose_im_controller_test.exs b/test/pleroma/web/mongoose_im_controller_test.exs index 183a17a02..a7225d45c 100644 --- a/test/pleroma/web/mongoose_im_controller_test.exs +++ b/test/pleroma/web/mongoose_im_controller_test.exs @@ -41,13 +41,13 @@ defmodule Pleroma.Web.MongooseIMControllerTest do end test "/check_password", %{conn: conn} do - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt("cool")) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool")) _deactivated_user = insert(:user, nickname: "konata", deactivated: true, - password_hash: Pleroma.Password.hash_pwd_salt("cool") + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool") ) res = diff --git a/test/pleroma/web/o_auth/ldap_authorization_test.exs b/test/pleroma/web/o_auth/ldap_authorization_test.exs index 9ebd084a5..61b9ce6b7 100644 --- a/test/pleroma/web/o_auth/ldap_authorization_test.exs +++ b/test/pleroma/web/o_auth/ldap_authorization_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do @tag @skip test "authorizes the existing user using LDAP credentials" do password = "testpassword" - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt(password)) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)) app = insert(:oauth_app, scopes: ["read", "write"]) host = Pleroma.Config.get([:ldap, :host]) |> to_charlist @@ -101,7 +101,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do @tag @skip test "disallow authorization for wrong LDAP credentials" do password = "testpassword" - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt(password)) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)) app = insert(:oauth_app, scopes: ["read", "write"]) host = Pleroma.Config.get([:ldap, :host]) |> to_charlist diff --git a/test/pleroma/web/o_auth/mfa_controller_test.exs b/test/pleroma/web/o_auth/mfa_controller_test.exs index dacf03b2b..17bbde85b 100644 --- a/test/pleroma/web/o_auth/mfa_controller_test.exs +++ b/test/pleroma/web/o_auth/mfa_controller_test.exs @@ -20,7 +20,7 @@ defmodule Pleroma.Web.OAuth.MFAControllerTest do insert(:user, multi_factor_authentication_settings: %MFA.Settings{ enabled: true, - backup_codes: [Pleroma.Password.hash_pwd_salt("test-code")], + backup_codes: [Pleroma.Password.Pbkdf2.hash_pwd_salt("test-code")], totp: %MFA.Settings.TOTP{secret: otp_secret, confirmed: true} } ) @@ -246,7 +246,7 @@ defmodule Pleroma.Web.OAuth.MFAControllerTest do hashed_codes = backup_codes - |> Enum.map(&Pleroma.Password.hash_pwd_salt(&1)) + |> Enum.map(&Pleroma.Password.Pbkdf2.hash_pwd_salt(&1)) user = insert(:user, diff --git a/test/pleroma/web/o_auth/o_auth_controller_test.exs b/test/pleroma/web/o_auth/o_auth_controller_test.exs index c6ee7b7e8..bf47afed8 100644 --- a/test/pleroma/web/o_auth/o_auth_controller_test.exs +++ b/test/pleroma/web/o_auth/o_auth_controller_test.exs @@ -316,7 +316,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do app: app, conn: conn } do - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt("testpassword")) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("testpassword")) registration = insert(:registration, user: nil) redirect_uri = OAuthController.default_redirect_uri(app) @@ -347,7 +347,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do app: app, conn: conn } do - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt("testpassword")) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("testpassword")) registration = insert(:registration, user: nil) unlisted_redirect_uri = "http://cross-site-request.com" @@ -790,7 +790,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do password = "testpassword" - user = insert(:user, password_hash: Pleroma.Password.hash_pwd_salt(password)) + user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)) app = insert(:oauth_app, scopes: ["read", "write"]) @@ -818,7 +818,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do user = insert(:user, - password_hash: Pleroma.Password.hash_pwd_salt(password), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), multi_factor_authentication_settings: %MFA.Settings{ enabled: true, totp: %MFA.Settings.TOTP{secret: otp_secret, confirmed: true} @@ -927,7 +927,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do password = "testpassword" {:ok, user} = - insert(:user, password_hash: Pleroma.Password.hash_pwd_salt(password)) + insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)) |> User.confirmation_changeset(need_confirmation: true) |> User.update_and_set_cache() @@ -955,7 +955,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do user = insert(:user, - password_hash: Pleroma.Password.hash_pwd_salt(password), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), deactivated: true ) @@ -983,7 +983,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do user = insert(:user, - password_hash: Pleroma.Password.hash_pwd_salt(password), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), password_reset_pending: true ) @@ -1012,7 +1012,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do user = insert(:user, - password_hash: Pleroma.Password.hash_pwd_salt(password), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), confirmation_pending: true ) @@ -1040,7 +1040,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do user = insert(:user, - password_hash: Pleroma.Password.hash_pwd_salt(password), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), approval_pending: true ) diff --git a/test/pleroma/web/plugs/authentication_plug_test.exs b/test/pleroma/web/plugs/authentication_plug_test.exs index 4a0ff6710..118ab302a 100644 --- a/test/pleroma/web/plugs/authentication_plug_test.exs +++ b/test/pleroma/web/plugs/authentication_plug_test.exs @@ -17,7 +17,7 @@ defmodule Pleroma.Web.Plugs.AuthenticationPlugTest do user = %User{ id: 1, name: "dude", - password_hash: Pleroma.Password.hash_pwd_salt("guy") + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("guy") } conn = diff --git a/test/pleroma/web/twitter_api/password_controller_test.exs b/test/pleroma/web/twitter_api/password_controller_test.exs index 880f097cb..cf99e2434 100644 --- a/test/pleroma/web/twitter_api/password_controller_test.exs +++ b/test/pleroma/web/twitter_api/password_controller_test.exs @@ -92,7 +92,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do assert response =~ "<h2>Password changed!</h2>" user = refresh_record(user) - assert Pleroma.Password.verify_pass("test", user.password_hash) + assert Pleroma.Password.Pbkdf2.verify_pass("test", user.password_hash) assert Enum.empty?(Token.get_user_tokens(user)) end diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs index 923be8fae..6d007ab66 100644 --- a/test/pleroma/web/twitter_api/util_controller_test.exs +++ b/test/pleroma/web/twitter_api/util_controller_test.exs @@ -397,7 +397,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert json_response(conn, 200) == %{"status" => "success"} fetched_user = User.get_cached_by_id(user.id) - assert Pleroma.Password.verify_pass("newpass", fetched_user.password_hash) == true + assert Pleroma.Password.Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true end end diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex index 27470498d..6bccbb35a 100644 --- a/test/support/builders/user_builder.ex +++ b/test/support/builders/user_builder.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Builders.UserBuilder do email: "test@example.org", name: "Test Name", nickname: "testname", - password_hash: Pleroma.Password.hash_pwd_salt("test"), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"), bio: "A tester.", ap_id: "some id", last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second), diff --git a/test/support/factory.ex b/test/support/factory.ex index 53b1dfd09..bf9592064 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -29,7 +29,7 @@ defmodule Pleroma.Factory do name: sequence(:name, &"Test テスト User #{&1}"), email: sequence(:email, &"user#{&1}@example.com"), nickname: sequence(:nickname, &"nick#{&1}"), - password_hash: Pleroma.Password.hash_pwd_salt("test"), + password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"), bio: sequence(:bio, &"Tester Number #{&1}"), is_discoverable: true, last_digest_emailed_at: NaiveDateTime.utc_now(), |