It is not allowed to use the Sec-WebSocket-Protocol header for arbitrary values. This was possible due to the raw websocket handling we were doing with Cowboy, but Phoenix.Socket.Transport does not allow this as the value of this header is compared against a static list of subprotocols.
https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#socket/3-websocket-configuration
Additionally I cannot find anywhere that we depended on this behavior. Setting the Sec-WebSocket-Protocol header does not appear to be a part of PleromaFE.
Also consolidate Tesla mocks into the HttpRequestMock module.
Tests were not exercising the real codepaths. The Rich Media Preview only works with https, but most of these tests were only mocking http.
The Rich Media Previews were not regenerated when a post was updated due to a cache invalidation issue. They are now cached by the activity id so they can be evicted with the other activity cache objects in the :scrubber_cache.
lib/pleroma/web/media_proxy/media_proxy_controller.ex:55:no_return
Function handle_preview/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:59:call
The function call will not succeed.
Pleroma.HTTP.request(<<72, 69, 65, 68>>, _media_proxy_url :: any(), [], [], [{:pool, :media}])
will never return since the success typing is:
(
:delete | :get | :head | :options | :patch | :post | :put | :trace,
binary(),
any(),
[{binary(), binary()}],
Keyword.t()
) :: any()
and the contract is
(
method(),
Pleroma.HTTP.Request.url(),
String.t(),
Pleroma.HTTP.Request.headers(),
:elixir.keyword()
) :: {:ok, Tesla.Env.t()} | {:error, any()}
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:95:unused_fun
Function handle_preview/3 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:111:unused_fun
Function handle_png_preview/2 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:134:unused_fun
Function handle_jpeg_preview/2 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:152:unused_fun
Function handle_video_preview/2 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:164:unused_fun
Function drop_static_param_and_redirect/1 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:173:unused_fun
Function fallback_on_preview_error/2 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:177:unused_fun
Function put_preview_response_headers/1 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:177:unused_fun
Function put_preview_response_headers/2 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:187:unused_fun
Function thumbnail_max_dimensions/0 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:196:unused_fun
Function min_content_length_for_preview/0 will never be called.
________________________________________________________________________________
lib/pleroma/web/media_proxy/media_proxy_controller.ex:200:unused_fun
Function media_preview_proxy_config/0 will never be called.
lib/pleroma/signature.ex:30:pattern_match
The pattern can never match the type.
Pattern:
%{<<97, 112, 95, 105, 100>> => _ap_id}
Type:
{:error, _} | {:ok, map()}
This check was recently improved in Credo and it does make sense for readability.
The offending functions in Pleroma have been renamed and a couple missing the ? suffix have been fixed as well.
This is not necessary for the tests to pass and breaks other tests as this change doesn't get cleanly reverted causing the hostname to stay set this way and leak into other test causing failures with "sub.example.com" not matching "localhost"