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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All public functions in `TestServer` have been moved to `TestServer.HTTP`. The
HTTP server adapters in `TestServer.HTTPServer.*` have been moved to
`TestServer.HTTP.Server.*`. `add/2` has been renamed to `handle/2`, `websocket_init/3` has been renamed to `websocket/3` and now returns the websocket directly instead of `{:ok, websocket}`, and `websocket_info/2` has been renamed to `websocket_send/2` and now takes options as second argument. `x509_suite/0` has been replaced by `TestServer.HTTP.cacerts/0` that provides the CA certificates directly.

TestServer now has SSH support with `TestServer.SSH` and TCP support with `TestServer.TCP`.
TestServer now has SSH support with `TestServer.SSH`, TCP support with `TestServer.TCP`, and UDP support with `TestServer.UDP`.

- `TestServer.HTTP.start/1` now returns `{:error, reason}` instead of raising
- HTTP and WebSocket handlers no longer requires a path in the arguments
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ No fuzz ExUnit test server to mock third party services.
- [`TestServer.HTTP`](lib/test_server/http/README.md) - HTTP/1, HTTP/2, and WebSocket.
- [`TestServer.SSH`](lib/test_server/ssh/README.md) - SSH exec and shell.
- [`TestServer.TCP`](lib/test_server/tcp/README.md) - TCP socket endpoints.
- [`TestServer.UDP`](lib/test_server/udp/README.md) - UDP datagram endpoints.

TLS are supported with automatically generated certificates.
TLS and DTLS are supported with automatically generated certificates.

<!-- MDOC !-->

Expand Down
11 changes: 8 additions & 3 deletions lib/test_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,23 @@ defmodule TestServer do

@doc false
@spec put_tls_options(keyword()) :: keyword()
def put_tls_options(options) do
@spec put_tls_options(
keyword(),
{:rsa, non_neg_integer()} | {:ec, :crypto.ec_named_curve() | :public_key.oid()}
) :: keyword()
def put_tls_options(options, key_type \\ {:rsa, 1_024}) do
tls_options = Keyword.get(options, :tls, [])

case Keyword.take(tls_options, [:key, :keyfile]) do
[] ->
suite = X509.Test.Suite.new()
suite = X509.Test.Suite.new(key_type: key_type)
type = elem(suite.server_key, 0)
server_key = X509.PrivateKey.to_der(suite.server_key)
cert = X509.Certificate.to_der(suite.valid)

tls =
[
key: {:RSAPrivateKey, server_key},
key: {type, server_key},
cert: cert,
cacerts: suite.chain ++ suite.cacerts
]
Expand Down
Loading
Loading