Remove LDAP mail attribute as a requirement for registering an account
authorMark Felder <feld@FreeBSD.org>
Wed, 5 Aug 2020 13:15:57 +0000 (08:15 -0500)
committerMark Felder <feld@FreeBSD.org>
Wed, 5 Aug 2020 13:15:57 +0000 (08:15 -0500)
lib/pleroma/web/auth/ldap_authenticator.ex
test/web/oauth/ldap_authorization_test.exs

index f63a66c039fc56585b6b920f7420c4a160765dff..f320ec7466d3c3805183c60872c9770f25055908 100644 (file)
@@ -105,29 +105,21 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
            {:base, to_charlist(base)},
            {:filter, :eldap.equalityMatch(to_charlist(uid), to_charlist(name))},
            {:scope, :eldap.wholeSubtree()},
-           {:attributes, ['mail', 'email']},
            {:timeout, @search_timeout}
          ]) do
-      {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
-        with {_, [mail]} <- List.keyfind(attributes, 'mail', 0) do
-          params = %{
-            email: :erlang.list_to_binary(mail),
-            name: name,
-            nickname: name,
-            password: password,
-            password_confirmation: password
-          }
-
-          changeset = User.register_changeset(%User{}, params)
-
-          case User.register(changeset) do
-            {:ok, user} -> user
-            error -> error
-          end
-        else
-          _ ->
-            Logger.error("Could not find LDAP attribute mail: #{inspect(attributes)}")
-            {:error, :ldap_registration_missing_attributes}
+      {:ok, {:eldap_search_result, [{:eldap_entry, _, _}], _}} ->
+        params = %{
+          name: name,
+          nickname: name,
+          password: password,
+          password_confirmation: password
+        }
+
+        changeset = User.register_changeset(%User{}, params)
+
+        case User.register(changeset) do
+          {:ok, user} -> user
+          error -> error
         end
 
       error ->
index 011642c0874d13dc31e0455bffd1ab5022d73e4c..76ae461c35301b0893ec46cdda7d1b3002f263f8 100644 (file)
@@ -72,9 +72,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
          equalityMatch: fn _type, _value -> :ok end,
          wholeSubtree: fn -> :ok end,
          search: fn _connection, _options ->
-           {:ok,
-            {:eldap_search_result, [{:eldap_entry, '', [{'mail', [to_charlist(user.email)]}]}],
-             []}}
+           {:ok, {:eldap_search_result, [{:eldap_entry, '', []}], []}}
          end,
          close: fn _connection ->
            send(self(), :close_connection)