summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-24 21:17:33 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-24 21:17:33 -0700
commita92ec583772221f818fe1c7259b4e2f2ae8acb8d (patch)
tree5bb1a37fc858c0f4b76f87f862022408882c7a0d /src
parentde6a705de31c11ee5892c94cc9afc5c8e49a90ce (diff)
downloadDotNetOpenAuth-a92ec583772221f818fe1c7259b4e2f2ae8acb8d.zip
DotNetOpenAuth-a92ec583772221f818fe1c7259b4e2f2ae8acb8d.tar.gz
DotNetOpenAuth-a92ec583772221f818fe1c7259b4e2f2ae8acb8d.tar.bz2
Added logging.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth.Test/Logging.config6
-rw-r--r--src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs4
-rw-r--r--src/DotNetOAuth.Test/TestBase.cs9
-rw-r--r--src/DotNetOAuth/Messages/MessageBase.cs27
4 files changed, 37 insertions, 9 deletions
diff --git a/src/DotNetOAuth.Test/Logging.config b/src/DotNetOAuth.Test/Logging.config
index a1d675b..66e595f 100644
--- a/src/DotNetOAuth.Test/Logging.config
+++ b/src/DotNetOAuth.Test/Logging.config
@@ -24,10 +24,10 @@
<appender-ref ref="TraceAppender" />
</root>
<!-- Specify the level for some specific categories -->
- <logger name="DotNetOpenId">
- <level value="Off" />
+ <logger name="DotNetOAuth">
+ <level value="Warn" />
</logger>
- <logger name="DotNetOpenId.Test">
+ <logger name="DotNetOAuth.Test">
<level value="Info" />
</logger>
</log4net>
diff --git a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
index 4c34a0d..abd95d1 100644
--- a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
@@ -13,6 +13,7 @@ namespace DotNetOAuth.Test.Scenarios {
using DotNetOAuth.Messaging.Bindings;
using DotNetOAuth.Messaging;
using System.Threading;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// A special channel used in test simulations to pass messages directly between two parties.
@@ -37,6 +38,7 @@ using System.Threading;
private IProtocolMessage incomingMessage;
protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
+ TestBase.TestLogger.InfoFormat("Sending request: {0}", request);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
RemoteChannel.incomingMessage = request;
RemoteChannel.incomingMessageSignal.Set();
@@ -45,11 +47,13 @@ using System.Threading;
}
protected override void SendDirectMessageResponse(IProtocolMessage response) {
+ TestBase.TestLogger.InfoFormat("Sending response: {0}", response);
RemoteChannel.incomingMessage = response;
RemoteChannel.incomingMessageSignal.Set();
}
protected override void SendIndirectMessage(IDirectedProtocolMessage message) {
+ TestBase.TestLogger.InfoFormat("Sending indirect message: {0}", message);
// In this mock transport, direct and indirect messages are the same.
SendDirectMessageResponse(message);
}
diff --git a/src/DotNetOAuth.Test/TestBase.cs b/src/DotNetOAuth.Test/TestBase.cs
index 5877a08..55d1858 100644
--- a/src/DotNetOAuth.Test/TestBase.cs
+++ b/src/DotNetOAuth.Test/TestBase.cs
@@ -5,12 +5,8 @@
//-----------------------------------------------------------------------
namespace DotNetOAuth.Test {
- using System;
- using System.Collections.Generic;
using System.Reflection;
- using System.Threading;
- using DotNetOAuth.ChannelElements;
- using DotNetOAuth.Messaging;
+ using DotNetOAuth.Messages;
using log4net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -21,7 +17,7 @@ namespace DotNetOAuth.Test {
/// <summary>
/// The logger that tests should use.
/// </summary>
- internal static readonly ILog Logger = LogManager.GetLogger("DotNetOAuth.Test");
+ internal static readonly ILog TestLogger = LogManager.GetLogger("DotNetOAuth.Test");
/// <summary>
/// Gets or sets the test context which provides
@@ -35,6 +31,7 @@ namespace DotNetOAuth.Test {
[TestInitialize]
public virtual void SetUp() {
log4net.Config.XmlConfigurator.Configure(Assembly.GetExecutingAssembly().GetManifestResourceStream("DotNetOAuth.Test.Logging.config"));
+ MessageBase.LowSecurityMode = true;
}
/// <summary>
diff --git a/src/DotNetOAuth/Messages/MessageBase.cs b/src/DotNetOAuth/Messages/MessageBase.cs
index 599cc4f..097749d 100644
--- a/src/DotNetOAuth/Messages/MessageBase.cs
+++ b/src/DotNetOAuth/Messages/MessageBase.cs
@@ -10,6 +10,9 @@ namespace DotNetOAuth.Messages {
using DotNetOAuth.ChannelElements;
using DotNetOAuth.Messaging;
using DotNetOAuth.Messaging.Bindings;
+ using DotNetOAuth.Messaging.Reflection;
+ using System.Text;
+ using System.Globalization;
/// <summary>
/// A base class for all OAuth messages.
@@ -115,6 +118,11 @@ namespace DotNetOAuth.Messages {
#endregion
+ /// <summary>
+ /// Gets or sets whether security sensitive strings are emitted from the ToString() method.
+ /// </summary>
+ internal static bool LowSecurityMode { get; set; }
+
#region IProtocolMessage Methods
/// <summary>
@@ -127,6 +135,25 @@ namespace DotNetOAuth.Messages {
#endregion
+ public override string ToString() {
+ StringBuilder builder = new StringBuilder();
+ builder.AppendFormat(CultureInfo.InvariantCulture, "{0} message", GetType().Name);
+ builder.AppendLine();
+ MessageDictionary dictionary = new MessageDictionary(this);
+ foreach (var pair in dictionary) {
+ string value = pair.Value;
+ if (pair.Key == "oauth_signature" && !LowSecurityMode) {
+ value = "xxxxxxxxxxxxx (not shown)";
+ }
+ builder.Append('\t');
+ builder.Append(pair.Key);
+ builder.Append(": ");
+ builder.AppendLine(value);
+ }
+
+ return builder.ToString();
+ }
+
/// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.