From 40898791d9f1cfc76f10d805eb9f048bb4e4923d Mon Sep 17 00:00:00 2001 From: Andrew Tunnell-Jones Date: Sat, 30 Oct 2010 09:19:23 +0000 Subject: [PATCH] Set claimed identifier when doing HTML discovery --- src/openid.erl | 16 ++++++++-------- src/yadis.erl | 2 +- test/openid_test.erl | 8 ++++---- test/yadis_test.erl | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/openid.erl b/src/openid.erl index 225f2b3..0b84d82 100644 --- a/src/openid.erl +++ b/src/openid.erl @@ -19,7 +19,7 @@ discover(Identifier) -> Req = case yadis:retrieve(Identifier) of - {none, Body} -> html_discovery(Body); + {none, NormalizedId, Body} -> html_discovery(NormalizedId, Body); #openid_xrds{}=XRDS -> extract_authreq(XRDS); {error, _Error} -> %?DBG({error, Error}), @@ -81,22 +81,22 @@ build_authReq(XRDS, Service, Version) -> localID=Service#openid_xrdservice.localID}. -html_discovery(Body) -> - html_discovery(Body, [{"openid2.provider", "openid2.local_id", {2,0}}, - {"openid.server", "openid.delegate", {1,1}}]). +html_discovery(Id, Body) -> + html_discovery(Id, Body, [{"openid2.provider", "openid2.local_id", {2,0}}, + {"openid.server", "openid.delegate", {1,1}}]). -html_discovery(_, []) -> +html_discovery(_Id, _, []) -> none; -html_discovery(Body, [{ProviderRel, LocalIDRel, Version}|Rest]) -> +html_discovery(Id, Body, [{ProviderRel, LocalIDRel, Version}|Rest]) -> case openid_utils:get_tags(Body, "link", "rel", ProviderRel) of [Tag|_] -> case ?GVD("href", Tag, none) of none -> html_discovery(Body, Rest); URL -> LocalID = html_local_id(Body, LocalIDRel), - #openid_authreq{opURLs=[URL], version=Version, localID=LocalID} + #openid_authreq{opURLs=[URL], version=Version, localID=LocalID, claimedID=Id} end; - _ -> html_discovery(Body, Rest) + _ -> html_discovery(Id, Body, Rest) end. html_local_id(Body, RelName) -> diff --git a/src/yadis.erl b/src/yadis.erl index dd0ec10..0d61be2 100644 --- a/src/yadis.erl +++ b/src/yadis.erl @@ -40,7 +40,7 @@ retrieve(Identifier) -> XRDS = handle_response(DescriptorURL, Headers, Body), case XRDS of none -> - {none, Body}; + {none, Normalized, Body}; #openid_xrds{} -> % XXX Todo -- Normalize DescriptorURL as claimedID diff --git a/test/openid_test.erl b/test/openid_test.erl index a8d09ac..0a88a9a 100644 --- a/test/openid_test.erl +++ b/test/openid_test.erl @@ -16,8 +16,8 @@ discover2_test_() -> {"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", + claimedID = "http://flickr.com/exbrend", + localID = "http://flickr.com/exbrend", assoc = none}} ], {setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL)) @@ -27,8 +27,8 @@ 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", + claimedID = "http://blog.paulbonser.com/", + localID = "http://misterpib.livejournal.com/", assoc = none}} ], {setup, fun setup/0, [?_assertEqual(Result, openid:discover(URL)) diff --git a/test/yadis_test.erl b/test/yadis_test.erl index 819e4a7..670b0bd 100644 --- a/test/yadis_test.erl +++ b/test/yadis_test.erl @@ -28,5 +28,5 @@ retrieve_test_() -> #openid_xrds{origID = "=brendonh",claimedID = "=brendonh", canonicalID = none,isXRI = true,services = []}} ], - {setup, fun setup/0, [?_assertEqual(Result, yadis:retrieve(URL)) + {setup, fun setup/0, [?_test(?_assertEqual(Result, yadis:retrieve(URL))) || {URL, Result} <- Cases ]}.