aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/test/uri_SUITE.erl
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2013-01-31 15:34:51 +0100
committerIngela Anderton Andin <[email protected]>2013-02-18 18:02:59 +0100
commitbaca1b6cf223b03786ea47fc101f4249bda3cb3c (patch)
treed5c733444f16e34188f7bc3d9bedf24c35ef63d5 /lib/inets/test/uri_SUITE.erl
parent79f4745f6e7254a5399c63f9947dc39c1abd21ba (diff)
downloadotp-baca1b6cf223b03786ea47fc101f4249bda3cb3c.tar.gz
otp-baca1b6cf223b03786ea47fc101f4249bda3cb3c.tar.bz2
otp-baca1b6cf223b03786ea47fc101f4249bda3cb3c.zip
inets: Improve ssl handling
httpc: CTfy test suite httpd: Simplify ssl configuration OTP-10846
Diffstat (limited to 'lib/inets/test/uri_SUITE.erl')
-rw-r--r--lib/inets/test/uri_SUITE.erl159
1 files changed, 159 insertions, 0 deletions
diff --git a/lib/inets/test/uri_SUITE.erl b/lib/inets/test/uri_SUITE.erl
new file mode 100644
index 0000000000..9ba09e1474
--- /dev/null
+++ b/lib/inets/test/uri_SUITE.erl
@@ -0,0 +1,159 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2004-2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%
+
+%%
+%% ct:run("../inets_test", uri_SUITE).
+%%
+
+-module(uri_SUITE).
+
+-include_lib("common_test/include/ct.hrl").
+-include("inets_test_lib.hrl").
+
+%% Note: This directive should only be used in test suites.
+-compile(export_all).
+
+-define(GOOGLE, "www.google.com").
+
+%%--------------------------------------------------------------------
+%% Common Test interface functions -----------------------------------
+%%--------------------------------------------------------------------
+suite() ->
+ [{ct_hooks,[ts_install_cth]}].
+
+all() ->
+ [
+ ipv4,
+ ipv6,
+ host,
+ userinfo,
+ scheme,
+ queries,
+ escaped,
+ hexed_query
+ ].
+
+%%--------------------------------------------------------------------
+
+init_per_suite(Config) ->
+ Config.
+end_per_suite(_Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+
+init_per_testcase(_Case, Config) ->
+ Config.
+end_per_testcase(_Case, _Config) ->
+ ok.
+
+%%-------------------------------------------------------------------------
+%% Test cases starts here.
+%%-------------------------------------------------------------------------
+
+ipv4(Config) when is_list(Config) ->
+ {ok, {http,[],"127.0.0.1",80,"/foobar.html",[]}} =
+ http_uri:parse("http://127.0.0.1/foobar.html").
+
+ipv6(Config) when is_list(Config) ->
+ {ok, {http,[],"2010:836B:4179::836B:4179",80,"/foobar.html",[]}} =
+ http_uri:parse("http://[2010:836B:4179::836B:4179]/foobar.html"),
+ {ok, {http,[],"[2010:836B:4179::836B:4179]",80,"/foobar.html",[]}} =
+ http_uri:parse("http://[2010:836B:4179::836B:4179]/foobar.html",
+ [{ipv6_host_with_brackets, true}]),
+ {ok, {http,[],"2010:836B:4179::836B:4179",80,"/foobar.html",[]}} =
+ http_uri:parse("http://[2010:836B:4179::836B:4179]/foobar.html",
+ [{ipv6_host_with_brackets, false}]),
+ {ok, {http,[],"2010:836B:4179::836B:4179",80,"/foobar.html",[]}} =
+ http_uri:parse("http://[2010:836B:4179::836B:4179]/foobar.html",
+ [{foo, false}]),
+ {error,
+ {malformed_url, _, "http://2010:836B:4179::836B:4179/foobar.html"}} =
+ http_uri:parse("http://2010:836B:4179::836B:4179/foobar.html").
+
+host(Config) when is_list(Config) ->
+ {ok, {http,[],"localhost",8888,"/foobar.html",[]}} =
+ http_uri:parse("http://localhost:8888/foobar.html").
+
+userinfo(Config) when is_list(Config) ->
+ {ok, {http,"nisse:foobar","localhost",8888,"/foobar.html",[]}} =
+ http_uri:parse("http://nisse:foobar@localhost:8888/foobar.html").
+
+scheme(Config) when is_list(Config) ->
+ {error, no_scheme} = http_uri:parse("localhost/foobar.html"),
+ {error, {malformed_url, _, _}} =
+ http_uri:parse("localhost:8888/foobar.html").
+
+queries(Config) when is_list(Config) ->
+ {ok, {http,[],"localhost",8888,"/foobar.html","?foo=bar&foobar=42"}} =
+ http_uri:parse("http://localhost:8888/foobar.html?foo=bar&foobar=42").
+
+escaped(Config) when is_list(Config) ->
+ {ok, {http,[],"www.somedomain.com",80,"/%2Eabc",[]}} =
+ http_uri:parse("http://www.somedomain.com/%2Eabc"),
+ {ok, {http,[],"www.somedomain.com",80,"/%252Eabc",[]}} =
+ http_uri:parse("http://www.somedomain.com/%252Eabc"),
+ {ok, {http,[],"www.somedomain.com",80,"/%25abc",[]}} =
+ http_uri:parse("http://www.somedomain.com/%25abc"),
+ {ok, {http,[],"www.somedomain.com",80,"/%25abc", "?foo=bar"}} =
+ http_uri:parse("http://www.somedomain.com/%25abc?foo=bar").
+
+hexed_query(doc) ->
+ [{doc, "Solves OTP-6191"}];
+hexed_query(Config) when is_list(Config) ->
+ Google = ?GOOGLE,
+ GoogleSearch = "http://" ++ Google ++ "/search",
+ Search1 = "?hl=en&q=a%D1%85%D1%83%D0%B9&btnG=Google+Search",
+ URI1 = GoogleSearch ++ Search1,
+ Search2 = "?hl=en&q=%25%25",
+ URI2 = GoogleSearch ++ Search2,
+ Search3 = "?hl=en&q=%foo",
+ URI3 = GoogleSearch ++ Search3,
+
+ Verify1 =
+ fun({http, [], ?GOOGLE, 80, "/search", _}) -> ok;
+ (_) -> error
+ end,
+ Verify2 = Verify1,
+ Verify3 = Verify1,
+ verify_uri(URI1, Verify1),
+ verify_uri(URI2, Verify2),
+ verify_uri(URI3, Verify3).
+
+
+%%--------------------------------------------------------------------
+%% Internal Functions ------------------------------------------------
+%%--------------------------------------------------------------------
+
+
+verify_uri(URI, Verify) ->
+ case http_uri:parse(URI) of
+ {ok, ParsedURI} ->
+ case Verify(ParsedURI) of
+ ok ->
+ ok;
+ error ->
+ Reason = {unexpected_parse_result, URI, ParsedURI},
+ ERROR = {error, Reason},
+ throw(ERROR)
+ end;
+ {error, _} = ERROR ->
+ throw(ERROR)
+ end.