generate keys at registration time

This commit is contained in:
FloatingGhost 2022-08-24 13:31:00 +01:00
parent 935d397692
commit 0772d003e3
2 changed files with 9 additions and 1 deletions

View File

@ -681,6 +681,7 @@ defmodule Pleroma.User do
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|> validate_format(:nickname, local_nickname_regex())
|> put_ap_id()
|> put_keys()
|> unique_constraint(:ap_id)
|> put_following_and_follower_and_featured_address()
end
@ -740,6 +741,7 @@ defmodule Pleroma.User do
|> validate_length(:registration_reason, max: reason_limit)
|> maybe_validate_required_email(opts[:external])
|> put_password_hash
|> put_keys()
|> put_ap_id()
|> unique_constraint(:ap_id)
|> put_following_and_follower_and_featured_address()
@ -755,6 +757,11 @@ defmodule Pleroma.User do
end
end
def put_keys(changeset) do
{:ok, pem} = Keys.generate_rsa_pem()
put_change(changeset, :keys, pem)
end
def put_ap_id(changeset) do
ap_id = ap_id(%User{nickname: get_field(changeset, :nickname)})
put_change(changeset, :ap_id, ap_id)

View File

@ -620,13 +620,14 @@ defmodule Pleroma.UserTest do
assert changeset.valid?
end
test "it sets the password_hash and ap_id" do
test "it sets the password_hash, ap_id and PEM key" do
changeset = User.register_changeset(%User{}, @full_user_data)
assert changeset.valid?
assert is_binary(changeset.changes[:password_hash])
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
assert is_binary(changeset.changes[:keys])
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
end