Merge branch 'develop' into feature/update-welcome-setting-in-description
This commit is contained in:
commit
8e90cc58e7
38 changed files with 435 additions and 70 deletions
|
|
@ -28,6 +28,34 @@ defmodule Pleroma.ConfigTest do
|
|||
assert Pleroma.Config.get([:azerty, :uiop], true) == true
|
||||
end
|
||||
|
||||
describe "nil values" do
|
||||
setup do
|
||||
Pleroma.Config.put(:lorem, nil)
|
||||
Pleroma.Config.put(:ipsum, %{dolor: [sit: nil]})
|
||||
Pleroma.Config.put(:dolor, sit: %{amet: nil})
|
||||
|
||||
on_exit(fn -> Enum.each(~w(lorem ipsum dolor)a, &Pleroma.Config.delete/1) end)
|
||||
end
|
||||
|
||||
test "get/1 with an atom for nil value" do
|
||||
assert Pleroma.Config.get(:lorem) == nil
|
||||
end
|
||||
|
||||
test "get/2 with an atom for nil value" do
|
||||
assert Pleroma.Config.get(:lorem, true) == nil
|
||||
end
|
||||
|
||||
test "get/1 with a list of keys for nil value" do
|
||||
assert Pleroma.Config.get([:ipsum, :dolor, :sit]) == nil
|
||||
assert Pleroma.Config.get([:dolor, :sit, :amet]) == nil
|
||||
end
|
||||
|
||||
test "get/2 with a list of keys for nil value" do
|
||||
assert Pleroma.Config.get([:ipsum, :dolor, :sit], true) == nil
|
||||
assert Pleroma.Config.get([:dolor, :sit, :amet], true) == nil
|
||||
end
|
||||
end
|
||||
|
||||
test "get/1 when value is false" do
|
||||
Pleroma.Config.put([:instance, :false_test], false)
|
||||
Pleroma.Config.put([:instance, :nested], [])
|
||||
|
|
@ -89,5 +117,23 @@ defmodule Pleroma.ConfigTest do
|
|||
Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
|
||||
Pleroma.Config.delete([:delete_me, :delete_me, :world])
|
||||
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
|
||||
|
||||
assert Pleroma.Config.delete([:this_key_does_not_exist])
|
||||
assert Pleroma.Config.delete([:non, :existing, :key])
|
||||
end
|
||||
|
||||
test "fetch/1" do
|
||||
Pleroma.Config.put([:lorem], :ipsum)
|
||||
Pleroma.Config.put([:ipsum], dolor: :sit)
|
||||
|
||||
assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch([:ipsum, :dolor]) == {:ok, :sit}
|
||||
assert Pleroma.Config.fetch([:lorem, :ipsum]) == :error
|
||||
assert Pleroma.Config.fetch([:loremipsum]) == :error
|
||||
assert Pleroma.Config.fetch(:loremipsum) == :error
|
||||
|
||||
Pleroma.Config.delete([:lorem])
|
||||
Pleroma.Config.delete([:ipsum])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
24
test/migrations/20200802170532_fix_legacy_tags_test.exs
Normal file
24
test/migrations/20200802170532_fix_legacy_tags_test.exs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
|
||||
alias Pleroma.User
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
|
||||
setup_all do: require_migration("20200802170532_fix_legacy_tags")
|
||||
|
||||
test "change/0 converts legacy user tags into correct values", %{migration: migration} do
|
||||
user = insert(:user, tags: ["force_nsfw", "force_unlisted", "verified"])
|
||||
user2 = insert(:user)
|
||||
|
||||
assert :ok == migration.change()
|
||||
|
||||
fixed_user = User.get_by_id(user.id)
|
||||
fixed_user2 = User.get_by_id(user2.id)
|
||||
|
||||
assert fixed_user.tags == ["mrf_tag:media-force-nsfw", "mrf_tag:force-unlisted", "verified"]
|
||||
assert fixed_user2.tags == []
|
||||
|
||||
# user2 should not have been updated
|
||||
assert fixed_user2.updated_at == fixed_user2.inserted_at
|
||||
end
|
||||
end
|
||||
|
|
@ -17,9 +17,19 @@ defmodule Pleroma.Tests.Helpers do
|
|||
|
||||
defmacro clear_config(config_path, do: yield) do
|
||||
quote do
|
||||
initial_setting = Config.get(unquote(config_path))
|
||||
initial_setting = Config.fetch(unquote(config_path))
|
||||
unquote(yield)
|
||||
on_exit(fn -> Config.put(unquote(config_path), initial_setting) end)
|
||||
|
||||
on_exit(fn ->
|
||||
case initial_setting do
|
||||
:error ->
|
||||
Config.delete(unquote(config_path))
|
||||
|
||||
{:ok, value} ->
|
||||
Config.put(unquote(config_path), value)
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ defmodule Mix.Tasks.Pleroma.AppTest do
|
|||
defp assert_app(name, redirect, scopes) do
|
||||
app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "#{name} successfully created:"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "App client_id: #{app.client_id}"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "App client_secret: #{app.client_secret}"
|
||||
|
||||
assert app.scopes == scopes
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
|||
alias Pleroma.Upload.Filter
|
||||
|
||||
test "apply exiftool filter" do
|
||||
assert Pleroma.Utils.command_available?("exiftool")
|
||||
|
||||
File.cp!(
|
||||
"test/fixtures/DSCN0010.jpg",
|
||||
"test/fixtures/DSCN0010_tmp.jpg"
|
||||
|
|
|
|||
|
|
@ -513,6 +513,29 @@ defmodule Pleroma.UserTest do
|
|||
refute changeset.valid?
|
||||
end
|
||||
|
||||
test "it blocks blacklisted email domains" do
|
||||
clear_config([User, :email_blacklist], ["trolling.world"])
|
||||
|
||||
# Block with match
|
||||
params = Map.put(@full_user_data, :email, "troll@trolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
refute changeset.valid?
|
||||
|
||||
# Block with subdomain match
|
||||
params = Map.put(@full_user_data, :email, "troll@gnomes.trolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
refute changeset.valid?
|
||||
|
||||
# Pass with different domains that are similar
|
||||
params = Map.put(@full_user_data, :email, "troll@gnomestrolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
assert changeset.valid?
|
||||
|
||||
params = Map.put(@full_user_data, :email, "troll@trolling.world.us")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
assert changeset.valid?
|
||||
end
|
||||
|
||||
test "it sets the password_hash and ap_id" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
|
||||
|
||||
@id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
|
||||
@local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
|
||||
|
||||
test "adds `expires_at` property" do
|
||||
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note"}
|
||||
})
|
||||
|
|
@ -25,6 +27,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"expires_at" => expires_at,
|
||||
"object" => %{"type" => "Note"}
|
||||
|
|
@ -37,6 +40,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"expires_at" => too_distant_future,
|
||||
"object" => %{"type" => "Note"}
|
||||
|
|
@ -49,6 +53,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note"}
|
||||
})
|
||||
|
|
@ -60,6 +65,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Follow"
|
||||
})
|
||||
|
||||
|
|
@ -68,6 +74,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Cofe"}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -124,6 +124,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
{:ok, %Activity{} = _activity} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it doesn't work for deactivated users" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
_author =
|
||||
insert(:user,
|
||||
ap_id: data["actor"],
|
||||
local: false,
|
||||
last_refreshed_at: DateTime.utc_now(),
|
||||
deactivated: true
|
||||
)
|
||||
|
||||
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it inserts it and creates a chat" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|
|
|
|||
|
|
@ -163,6 +163,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||
end
|
||||
|
||||
test "it does not work for deactivated users" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
insert(:user, ap_id: data["actor"], deactivated: true)
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
|
|
|
|||
|
|
@ -458,6 +458,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
describe "posting" do
|
||||
test "deactivated users can't post" do
|
||||
user = insert(:user, deactivated: true)
|
||||
assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
|
||||
end
|
||||
|
||||
test "it supports explicit addressing" do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
|
|
|||
|
|
@ -940,17 +940,32 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert refresh
|
||||
assert scope == "read write follow"
|
||||
|
||||
clear_config([User, :email_blacklist], ["example.org"])
|
||||
|
||||
params = %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
bio: "Test Bio",
|
||||
agreement: true
|
||||
}
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer " <> token)
|
||||
|> post("/api/v1/accounts", %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
bio: "Test Bio",
|
||||
agreement: true
|
||||
})
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
|
||||
json_response_and_validate_schema(conn, 400)
|
||||
|
||||
Pleroma.Config.put([User, :email_blacklist], [])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer " <> token)
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
%{
|
||||
"access_token" => token,
|
||||
|
|
|
|||
|
|
@ -64,11 +64,13 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
test "get a filter" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:filters"])
|
||||
|
||||
# check whole_word false
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"]
|
||||
context: ["home"],
|
||||
whole_word: false
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
|
@ -76,6 +78,25 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert response = json_response_and_validate_schema(conn, 200)
|
||||
assert response["whole_word"] == false
|
||||
|
||||
# check whole_word true
|
||||
%{user: user, conn: conn} = oauth_access(["read:filters"])
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 3,
|
||||
phrase: "knight",
|
||||
context: ["home"],
|
||||
whole_word: true
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
||||
conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert response = json_response_and_validate_schema(conn, 200)
|
||||
assert response["whole_word"] == true
|
||||
end
|
||||
|
||||
test "update a filter" do
|
||||
|
|
@ -86,7 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"],
|
||||
hide: true
|
||||
hide: true,
|
||||
whole_word: true
|
||||
}
|
||||
|
||||
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||
|
|
@ -108,6 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
assert response["phrase"] == new.phrase
|
||||
assert response["context"] == new.context
|
||||
assert response["irreversible"] == true
|
||||
assert response["whole_word"] == true
|
||||
end
|
||||
|
||||
test "delete a filter" do
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
test "returns error when followed user is deactivated" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user, local: true, deactivated: true)
|
||||
{:error, error} = MastodonAPI.follow(follower, user)
|
||||
assert error == :rejected
|
||||
assert {:error, _error} = MastodonAPI.follow(follower, user)
|
||||
end
|
||||
|
||||
test "following for user" do
|
||||
|
|
|
|||
|
|
@ -29,5 +29,16 @@ defmodule Pleroma.Web.OAuth.AppTest do
|
|||
assert exist_app.id == app.id
|
||||
assert exist_app.scopes == ["read", "write", "follow", "push"]
|
||||
end
|
||||
|
||||
test "has unique client_id" do
|
||||
insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop")
|
||||
|
||||
error =
|
||||
catch_error(insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop"))
|
||||
|
||||
assert %Ecto.ConstraintError{} = error
|
||||
assert error.constraint == "apps_client_id_index"
|
||||
assert error.type == :unique
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue