Skip to content

Commit

Permalink
Add custom exception type for insecure remoting
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Cully committed Nov 21, 2023
1 parent 1d76454 commit 97672b5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Hosting.Services.Remoting/RemotingListenerBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Fabric;
using Microsoft.Omex.Extensions.Services.Remoting;
using Microsoft.Omex.Extensions.Services.Remoting.Runtime;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Remoting;
Expand Down Expand Up @@ -33,7 +33,7 @@ protected RemotingListenerBuilder(
{
if (settings == null && !FabricTransportRemotingListenerSettings.TryLoadFrom("TransportSettings", out settings))
{
throw new InvalidOperationException("Transport security is required for Service Fabric Remoting connections. TransportSettings must be defined in settings.xml.");
throw new InsecureRemotingUnsupportedException();
}

settings.ExceptionSerializationTechnique = FabricTransportRemotingListenerSettings.ExceptionSerialization.Default;
Expand Down
3 changes: 1 addition & 2 deletions src/Services.Remoting/Client/OmexServiceProxyFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using Microsoft.ServiceFabric.Services.Remoting.Client;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport;
using Microsoft.ServiceFabric.Services.Remoting.V2.FabricTransport.Client;
Expand All @@ -24,7 +23,7 @@ public static class OmexServiceProxyFactory
{
if (!FabricTransportRemotingSettings.TryLoadFrom("TransportSettings", out FabricTransportRemotingSettings remotingSettings))
{
throw new InvalidOperationException("Transport security is required for Service Fabric Remoting connections. TransportSettings must be defined in settings.xml.");
throw new InsecureRemotingUnsupportedException();
}

remotingSettings.ExceptionDeserializationTechnique = FabricTransportRemotingSettings.ExceptionDeserialization.Default;
Expand Down
22 changes: 22 additions & 0 deletions src/Services.Remoting/InsecureRemotingUnsupportedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;

namespace Microsoft.Omex.Extensions.Services.Remoting
{
/// <summary>
/// Specific exception type used when an attempt to create an insecure listener or insecure proxy is made.
/// </summary>
[Serializable]
public class InsecureRemotingUnsupportedException : InvalidOperationException
{
/// <summary>
/// Creates an instance of <see cref="InsecureRemotingUnsupportedException"/>.
/// </summary>
public InsecureRemotingUnsupportedException()
: base("Transport security is required for Service Fabric Remoting connections. TransportSettings must be defined in settings.xml.")
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Microsoft.Omex.Extensions.Hosting.Services.UnitTests;
using Microsoft.Omex.Extensions.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -21,7 +22,7 @@ public void GenericRemotingListenerBuilder_NoTransportSettigns_ThrowsException()
IServiceProvider mockProvider = new Mock<IServiceProvider>().Object;
OmexStatefulService omexStatefulService = MockServiceFabricServices.MockOmexStatefulService;

Assert.ThrowsException<InvalidOperationException>(() => new GenericRemotingListenerBuilder<OmexStatefulService>(name, mockProvider,
Assert.ThrowsException<InsecureRemotingUnsupportedException>(() => new GenericRemotingListenerBuilder<OmexStatefulService>(name, mockProvider,
(p, s) =>
{
Assert.AreEqual(omexStatefulService, s);
Expand Down

0 comments on commit 97672b5

Please sign in to comment.