Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.4KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.WebFingerTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.Web.WebFinger
  7. import Pleroma.Factory
  8. import Tesla.Mock
  9. setup do
  10. mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
  11. :ok
  12. end
  13. describe "host meta" do
  14. test "returns a link to the xml lrdd" do
  15. host_info = WebFinger.host_meta()
  16. assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
  17. end
  18. end
  19. describe "incoming webfinger request" do
  20. test "works for fqns" do
  21. user = insert(:user)
  22. {:ok, result} =
  23. WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
  24. assert is_binary(result)
  25. end
  26. test "works for ap_ids" do
  27. user = insert(:user)
  28. {:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
  29. assert is_binary(result)
  30. end
  31. end
  32. describe "fingering" do
  33. test "returns error for nonsensical input" do
  34. assert {:error, _} = WebFinger.finger("bliblablu")
  35. assert {:error, _} = WebFinger.finger("pleroma.social")
  36. end
  37. test "returns error when fails parse xml or json" do
  38. user = "invalid_content@social.heldscal.la"
  39. assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
  40. end
  41. test "returns the ActivityPub actor URI for an ActivityPub user" do
  42. user = "framasoft@framatube.org"
  43. {:ok, _data} = WebFinger.finger(user)
  44. end
  45. test "returns the ActivityPub actor URI and subscribe address for an ActivityPub user with the ld+json mimetype" do
  46. user = "kaniini@gerzilla.de"
  47. {:ok, data} = WebFinger.finger(user)
  48. assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
  49. assert data["subscribe_address"] == "https://gerzilla.de/follow?f=&url={uri}"
  50. end
  51. test "it work for AP-only user" do
  52. user = "kpherox@mstdn.jp"
  53. {:ok, data} = WebFinger.finger(user)
  54. assert data["magic_key"] == nil
  55. assert data["salmon"] == nil
  56. assert data["topic"] == nil
  57. assert data["subject"] == "acct:kPherox@mstdn.jp"
  58. assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
  59. assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
  60. end
  61. test "it works for friendica" do
  62. user = "lain@squeet.me"
  63. {:ok, _data} = WebFinger.finger(user)
  64. end
  65. test "it gets the xrd endpoint" do
  66. {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
  67. assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
  68. end
  69. test "it gets the xrd endpoint for hubzilla" do
  70. {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
  71. assert template == "https://macgirvin.com/xrd/?uri={uri}"
  72. end
  73. test "it gets the xrd endpoint for statusnet" do
  74. {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
  75. assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
  76. end
  77. test "it works with idna domains as nickname" do
  78. nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
  79. {:ok, _data} = WebFinger.finger(nickname)
  80. end
  81. test "it works with idna domains as link" do
  82. ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
  83. {:ok, _data} = WebFinger.finger(ap_id)
  84. end
  85. end
  86. end