From bd2455f3e563d432eb26f8b4dd46908551ee5694 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 10 Jan 2009 10:24:45 -0800 Subject: [PATCH] Added more tests for RP.AuthenticationRequest. --- .../RelyingParty/AuthenticationRequestTests.cs | 46 +++++++++++++++++++--- src/DotNetOpenAuth.Test/OpenId/TestSupport.cs | 1 + src/DotNetOpenAuth.vsmdi | 46 ++++++++++++---------- src/DotNetOpenAuth/Messaging/UserAgentResponse.cs | 4 +- 4 files changed, 68 insertions(+), 29 deletions(-) diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs index d6a0600..91d404e 100644 --- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs @@ -7,9 +7,12 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty { using System; using System.Collections.Generic; + using System.Collections.Specialized; using System.Linq; using System.Text; + using System.Web; using DotNetOpenAuth.OpenId; + using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.RelyingParty; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -32,7 +35,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty { /// [TestMethod] public void IsDirectedIdentity() { - var iauthRequest = this.CreateAuthenticationRequest(this.claimedId, this.claimedId); + IAuthenticationRequest_Accessor iauthRequest = this.CreateAuthenticationRequest(this.claimedId, this.claimedId); Assert.IsFalse(iauthRequest.IsDirectedIdentity); iauthRequest = this.CreateAuthenticationRequest(IdentifierSelect, IdentifierSelect); @@ -40,6 +43,18 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty { } /// + /// Verifies ClaimedIdentifier behavior. + /// + [TestMethod] + public void ClaimedIdentifier() { + IAuthenticationRequest_Accessor iauthRequest = this.CreateAuthenticationRequest(this.claimedId, this.delegatedLocalId); + Assert.AreEqual(this.claimedId, iauthRequest.ClaimedIdentifier); + + iauthRequest = this.CreateAuthenticationRequest(IdentifierSelect, IdentifierSelect); + Assert.IsNull(iauthRequest.ClaimedIdentifier, "In directed identity mode, the ClaimedIdentifier should be null."); + } + + /// /// Verifies ProviderVersion behavior. /// [TestMethod] @@ -52,14 +67,35 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty { /// Verifies RedirectingResponse. /// [TestMethod] - public void RedirectingResponse() { + public void CreateRequestMessage() { OpenIdCoordinator coordinator = new OpenIdCoordinator( rp => { Identifier id = this.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20); IAuthenticationRequest authRequest = rp.CreateRequest(id, this.realm, this.returnTo); - var response = authRequest.RedirectingResponse; - Assert.IsNotNull(response); - Assert.IsInstanceOfType(response.OriginalMessage, typeof(CheckIdRequest)); + + // Add some callback arguments + authRequest.AddCallbackArguments("a", "b"); + authRequest.AddCallbackArguments(new Dictionary { { "c", "d" }, { "e", "f" } }); + + // Assembly an extension request. + ClaimsRequest sregRequest = new ClaimsRequest(); + sregRequest.Nickname = DemandLevel.Request; + authRequest.AddExtension(sregRequest); + + // Construct the actual authentication request message. + var authRequestAccessor = AuthenticationRequest_Accessor.AttachShadow(authRequest); + var req = authRequestAccessor.CreateRequestMessage(); + Assert.IsNotNull(req); + + // Verify that callback arguments were included. + NameValueCollection callbackArguments = HttpUtility.ParseQueryString(req.ReturnTo.Query); + Assert.AreEqual("b", callbackArguments["a"]); + Assert.AreEqual("d", callbackArguments["c"]); + Assert.AreEqual("f", callbackArguments["e"]); + + // Verify that extensions were included. + Assert.AreEqual(1, req.Extensions.Count); + Assert.IsTrue(req.Extensions.Contains(sregRequest)); }, TestSupport.AutoProvider); coordinator.Run(); diff --git a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs index 9a4b0ac..e82841d 100644 --- a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs +++ b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs @@ -148,6 +148,7 @@ namespace DotNetOpenAuth.Test.OpenId { var providerEndpoint = new ProviderEndpointDescription(GetFullUrl("/" + ProviderPage, null, useSsl), new string[] { Protocol.Lookup(providerVersion).ClaimedIdentifierServiceTypeURI }); return ServiceEndpoint.CreateForClaimedIdentifier( GetIdentityUrl(scenario, providerVersion, useSsl), + GetIdentityUrl(scenario, providerVersion, useSsl), GetDelegateUrl(scenario, useSsl), providerEndpoint, servicePriority, diff --git a/src/DotNetOpenAuth.vsmdi b/src/DotNetOpenAuth.vsmdi index ac92a10..c3b5a98 100644 --- a/src/DotNetOpenAuth.vsmdi +++ b/src/DotNetOpenAuth.vsmdi @@ -58,11 +58,11 @@ - + - + @@ -101,7 +101,6 @@ - @@ -123,7 +122,6 @@ - @@ -133,7 +131,7 @@ - + @@ -149,7 +147,6 @@ - @@ -174,14 +171,16 @@ - - + + + + + - @@ -201,10 +200,12 @@ + + @@ -214,7 +215,7 @@ - + @@ -227,19 +228,20 @@ + - + - + - + @@ -251,7 +253,7 @@ - + @@ -274,13 +276,14 @@ - + - + + @@ -292,10 +295,10 @@ - + - + @@ -307,6 +310,7 @@ + @@ -315,11 +319,11 @@ - + - + - + diff --git a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs index 0e47945..6ae1839 100644 --- a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs +++ b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs @@ -137,9 +137,7 @@ namespace DotNetOpenAuth.Messaging { /// Requires a current HttpContext. /// public virtual void Send() { - if (HttpContext.Current == null) { - throw new InvalidOperationException(MessagingStrings.CurrentHttpContextRequired); - } + ErrorUtilities.VerifyOperation(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.StatusCode = (int)this.Status; -- 2.11.4.GIT