Convert tests to all use clear_config instead of Pleroma.Config.put

This commit is contained in:
Mark Felder 2021-01-26 11:58:43 -06:00
commit e854c35e65
69 changed files with 325 additions and 368 deletions

View file

@ -35,7 +35,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
end
test "with `admin_token` query parameter", %{conn: conn} do
Pleroma.Config.put(:admin_token, "password123")
clear_config(:admin_token, "password123")
conn =
%{conn | params: %{"admin_token" => "wrong_password"}}
@ -54,7 +54,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
end
test "with `x-admin-token` HTTP header", %{conn: conn} do
Pleroma.Config.put(:admin_token, "☕️")
clear_config(:admin_token, "☕️")
conn =
conn

View file

@ -5,14 +5,13 @@
defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
use Pleroma.Web.ConnCase
alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
setup do: clear_config([:instance, :public])
test "it halts if not public and no user is assigned", %{conn: conn} do
Config.put([:instance, :public], false)
clear_config([:instance, :public], false)
conn =
conn
@ -23,7 +22,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if public", %{conn: conn} do
Config.put([:instance, :public], true)
clear_config([:instance, :public], true)
ret_conn =
conn
@ -33,7 +32,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if a user is assigned, even if not public", %{conn: conn} do
Config.put([:instance, :public], false)
clear_config([:instance, :public], false)
conn =
conn

View file

@ -8,7 +8,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
setup do: clear_config([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
Pleroma.Config.put([:instance, :federating], false)
clear_config([:instance, :federating], false)
conn =
build_conn()
@ -19,7 +19,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
end
test "does nothing when federating is enabled" do
Pleroma.Config.put([:instance, :federating], true)
clear_config([:instance, :federating], true)
conn =
build_conn()

View file

@ -32,11 +32,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
describe "requires a signature when `authorized_fetch_mode` is enabled" do
setup do
Pleroma.Config.put([:activitypub, :authorized_fetch_mode], true)
on_exit(fn ->
Pleroma.Config.put([:activitypub, :authorized_fetch_mode], false)
end)
clear_config([:activitypub, :authorized_fetch_mode], true)
params = %{"actor" => "http://mastodon.example.org/users/admin"}
conn = build_conn(:get, "/doesntmattter", params) |> put_format("activity+json")

View file

@ -181,7 +181,7 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
"and [optionally] keeps only prefixed scopes, " <>
"depending on `[:auth, :enforce_oauth_admin_scope_usage]` setting",
%{f: f} do
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
assert f.(["read"], %{admin: true}) == ["admin:read", "read"]
@ -192,7 +192,7 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
"write"
]
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
assert f.(["read:accounts"], %{admin: true}) == ["admin:read:accounts"]

View file

@ -6,7 +6,6 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
use Pleroma.Web.ConnCase
alias Phoenix.ConnTest
alias Pleroma.Config
alias Pleroma.Web.Plugs.RateLimiter
alias Plug.Conn
@ -22,8 +21,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
setup do: clear_config([Pleroma.Web.Plugs.RemoteIp, :enabled])
test "config is required for plug to work" do
Config.put([:rate_limit, @limiter_name], {1, 1})
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, @limiter_name], {1, 1})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
assert %{limits: {1, 1}, name: :test_init, opts: [name: :test_init]} ==
[name: @limiter_name]
@ -54,8 +53,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
scale = 80
limit = 5
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
Config.put([:rate_limit, limiter_name], {scale, limit})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], {scale, limit})
plug_opts = RateLimiter.init(name: limiter_name)
conn = build_conn(:get, "/")
@ -86,8 +85,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "`bucket_name` option overrides default bucket name" do
limiter_name = :test_bucket_name
Config.put([:rate_limit, limiter_name], {1000, 5})
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], {1000, 5})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
plug_opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name)
@ -101,8 +100,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "`params` option allows different queries to be tracked independently" do
limiter_name = :test_params
Config.put([:rate_limit, limiter_name], {1000, 5})
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], {1000, 5})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name, params: ["id"])
@ -117,8 +116,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "it supports combination of options modifying bucket name" do
limiter_name = :test_options_combo
Config.put([:rate_limit, limiter_name], {1000, 5})
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], {1000, 5})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
@ -140,8 +139,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
describe "unauthenticated users" do
test "are restricted based on remote IP" do
limiter_name = :test_unauthenticated
Config.put([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
@ -180,8 +179,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
scale = 50
limit = 5
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
Config.put([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
plug_opts = RateLimiter.init(name: limiter_name)
@ -202,8 +201,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "different users are counted independently" do
limiter_name = :test_authenticated2
Config.put([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
@ -232,8 +231,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "doesn't crash due to a race condition when multiple requests are made at the same time and the bucket is not yet initialized" do
limiter_name = :test_race_condition
Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5})
Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
clear_config([:rate_limit, limiter_name], {1000, 5})
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
opts = RateLimiter.init(name: limiter_name)

View file

@ -26,7 +26,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
)
test "disabled" do
Pleroma.Config.put(RemoteIp, enabled: false)
clear_config(RemoteIp, enabled: false)
%{remote_ip: remote_ip} = conn(:get, "/")
@ -48,7 +48,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "custom headers" do
Pleroma.Config.put(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
clear_config(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
conn =
conn(:get, "/")
@ -73,7 +73,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
refute conn.remote_ip == {1, 1, 1, 1}
Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.0/20"])
clear_config([RemoteIp, :proxies], ["173.245.48.0/20"])
conn =
conn(:get, "/")
@ -84,7 +84,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "proxies set without CIDR format" do
Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.1"])
clear_config([RemoteIp, :proxies], ["173.245.48.1"])
conn =
conn(:get, "/")
@ -95,8 +95,8 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "proxies set `nonsensical` CIDR" do
Pleroma.Config.put([RemoteIp, :reserved], ["127.0.0.0/8"])
Pleroma.Config.put([RemoteIp, :proxies], ["10.0.0.3/24"])
clear_config([RemoteIp, :reserved], ["127.0.0.0/8"])
clear_config([RemoteIp, :proxies], ["10.0.0.3/24"])
conn =
conn(:get, "/")

View file

@ -20,7 +20,7 @@ defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
%{conn: conn} do
Pleroma.Config.put([:instance, :account_activation_required], true)
clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: false)