Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bare list concatenation to allow non keyword options #112

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions lib/thousand_island/transports/ssl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ defmodule ThousandIsland.Transports.SSL do
reuseaddr: true
]

# We can't use Keyword functions here because :ssl accepts non-keyword style options
resolved_options =
default_options
|> Keyword.merge(user_options)
|> Keyword.merge(@hardcoded_options)
default_options ++
user_options ++
@hardcoded_options

if not Enum.any?(
[:keyfile, :key, :sni_hosts, :sni_fun],
Expand Down
7 changes: 4 additions & 3 deletions lib/thousand_island/transports/tcp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ defmodule ThousandIsland.Transports.TCP do
reuseaddr: true
]

# We can't use Keyword functions here because :gen_tcp accepts non-keyword style options
resolved_options =
default_options
|> Keyword.merge(user_options)
|> Keyword.merge(@hardcoded_options)
default_options ++
user_options ++
@hardcoded_options

:gen_tcp.listen(port, resolved_options)
end
Expand Down
30 changes: 30 additions & 0 deletions test/thousand_island/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,14 @@
{:ok, ~c"{:ok, [mode: :binary]}"} = :gen_tcp.recv(client, 0, 100)
end

test "tcp should allow Erlang style bare options" do
{:ok, _, port} = start_handler(Echo, transport_options: [:inet6])
{:ok, client} = :gen_tcp.connect(:localhost, port, active: false)
:gen_tcp.send(client, "HI")
{:ok, ~c"HI"} = :gen_tcp.recv(client, 0, 100)
end

test "ssl should allow default options to be overridden" do

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.13.x, 24.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.13.x, 25.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.14.x, 24.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.14.x, 25.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.14.x, 26.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.15.x, 24.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.15.x, 25.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)

Check failure on line 400 in test/thousand_island/server_test.exs

View workflow job for this annotation

GitHub Actions / test / test (1.15.x, 26.x)

test configuration ssl should allow default options to be overridden (ThousandIsland.ServerTest)
{:ok, _, port} =
start_handler(ReadOpt,
transport_module: ThousandIsland.Transports.SSL,
Expand Down Expand Up @@ -433,6 +440,29 @@
:ssl.send(client, "mode")
{:ok, ~c"{:ok, [mode: :binary]}"} = :ssl.recv(client, 0, 100)
end

test "ssl should allow Erlang style bare options" do
{:ok, _, port} =
start_handler(Echo,
transport_module: ThousandIsland.Transports.SSL,
transport_options:
[:inet6] ++
[
certfile: Path.join(__DIR__, "../support/cert.pem"),
keyfile: Path.join(__DIR__, "../support/key.pem")
]
)

{:ok, client} =
:ssl.connect(:localhost, port,
active: false,
verify: :verify_none,
cacertfile: Path.join(__DIR__, "../support/ca.pem")
)

:ssl.send(client, "HI")
{:ok, ~c"HI"} = :ssl.recv(client, 0, 100)
end
end

describe "invalid configuration" do
Expand Down
Loading