aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-25 20:17:21 +0100
committerLoïc Hoguin <[email protected]>2017-10-25 21:03:26 +0100
commitef58e15547ee171a716eaa768374e2e7e2f7d397 (patch)
tree0871f7f142014592f581f7c1a9705eb95d65dc2a /test
parent4090adaecc6ba30eeeabf50aee57c22945fa27eb (diff)
downloadcowboy-ef58e15547ee171a716eaa768374e2e7e2f7d397.tar.gz
cowboy-ef58e15547ee171a716eaa768374e2e7e2f7d397.tar.bz2
cowboy-ef58e15547ee171a716eaa768374e2e7e2f7d397.zip
Introduce cowboy_req:sock/1 and cowboy_req:cert/1
To obtain the local socket ip/port and the client TLS certificate, respectively.
Diffstat (limited to 'test')
-rw-r--r--test/cowboy_test.erl1
-rw-r--r--test/req_SUITE.erl32
2 files changed, 32 insertions, 1 deletions
diff --git a/test/cowboy_test.erl b/test/cowboy_test.erl
index bdae7e4..31cba63 100644
--- a/test/cowboy_test.erl
+++ b/test/cowboy_test.erl
@@ -110,6 +110,7 @@ gun_open(Config, Opts) ->
{ok, ConnPid} = gun:open("localhost", config(port, Config), Opts#{
retry => 0,
transport => config(type, Config),
+ transport_opts => proplists:get_value(transport_opts, Config, []),
protocols => [config(protocol, Config)]
}),
ConnPid.
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 3b32b3a..26ced62 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -134,6 +134,30 @@ bindings(Config) ->
<<"#{key => <<\"bindings\">>}">> = do_get_body("/bindings", Config),
ok.
+cert(Config) ->
+ case config(type, Config) of
+ tcp -> doc("TLS certificates can only be provided over TLS.");
+ ssl -> do_cert(Config)
+ end.
+
+do_cert(Config0) ->
+ doc("A client TLS certificate was provided."),
+ {CaCert, Cert, Key} = ct_helper:make_certs(),
+ Config = [{transport_opts, [
+ {cert, Cert},
+ {key, Key},
+ {cacerts, [CaCert]}
+ ]}|Config0],
+ Cert = do_get_body("/cert", Config),
+ Cert = do_get_body("/direct/cert", Config),
+ ok.
+
+cert_undefined(Config) ->
+ doc("No client TLS certificate was provided."),
+ <<"undefined">> = do_get_body("/cert", Config),
+ <<"undefined">> = do_get_body("/direct/cert", Config),
+ ok.
+
header(Config) ->
doc("Request header with/without default."),
<<"value">> = do_get_body("/args/header/defined", [{<<"defined">>, "value"}], Config),
@@ -274,7 +298,7 @@ path_info(Config) ->
ok.
peer(Config) ->
- doc("Request peer."),
+ doc("Remote socket address."),
<<"{{127,0,0,1},", _/bits >> = do_get_body("/peer", Config),
<<"{{127,0,0,1},", _/bits >> = do_get_body("/direct/peer", Config),
ok.
@@ -309,6 +333,12 @@ do_scheme(Path, Config) ->
<<"https">> when Transport =:= ssl -> ok
end.
+sock(Config) ->
+ doc("Local socket address."),
+ <<"{{127,0,0,1},", _/bits >> = do_get_body("/sock", Config),
+ <<"{{127,0,0,1},", _/bits >> = do_get_body("/direct/sock", Config),
+ ok.
+
uri(Config) ->
doc("Request URI building/modification."),
Scheme = case config(type, Config) of