Skip to content

Commit

Permalink
Merge pull request connamara#740 from rars/improve-authentication-err…
Browse files Browse the repository at this point in the history
…or-log

Capture inner exception messages when handling authentication exceptions
  • Loading branch information
gbirchmeier authored Feb 13, 2024
2 parents f75123b + d0f36cf commit 15ec497
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
7 changes: 4 additions & 3 deletions QuickFIXn/Transport/SocketInitiator.cs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using QuickFix.Logger;
using QuickFix.Store;
using QuickFix.Util;

namespace QuickFix.Transport
{
Expand Down Expand Up @@ -73,7 +74,7 @@ public static void SocketInitiatorThreadStart(object socketInitiatorThread)
}
catch (System.Security.Authentication.AuthenticationException ex) // some certificate problems
{
exceptionEvent = $"Connection failed (AuthenticationException): {ex.Message}";
exceptionEvent = $"Connection failed (AuthenticationException): {ex.GetFullMessage()}";
}
catch (Exception ex)
{
Expand Down
15 changes: 8 additions & 7 deletions QuickFIXn/Transport/StreamFactory.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Diagnostics;
using System.Net;
using QuickFix.Logger;
using QuickFix.Util;

namespace QuickFix.Transport
{
Expand Down Expand Up @@ -271,7 +272,7 @@ public Stream CreateClientStreamAndAuthenticate(Stream innerStream)
}
catch (System.Security.Authentication.AuthenticationException ex)
{
_log.OnEvent("Unable to perform authentication against server: " + ex.Message);
_log.OnEvent("Unable to perform authentication against server: " + ex.GetFullMessage());
throw;
}

Expand Down Expand Up @@ -312,7 +313,7 @@ public Stream CreateServerStreamAndAuthenticate(Stream innerStream)
}
catch (System.Security.Authentication.AuthenticationException ex)
{
_log.OnEvent("Unable to perform authentication against server: " + ex.Message);
_log.OnEvent("Unable to perform authentication against server: " + ex.GetFullMessage());
throw;
}

Expand Down
14 changes: 14 additions & 0 deletions QuickFIXn/Util/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace QuickFix.Util
{
internal static class ExceptionExtensions
{
public static string GetFullMessage(this Exception ex)
{
return ex.InnerException == null
? ex.Message
: ex.Message + " --> " + ex.InnerException.GetFullMessage();
}
}
}
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ What's New
* #823 - get rid of IOIQty enums in FIX5 DDs, allow free string (gbirchmeier)
* #786 - rewrite HttpServer: better HTML, no crash on errors (gbirchmeier)
* #697 - new SocketIgnoreProxy setting (ABSJ415)
* #740 - Capture inner exception messages when handling authentication exceptions (rars)

### v1.11.2:
* same as v1.11.1, but I fixed the readme in the pushed nuget packages
Expand Down
29 changes: 29 additions & 0 deletions UnitTests/Util/ExceptionExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using NUnit.Framework;
using QuickFix.Util;

namespace UnitTests.Util
{
public sealed class ExceptionExtensionsTests
{
[Test]
public void WhenInnerExceptionShouldReturnJoinedInnerExceptionMessages()
{
var exception = new Exception(
"Outer exception, see inner exception",
new Exception("My inner exception message"));

Assert.AreEqual(
exception.GetFullMessage(),
"Outer exception, see inner exception --> My inner exception message");
}

[Test]
public void WhenNoInnerExceptionShouldReturnExceptionMessageUnmodified()
{
var exception = new Exception("My exception message");

Assert.AreEqual(exception.GetFullMessage(), "My exception message");
}
}
}

0 comments on commit 15ec497

Please sign in to comment.