logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

web_finger_test.exs (3381B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.WebFingerTest do
  5. use Pleroma.DataCase
  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.base_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 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. end
  50. test "it work for AP-only user" do
  51. user = "kpherox@mstdn.jp"
  52. {:ok, data} = WebFinger.finger(user)
  53. assert data["magic_key"] == nil
  54. assert data["salmon"] == nil
  55. assert data["topic"] == nil
  56. assert data["subject"] == "acct:kPherox@mstdn.jp"
  57. assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
  58. assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
  59. end
  60. test "it works for friendica" do
  61. user = "lain@squeet.me"
  62. {:ok, _data} = WebFinger.finger(user)
  63. end
  64. test "it gets the xrd endpoint" do
  65. {:ok, template} = WebFinger.find_lrdd_template("social.heldscal.la")
  66. assert template == "https://social.heldscal.la/.well-known/webfinger?resource={uri}"
  67. end
  68. test "it gets the xrd endpoint for hubzilla" do
  69. {:ok, template} = WebFinger.find_lrdd_template("macgirvin.com")
  70. assert template == "https://macgirvin.com/xrd/?uri={uri}"
  71. end
  72. test "it gets the xrd endpoint for statusnet" do
  73. {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
  74. assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
  75. end
  76. test "it works with idna domains as nickname" do
  77. nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
  78. {:ok, _data} = WebFinger.finger(nickname)
  79. end
  80. test "it works with idna domains as link" do
  81. ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
  82. {:ok, _data} = WebFinger.finger(ap_id)
  83. end
  84. end
  85. end