Merge branch 'develop' into 'develop'
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>
Sun, 16 Dec 2018 12:13:32 +0000 (12:13 +0000)
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>
Sun, 16 Dec 2018 12:13:32 +0000 (12:13 +0000)
Added init file for OpenBSD

See merge request pleroma/pleroma!549

24 files changed:
config/config.exs
config/config.md
config/dev.exs
lib/mix/tasks/pleroma/instance.ex
lib/mix/tasks/pleroma/sample_config.eex
lib/pleroma/emails/user_email.ex
lib/pleroma/formatter.ex
lib/pleroma/html.ex
lib/pleroma/user/info.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/controllers/util_controller.ex
lib/pleroma/web/twitter_api/views/activity_view.ex
mix.exs
mix.lock
test/formatter_test.exs
test/web/admin_api/admin_api_controller_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/mastodon_api/status_view_test.exs
test/web/web_finger/web_finger_controller_test.exs [new file with mode: 0644]

index 1401b0a3dadabe90c276c04b97df163aee154c11..1777a54c0918d0d8b2b1a158adb49160b364e841 100644 (file)
@@ -65,6 +65,7 @@ config :logger, :console,
 config :mime, :types, %{
   "application/xml" => ["xml"],
   "application/xrd+xml" => ["xrd+xml"],
+  "application/jrd+json" => ["jrd+json"],
   "application/activity+json" => ["activity+json"],
   "application/ld+json" => ["activity+json"]
 }
index d4dad77b1fb90dd838beefc8121d38711a79ff45..8282eab1480a443b88b6c466cdeb264e1d09aded 100644 (file)
@@ -67,7 +67,8 @@ config :pleroma, Pleroma.Mailer,
 * `avatar_upload_limit`: File size limit of user’s profile avatars
 * `background_upload_limit`: File size limit of user’s profile backgrounds
 * `banner_upload_limit`: File size limit of user’s profile banners
-* `registrations_open`: Enable registrations for anyone, invitations can be used when false.
+* `registrations_open`: Enable registrations for anyone, invitations can be enabled when false.
+* `invites_enabled`: Enable user invitations for admins (depends on `registrations_open: false`).
 * `federating`: Enable federation with other instances
 * `allow_relay`: Enable Pleroma’s Relay, which makes it possible to follow a whole instance
 * `rewrite_policy`: Message Rewrite Policy, either one or a list. Here are the ones available by default:
index 080a2f8dbcdd8f0a21cf4b22d0a41024094537a0..8f89aa03c3d4a68e0097a652fc9e24f6d1c5c2af 100644 (file)
@@ -12,6 +12,7 @@ config :pleroma, Pleroma.Web.Endpoint,
     protocol_options: [max_request_line_length: 8192, max_header_value_length: 8192]
   ],
   protocol: "http",
+  secure_cookie_flag: false,
   debug_errors: true,
   code_reloader: true,
   check_origin: false,
index 3be856115794694e8a405c7c944f5efdafb14dcc..02e1ce27dfc6130abcf1fc551b4edb514ae18c86 100644 (file)
@@ -58,12 +58,15 @@ defmodule Mix.Tasks.Pleroma.Instance do
     proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false)
 
     unless not proceed? do
