Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
storage file_system /caddy_storage
}

https://localhost:8443 {
https://localhost:{$HTTPBIN_HTTPS_PORT:8443} {
reverse_proxy httpbin:80
}

http://localhost:8080 {
http://localhost:{$HTTPBIN_HTTP_PORT:8080} {
reverse_proxy httpbin:80
}

https://caddyhttpbin:8443 {
https://caddyhttpbin:{$HTTPBIN_HTTPS_PORT:8443} {
reverse_proxy httpbin:80
}

http://caddyhttpbin:8080 {
http://caddyhttpbin:{$HTTPBIN_HTTP_PORT:8080} {
reverse_proxy httpbin:80
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ DOCKER_USER="$UID:$GID" docker compose up --detach # or podman-compose up --deta
mix test --include proxy
```

If the default ports are already in use, you can configure them via environment variables:

```sh
TINYPROXY_PORT=8887 docker compose up --detach
TINYPROXY_PORT=8887 mix test --include proxy
```

Available port variables: `TINYPROXY_PORT` (default 8888), `TINYPROXY_AUTH_PORT` (default 8889), `HTTPBIN_HTTP_PORT` (default 8080), `HTTPBIN_HTTPS_PORT` (default 8443).

## License

Copyright 2018 Eric Meadows-Jönsson and Andrea Leopardi
Expand Down
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ services:
proxy:
build: ./test/docker/tinyproxy
ports:
- "8888:8888"
- "${TINYPROXY_PORT:-8888}:8888"

proxy-auth:
build: ./test/docker/tinyproxy-auth
ports:
- "8889:8888"
- "${TINYPROXY_AUTH_PORT:-8889}:8888"

httpbin:
image: docker.io/kennethreitz/httpbin:latest
platform: linux/amd64
ports:
- "8080:80"
- "${HTTPBIN_HTTP_PORT:-8080}:80"

caddyhttpbin:
image: docker.io/caddy:2.8.4-alpine
Expand All @@ -24,10 +24,13 @@ services:
# because the container by default runs using the root user
# and we are not root in the GH action so we cannot access them.
user: "${DOCKER_USER}"
environment:
- HTTPBIN_HTTP_PORT=${HTTPBIN_HTTP_PORT:-8080}
- HTTPBIN_HTTPS_PORT=${HTTPBIN_HTTPS_PORT:-8443}
volumes:
# The :z mount option solves issues with SELinux.
# See https://github.com/elixir-mint/mint/pull/406.
- "./caddy_storage:/caddy_storage:z"
- "./Caddyfile:/etc/caddy/Caddyfile:z"
ports:
- "8443:8443"
- "${HTTPBIN_HTTPS_PORT:-8443}:${HTTPBIN_HTTPS_PORT:-8443}"
14 changes: 7 additions & 7 deletions test/mint/http1/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Mint.HTTP1.IntegrationTest do

describe "local httpbin" do
test "200 response" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())
assert {:ok, conn, request} = HTTP1.request(conn, "GET", "/", [], nil)
assert {:ok, conn, responses} = receive_stream(conn)

Expand All @@ -22,7 +22,7 @@ defmodule Mint.HTTP1.IntegrationTest do
end

test "POST body" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())
assert {:ok, conn, request} = HTTP1.request(conn, "POST", "/post", [], "BODY")
assert {:ok, conn, responses} = receive_stream(conn)

Expand All @@ -35,7 +35,7 @@ defmodule Mint.HTTP1.IntegrationTest do

test "POST body streaming" do
headers = [{"content-length", "4"}]
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())
assert {:ok, conn, request} = HTTP1.request(conn, "POST", "/post", headers, :stream)
assert {:ok, conn} = HTTP1.stream_request_body(conn, request, "BO")
assert {:ok, conn} = HTTP1.stream_request_body(conn, request, "DY")
Expand All @@ -50,7 +50,7 @@ defmodule Mint.HTTP1.IntegrationTest do
end

test "pipelining" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())
assert {:ok, conn, request1} = HTTP1.request(conn, "GET", "/", [], nil)
assert {:ok, conn, request2} = HTTP1.request(conn, "GET", "/", [], nil)
assert {:ok, conn, request3} = HTTP1.request(conn, "GET", "/", [], nil)
Expand All @@ -71,7 +71,7 @@ defmodule Mint.HTTP1.IntegrationTest do
end

test "chunked with no chunks" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())
assert {:ok, conn, request} = HTTP1.request(conn, "GET", "/stream-bytes/0", [], nil)

assert {:ok, _conn, [_status, _headers | responses]} = receive_stream(conn)
Expand All @@ -80,7 +80,7 @@ defmodule Mint.HTTP1.IntegrationTest do
end

test "chunked with single chunk" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())

assert {:ok, conn, request} =
HTTP1.request(conn, "GET", "/stream-bytes/1024?chunk_size=1024", [], nil)
Expand All @@ -91,7 +91,7 @@ defmodule Mint.HTTP1.IntegrationTest do
end

test "chunked with multiple chunks" do
assert {:ok, conn} = HTTP1.connect(:http, "localhost", 8080)
assert {:ok, conn} = HTTP1.connect(:http, "localhost", HttpBin.http_port())

assert {:ok, conn, request} =
HTTP1.request(conn, "GET", "/stream-bytes/1024?chunk_size=100", [], nil)
Expand Down
8 changes: 4 additions & 4 deletions test/mint/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Mint.IntegrationTest do
test "200 response - http://httpbin.org" do
assert {:ok, conn} =
HTTP.connect(:http, HttpBin.proxy_host(), HttpBin.http_port(),
proxy: {:http, "localhost", 8888, []}
proxy: {:http, "localhost", HttpBin.proxy_port(), []}
)

assert conn.__struct__ == Mint.UnsafeProxy
Expand All @@ -174,7 +174,7 @@ defmodule Mint.IntegrationTest do
test "200 response - https://httpbin.org" do
assert {:ok, conn} =
HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8888, []},
proxy: {:http, "localhost", HttpBin.proxy_port(), []},
transport_opts: HttpBin.https_transport_opts()
)

Expand All @@ -191,7 +191,7 @@ defmodule Mint.IntegrationTest do
test "200 response with explicit http2 - https://httpbin.org" do
assert {:ok, conn} =
HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8888, []},
proxy: {:http, "localhost", HttpBin.proxy_port(), []},
protocols: [:http2],
transport_opts: HttpBin.https_transport_opts()
)
Expand All @@ -210,7 +210,7 @@ defmodule Mint.IntegrationTest do
test "200 response without explicit http2 - https://httpbin.org" do
assert {:ok, conn} =
HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8888, []},
proxy: {:http, "localhost", HttpBin.proxy_port(), []},
protocols: [:http1, :http2],
transport_opts: HttpBin.https_transport_opts()
)
Expand Down
16 changes: 8 additions & 8 deletions test/mint/tunnel_proxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Mint.TunnelProxyTest do

assert {:ok, conn} =
Mint.TunnelProxy.connect(
{:http, "localhost", 8888, []},
{:http, "localhost", HttpBin.proxy_port(), []},
{:http, HttpBin.proxy_host(), HttpBin.http_port(), []}
)

Expand All @@ -37,7 +37,7 @@ defmodule Mint.TunnelProxyTest do
test "200 response - https://httpbin.org" do
assert {:ok, conn} =
Mint.TunnelProxy.connect(
{:http, "localhost", 8888, []},
{:http, "localhost", HttpBin.proxy_port(), []},
{:https, HttpBin.proxy_host(), HttpBin.https_port(),
transport_opts: HttpBin.https_transport_opts()}
)
Expand All @@ -55,7 +55,7 @@ defmodule Mint.TunnelProxyTest do
test "407 response - proxy with missing authentication" do
assert {:error, %Mint.HTTPError{reason: {:proxy, {:unexpected_status, 407}}}} =
Mint.HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8889, []},
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []},
transport_opts: HttpBin.https_transport_opts()
)
end
Expand All @@ -65,7 +65,7 @@ defmodule Mint.TunnelProxyTest do

assert {:error, %Mint.HTTPError{reason: {:proxy, {:unexpected_status, 401}}}} =
Mint.HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8889, []},
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []},
proxy_headers: [{"proxy-authorization", "basic #{invalid_auth64}"}],
transport_opts: HttpBin.https_transport_opts()
)
Expand All @@ -76,7 +76,7 @@ defmodule Mint.TunnelProxyTest do

assert {:ok, conn} =
Mint.HTTP.connect(:https, HttpBin.proxy_host(), HttpBin.https_port(),
proxy: {:http, "localhost", 8889, []},
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []},
proxy_headers: [{"proxy-authorization", "basic #{auth64}"}],
transport_opts: HttpBin.https_transport_opts()
)
Expand All @@ -94,7 +94,7 @@ defmodule Mint.TunnelProxyTest do
test "200 response with explicit http2 - https://httpbin.org" do
assert {:ok, conn} =
Mint.TunnelProxy.connect(
{:http, "localhost", 8888, []},
{:http, "localhost", HttpBin.proxy_port(), []},
{:https, HttpBin.proxy_host(), HttpBin.https_port(),
[protocols: [:http2], transport_opts: HttpBin.https_transport_opts()]}
)
Expand All @@ -117,7 +117,7 @@ defmodule Mint.TunnelProxyTest do
test "200 response without explicit http2 - https://httpbin.org" do
assert {:ok, conn} =
Mint.TunnelProxy.connect(
{:http, "localhost", 8888, []},
{:http, "localhost", HttpBin.proxy_port(), []},
{:https, HttpBin.proxy_host(), HttpBin.https_port(),
[protocols: [:http1, :http2], transport_opts: HttpBin.https_transport_opts()]}
)
Expand All @@ -141,7 +141,7 @@ defmodule Mint.TunnelProxyTest do
test "do not support nested HTTPS connections - https://httpbin.org" do
assert {:ok, conn} =
Mint.TunnelProxy.connect(
{:https, "localhost", 8888, []},
{:https, "localhost", HttpBin.proxy_port(), []},
{:https, HttpBin.proxy_host(), HttpBin.https_port(),
[transport_opts: HttpBin.https_transport_opts()]}
)
Expand Down
12 changes: 6 additions & 6 deletions test/mint/unsafe_proxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Mint.UnsafeProxyTest do
test "200 response - http://httpbin.org" do
assert {:ok, conn} =
UnsafeProxy.connect(
{:http, "localhost", 8888},
{:http, "localhost", HttpBin.proxy_port()},
{:http, HttpBin.proxy_host(), HttpBin.http_port()}
)

Expand All @@ -28,7 +28,7 @@ defmodule Mint.UnsafeProxyTest do
test "407 response - proxy with missing authentication" do
assert {:ok, conn} =
HTTP.connect(:http, HttpBin.proxy_host(), HttpBin.http_port(),
proxy: {:http, "localhost", 8889, []}
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []}
)

assert {:ok, conn, request} = HTTP.request(conn, "GET", "/", [], nil)
Expand All @@ -42,7 +42,7 @@ defmodule Mint.UnsafeProxyTest do

assert {:ok, conn} =
HTTP.connect(:http, HttpBin.proxy_host(), HttpBin.http_port(),
proxy: {:http, "localhost", 8889, []},
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []},
proxy_headers: [{"proxy-authorization", "basic #{invalid_auth64}"}]
)

Expand All @@ -57,7 +57,7 @@ defmodule Mint.UnsafeProxyTest do

assert {:ok, conn} =
HTTP.connect(:http, HttpBin.proxy_host(), HttpBin.http_port(),
proxy: {:http, "localhost", 8889, []},
proxy: {:http, "localhost", HttpBin.proxy_auth_port(), []},
proxy_headers: [{"proxy-authorization", "basic #{auth64}"}]
)

Expand All @@ -73,7 +73,7 @@ defmodule Mint.UnsafeProxyTest do
test "Mint.HTTP.protocol/1 on an unsafe proxy connection" do
assert {:ok, %UnsafeProxy{} = conn} =
UnsafeProxy.connect(
{:http, "localhost", 8888},
{:http, "localhost", HttpBin.proxy_port()},
{:http, HttpBin.proxy_host(), HttpBin.http_port()}
)

Expand All @@ -86,7 +86,7 @@ defmodule Mint.UnsafeProxyTest do

assert {:ok, %UnsafeProxy{state: %{socket: socket}} = conn} =
UnsafeProxy.connect(
{:http, "localhost", 8888},
{:http, "localhost", HttpBin.proxy_port()},
{:http, HttpBin.proxy_host(), HttpBin.http_port()}
)

Expand Down
19 changes: 17 additions & 2 deletions test/support/mint/http_bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,29 @@ defmodule Mint.HttpBin do
end

def http_port() do
8080
get_env_port("HTTPBIN_HTTP_PORT", 8080)
end

def https_port() do
8443
get_env_port("HTTPBIN_HTTPS_PORT", 8443)
end

def proxy_port() do
get_env_port("TINYPROXY_PORT", 8888)
end

def proxy_auth_port() do
get_env_port("TINYPROXY_AUTH_PORT", 8889)
end

def https_transport_opts() do
[cacertfile: "caddy_storage/pki/authorities/local/root.crt"]
end

defp get_env_port(env_var, default) do
case System.get_env(env_var) do
nil -> default
value -> String.to_integer(value)
end
end
end