From f66eee714afabc3edbde4b716e89f551dc89d706 Mon Sep 17 00:00:00 2001 From: yallie Date: Sat, 7 Dec 2024 02:38:14 +0300 Subject: [PATCH] AuthenticationProvider.Authenticate doesn't have access to RemotingSession.Current. --- CoreRemoting.Tests/RpcTests.cs | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/CoreRemoting.Tests/RpcTests.cs b/CoreRemoting.Tests/RpcTests.cs index 6691635..ddd6f5a 100644 --- a/CoreRemoting.Tests/RpcTests.cs +++ b/CoreRemoting.Tests/RpcTests.cs @@ -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; @@ -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() @@ -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(); + Assert.Equal("123", proxy.Reverse("321")); + } + finally + { + server.Config.AuthenticationProvider = authProvider; + server.Config.AuthenticationRequired = false; } } }