-      domain =
-        Common.get_option(
-          options,
-          :domain,
-          "What domain will your instance use? (e.g pleroma.soykaf.com)"
-        )
+      [domain, port | _] =
+        String.split(
+          Common.get_option(
+            options,
+            :domain,
+            "What domain will your instance use? (e.g pleroma.soykaf.com)"
+          ),
+          ":"
+        ) ++ [443]
 
       name =
         Common.get_option(
@@ -104,6 +107,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
         EEx.eval_file(
           "sample_config.eex" |> Path.expand(__DIR__),
           domain: domain,
+          port: port,
           email: email,
           name: name,
           dbhost: dbhost,
index 0cd572797567a28e918c590c78b1fbceade68ca3..740b9f8d1da4ae7d50ca252b41b5c717780bd3b8 100644 (file)
@@ -6,7 +6,7 @@
 use Mix.Config
 
 config :pleroma, Pleroma.Web.Endpoint,
-   url: [host: "<%= domain %>", scheme: "https", port: 443],
+   url: [host: "<%= domain %>", scheme: "https", port: <%= port %>],
    secret_key_base: "<%= secret %>"
 
 config :pleroma, :instance,
index 9cdf002f30eaf2b8b7e50c47dd2bcb09eb93ea4f..7e3e9b0207d120d2a4f4a09159db6965a7e4a9cc 100644 (file)
@@ -37,4 +37,30 @@ defmodule Pleroma.UserEmail do
     |> subject("Password reset")
     |> html_body(html_body)
   end
+
+  def user_invitation_email(
+        user,
+        %Pleroma.UserInviteToken{} = user_invite_token,
+        to_email,
+        to_name \\ nil
+      ) do
+    registration_url =
+      Router.Helpers.redirect_url(
+        Endpoint,
+        :registration_page,
+        user_invite_token.token
+      )
+
+    html_body = """
+    <h3>You are invited to #{instance_name()}</h3>
+    <p>#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.</p>
+    <p>Click the following link to register: <a href="#{registration_url}">accept invitation</a>.</p>
+    """
+
+    new()
+    |> to(recipient(to_email, to_name))
+    |> from(sender())
+    |> subject("Invitation to #{instance_name()}")
+    |> html_body(html_body)
+  end
 end
index 1336837944af4c3c80b2e8013dab5cb6870debe0..46d0d926a814b2177c4aeefff7cc79e37b8f74e6 100644 (file)
@@ -5,6 +5,8 @@ defmodule Pleroma.Formatter do
   alias Pleroma.Emoji
 
   @tag_regex ~r/\#\w+/u
+  @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
+
   def parse_tags(text, data \\ %{}) do
     Regex.scan(@tag_regex, text)
     |> Enum.map(fn ["#" <> tag = full_tag] -> {full_tag, String.downcase(tag)} end)
@@ -76,6 +78,18 @@ defmodule Pleroma.Formatter do
     |> Enum.join("")
   end
 
+  @doc """
+  Escapes a special characters in mention names.
+  """
+  @spec mentions_escape(String.t(), list({String.t(), any()})) :: String.t()
+  def mentions_escape(text, mentions) do
+    mentions
+    |> Enum.reduce(text, fn {name, _}, acc ->
+      escape_name = String.replace(name, @markdown_characters_regex, "\\\\\\1")
+      String.replace(acc, name, escape_name)
+    end)
+  end
+
   @doc "changes scheme:... urls to html links"
   def add_links({subs, text}) do
     links =
index 8a0333461557a1000108e8b3d802d77be1d310ff..583f05aebc0d33535c1c788ca5dc486582efd35d 100644 (file)
@@ -17,15 +17,9 @@ defmodule Pleroma.HTML do
     end)
   end
 
-  def filter_tags(html, scrubber) do
-    html |> Scrubber.scrub(scrubber)
-  end
-
+  def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber)
   def filter_tags(html), do: filter_tags(html, nil)
-
-  def strip_tags(html) do
-    html |> Scrubber.scrub(Scrubber.StripTags)
-  end
+  def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
 end
 
 defmodule Pleroma.HTML.Scrubber.TwitterText do
index d81b45b8d077322a3645d74442c82d638f8aed40..a3785447c39164876ed9af74ec2551bbc44ed0e4 100644 (file)
@@ -149,9 +149,12 @@ defmodule Pleroma.User.Info do
     ])
   end
 
-  def mastodon_settings_update(info, params) do
+  def mastodon_settings_update(info, settings) do
+    params = %{settings: settings}
+
     info
     |> cast(params, [:settings])
+    |> validate_required([:settings])
   end
 
   def set_source_data(info, source_data) do
index 06c3c7c817a61c908e859254845aba44bbfc620c..4d73cf219c379f47022b6fcddfb0d5674ee0babb 100644 (file)
@@ -147,6 +147,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
     end
   end
 
+  @doc "Sends registration invite via email"
+  def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do
+    with true <-
+           Pleroma.Config.get([:instance, :invites_enabled]) &&
+             !Pleroma.Config.get([:instance, :registrations_open]),
+         {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(),
+         email <-
+           Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]),
+         {:ok, _} <- Pleroma.Mailer.deliver(email) do
+      json_response(conn, :no_content, "")
+    end
+  end
+
   @doc "Get a account registeration invite token (base64 string)"
   def get_invite_token(conn, _params) do
     {:ok, token} = Pleroma.UserInviteToken.create_token()
index ce0926b99b65fb097ce48599e852921ab4ee0ab4..142283684b4d176448edd7605c8bae7eb7b79b0f 100644 (file)
@@ -112,6 +112,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     Enum.join([text | attachment_text], "<br>")
   end
 
+  @doc """
+  Formatting text to plain text.
+  """
   def format_input(text, mentions, tags, "text/plain") do
     text
     |> Formatter.html_escape("text/plain")
@@ -123,6 +126,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     |> Formatter.finalize()
   end
 
+  @doc """
+  Formatting text to html.
+  """
   def format_input(text, mentions, _tags, "text/html") do
     text
     |> Formatter.html_escape("text/html")
