@@ -9,6 +9,7 @@ namespace DotNetOpenAuth.Test.OpenId.DiscoveryServices {
99 using System . Collections . Generic ;
1010 using System . Linq ;
1111 using System . Net ;
12+ using System . Net . Http ;
1213 using System . Text ;
1314 using System . Threading ;
1415 using System . Threading . Tasks ;
@@ -237,11 +238,25 @@ private async Task DiscoverAsync(string url, ProtocolVersion version, Identifier
237238 await this . DiscoverAsync ( url , version , expectedLocalId , providerEndpoint , expectSreg , useRedirect , null ) ;
238239 }
239240
241+ private string RegisterDiscoveryRedirector ( Uri baseUrl ) {
242+ var redirectorUrl = new Uri ( baseUrl , "Discovery/htmldiscovery/redirect.aspx" ) ;
243+ this . Handle ( redirectorUrl ) . By ( req => {
244+ string redirectTarget = HttpUtility . ParseQueryString ( req . RequestUri . Query ) [ "target" ] ;
245+ var response = new HttpResponseMessage ( HttpStatusCode . Redirect ) ;
246+ response . Headers . Location = new Uri ( redirectTarget , UriKind . RelativeOrAbsolute ) ;
247+ response . RequestMessage = req ;
248+ return response ;
249+ } ) ;
250+
251+ return redirectorUrl . AbsoluteUri + "?target=" ;
252+ }
253+
240254 private async Task DiscoverAsync ( string url , ProtocolVersion version , Identifier expectedLocalId , string providerEndpoint , bool expectSreg , bool useRedirect , WebHeaderCollection headers ) {
241255 Protocol protocol = Protocol . Lookup ( version ) ;
242256 Uri baseUrl = new Uri ( "http://localhost/" ) ;
257+ string redirectBase = this . RegisterDiscoveryRedirector ( baseUrl ) ;
243258 UriIdentifier claimedId = new Uri ( baseUrl , url ) ;
244- UriIdentifier userSuppliedIdentifier = new Uri ( baseUrl , "Discovery/htmldiscovery/redirect.aspx?target=" + url ) ;
259+ UriIdentifier userSuppliedIdentifier = new Uri ( redirectBase + Uri . EscapeDataString ( url ) ) ;
245260 if ( expectedLocalId == null ) {
246261 expectedLocalId = claimedId ;
247262 }
@@ -255,7 +270,7 @@ private async Task DiscoverAsync(string url, ProtocolVersion version, Identifier
255270 } else {
256271 throw new InvalidOperationException ( ) ;
257272 }
258- this . RegisterMockResponse ( new Uri ( idToDiscover ) , claimedId , contentType , headers ?? new WebHeaderCollection ( ) , LoadEmbeddedFile ( url ) ) ;
273+ this . RegisterMockResponse ( claimedId , claimedId , contentType , headers ?? new WebHeaderCollection ( ) , LoadEmbeddedFile ( url ) ) ;
259274
260275 IdentifierDiscoveryResult expected = IdentifierDiscoveryResult . CreateForClaimedIdentifier (
261276 claimedId ,
0 commit comments