Skip to content

Commit

Permalink
AuthenticationProvider.Authenticate doesn't have access to RemotingSe…
Browse files Browse the repository at this point in the history
…ssion.Current.
  • Loading branch information
yallie committed Dec 7, 2024
1 parent 22703c7 commit f66eee7
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions CoreRemoting.Tests/RpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using CoreRemoting.Authentication;
using CoreRemoting.Channels;
using CoreRemoting.Serialization;
using CoreRemoting.Tests.ExternalTypes;
Expand Down Expand Up @@ -832,8 +833,10 @@ public void Authentication_is_taken_into_account_and_RejectCall_event_is_fired()
void RejectCall(object sender, ServerRpcContext e) =>
rejectedMethod = e.MethodCallMessage.MethodName;

_serverFixture.Server.Config.AuthenticationRequired = true;
_serverFixture.Server.RejectCall += RejectCall;
var server = _serverFixture.Server;
server.RejectCall += RejectCall;
server.Config.AuthenticationRequired = true;

try
{
using var client = new RemotingClient(new ClientConfig()
Expand All @@ -859,8 +862,44 @@ void RejectCall(object sender, ServerRpcContext e) =>
}
finally
{
_serverFixture.Server.Config.AuthenticationRequired = false;
_serverFixture.Server.RejectCall -= RejectCall;
server.Config.AuthenticationRequired = false;
server.RejectCall -= RejectCall;
}
}

[Fact]
public void Authentication_handler_has_access_to_the_current_session()
{
var server = _serverFixture.Server;
var authProvider = server.Config.AuthenticationProvider;
server.Config.AuthenticationRequired = true;
server.Config.AuthenticationProvider = new FakeAuthProvider
{
AuthenticateFake = c => RemotingSession.Current != null
};

try
{
using var client = new RemotingClient(new ClientConfig()
{
ConnectionTimeout = 0,
InvocationTimeout = 0,
SendTimeout = 0,
Channel = ClientChannel,
MessageEncryption = false,
ServerPort = _serverFixture.Server.Config.NetworkPort,
Credentials = [new Credential()],
});

client.Connect();

var proxy = client.CreateProxy<ITestService>();
Assert.Equal("123", proxy.Reverse("321"));
}
finally
{
server.Config.AuthenticationProvider = authProvider;
server.Config.AuthenticationRequired = false;
}
}
}
Expand Down

0 comments on commit f66eee7

Please sign in to comment.