2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-06-13 14:38:43 +00:00
This commit is contained in:
2026-05-25 23:46:29 +03:00
parent 959bc76721
commit ae6a1fc8d7
8 changed files with 123 additions and 20 deletions
@@ -0,0 +1,44 @@
using Esiur.Core;
using Esiur.Security.Authority;
using Esiur.Security.Authority.Providers;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace Esiur.Tests.Functional
{
internal class ClientAuthenticationProvider : PasswordAuthenticationProvider
{
public override (byte[], byte[]) GetHostedAccountCredential(string identity, string domain)
{
throw new NotImplementedException();
}
public override byte[] GetSelfCredential(string identity, string domain, string hostname)
{
if (identity == "tester" && domain == "test" && hostname == "localhost")
return new byte[] { 1, 2, 3, 4, 5 };
else
return null;
}
public override (string, byte[]) GetSelfIdentityAndCredential(string domain, string hostname)
{
if (domain == "test" && hostname == "localhost")
return ("tester", new byte[] { 1, 2, 3, 4, 5 });
else
return (null, null);
}
public override AsyncReply<bool> Login(Session session)
{
return base.Login(session);
}
public override AsyncReply<bool> Logout(Session session)
{
return base.Logout(session);
}
}
}
+9 -7
View File
@@ -49,6 +49,7 @@ using Esiur.Security.Membership;
using Esiur.Net.Packets;
using System.Numerics;
using Esiur.Protocol;
using Esiur.Security.Authority.Providers;
namespace Esiur.Tests.Functional;
@@ -142,12 +143,12 @@ class Program
//});
var wh = new Warehouse();
wh.RegisterAuthenticationProvider(new ServerAuthenticationProvider());
// Create stores to keep objects.
var system = await wh.Put("sys", new MemoryStore());
var server = await wh.Put("sys/server", new EpServer() {
// Membership = membership
var server = await wh.Put("sys/server", new EpServer() {
AllowedAuthenticationProviders = new string[] { "hash" },
});
@@ -213,13 +214,14 @@ class Program
private static async void TestClient(IResource local)
{
var wh = new Warehouse();
var auth = new ClientAuthenticationProvider();
wh.RegisterAuthenticationProvider(auth);
var con = await new Warehouse().Get<EpConnection>("EP://localhost", new EpConnectionContext
{
AutoReconnect = true,
//Username = "admin",
//Password = "admin",
Identity = "demo",
Identity = "tester",
AuthenticationProtocol = "hash"
});
@@ -0,0 +1,40 @@
using Esiur.Core;
using Esiur.Security.Authority;
using Esiur.Security.Authority.Providers;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Tests.Functional
{
internal class ServerAuthenticationProvider: PasswordAuthenticationProvider
{
public override (byte[], byte[]) GetHostedAccountCredential(string identity, string domain)
{
if (identity == "tester" && domain == "test")
return (new byte[] { 1, 2, 3, 4, 5 }, new byte[] { 6, 7, 8, 9, 10 });
else
return (null, null);
}
public override byte[] GetSelfCredential(string identity, string domain, string hostname)
{
return base.GetSelfCredential(identity, domain, hostname);
}
public override (string, byte[]) GetSelfIdentityAndCredential(string domain, string hostname)
{
return base.GetSelfIdentityAndCredential(domain, hostname);
}
public override AsyncReply<bool> Login(Session session)
{
return base.Login(session);
}
public override AsyncReply<bool> Logout(Session session)
{
return base.Logout(session);
}
}
}