commit: 619f247e38eb70746426d6440a373c4d682c776b
parent 0f3b1808fd3dc835e0fe993ceb16ec4d6ea12c03
Author: Phantasm <phantasm@centrum.cz>
Date: Sat, 23 Aug 2025 23:55:36 +0200
Add more URL-encoding tests
Diffstat:
2 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/test/pleroma/http_test.exs b/test/pleroma/http_test.exs
@@ -28,6 +28,15 @@ defmodule Pleroma.HTTPTest do
%{method: :get, url: "https://example.com/emoji/Pack%201/koronebless.png?foo=bar+baz"} ->
%Tesla.Env{status: 200, body: "emoji data"}
+
+ %{
+ method: :get,
+ url: "https://example.com/media/foo/bar%20!$&'()*+,;=/:%20@a%20%5Bbaz%5D.mp4"
+ } ->
+ %Tesla.Env{status: 200, body: "video data"}
+
+ %{method: :get, url: "https://example.com/media/unicode%20%F0%9F%99%82%20.gif"} ->
+ %Tesla.Env{status: 200, body: "unicode data"}
end)
:ok
@@ -85,5 +94,17 @@ defmodule Pleroma.HTTPTest do
{:ok, result} = HTTP.get(properly_encoded_url)
assert result.status == 200
+
+ url_with_reserved_chars = "https://example.com/media/foo/bar !$&'()*+,;=/: @a [baz].mp4"
+
+ {:ok, result} = HTTP.get(url_with_reserved_chars)
+
+ assert result.status == 200
+
+ url_with_unicode = "https://example.com/media/unicode 🙂 .gif"
+
+ {:ok, result} = HTTP.get(url_with_unicode)
+
+ assert result.status == 200
end
end
diff --git a/test/pleroma/reverse_proxy_test.exs b/test/pleroma/reverse_proxy_test.exs
@@ -402,12 +402,27 @@ defmodule Pleroma.ReverseProxyTest do
describe "Hackney URL encoding:" do
setup do
ClientMock
- |> expect(:request, fn :get,
- "https://example.com/emoji/Pack%201/koronebless.png?foo=bar+baz",
- _headers,
- _body,
- _opts ->
- {:ok, 200, [{"content-type", "image/png"}], "It works!"}
+ |> expect(:request, fn
+ :get,
+ "https://example.com/emoji/Pack%201/koronebless.png?foo=bar+baz",
+ _headers,
+ _body,
+ _opts ->
+ {:ok, 200, [{"content-type", "image/png"}], "It works!"}
+
+ :get,
+ "https://example.com/media/foo/bar%20!$&'()*+,;=/:%20@a%20%5Bbaz%5D.mp4",
+ _headers,
+ _body,
+ _opts ->
+ {:ok, 200, [{"content-type", "video/mp4"}], "Allowed reserved chars."}
+
+ :get,
+ "https://example.com/media/unicode%20%F0%9F%99%82%20.gif",
+ _headers,
+ _body,
+ _opts ->
+ {:ok, 200, [{"content-type", "image/gif"}], "Unicode emoji in path"}
end)
|> stub(:stream_body, fn _ -> :done end)
|> stub(:close, fn _ -> :ok end)
@@ -430,5 +445,21 @@ defmodule Pleroma.ReverseProxyTest do
assert result.status == 200
end
+
+ test "properly encodes URLs with allowed reserved characters", %{conn: conn} do
+ url_with_reserved_chars = "https://example.com/media/foo/bar !$&'()*+,;=/: @a [baz].mp4"
+
+ result = ReverseProxy.call(conn, url_with_reserved_chars)
+
+ assert result.status == 200
+ end
+
+ test "properly encodes URLs with unicode in path", %{conn: conn} do
+ url_with_unicode = "https://example.com/media/unicode 🙂 .gif"
+
+ result = ReverseProxy.call(conn, url_with_unicode)
+
+ assert result.status == 200
+ end
end
end