Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture inner exception messages when handling authentication exceptions #740

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}
Loading