2022-03-12 22:52:28 +01:00
|
|
|
|
using Capnp.Rpc;
|
|
|
|
|
using FabAccessAPI;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-04-20 17:13:40 +02:00
|
|
|
|
using System.Net.Security;
|
|
|
|
|
using System.Security.Authentication;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2022-03-12 22:52:28 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FabAccessAPI_Test
|
|
|
|
|
{
|
2022-04-21 01:20:30 +02:00
|
|
|
|
[TestFixture, Order(0)]
|
2022-03-12 22:52:28 +01:00
|
|
|
|
public class Connection_Test
|
|
|
|
|
{
|
2022-04-20 17:13:40 +02:00
|
|
|
|
const string TESTSERVER = "bffh.lab.bln.kjknet.de";
|
|
|
|
|
const int TESTSERVER_PORT = 59666;
|
|
|
|
|
|
|
|
|
|
private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(TESTSERVER, TESTSERVER_PORT)]
|
2022-03-12 22:52:28 +01:00
|
|
|
|
public async Task Connect(string host, int port)
|
|
|
|
|
{
|
|
|
|
|
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
2022-04-20 17:13:40 +02:00
|
|
|
|
tcpRpcClient.InjectMidlayer((tcpstream) =>
|
|
|
|
|
{
|
|
|
|
|
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sslStream.AuthenticateAsClient("bffhd");
|
|
|
|
|
return sslStream;
|
|
|
|
|
}
|
|
|
|
|
catch (AuthenticationException)
|
|
|
|
|
{
|
|
|
|
|
sslStream.Close();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-03-12 22:52:28 +01:00
|
|
|
|
tcpRpcClient.Connect(host, port);
|
|
|
|
|
await tcpRpcClient.WhenConnected;
|
|
|
|
|
|
|
|
|
|
Connection connection = new Connection(tcpRpcClient);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 17:13:40 +02:00
|
|
|
|
[TestCase(TESTSERVER, TESTSERVER_PORT, "Admin1", "secret")]
|
2022-03-12 22:52:28 +01:00
|
|
|
|
public async Task Authenticate_PLAIN(string host, int port, string username, string password)
|
|
|
|
|
{
|
|
|
|
|
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
2022-04-20 17:13:40 +02:00
|
|
|
|
tcpRpcClient.InjectMidlayer((tcpstream) =>
|
|
|
|
|
{
|
|
|
|
|
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sslStream.AuthenticateAsClient("bffhd");
|
|
|
|
|
return sslStream;
|
|
|
|
|
}
|
|
|
|
|
catch (AuthenticationException)
|
|
|
|
|
{
|
|
|
|
|
sslStream.Close();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-03-12 22:52:28 +01:00
|
|
|
|
tcpRpcClient.Connect(host, port);
|
|
|
|
|
await tcpRpcClient.WhenConnected;
|
|
|
|
|
|
|
|
|
|
Connection connection = new Connection(tcpRpcClient);
|
|
|
|
|
await connection.Auth("PLAIN", new Dictionary<string, object>(StringComparer.Ordinal) { { "Username", username }, { "Password", password } });
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(connection.Session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|