diff options
26 files changed, 92 insertions, 69 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index af0ef37..b2c4d3a 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -21,6 +21,28 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking> + <CodeContractsCustomRewriterAssembly> + </CodeContractsCustomRewriterAssembly> + <CodeContractsCustomRewriterClass> + </CodeContractsCustomRewriterClass> + <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel> + <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis> + <CodeContractsBuildReferenceAssembly>False</CodeContractsBuildReferenceAssembly> + <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations> + <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations> + <CodeContractsArithmeticObligations>False</CodeContractsArithmeticObligations> + <CodeContractsLibPaths> + </CodeContractsLibPaths> + <CodeContractsPlatformPath> + </CodeContractsPlatformPath> + <CodeContractsExtraAnalysisOptions> + </CodeContractsExtraAnalysisOptions> + <CodeContractsBaseLineFile> + </CodeContractsBaseLineFile> + <CodeContractsUseBaseLine>False</CodeContractsUseBaseLine> + <CodeContractsRunInBackground>True</CodeContractsRunInBackground> + <CodeContractsShowSquigglies>False</CodeContractsShowSquigglies> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> diff --git a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs index eaf59e0..26ce01c 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs @@ -40,13 +40,13 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// </summary> [TestMethod] public void RandomCharactersTest() { - Assert.IsNotNull(this.nonceElement.PrepareMessageForSending(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessOutgoingMessage(this.message)); Assert.IsNotNull(this.message.Nonce, "No nonce was set on the message."); Assert.AreNotEqual(0, this.message.Nonce.Length, "The generated nonce was empty."); string firstNonce = this.message.Nonce; // Apply another nonce and verify that they are different than the first ones. - Assert.IsNotNull(this.nonceElement.PrepareMessageForSending(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessOutgoingMessage(this.message)); Assert.IsNotNull(this.message.Nonce, "No nonce was set on the message."); Assert.AreNotEqual(0, this.message.Nonce.Length, "The generated nonce was empty."); Assert.AreNotEqual(firstNonce, this.message.Nonce, "The two generated nonces are identical."); @@ -58,7 +58,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { [TestMethod] public void ValidMessageReceivedTest() { this.message.Nonce = "a"; - Assert.IsNotNull(this.nonceElement.PrepareMessageForReceiving(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); } /// <summary> @@ -68,7 +68,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { public void ValidMessageNoNonceReceivedTest() { this.message.Nonce = string.Empty; this.nonceElement.AllowZeroLengthNonce = true; - Assert.IsNotNull(this.nonceElement.PrepareMessageForReceiving(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); } /// <summary> @@ -78,7 +78,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { public void InvalidMessageNoNonceReceivedTest() { this.message.Nonce = string.Empty; this.nonceElement.AllowZeroLengthNonce = false; - Assert.IsNotNull(this.nonceElement.PrepareMessageForReceiving(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); } /// <summary> @@ -87,10 +87,10 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { [TestMethod, ExpectedException(typeof(ReplayedMessageException))] public void ReplayDetectionTest() { this.message.Nonce = "a"; - Assert.IsNotNull(this.nonceElement.PrepareMessageForReceiving(this.message)); + Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); // Now receive the same message again. This should throw because it's a message replay. - this.nonceElement.PrepareMessageForReceiving(this.message); + this.nonceElement.ProcessIncomingMessage(this.message); } } } diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs index ca902cd..ac94ea2 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs @@ -254,7 +254,7 @@ namespace DotNetOpenAuth.Test.Messaging { new MockSigningBindingElement(), new MockSigningBindingElement()); Channel_Accessor accessor = Channel_Accessor.AttachShadow(channel); - accessor.PrepareMessageForSending(new TestSignedDirectedMessage()); + accessor.ProcessOutgoingMessage(new TestSignedDirectedMessage()); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs index 4afd2cf..e654f02 100644 --- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs @@ -118,7 +118,7 @@ namespace DotNetOpenAuth.Test.Mocks { /// </summary> /// <param name="message">The message to replay.</param> internal void Replay(IProtocolMessage message) { - this.VerifyMessageAfterReceiving(CloneSerializedParts(message)); + this.ProcessIncomingMessage(CloneSerializedParts(message)); } /// <summary> @@ -191,9 +191,9 @@ namespace DotNetOpenAuth.Test.Mocks { return accessor.ReadFromResponseCore(response); } - protected override void VerifyMessageAfterReceiving(IProtocolMessage message) { + protected override void ProcessIncomingMessage(IProtocolMessage message) { Channel_Accessor accessor = Channel_Accessor.AttachShadow(this.wrappedChannel); - accessor.VerifyMessageAfterReceiving(message); + accessor.ProcessIncomingMessage(message); } /// <summary> diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs index 2c02a7f..88ada15 100644 --- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs @@ -43,7 +43,7 @@ namespace DotNetOpenAuth.Test.Mocks { internal OutgoingWebResponse RequestProtectedResource(AccessProtectedResourceRequest request) { ((ITamperResistantOAuthMessage)request).HttpMethod = this.GetHttpMethod(((ITamperResistantOAuthMessage)request).HttpMethods); - this.PrepareMessageForSending(request); + this.ProcessOutgoingMessage(request); HttpRequestInfo requestInfo = this.SpoofHttpMethod(request); TestBase.TestLogger.InfoFormat("Sending protected resource request: {0}", requestInfo.Message); // Drop the outgoing message in the other channel's in-slot and let them know it's there. @@ -74,7 +74,7 @@ namespace DotNetOpenAuth.Test.Mocks { protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) { this.RemoteChannel.incomingMessage = CloneSerializedParts(response, null); this.RemoteChannel.incomingMessageSignal.Set(); - return null; + return new OutgoingWebResponse(); // not used, but returning null is not allowed } protected override OutgoingWebResponse PrepareIndirectResponse(IDirectedProtocolMessage message) { diff --git a/src/DotNetOpenAuth.Test/Mocks/MockReplayProtectionBindingElement.cs b/src/DotNetOpenAuth.Test/Mocks/MockReplayProtectionBindingElement.cs index bde8380..75281e2 100644 --- a/src/DotNetOpenAuth.Test/Mocks/MockReplayProtectionBindingElement.cs +++ b/src/DotNetOpenAuth.Test/Mocks/MockReplayProtectionBindingElement.cs @@ -23,7 +23,7 @@ namespace DotNetOpenAuth.Test.Mocks { /// </summary> public Channel Channel { get; set; } - MessageProtections? IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessOutgoingMessage(IProtocolMessage message) { var replayMessage = message as IReplayProtectedProtocolMessage; if (replayMessage != null) { replayMessage.Nonce = "someNonce"; @@ -33,7 +33,7 @@ namespace DotNetOpenAuth.Test.Mocks { return null; } - MessageProtections? IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessIncomingMessage(IProtocolMessage message) { var replayMessage = message as IReplayProtectedProtocolMessage; if (replayMessage != null) { Assert.AreEqual("someNonce", replayMessage.Nonce, "The nonce didn't serialize correctly, or something"); diff --git a/src/DotNetOpenAuth.Test/Mocks/MockSigningBindingElement.cs b/src/DotNetOpenAuth.Test/Mocks/MockSigningBindingElement.cs index 803e471..32ada16 100644 --- a/src/DotNetOpenAuth.Test/Mocks/MockSigningBindingElement.cs +++ b/src/DotNetOpenAuth.Test/Mocks/MockSigningBindingElement.cs @@ -26,7 +26,7 @@ namespace DotNetOpenAuth.Test.Mocks { /// </summary> public Channel Channel { get; set; } - MessageProtections? IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessOutgoingMessage(IProtocolMessage message) { ITamperResistantProtocolMessage signedMessage = message as ITamperResistantProtocolMessage; if (signedMessage != null) { signedMessage.Signature = MessageSignature; @@ -36,7 +36,7 @@ namespace DotNetOpenAuth.Test.Mocks { return null; } - MessageProtections? IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessIncomingMessage(IProtocolMessage message) { ITamperResistantProtocolMessage signedMessage = message as ITamperResistantProtocolMessage; if (signedMessage != null) { if (signedMessage.Signature != MessageSignature) { diff --git a/src/DotNetOpenAuth.Test/Mocks/MockTransformationBindingElement.cs b/src/DotNetOpenAuth.Test/Mocks/MockTransformationBindingElement.cs index 4006f65..e88fe52 100644 --- a/src/DotNetOpenAuth.Test/Mocks/MockTransformationBindingElement.cs +++ b/src/DotNetOpenAuth.Test/Mocks/MockTransformationBindingElement.cs @@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Test.Mocks { /// </summary> public Channel Channel { get; set; } - MessageProtections? IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessOutgoingMessage(IProtocolMessage message) { var testMessage = message as TestMessage; if (testMessage != null) { testMessage.Name = this.transform + testMessage.Name; @@ -44,7 +44,7 @@ namespace DotNetOpenAuth.Test.Mocks { return null; } - MessageProtections? IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessIncomingMessage(IProtocolMessage message) { var testMessage = message as TestMessage; if (testMessage != null) { StringAssert.StartsWith(testMessage.Name, this.transform); diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs index 3447ddb..ca63b50 100644 --- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs +++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs @@ -20,7 +20,7 @@ namespace DotNetOpenAuth.Test.ChannelElements ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint); message.ConsumerSecret = "cs"; message.TokenSecret = "ts"; - Assert.IsNotNull(target.PrepareMessageForSending(message)); + Assert.IsNotNull(target.ProcessOutgoingMessage(message)); Assert.AreEqual("PLAINTEXT", message.SignatureMethod); Assert.AreEqual("cs&ts", message.Signature); } @@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Test.ChannelElements message.TokenSecret = "ts"; message.SignatureMethod = "PLAINTEXT"; message.Signature = "cs&ts"; - Assert.IsNotNull(target.PrepareMessageForReceiving(message)); + Assert.IsNotNull(target.ProcessIncomingMessage(message)); } [TestMethod] @@ -46,7 +46,7 @@ namespace DotNetOpenAuth.Test.ChannelElements message.TokenSecret = "ts"; message.SignatureMethod = "ANOTHERALGORITHM"; message.Signature = "somethingelse"; - Assert.AreEqual(MessageProtections.None, target.PrepareMessageForReceiving(message), "PLAINTEXT binding element should opt-out where it doesn't understand."); + Assert.AreEqual(MessageProtections.None, target.ProcessIncomingMessage(message), "PLAINTEXT binding element should opt-out where it doesn't understand."); } [TestMethod] @@ -58,7 +58,7 @@ namespace DotNetOpenAuth.Test.ChannelElements message.TokenSecret = "ts"; // Since this is (non-encrypted) HTTP, so the plain text signer should not be used - Assert.IsNull(target.PrepareMessageForSending(message)); + Assert.IsNull(target.ProcessOutgoingMessage(message)); Assert.IsNull(message.SignatureMethod); Assert.IsNull(message.Signature); } @@ -72,7 +72,7 @@ namespace DotNetOpenAuth.Test.ChannelElements message.TokenSecret = "ts"; message.SignatureMethod = "PLAINTEXT"; message.Signature = "cs%26ts"; - Assert.IsNull(target.PrepareMessageForReceiving(message), "PLAINTEXT signature binding element should refuse to participate in non-encrypted messages."); + Assert.IsNull(target.ProcessIncomingMessage(message), "PLAINTEXT signature binding element should refuse to participate in non-encrypted messages."); } } } diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs index 7428a28..67f7a54 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs @@ -53,7 +53,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void PrepareMessageForSendingNull() { - this.rpElement.PrepareMessageForSending(null); + this.rpElement.ProcessOutgoingMessage(null); } /// <summary> @@ -62,13 +62,13 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { [TestMethod] public void PrepareMessageForSendingNonExtendableMessage() { IProtocolMessage request = new AssociateDiffieHellmanRequest(Protocol.Default.Version, OpenIdTestBase.OPUri); - Assert.IsNull(this.rpElement.PrepareMessageForSending(request)); + Assert.IsNull(this.rpElement.ProcessOutgoingMessage(request)); } [TestMethod] public void PrepareMessageForSending() { this.request.Extensions.Add(new MockOpenIdExtension("part", "extra")); - Assert.IsNotNull(this.rpElement.PrepareMessageForSending(this.request)); + Assert.IsNotNull(this.rpElement.ProcessOutgoingMessage(this.request)); string alias = GetAliases(this.request.ExtraData).Single(); Assert.AreEqual(MockOpenIdExtension.MockTypeUri, this.request.ExtraData["openid.ns." + alias]); @@ -81,7 +81,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { this.request.ExtraData["openid.ns.mock"] = MockOpenIdExtension.MockTypeUri; this.request.ExtraData["openid.mock.Part"] = "part"; this.request.ExtraData["openid.mock.data"] = "extra"; - Assert.IsNotNull(this.rpElement.PrepareMessageForReceiving(this.request)); + Assert.IsNotNull(this.rpElement.ProcessIncomingMessage(this.request)); MockOpenIdExtension ext = this.request.Extensions.OfType<MockOpenIdExtension>().Single(); Assert.AreEqual("part", ext.Part); Assert.AreEqual("extra", ext.Data); diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs index 8cfa106..6bd2c00 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs @@ -35,7 +35,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { message.ProviderEndpoint = new Uri("http://provider"); signedMessage.UtcCreationDate = DateTime.Parse("1/1/2009"); signedMessage.AssociationHandle = association.Handle; - Assert.IsNotNull(signer.PrepareMessageForSending(message)); + Assert.IsNotNull(signer.ProcessOutgoingMessage(message)); Assert.AreEqual("0wOdvNgzCZ5I5AzbU58Nq2Tg8EJZ7QoNz4gpx2r7jII=", signedMessage.Signature); } @@ -54,7 +54,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { response.ExtraData["someunsigned"] = "value"; response.ExtraData["openid.somesigned"] = "value"; - Assert.IsNotNull(sbe.PrepareMessageForSending(response)); + Assert.IsNotNull(sbe.ProcessOutgoingMessage(response)); ITamperResistantOpenIdMessage signedResponse = (ITamperResistantOpenIdMessage)response; // Make sure that the extra parameters are signed. diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj index 61fbf1c..b674dce 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj @@ -32,7 +32,7 @@ </CodeContractsCustomRewriterClass> <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel> <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis> - <CodeContractsBuildReferenceAssembly>False</CodeContractsBuildReferenceAssembly> + <CodeContractsBuildReferenceAssembly>True</CodeContractsBuildReferenceAssembly> <CodeContractsNonNullObligations>True</CodeContractsNonNullObligations> <CodeContractsBoundsObligations>True</CodeContractsBoundsObligations> <CodeContractsLibPaths> diff --git a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs index f1ab1cc..5fcf4bd 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs @@ -59,7 +59,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { IExpiringProtocolMessage expiringMessage = message as IExpiringProtocolMessage; if (expiringMessage != null) { expiringMessage.UtcCreationDate = DateTime.UtcNow; @@ -82,7 +82,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// Thrown when the binding element rules indicate that this message is invalid and should /// NOT be processed. /// </exception> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { IExpiringProtocolMessage expiringMessage = message as IExpiringProtocolMessage; if (expiringMessage != null) { // Yes the UtcCreationDate is supposed to always be in UTC already, diff --git a/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs index c72c29b..bb2b28a 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs @@ -104,7 +104,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { IReplayProtectedProtocolMessage nonceMessage = message as IReplayProtectedProtocolMessage; if (nonceMessage != null) { nonceMessage.Nonce = this.GenerateUniqueFragment(); @@ -123,7 +123,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// Null if this binding element did not even apply to this binding element. /// </returns> /// <exception cref="ReplayedMessageException">Thrown when the nonce check revealed a replayed message.</exception> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { IReplayProtectedProtocolMessage nonceMessage = message as IReplayProtectedProtocolMessage; if (nonceMessage != null && nonceMessage.Nonce != null) { ErrorUtilities.VerifyProtocol(nonceMessage.Nonce.Length > 0 || this.AllowZeroLengthNonce, MessagingStrings.InvalidNonceReceived); diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index b9f4b73..2b3884e 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -234,7 +234,7 @@ namespace DotNetOpenAuth.Messaging { Contract.Ensures(Contract.Result<OutgoingWebResponse>() != null); ErrorUtilities.VerifyArgumentNotNull(message, "message"); - this.PrepareMessageForSending(message); + this.ProcessOutgoingMessage(message); Logger.DebugFormat("Sending message: {0}", message); switch (message.Transport) { @@ -361,7 +361,7 @@ namespace DotNetOpenAuth.Messaging { IDirectedProtocolMessage requestMessage = this.ReadFromRequestCore(httpRequest); if (requestMessage != null) { Logger.DebugFormat("Incoming request received: {0}", requestMessage); - this.VerifyMessageAfterReceiving(requestMessage); + this.ProcessIncomingMessage(requestMessage); } return requestMessage; @@ -400,13 +400,13 @@ namespace DotNetOpenAuth.Messaging { Contract.Requires(requestMessage != null); ErrorUtilities.VerifyArgumentNotNull(requestMessage, "requestMessage"); - this.PrepareMessageForSending(requestMessage); + this.ProcessOutgoingMessage(requestMessage); Logger.DebugFormat("Sending request: {0}", requestMessage); var responseMessage = this.RequestCore(requestMessage); ErrorUtilities.VerifyProtocol(responseMessage != null, MessagingStrings.ExpectedMessageNotReceived, typeof(IProtocolMessage).Name); Logger.DebugFormat("Received message response: {0}", responseMessage); - this.VerifyMessageAfterReceiving(responseMessage); + this.ProcessIncomingMessage(responseMessage); return responseMessage; } @@ -581,6 +581,7 @@ namespace DotNetOpenAuth.Messaging { /// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns> protected virtual OutgoingWebResponse PrepareIndirectResponse(IDirectedProtocolMessage message) { Contract.Requires(message != null && message.Recipient != null); + Contract.Ensures(Contract.Result<OutgoingWebResponse>() != null); ErrorUtilities.VerifyArgumentNotNull(message, "message"); var messageAccessor = this.MessageDescriptions.GetAccessor(message); @@ -708,7 +709,7 @@ namespace DotNetOpenAuth.Messaging { /// This method should NOT be called by derived types /// except when sending ONE WAY request messages. /// </remarks> - protected void PrepareMessageForSending(IProtocolMessage message) { + protected void ProcessOutgoingMessage(IProtocolMessage message) { Contract.Requires(message != null); ErrorUtilities.VerifyArgumentNotNull(message, "message"); @@ -723,7 +724,7 @@ namespace DotNetOpenAuth.Messaging { MessageProtections appliedProtection = MessageProtections.None; foreach (IChannelBindingElement bindingElement in this.outgoingBindingElements) { - MessageProtections? elementProtection = bindingElement.PrepareMessageForSending(message); + MessageProtections? elementProtection = bindingElement.ProcessOutgoingMessage(message); if (elementProtection.HasValue) { Logger.DebugFormat("Binding element {0} applied to message.", bindingElement.GetType().FullName); @@ -832,7 +833,7 @@ namespace DotNetOpenAuth.Messaging { /// Thrown when the message is somehow invalid. /// This can be due to tampering, replay attack or expiration, among other things. /// </exception> - protected virtual void VerifyMessageAfterReceiving(IProtocolMessage message) { + protected virtual void ProcessIncomingMessage(IProtocolMessage message) { Contract.Requires(message != null); if (Logger.IsDebugEnabled) { @@ -847,7 +848,7 @@ namespace DotNetOpenAuth.Messaging { MessageProtections appliedProtection = MessageProtections.None; foreach (IChannelBindingElement bindingElement in this.incomingBindingElements) { - MessageProtections? elementProtection = bindingElement.PrepareMessageForReceiving(message); + MessageProtections? elementProtection = bindingElement.ProcessIncomingMessage(message); if (elementProtection.HasValue) { Logger.DebugFormat("Binding element {0} applied to message.", bindingElement.GetType().FullName); diff --git a/src/DotNetOpenAuth/Messaging/IChannelBindingElement.cs b/src/DotNetOpenAuth/Messaging/IChannelBindingElement.cs index f73c65f..5ae07c3 100644 --- a/src/DotNetOpenAuth/Messaging/IChannelBindingElement.cs +++ b/src/DotNetOpenAuth/Messaging/IChannelBindingElement.cs @@ -42,7 +42,7 @@ namespace DotNetOpenAuth.Messaging { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - MessageProtections? PrepareMessageForSending(IProtocolMessage message); + MessageProtections? ProcessOutgoingMessage(IProtocolMessage message); /// <summary> /// Performs any transformation on an incoming message that may be necessary and/or @@ -61,7 +61,7 @@ namespace DotNetOpenAuth.Messaging { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - MessageProtections? PrepareMessageForReceiving(IProtocolMessage message); + MessageProtections? ProcessIncomingMessage(IProtocolMessage message); } /// <summary> @@ -106,7 +106,7 @@ namespace DotNetOpenAuth.Messaging { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - MessageProtections? IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessOutgoingMessage(IProtocolMessage message) { Contract.Requires(((IChannelBindingElement)this).Channel != null); Contract.Requires(message != null); throw new NotImplementedException(); @@ -129,7 +129,7 @@ namespace DotNetOpenAuth.Messaging { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - MessageProtections? IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) { + MessageProtections? IChannelBindingElement.ProcessIncomingMessage(IProtocolMessage message) { Contract.Requires(((IChannelBindingElement)this).Channel != null); Contract.Requires(message != null); throw new NotImplementedException(); diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs index b7c8715..f556a1d 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs @@ -93,7 +93,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { internal HttpWebRequest InitializeRequest(IDirectedProtocolMessage request) { ErrorUtilities.VerifyArgumentNotNull(request, "request"); - PrepareMessageForSending(request); + ProcessOutgoingMessage(request); return this.CreateHttpRequest(request); } diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs index afc99d9..c9df0e8 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs @@ -37,7 +37,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// True if the <paramref name="message"/> applied to this binding element /// and the operation was successful. False otherwise. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { var oauthMessage = message as ITamperResistantOAuthMessage; if (oauthMessage != null) { @@ -69,7 +69,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// Thrown when the binding element rules indicate that this message is invalid and should /// NOT be processed. /// </exception> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { return null; } diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs index 3c0e840..18757ba 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs @@ -80,7 +80,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { var signedMessage = message as ITamperResistantOAuthMessage; if (signedMessage != null && this.IsMessageApplicable(signedMessage)) { if (this.SignatureCallback != null) { @@ -107,7 +107,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// Null if this binding element did not even apply to this binding element. /// </returns> /// <exception cref="InvalidSignatureException">Thrown if the signature is invalid.</exception> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { var signedMessage = message as ITamperResistantOAuthMessage; if (signedMessage != null && this.IsMessageApplicable(signedMessage)) { Logger.DebugFormat("Verifying incoming {0} message signature of: {1}", message.GetType().Name, signedMessage.Signature); diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs index 7e6912f..f88e7ab 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementChain.cs @@ -99,9 +99,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { foreach (IChannelBindingElement signer in this.signers) { - MessageProtections? result = signer.PrepareMessageForSending(message); + MessageProtections? result = signer.ProcessOutgoingMessage(message); if (result.HasValue) { return result; } @@ -119,9 +119,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { foreach (IChannelBindingElement signer in this.signers) { - MessageProtections? result = signer.PrepareMessageForReceiving(message); + MessageProtections? result = signer.ProcessIncomingMessage(message); if (result.HasValue) { return result; } diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/BackwardCompatibilityBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/BackwardCompatibilityBindingElement.cs index 4484fa4..f23da51 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/BackwardCompatibilityBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/BackwardCompatibilityBindingElement.cs @@ -59,7 +59,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { SignedResponseRequest request = message as SignedResponseRequest; if (request != null && request.Version.Major < 2) { request.AddReturnToArguments(ProviderEndpointParameterName, request.Recipient.AbsoluteUri); @@ -92,7 +92,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { IndirectSignedResponse response = message as IndirectSignedResponse; if (response != null && response.Version.Major < 2) { // GetReturnToArgument may return parameters that are not signed, diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/ExtensionsBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/ExtensionsBindingElement.cs index 9fb8846..2102957 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/ExtensionsBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/ExtensionsBindingElement.cs @@ -94,7 +94,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { ErrorUtilities.VerifyArgumentNotNull(message, "message"); ErrorUtilities.VerifyOperation(this.Channel != null, "Channel property has not been set."); @@ -156,7 +156,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { var extendableMessage = message as IProtocolMessageWithExtensions; if (extendableMessage != null) { // We have a helper class that will do all the heavy-lifting of organizing diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs index 9d0b881..c13df36 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/OpenIdChannel.cs @@ -137,18 +137,18 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Thrown when the message is somehow invalid, except for check_authentication messages. /// This can be due to tampering, replay attack or expiration, among other things. /// </exception> - protected override void VerifyMessageAfterReceiving(IProtocolMessage message) { + protected override void ProcessIncomingMessage(IProtocolMessage message) { var checkAuthRequest = message as CheckAuthenticationRequest; if (checkAuthRequest != null) { IndirectSignedResponse originalResponse = new IndirectSignedResponse(checkAuthRequest, this); try { - base.VerifyMessageAfterReceiving(originalResponse); + base.ProcessIncomingMessage(originalResponse); checkAuthRequest.IsValid = true; } catch (ProtocolException) { checkAuthRequest.IsValid = false; } } else { - base.VerifyMessageAfterReceiving(message); + base.ProcessIncomingMessage(message); } // Convert an OpenID indirect error message, which we never expect diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToNonceBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToNonceBindingElement.cs index 2e81d1a..98a8cc5 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToNonceBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToNonceBindingElement.cs @@ -123,7 +123,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { // We only add a nonce to 1.x auth requests. SignedResponseRequest request = message as SignedResponseRequest; if (request != null && request.Version.Major < 2) { @@ -152,7 +152,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { IndirectSignedResponse response = message as IndirectSignedResponse; if (response != null && response.Version.Major < 2) { string nonceValue = response.GetReturnToArgument(NonceParameter); diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs index 2aed5ad..1515298 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/ReturnToSignatureBindingElement.cs @@ -92,7 +92,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { SignedResponseRequest request = message as SignedResponseRequest; if (request != null) { request.AddReturnToArguments(ReturnToSignatureHandleParameterName, this.secretManager.CurrentHandle); @@ -122,7 +122,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Implementations that provide message protection must honor the /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable. /// </remarks> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { IndirectSignedResponse response = message as IndirectSignedResponse; if (response != null) { diff --git a/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs b/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs index 5c7f0d2..d755426 100644 --- a/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs +++ b/src/DotNetOpenAuth/OpenId/ChannelElements/SigningBindingElement.cs @@ -101,7 +101,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// The protections (if any) that this binding element applied to the message. /// Null if this binding element did not even apply to this binding element. /// </returns> - public MessageProtections? PrepareMessageForSending(IProtocolMessage message) { + public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { var signedMessage = message as ITamperResistantOpenIdMessage; if (signedMessage != null) { Logger.DebugFormat("Signing {0} message.", message.GetType().Name); @@ -128,7 +128,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { /// Thrown when the binding element rules indicate that this message is invalid and should /// NOT be processed. /// </exception> - public MessageProtections? PrepareMessageForReceiving(IProtocolMessage message) { + public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { var signedMessage = message as ITamperResistantOpenIdMessage; if (signedMessage != null) { Logger.DebugFormat("Verifying incoming {0} message signature of: {1}", message.GetType().Name, signedMessage.Signature); |