@@ -132,8 +138,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     |> Formatter.finalize()
   end
 
+  @doc """
+  Formatting text to markdown.
+  """
   def format_input(text, mentions, tags, "text/markdown") do
     text
+    |> Formatter.mentions_escape(mentions)
     |> Earmark.as_html!()
     |> Formatter.html_escape("text/html")
     |> String.replace(~r/\r?\n/, "")
index 0414d73d86d815af5a4f3b64d1b06f6edc284789..726807f0aa3590cef98329fa7b3807dcc1a1536f 100644 (file)
@@ -929,7 +929,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
             ]
           },
           settings:
-            Map.get(user.info, :settings) ||
+            user.info.settings ||
               %{
                 onboarded: true,
                 home: %{
@@ -978,13 +978,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
     info_cng = User.Info.mastodon_settings_update(user.info, settings)
 
-    with changeset <- User.update_changeset(user),
+    with changeset <- Ecto.Changeset.change(user),
          changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
          {:ok, _user} <- User.update_and_set_cache(changeset) do
       json(conn, %{})
     else
       e ->
-        json(conn, %{error: inspect(e)})
+        conn
+        |> put_resp_content_type("application/json")
+        |> send_resp(500, Jason.encode!(%{"error" => inspect(e)}))
     end
   end
 
index c3c735d5d52c53af3ad83ca012cca0436d248f10..46c559e3ac0740687f64e24064d701e62e63dcf6 100644 (file)
@@ -140,7 +140,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       visibility: get_visibility(object),
       media_attachments: attachments |> Enum.take(4),
       mentions: mentions,
-      tags: tags,
+      tags: build_tags(tags),
       application: %{
         name: "Web",
         website: nil
@@ -234,6 +234,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
   def render_content(object), do: object["content"] || ""
 
+  @doc """
+  Builds a dictionary tags.
+
+  ## Examples
+
+  iex> Pleroma.Web.MastodonAPI.StatusView.build_tags(["fediverse", "nextcloud"])
+  [{"name": "fediverse", "url": "/tag/fediverse"},
+   {"name": "nextcloud", "url": "/tag/nextcloud"}]
+
+  """
+  @spec build_tags(list(any())) :: list(map())
+  def build_tags(object_tags) when is_list(object_tags) do
+    object_tags = for tag when is_binary(tag) <- object_tags, do: tag
+
+    Enum.reduce(object_tags, [], fn tag, tags ->
+      tags ++ [%{name: tag, url: "/tag/#{tag}"}]
+    end)
+  end
+
+  def build_tags(_), do: []
+
   @doc """
   Builds list emojis.
 
index 277dc6ba1bc6fed75af858f88c0d302e88fc0a79..44c11f40a35efaec656778044a7b70c5762e1737 100644 (file)
@@ -132,6 +132,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
           banner: Keyword.get(instance, :banner_upload_limit),
           background: Keyword.get(instance, :background_upload_limit)
         },
+        invitesEnabled: Keyword.get(instance, :invites_enabled, false),
         features: features
       }
     }
index 6253a28dbf8b9d90dd727097ecdf81fc02712068..daff3362c9b9ae3a039883253e886706558e6961 100644 (file)
@@ -117,6 +117,8 @@ defmodule Pleroma.Web.Router do
     delete("/relay", AdminAPIController, :relay_unfollow)
 
     get("/invite_token", AdminAPIController, :get_invite_token)
+    post("/email_invite", AdminAPIController, :email_invite)
+
     get("/password_reset", AdminAPIController, :get_password_reset)
   end
 
index a8e3467c46a0398bd6827b351d867a652f7ade46..2f2b69623d63474bd48f2784ef4eb34703396ae5 100644 (file)
@@ -173,7 +173,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
           uploadlimit: uploadlimit,
           closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"),
           private: if(Keyword.get(instance, :public, true), do: "0", else: "1"),
-          vapidPublicKey: vapid_public_key
+          vapidPublicKey: vapid_public_key,
+          invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0")
         }
 
         pleroma_fe = %{
index e5caed28f5011162f20a96ee79d6c28bb69949c6..0699bf1da9f0d0b737cff5720e65c134746b4265 100644 (file)
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
   alias Pleroma.HTML
 
   import Ecto.Query
+  require Logger
 
   defp query_context_ids([]), do: []
 
@@ -239,7 +240,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
     {summary, content} = render_content(object)
 
     html =
-      HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
+      content
+      |> HTML.filter_tags(User.html_filter_policy(opts[:for]))
       |> Formatter.emojify(object["emoji"])
 
     reply_parent = Activity.get_in_reply_to_activity(activity)
@@ -276,6 +278,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
     }
   end
 
+  def render("activity.json", %{activity: unhandled_activity}) do
+    Logger.warn("#{__MODULE__} unhandled activity: #{inspect(unhandled_activity)}")
+    nil
+  end
+
   def render_content(%{"type" => "Note"} = object) do
     summary = object["summary"]
 
diff --git a/mix.exs b/mix.exs
index 0fb40e07b11387b98ae161f5d83ddb939d6d2d5d..5b56b94904dd8c1551a2bab4757f6f5c619e65a2 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -8,12 +8,7 @@ defmodule Pleroma.Mixfile do
       elixir: "~> 1.4",
       elixirc_paths: elixirc_paths(Mix.env()),
       compilers: [:phoenix, :gettext] ++ Mix.compilers(),
-      elixirc_options:
-        if Mix.env() == :test do
-          []
-        else
-          [warnings_as_errors: true]
-        end,
+      elixirc_options: [warnings_as_errors: true],
       start_permanent: Mix.env() == :prod,
       aliases: aliases(),
       deps: deps(),
@@ -67,7 +62,7 @@ defmodule Pleroma.Mixfile do
       {:mogrify, "~> 0.6.1"},
       {:ex_aws, "~> 2.0"},
       {:ex_aws_s3, "~> 2.0"},
-      {:earmark, "~> 1.2"},
+      {:earmark, "~> 1.3"},
       {:ex_machina, "~> 2.2", only: :test},
       {:credo, "~> 0.9.3", only: [:dev, :test]},
       {:mock, "~> 0.3.1", only: :test},
index d9ae9a83b22ddf0ae6050244f0dd7ed03684fc4d..6f8ca5bb034be2cafc2fc4d8bab5b9fe99d394d6 100644 (file)
--- a/mix.lock
+++ b/mix.lock
@@ -13,7 +13,7 @@
   "crypt": {:git, "https://github.com/msantos/crypt", "1f2b58927ab57e72910191a7ebaeff984382a1d3", [ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"]},
   "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
   "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
-  "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
+  "earmark": {:hex, :earmark, "1.3.0", "17f0c38eaafb4800f746b457313af4b2442a8c2405b49c645768680f900be603", [:mix], [], "hexpm"},
   "ecto": {:hex, :ecto, "2.2.10", "e7366dc82f48f8dd78fcbf3ab50985ceeb11cb3dc93435147c6e13f2cda0992e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
   "eternal": {:hex, :eternal, "1.2.0", "e2a6b6ce3b8c248f7dc31451aefca57e3bdf0e48d73ae5043229380a67614c41", [:mix], [], "hexpm"},
   "ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
index 428227d7826bcb4b0aab89e365ca3d0f280e7c3c..bb318b7d5fe9594f50b84aaf57cfe57060fb316b 100644 (file)
@@ -257,4 +257,23 @@ defmodule Pleroma.FormatterTest do
     text = nil
     assert Formatter.get_emoji(text) == []
   end
+
+  describe "/mentions_escape" do
+    test "it returns text with escaped mention names" do
+      text = """
+      @a_breakin_glass@cybre.space
+      (also, little voice inside my head thinking "maybe this will encourage people
+      pronouncing it properly instead of saying _raKEWdo_ ")
+      """
+
+      escape_text = """
+      @a\\_breakin\\_glass@cybre\\.space
+      (also, little voice inside my head thinking \"maybe this will encourage people
+      pronouncing it properly instead of saying _raKEWdo_ \")
+      """
+
+      mentions = [{"@a_breakin_glass@cybre.space", %{}}]
+      assert Formatter.mentions_escape(text, mentions) == escape_text
+    end
+  end
 end
index 4c12dd988dfd404efa97ed74fa52496d51a15abe..e183da3a121f484d2942897743ae0c54d9da90a5 100644 (file)
@@ -154,6 +154,105 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
     end
   end
 
+  describe "POST /api/pleroma/admin/email_invite, with valid config" do
+    setup do
+      registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+      invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+      Pleroma.Config.put([:instance, :registrations_open], false)
+      Pleroma.Config.put([:instance, :invites_enabled], true)
+
+      on_exit(fn ->
+        Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+        Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+        :ok
+      end)
+
+      [user: insert(:user, info: %{is_admin: true})]
+    end
+
+    test "sends invitation and returns 204", %{conn: conn, user: user} do
+      recipient_email = "foo@bar.com"
+      recipient_name = "J. D."
+
+      conn =
+        conn
+        |> assign(:user, user)
+        |> post("/api/pleroma/admin/email_invite?email=#{recipient_email}&name=#{recipient_name}")
+
+      assert json_response(conn, :no_content)
+
+      token_record = List.last(Pleroma.Repo.all(Pleroma.UserInviteToken))
+      assert token_record
+      refute token_record.used
+
+      Swoosh.TestAssertions.assert_email_sent(
+        Pleroma.UserEmail.user_invitation_email(
+          user,
+          token_record,
+          recipient_email,
+          recipient_name
+        )
+      )
+    end
+
+    test "it returns 403 if requested by a non-admin", %{conn: conn} do
+      non_admin_user = insert(:user)
+
+      conn =
+        conn
+        |> assign(:user, non_admin_user)
+        |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+      assert json_response(conn, :forbidden)
+    end
+  end
+
+  describe "POST /api/pleroma/admin/email_invite, with invalid config" do
+    setup do
+      [user: insert(:user, info: %{is_admin: true})]
+    end
+
+    test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
+      registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+      invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+      Pleroma.Config.put([:instance, :registrations_open], false)
+      Pleroma.Config.put([:instance, :invites_enabled], false)
+
+      on_exit(fn ->
+        Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+        Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+        :ok
+      end)
+
+      conn =
+        conn
+        |> assign(:user, user)
+        |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+      assert json_response(conn, :internal_server_error)
+    end
+
+    test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
+      registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+      invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+      Pleroma.Config.put([:instance, :registrations_open], true)
+      Pleroma.Config.put([:instance, :invites_enabled], true)
+
+      on_exit(fn ->
+        Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+        Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+        :ok
+      end)
+
+      conn =
+        conn
+        |> assign(:user, user)
+        |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+      assert json_response(conn, :internal_server_error)
+    end
+  end
+
   test "/api/pleroma/admin/invite_token" do
     admin = insert(:user, info: %{is_admin: true})
 
index e8275d4ab91bb4b4fbf71b726e29578841afa40c..aec0f851cf2717fe1ea35fc0a61553ef9acc44f7 100644 (file)
@@ -1415,4 +1415,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert result["stats"]["user_count"] == 2
     assert result["stats"]["status_count"] == 1
   end
+
+  test "put settings", %{conn: conn} do
+    user = insert(:user)
+
+    conn =
+      conn
+      |> assign(:user, user)
+      |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
+
+    assert result = json_response(conn, 200)
+
+    user = User.get_cached_by_ap_id(user.ap_id)
+    assert user.info.settings == %{"programming" => "socks"}
+  end
 end
index d10d59d6c75cdbb6ee0d501135372c6d103ee952..b7ac92760a35a6f23c9c9e1fd80a71e32ee795e1 100644 (file)
@@ -62,7 +62,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       visibility: "public",
       media_attachments: [],
       mentions: [],
-      tags: note.data["object"]["tag"],
+      tags: [
+        %{
+          name: "#{note.data["object"]["tag"]}",
+          url: "/tag/#{note.data["object"]["tag"]}"
+        }
+      ],
       application: %{
         name: "Web",
         website: nil
@@ -151,4 +156,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     assert represented[:reblog][:id] == to_string(activity.id)
     assert represented[:emojis] == []
   end
+
+  describe "build_tags/1" do
+    test "it returns a a dictionary tags" do
+      object_tags = [
+        "fediverse",
+        "mastodon",
+        "nextcloud",
+        %{
+          "href" => "https://kawen.space/users/lain",
+          "name" => "@lain@kawen.space",
+          "type" => "Mention"
+        }
+      ]
+
+      assert StatusView.build_tags(object_tags) == [
+               %{name: "fediverse", url: "/tag/fediverse"},
+               %{name: "mastodon", url: "/tag/mastodon"},
+               %{name: "nextcloud", url: "/tag/nextcloud"}
+             ]
+    end
+  end
 end
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
new file mode 100644 (file)
index 0000000..cac003e
--- /dev/null
@@ -0,0 +1,37 @@
+defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
+  use Pleroma.Web.ConnCase
+
+  alias Pleroma.User
+  alias Pleroma.Web.WebFinger.WebFingerController
+
+  import Pleroma.Factory
+  import ExUnit.CaptureLog
+  import Tesla.Mock
+
+  setup do
+    mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
+
+  test "Webfinger JRD" do
+    user = insert(:user)
+
+    response =
+      build_conn()
+      |> put_req_header("accept", "application/jrd+json")
+      |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+
+    assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
+  end
+
+  test "Webfinger XML" do
+    user = insert(:user)
+
+    response =
+      build_conn()
+      |> put_req_header("accept", "application/jrd+json")
+      |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+
+    assert response(response, 200)
+  end
+end