forked from brendonh/erl_openid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert test/0 funs into eunit tests
mochi reloader triggering the test/0 funs was bugging me. I'm not that familiar with eunit so there will be bugs.
- Loading branch information
Showing
10 changed files
with
151 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ Mnesia.* | |
sasl_err* | ||
erl_crash* | ||
ebin/openid.app | ||
deps/* | ||
deps/* | ||
.eunit/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{cover_enabled, true}. | ||
{erl_opts, [fail_on_warning, debug_info]}. | ||
{deps, [{ibrowse, ".*", {git, "git://github.com/andrewtj/ibrowse.git", "master"}}]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-module(openid_pm_test). | ||
-compile([export_all]). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
-define(PL, [{"mode", "error"}, {"error", "This is an example message"}]). | ||
-define(KVF, "mode:error\nerror:This is an example message\n"). | ||
-define(URL, "openid.mode=error&openid.error=This%20is%20an%20example%20message"). | ||
-define(URI, "openid.mode=error&openid.error=This+is+an+example+message"). | ||
|
||
url_encode_test_() -> | ||
{"URL Encode", ?_assertEqual(?URL, openid_pm:url_encode(?PL))}. | ||
|
||
uri_encode_test_() -> | ||
{"URI Encode", ?_assertEqual(?URI, openid_pm:uri_encode(?PL))}. | ||
|
||
kvf_encode_test_() -> | ||
{"Key-Value Form Encode", ?_assertEqual(?KVF, openid_pm:kvf_encode(?PL))}. | ||
|
||
kvf_decode_test_() -> | ||
{"Key-Value Form Decode", ?_assertEqual(?PL, openid_pm:kvf_decode(?KVF))}. | ||
|
||
prefix_check_test_() -> | ||
Input = [ {"openid." ++ K, V} || {K, V} <- ?PL ], | ||
{"Prefix Check", [?_assertEqual(?KVF, openid_pm:kvf_encode(Input)), | ||
?_assertEqual(?URI, openid_pm:uri_encode(Input))] | ||
}. | ||
|
||
types_test_() -> | ||
[ {"Encode " ++ Type, | ||
?_test(begin | ||
Input = [ {Fun(K), Fun(V)} || {K, V} <- ?PL ], | ||
?assertEqual(?KVF, openid_pm:kvf_encode(Input)) | ||
end) | ||
} || {Type, Fun} <- [{"Atom", fun erlang:list_to_atom/1}, | ||
{"Binary", fun erlang:list_to_binary/1} | ||
] ]. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-module(openid_srv_test). | ||
-compile([export_all]). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
-include("openid.hrl"). | ||
|
||
setup() -> | ||
[ application:start(X) || X <- [ crypto, ssl, sasl, inets, ibrowse ] ]. | ||
|
||
prepare_test_() -> | ||
{setup, fun setup/0, | ||
{timeout, 5000, | ||
?_test( | ||
begin | ||
{ok, Server} = gen_server:start(openid_srv, start_link, [test_server]), | ||
Result = (catch gen_server:call(Server, {prepare, "foo", "http://exbrend.livejournal.com", true})), | ||
?_assertEqual(ok, element(1, Result)) | ||
end) | ||
} | ||
}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-module(openid_test). | ||
-compile([export_all]). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
-include("openid.hrl"). | ||
|
||
setup() -> | ||
[ application:start(X) || X <- [ crypto, ssl, sasl, inets, ibrowse ] ]. | ||
|
||
discover2_test_() -> | ||
Cases = [{"https://www.google.com/accounts/o8/id", | ||
#openid_authreq{opURLs = ["https://www.google.com/accounts/o8/ud"], | ||
version = {2,0}, | ||
claimedID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
localID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
assoc = none}}, | ||
{"http://flickr.com/exbrend", | ||
#openid_authreq{opURLs = ["https://open.login.yahooapis.com/openid/op/auth"], | ||
version = {2,0}, | ||
claimedID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
localID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
assoc = none}} | ||
], | ||
{setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL)) | ||
|| {URL, Result} <- Cases ]}. | ||
|
||
discover1_test_() -> | ||
Cases = [{"blog.paulbonser.com", | ||
#openid_authreq{opURLs = ["http://www.livejournal.com/openid/server.bml"], | ||
version = {1,1}, | ||
claimedID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
localID = "http://specs.openid.net/auth/2.0/identifier_select", | ||
assoc = none}} | ||
], | ||
{setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL)) | ||
|| {URL, Result} <- Cases ]}. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-module(openid_utils_test). | ||
-compile([export_all]). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
normalization_test_() -> | ||
[?_assertEqual(Result, openid_utils:normalize_id(Id)) | ||
|| {Id, Result} <- [{"example.com", "http://example.com/"}, | ||
{"http://example.com", "http://example.com/"}, | ||
{"https://example.com/", "https://example.com/"}, | ||
{"http://example.com/user", "http://example.com/user"}, | ||
{"http://example.com/user/", "http://example.com/user/"}, | ||
{"http://example.com/", "http://example.com/"}, | ||
{"=example", "=example"}, | ||
{"xri://=example", "=example"}, | ||
{"http://ExAmPlE.CoM/foo/../a", "http://example.com/a"}, | ||
{"http://ExAmPlE.CoM/foo/../a/", "http://example.com/a/"}, | ||
{"http://eXAMPLE:80//a/./b/../b/%63/%7bfoo%7d", "http://example/a/b/c/%7Bfoo%7D"}, | ||
{"http://example//a/b/c/%7Bfoo%7D", "http://example/a/b/c/%7Bfoo%7D"} | ||
] | ||
]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-module(yadis_test). | ||
-compile([export_all]). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
-include("openid.hrl"). | ||
|
||
setup() -> | ||
[ application:start(X) || X <- [ crypto, ssl, sasl, inets, ibrowse ] ]. | ||
|
||
retrieve_test_() -> | ||
Cases = [{"https://www.google.com/accounts/o8/id", | ||
#openid_xrds{origID = "https://www.google.com/accounts/o8/id", | ||
claimedID = none, canonicalID = none, isXRI = false, | ||
services = [#openid_xrdservice{types = ["http://specs.openid.net/auth/2.0/server", | ||
"http://openid.net/srv/ax/1.0", | ||
"http://specs.openid.net/extensions/ui/1.0/mode/popup", | ||
"http://specs.openid.net/extensions/ui/1.0/icon", | ||
"http://specs.openid.net/extensions/pape/1.0"], | ||
uris = ["https://www.google.com/accounts/o8/ud"], | ||
localID = none}]}}, | ||
{"http://exbrend.livejournal.com", | ||
#openid_xrds{origID = "http://exbrend.livejournal.com", | ||
claimedID = "http://exbrend.livejournal.com/data/yadis", | ||
canonicalID = none,isXRI = false, | ||
services = [#openid_xrdservice{types = ["http://specs.openid.net/auth/2.0/signon"], | ||
uris = ["http://www.livejournal.com/openid/server.bml"], | ||
localID = "http://exbrend.livejournal.com/"}]}}, | ||
{"=brendonh", | ||
#openid_xrds{origID = "=brendonh",claimedID = "=brendonh", | ||
canonicalID = none,isXRI = true,services = []}} | ||
], | ||
{setup, fun setup/0, [?_assertEqual(Result, yadis:retrieve(URL)) | ||
|| {URL, Result} <- Cases ]}. |