summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-09-06 07:24:17 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-09-06 07:24:17 -0700
commitd8c635a1605d42d22125c30a275450c3dd7fb7b8 (patch)
treed6011f40510fd260b9b04d2586191965d14b11c7 /src
parent6d834307ab89df13ce96c49f0cc3971841e8f2db (diff)
downloadDotNetOpenAuth-d8c635a1605d42d22125c30a275450c3dd7fb7b8.zip
DotNetOpenAuth-d8c635a1605d42d22125c30a275450c3dd7fb7b8.tar.gz
DotNetOpenAuth-d8c635a1605d42d22125c30a275450c3dd7fb7b8.tar.bz2
More contracts work.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs2
-rw-r--r--src/DotNetOpenAuth/ComponentModel/SuggestedStringsConverter.cs3
-rw-r--r--src/DotNetOpenAuth/ComponentModel/UriConverter.cs8
-rw-r--r--src/DotNetOpenAuth/InfoCard/ClaimType.cs2
-rw-r--r--src/DotNetOpenAuth/InfoCard/InfoCardImage.cs2
-rw-r--r--src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs22
-rw-r--r--src/DotNetOpenAuth/InfoCard/Token/Token.cs1
-rw-r--r--src/DotNetOpenAuth/Messaging/Channel.cs2
-rw-r--r--src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/MessageSerializer.cs8
-rw-r--r--src/DotNetOpenAuth/Messaging/MessagingUtilities.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs9
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/AttributeRequest.cs2
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs3
-rw-r--r--src/DotNetOpenAuth/OpenId/UriIdentifier.cs1
-rw-r--r--src/DotNetOpenAuth/OpenId/XriIdentifier.cs1
16 files changed, 37 insertions, 37 deletions
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index d19d908..809fae7 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -41,7 +41,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
this.channel.WebRequestHandler = this.webRequestHandler;
}
- [TestMethod, ExpectedException(typeof(ArgumentException))]
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullSigner() {
new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageFactory());
}
diff --git a/src/DotNetOpenAuth/ComponentModel/SuggestedStringsConverter.cs b/src/DotNetOpenAuth/ComponentModel/SuggestedStringsConverter.cs
index 1c8c555..f5300cb 100644
--- a/src/DotNetOpenAuth/ComponentModel/SuggestedStringsConverter.cs
+++ b/src/DotNetOpenAuth/ComponentModel/SuggestedStringsConverter.cs
@@ -35,6 +35,9 @@ namespace DotNetOpenAuth.ComponentModel {
/// <param name="type">The type to reflect over.</param>
/// <returns>A collection of values.</returns>
internal static ICollection GetStandardValuesForCacheShared(Type type) {
+ Contract.Requires<ArgumentNullException>(type != null);
+ Contract.Ensures(Contract.Result<ICollection>() != null);
+
var fields = from field in type.GetFields(BindingFlags.Static | BindingFlags.Public)
select field.GetValue(null);
var properties = from prop in type.GetProperties(BindingFlags.Static | BindingFlags.Public)
diff --git a/src/DotNetOpenAuth/ComponentModel/UriConverter.cs b/src/DotNetOpenAuth/ComponentModel/UriConverter.cs
index cf8dde3..5e7c22b 100644
--- a/src/DotNetOpenAuth/ComponentModel/UriConverter.cs
+++ b/src/DotNetOpenAuth/ComponentModel/UriConverter.cs
@@ -101,9 +101,13 @@ namespace DotNetOpenAuth.ComponentModel {
protected override ICollection GetStandardValuesForCache() {
if (this.WellKnownValuesType != null) {
var fields = from field in this.WellKnownValuesType.GetFields(BindingFlags.Static | BindingFlags.Public)
- select new Uri((string)field.GetValue(null));
+ let value = (string)field.GetValue(null)
+ where value != null
+ select new Uri(value);
var properties = from prop in this.WellKnownValuesType.GetProperties(BindingFlags.Static | BindingFlags.Public)
- select new Uri((string)prop.GetValue(null, null));
+ let value = (string)prop.GetValue(null, null)
+ where value != null
+ select new Uri(value);
return (fields.Concat(properties)).ToArray();
} else {
return new Uri[0];
diff --git a/src/DotNetOpenAuth/InfoCard/ClaimType.cs b/src/DotNetOpenAuth/InfoCard/ClaimType.cs
index f9c4917..9d3056a 100644
--- a/src/DotNetOpenAuth/InfoCard/ClaimType.cs
+++ b/src/DotNetOpenAuth/InfoCard/ClaimType.cs
@@ -49,7 +49,7 @@ namespace DotNetOpenAuth.InfoCard {
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override string ToString() {
- return this.Name != null ? this.Name : null;
+ return this.Name ?? "<no name>";
}
}
}
diff --git a/src/DotNetOpenAuth/InfoCard/InfoCardImage.cs b/src/DotNetOpenAuth/InfoCard/InfoCardImage.cs
index 2b7b25f..247f461 100644
--- a/src/DotNetOpenAuth/InfoCard/InfoCardImage.cs
+++ b/src/DotNetOpenAuth/InfoCard/InfoCardImage.cs
@@ -23,6 +23,7 @@
namespace DotNetOpenAuth.InfoCard {
using System;
using System.Diagnostics.CodeAnalysis;
+ using System.Diagnostics.Contracts;
using System.Globalization;
/// <summary>
@@ -129,6 +130,7 @@ namespace DotNetOpenAuth.InfoCard {
/// <returns>The manifest resource stream name.</returns>
internal static string GetImageManifestResourceStreamName(InfoCardImageSize size) {
string imageSize = size.ToString();
+ Contract.Assume(imageSize.Length >= 6);
imageSize = imageSize.Substring(4);
return String.Format(CultureInfo.InvariantCulture, UrlFormatString, imageSize);
}
diff --git a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
index f367baa..275bb57 100644
--- a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
+++ b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
@@ -263,17 +263,19 @@ namespace DotNetOpenAuth.InfoCard {
}
set {
- if (this.Page != null && !this.DesignMode) {
- // Validate new value by trying to construct a Uri based on it.
- new Uri(new HttpRequestInfo(HttpContext.Current.Request).UrlBeforeRewriting, this.Page.ResolveUrl(value)); // throws an exception on failure.
- } else {
- // We can't fully test it, but it should start with either ~/ or a protocol.
- if (Regex.IsMatch(value, @"^https?://")) {
- new Uri(value); // make sure it's fully-qualified, but ignore wildcards
- } else if (value.StartsWith("~/", StringComparison.Ordinal)) {
- // this is valid too
+ if (!string.IsNullOrEmpty(value)) {
+ if (this.Page != null && !this.DesignMode) {
+ // Validate new value by trying to construct a Uri based on it.
+ new Uri(new HttpRequestInfo(HttpContext.Current.Request).UrlBeforeRewriting, this.Page.ResolveUrl(value)); // throws an exception on failure.
} else {
- throw new UriFormatException();
+ // We can't fully test it, but it should start with either ~/ or a protocol.
+ if (Regex.IsMatch(value, @"^https?://")) {
+ new Uri(value); // make sure it's fully-qualified, but ignore wildcards
+ } else if (value.StartsWith("~/", StringComparison.Ordinal)) {
+ // this is valid too
+ } else {
+ throw new UriFormatException();
+ }
}
}
diff --git a/src/DotNetOpenAuth/InfoCard/Token/Token.cs b/src/DotNetOpenAuth/InfoCard/Token/Token.cs
index 0eaf2f8..4656e3f 100644
--- a/src/DotNetOpenAuth/InfoCard/Token/Token.cs
+++ b/src/DotNetOpenAuth/InfoCard/Token/Token.cs
@@ -194,6 +194,7 @@ namespace DotNetOpenAuth.InfoCard {
Contract.Requires<ArgumentNullException>(tokenXml != null);
using (XmlReader tokenReader = XmlReader.Create(new StringReader(tokenXml))) {
+ Contract.Assume(tokenReader != null); // CC missing for XmlReader.Create
return IsEncrypted(tokenReader);
}
}
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs
index 027e014..93dcae2 100644
--- a/src/DotNetOpenAuth/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth/Messaging/Channel.cs
@@ -1035,8 +1035,6 @@ namespace DotNetOpenAuth.Messaging {
return new IChannelBindingElement[0];
}
- ErrorUtilities.VerifyArgumentNamed(!elements.Contains(null), "elements", MessagingStrings.SequenceContainsNullElement);
-
// Filter the elements between the mere transforming ones and the protection ones.
var transformationElements = new List<IChannelBindingElement>(
elements.Where(element => element.Protection == MessageProtections.None));
diff --git a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
index c2a39d0..f4b1633 100644
--- a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
+++ b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
@@ -336,7 +336,7 @@ namespace DotNetOpenAuth.Messaging {
UriBuilder publicRequestUri = new UriBuilder(request.Url);
Uri hostAndPort = new Uri(request.Url.Scheme + Uri.SchemeDelimiter + request.ServerVariables["HTTP_HOST"]);
publicRequestUri.Host = hostAndPort.Host;
- publicRequestUri.Port = hostAndPort.Port;
+ publicRequestUri.Port = hostAndPort.Port; // CC missing Uri.Port contract that's on UriBuilder.Port
if (request.ServerVariables["HTTP_X_FORWARDED_PROTO"] != null) {
publicRequestUri.Scheme = request.ServerVariables["HTTP_X_FORWARDED_PROTO"];
}
@@ -370,7 +370,7 @@ namespace DotNetOpenAuth.Messaging {
/// <param name="pairs">The collection a HTTP headers.</param>
/// <returns>A new collection of the given headers.</returns>
private static WebHeaderCollection GetHeaderCollection(NameValueCollection pairs) {
- Debug.Assert(pairs != null, "pairs == null");
+ Contract.Requires<ArgumentNullException>(pairs != null);
WebHeaderCollection headers = new WebHeaderCollection();
foreach (string key in pairs) {
diff --git a/src/DotNetOpenAuth/Messaging/MessageSerializer.cs b/src/DotNetOpenAuth/Messaging/MessageSerializer.cs
index 550df1a..a21559e 100644
--- a/src/DotNetOpenAuth/Messaging/MessageSerializer.cs
+++ b/src/DotNetOpenAuth/Messaging/MessageSerializer.cs
@@ -36,14 +36,6 @@ namespace DotNetOpenAuth.Messaging {
Contract.Requires<ArgumentNullException>(messageType != null);
Contract.Requires<ArgumentException>(typeof(IMessage).IsAssignableFrom(messageType));
Contract.Ensures(this.messageType != null);
-
- ErrorUtilities.VerifyArgumentNamed(
- typeof(IMessage).IsAssignableFrom(messageType),
- "messageType",
- MessagingStrings.UnexpectedType,
- typeof(IMessage).FullName,
- messageType.FullName);
-
this.messageType = messageType;
}
diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
index b0fb463..e84411f 100644
--- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
@@ -294,8 +294,8 @@ namespace DotNetOpenAuth.Messaging {
internal static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy) {
Contract.Requires<ArgumentNullException>(copyFrom != null);
Contract.Requires<ArgumentNullException>(copyTo != null);
- ErrorUtilities.VerifyArgument(copyFrom.CanRead, MessagingStrings.StreamUnreadable);
- ErrorUtilities.VerifyArgument(copyTo.CanWrite, MessagingStrings.StreamUnwritable, "copyTo");
+ Contract.Requires<ArgumentException>(copyFrom.CanRead, MessagingStrings.StreamUnreadable);
+ Contract.Requires<ArgumentException>(copyTo.CanWrite, MessagingStrings.StreamUnwritable);
byte[] buffer = new byte[1024];
int readBytes;
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
index 59d0fea..8c5980f 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
@@ -65,10 +65,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
internal OAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, ITokenManager tokenManager, IMessageFactory messageTypeProvider)
: base(messageTypeProvider, InitializeBindingElements(signingBindingElement, store, tokenManager)) {
Contract.Requires<ArgumentNullException>(tokenManager != null);
+ Contract.Requires<ArgumentNullException>(signingBindingElement != null);
+ Contract.Requires<ArgumentException>(signingBindingElement.SignatureCallback == null, OAuthStrings.SigningElementAlreadyAssociatedWithChannel);
this.TokenManager = tokenManager;
- ErrorUtilities.VerifyArgumentNamed(signingBindingElement.SignatureCallback == null, "signingBindingElement", OAuthStrings.SigningElementAlreadyAssociatedWithChannel);
-
signingBindingElement.SignatureCallback = this.SignatureCallback;
}
@@ -188,12 +188,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// The <see cref="HttpRequest"/> prepared to send the request.
/// </returns>
protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
- IDirectedProtocolMessage oauthRequest = request as IDirectedProtocolMessage;
- ErrorUtilities.VerifyArgument(oauthRequest != null, MessagingStrings.UnexpectedType, typeof(IDirectedProtocolMessage), request.GetType());
-
HttpWebRequest httpRequest;
- HttpDeliveryMethods transmissionMethod = oauthRequest.HttpMethods;
+ HttpDeliveryMethods transmissionMethod = request.HttpMethods;
if ((transmissionMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
httpRequest = this.InitializeRequestAsAuthHeader(request);
} else if ((transmissionMethod & HttpDeliveryMethods.PostRequest) != 0) {
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/AttributeRequest.cs b/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/AttributeRequest.cs
index 0858fd6..358db9b 100644
--- a/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/AttributeRequest.cs
+++ b/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/AttributeRequest.cs
@@ -99,7 +99,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange {
/// </returns>
public AttributeValues Respond(params string[] values) {
Contract.Requires<ArgumentNullException>(values != null);
- ErrorUtilities.VerifyArgument(values.Length <= this.Count, OpenIdStrings.AttributeTooManyValues, this.Count, this.TypeUri, values.Length);
+ Contract.Requires<ArgumentException>(values.Length <= this.Count);
return new AttributeValues(this.TypeUri, values);
}
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs
index 9571ee3..fa881d2 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs
@@ -87,8 +87,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
// If we are a smart-mode RP (supporting associations), then we MUST also be
// capable of storing nonces to prevent replay attacks.
// If we're a dumb-mode RP, then 2.0 OPs are responsible for preventing replays.
- Contract.Requires<ArgumentException>(associationStore == null || nonceStore != null);
- ErrorUtilities.VerifyArgument(associationStore == null || nonceStore != null, OpenIdStrings.AssociationStoreRequiresNonceStore);
+ Contract.Requires<ArgumentException>(associationStore == null || nonceStore != null, OpenIdStrings.AssociationStoreRequiresNonceStore);
this.securitySettings = DotNetOpenAuthSection.Configuration.OpenId.RelyingParty.SecuritySettings.CreateSecuritySettings();
this.behaviors.CollectionChanged += this.OnBehaviorsChanged;
diff --git a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
index 4339646..28d8b37 100644
--- a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
+++ b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
@@ -35,6 +35,7 @@ namespace DotNetOpenAuth.OpenId {
/// <param name="uri">The value this identifier will represent.</param>
internal UriIdentifier(string uri)
: this(uri, false) {
+ Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(uri));
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
index c61641e..9bcb9cf 100644
--- a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
+++ b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
@@ -63,6 +63,7 @@ namespace DotNetOpenAuth.OpenId {
internal XriIdentifier(string xri)
: this(xri, false) {
Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(xri));
+ Contract.Requires<FormatException>(IsValidXri(xri), OpenIdStrings.InvalidXri);
}
/// <summary>