summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-09-18 12:25:10 +0000
committerlain <lain@soykaf.club>2020-09-18 12:25:10 +0000
commit7e02f4ed3b9601c1590e77a1aa8e56bc7edf6d18 (patch)
treec5d3666775ffb9ffeac1b3285bb0122374806c0b
parent875b6654ec3f4cd0dd965bd3d2bdc1f67bb9c07a (diff)
parent226fa3e486e3ea9f82e8d3a7025244fdf11d14db (diff)
Merge branch 'feature/2118-web-push-encryption-http' into 'develop'
Make WebPushEncryption use Pleroma.HTTP as an HTTP adapter Closes #2118 See merge request pleroma/pleroma!3008
-rw-r--r--config/config.exs2
-rw-r--r--test/web/push/impl_test.exs18
2 files changed, 20 insertions, 0 deletions
diff --git a/config/config.exs b/config/config.exs
index 104013b41..147f09722 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -799,6 +799,8 @@ config :tzdata, :http_client, Pleroma.HTTP.Tzdata
config :ex_aws, http_client: Pleroma.HTTP.ExAws
+config :web_push_encryption, http_client: Pleroma.HTTP
+
config :pleroma, :instances_favicons, enabled: false
config :floki, :html_parser, Floki.HTMLParser.FastHtml
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index aeb5c1fbd..c7c17e156 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -12,7 +12,9 @@ defmodule Pleroma.Web.Push.ImplTest do
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
+ alias Pleroma.Web.WebPushHttpClientMock
+ import Mock
import Pleroma.Factory
setup do
@@ -78,6 +80,22 @@ defmodule Pleroma.Web.Push.ImplTest do
assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok
end
+ test_with_mock "uses WebPushHttpClientMock as an HTTP client", WebPushHttpClientMock,
+ post: fn _, _, _ -> {:ok, %{status_code: 200}} end do
+ Impl.push_message(@message, @sub, @api_key, %Subscription{})
+ assert_called(WebPushHttpClientMock.post("https://example.com/example/1234", :_, :_))
+ end
+
+ test_with_mock "uses Pleroma.HTTP as an HTTP client", Pleroma.HTTP,
+ post: fn _, _, _ -> {:ok, %{status_code: 200}} end do
+ client = Application.get_env(:web_push_encryption, :http_client)
+ on_exit(fn -> Application.put_env(:web_push_encryption, :http_client, client) end)
+ Application.put_env(:web_push_encryption, :http_client, Pleroma.HTTP)
+
+ Impl.push_message(@message, @sub, @api_key, %Subscription{})
+ assert_called(Pleroma.HTTP.post("https://example.com/example/1234", :_, :_))
+ end
+
@tag capture_log: true
test "fail message sending" do
assert Impl.push_message(