diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-02 13:41:00 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-22 10:14:19 -0700 |
commit | ed679ec8c4e60f2fe1f2ea074c0af90267a8af5e (patch) | |
tree | 450e3adaba955f8e372a850ce688f25ca679058b /src | |
parent | 9d81aa7b9af72a96b8dced55b69e23f9b757a041 (diff) | |
download | DotNetOpenAuth-ed679ec8c4e60f2fe1f2ea074c0af90267a8af5e.zip DotNetOpenAuth-ed679ec8c4e60f2fe1f2ea074c0af90267a8af5e.tar.gz DotNetOpenAuth-ed679ec8c4e60f2fe1f2ea074c0af90267a8af5e.tar.bz2 |
More contracts
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/Messaging/Channel.cs | 6 | ||||
-rw-r--r-- | src/DotNetOpenAuth/Messaging/IMessageFactory.cs | 43 | ||||
-rw-r--r-- | src/DotNetOpenAuth/Messaging/NetworkDirectWebResponse.cs | 2 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/Identifier.cs | 2 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs | 4 | ||||
-rw-r--r-- | src/DotNetOpenAuth/UriUtil.cs | 9 |
6 files changed, 58 insertions, 8 deletions
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index e2b7adc..161b0c4 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -447,6 +447,8 @@ namespace DotNetOpenAuth.Messaging { ErrorUtilities.VerifyHttpContext(); + Contract.Assume(HttpContext.Current.Request.Url != null); + Contract.Assume(HttpContext.Current.Request.RawUrl != null); return new HttpRequestInfo(HttpContext.Current.Request); } @@ -513,6 +515,9 @@ namespace DotNetOpenAuth.Messaging { } responseFields = this.ReadFromResponseCore(response); + if (responseFields == null) { + return null; + } responseMessage = this.MessageFactory.GetNewResponseMessage(request, responseFields); if (responseMessage == null) { @@ -737,6 +742,7 @@ namespace DotNetOpenAuth.Messaging { MessageProtections appliedProtection = MessageProtections.None; foreach (IChannelBindingElement bindingElement in this.outgoingBindingElements) { + Contract.Assume(bindingElement.Channel != null); MessageProtections? elementProtection = bindingElement.ProcessOutgoingMessage(message); if (elementProtection.HasValue) { Logger.Bindings.DebugFormat("Binding element {0} applied to message.", bindingElement.GetType().FullName); diff --git a/src/DotNetOpenAuth/Messaging/IMessageFactory.cs b/src/DotNetOpenAuth/Messaging/IMessageFactory.cs index 9ce5f89..23c291a 100644 --- a/src/DotNetOpenAuth/Messaging/IMessageFactory.cs +++ b/src/DotNetOpenAuth/Messaging/IMessageFactory.cs @@ -7,11 +7,13 @@ namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; + using System.Diagnostics.Contracts; /// <summary> /// A tool to analyze an incoming message to figure out what concrete class /// is designed to deserialize it and instantiates that class. /// </summary> + [ContractClass(typeof(IMessageFactoryContract))] public interface IMessageFactory { /// <summary> /// Analyzes an incoming request message payload to discover what kind of @@ -39,4 +41,45 @@ namespace DotNetOpenAuth.Messaging { /// </returns> IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields); } + + /// <summary> + /// Code contract for the <see cref="IMessageFactory"/> interface. + /// </summary> + [ContractClassFor(typeof(IMessageFactory))] + internal class IMessageFactoryContract : IMessageFactory { + #region IMessageFactory Members + + /// <summary> + /// Analyzes an incoming request message payload to discover what kind of + /// message is embedded in it and returns the type, or null if no match is found. + /// </summary> + /// <param name="recipient">The intended or actual recipient of the request message.</param> + /// <param name="fields">The name/value pairs that make up the message payload.</param> + /// <returns> + /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can + /// deserialize to. Null if the request isn't recognized as a valid protocol message. + /// </returns> + IDirectedProtocolMessage IMessageFactory.GetNewRequestMessage(MessageReceivingEndpoint recipient, IDictionary<string, string> fields) { + Contract.Requires(fields != null); + + throw new NotImplementedException(); + } + + /// <summary> + /// Analyzes an incoming request message payload to discover what kind of + /// message is embedded in it and returns the type, or null if no match is found. + /// </summary> + /// <param name="request">The message that was sent as a request that resulted in the response.</param> + /// <param name="fields">The name/value pairs that make up the message payload.</param> + /// <returns> + /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can + /// deserialize to. Null if the request isn't recognized as a valid protocol message. + /// </returns> + IDirectResponseProtocolMessage IMessageFactory.GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) { + Contract.Requires(fields != null); + throw new NotImplementedException(); + } + + #endregion + } } diff --git a/src/DotNetOpenAuth/Messaging/NetworkDirectWebResponse.cs b/src/DotNetOpenAuth/Messaging/NetworkDirectWebResponse.cs index 136b0d0..fd6e3ab 100644 --- a/src/DotNetOpenAuth/Messaging/NetworkDirectWebResponse.cs +++ b/src/DotNetOpenAuth/Messaging/NetworkDirectWebResponse.cs @@ -86,6 +86,8 @@ namespace DotNetOpenAuth.Messaging { /// </remarks> internal override CachedDirectWebResponse GetSnapshot(int maximumBytesToCache) { ErrorUtilities.VerifyOperation(!this.streamReadBegun, "Network stream reading has already begun."); + ErrorUtilities.VerifyOperation(this.RequestUri != null, "RequestUri != null"); + ErrorUtilities.VerifyOperation(this.httpWebResponse != null, "httpWebResponse != null"); this.streamReadBegun = true; var result = new CachedDirectWebResponse(this.RequestUri, this.httpWebResponse, maximumBytesToCache); diff --git a/src/DotNetOpenAuth/OpenId/Identifier.cs b/src/DotNetOpenAuth/OpenId/Identifier.cs index 53f5094..9c5f8f9 100644 --- a/src/DotNetOpenAuth/OpenId/Identifier.cs +++ b/src/DotNetOpenAuth/OpenId/Identifier.cs @@ -194,6 +194,7 @@ namespace DotNetOpenAuth.OpenId { /// <returns> /// An initialized structure containing the discovered provider endpoint information. /// </returns> + [Pure] internal abstract IEnumerable<ServiceEndpoint> Discover(IDirectWebRequestHandler requestHandler); /// <summary> @@ -203,6 +204,7 @@ namespace DotNetOpenAuth.OpenId { /// </summary> /// <returns>A new <see cref="Identifier"/> instance if there was a /// fragment to remove, otherwise this same instance..</returns> + [Pure] internal abstract Identifier TrimFragment(); /// <summary> diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs index b665a4b..d468ea8 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs @@ -287,7 +287,9 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { Contract.Requires(realm != null); Contract.Ensures(Contract.Result<IAuthenticationRequest>() != null); try { - return this.CreateRequests(userSuppliedIdentifier, realm).First(); + var result = this.CreateRequests(userSuppliedIdentifier, realm).First(); + Contract.Assume(result != null); + return result; } catch (InvalidOperationException ex) { throw ErrorUtilities.Wrap(ex, OpenIdStrings.OpenIdEndpointNotFound); } diff --git a/src/DotNetOpenAuth/UriUtil.cs b/src/DotNetOpenAuth/UriUtil.cs index d04491d..19a5380 100644 --- a/src/DotNetOpenAuth/UriUtil.cs +++ b/src/DotNetOpenAuth/UriUtil.cs @@ -30,8 +30,7 @@ namespace DotNetOpenAuth { /// </returns> [ContractVerification(false)] // bugs/limitations in CC static analysis internal static bool QueryStringContainPrefixedParameters(this Uri uri, string prefix) { - Contract.Requires(prefix != null && prefix.Length > 0); - ErrorUtilities.VerifyNonZeroLength(prefix, "prefix"); + Contract.Requires(!string.IsNullOrEmpty(prefix)); if (uri == null) { return false; } @@ -49,10 +48,7 @@ namespace DotNetOpenAuth { /// <c>true</c> if the URI represents an encrypted request; otherwise, <c>false</c>. /// </returns> internal static bool IsTransportSecure(this Uri uri) { - if (uri == null) { - throw new ArgumentNullException("uri"); - } - + Contract.Requires(uri != null); return string.Equals(uri.Scheme, "https", StringComparison.OrdinalIgnoreCase); } @@ -65,7 +61,6 @@ namespace DotNetOpenAuth { internal static string ToStringWithImpliedPorts(this UriBuilder builder) { Contract.Requires(builder != null); Contract.Ensures(Contract.Result<string>() != null); - ErrorUtilities.VerifyArgumentNotNull(builder, "builder"); // We only check for implied ports on HTTP and HTTPS schemes since those // are the only ones supported by OpenID anyway. |