mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 23:31:48 +01:00
Added: New API Class
This commit is contained in:
parent
bb4a74f8c4
commit
0d5ad01496
@ -13,6 +13,7 @@ using FabAccessAPI.Exceptions;
|
|||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
|
using FabAccessAPI;
|
||||||
|
|
||||||
namespace Borepin.Service.BFFH
|
namespace Borepin.Service.BFFH
|
||||||
{
|
{
|
||||||
@ -22,7 +23,6 @@ namespace Borepin.Service.BFFH
|
|||||||
private readonly ConnectionStorage _ConnectionStorage;
|
private readonly ConnectionStorage _ConnectionStorage;
|
||||||
private readonly ConnectionCredentialStorage _ConnectionCredentialStorage;
|
private readonly ConnectionCredentialStorage _ConnectionCredentialStorage;
|
||||||
|
|
||||||
private FabAccessAPI.Connection _APIConnection;
|
|
||||||
private Connection_Plain _CurrentConnection;
|
private Connection_Plain _CurrentConnection;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -37,31 +37,9 @@ namespace Borepin.Service.BFFH
|
|||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current Connection of Service
|
/// API Connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Connection CurrentConnection
|
public API API { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _CurrentConnection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if Service is connected to a Server
|
|
||||||
/// </summary>
|
|
||||||
public bool IsConnected
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_APIConnection != null && _APIConnection.RpcClient != null)
|
|
||||||
{
|
|
||||||
return _APIConnection.RpcClient.State == Capnp.Rpc.ConnectionState.Active;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Method
|
#region Method
|
||||||
@ -78,7 +56,7 @@ namespace Borepin.Service.BFFH
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task RemoveConnection(Connection connection)
|
public async Task RemoveConnection(Connection connection)
|
||||||
{
|
{
|
||||||
if (IsConnected && connection.Equals(CurrentConnection))
|
if (API != null && API.IsConnected && connection.Equals(_CurrentConnection))
|
||||||
{
|
{
|
||||||
await Disconnect().ConfigureAwait(false);
|
await Disconnect().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -109,7 +87,6 @@ namespace Borepin.Service.BFFH
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
|
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
|
||||||
rpcClient.Dispose();
|
rpcClient.Dispose();
|
||||||
|
|
||||||
@ -176,7 +153,6 @@ namespace Borepin.Service.BFFH
|
|||||||
/// <exception cref="AuthenticatingFailedException"></exception>
|
/// <exception cref="AuthenticatingFailedException"></exception>
|
||||||
public async Task Connect(Connection connection, string password)
|
public async Task Connect(Connection connection, string password)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
|
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
|
||||||
@ -229,6 +205,10 @@ namespace Borepin.Service.BFFH
|
|||||||
|
|
||||||
_APIConnection = new FabAccessAPI.Connection(rpcClient);
|
_APIConnection = new FabAccessAPI.Connection(rpcClient);
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using Capnp.Rpc;
|
using Capnp.Rpc;
|
||||||
using FabAccessAPI.Exceptions;
|
using FabAccessAPI.Exceptions;
|
||||||
using FabAccessAPI.Schema;
|
using FabAccessAPI.Schema;
|
||||||
|
using S22.Sasl;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
@ -13,7 +15,8 @@ namespace FabAccessAPI
|
|||||||
public class API : IAPI
|
public class API : IAPI
|
||||||
{
|
{
|
||||||
#region Private Members
|
#region Private Members
|
||||||
private Connection _APIConnection;
|
private TcpRpcClient _TcpRpcClient;
|
||||||
|
private IBootstrap _Bootstrap;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -25,6 +28,25 @@ namespace FabAccessAPI
|
|||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
public event EventHandler<ConnectionStatusChange> ConnectionStatusChanged;
|
public event EventHandler<ConnectionStatusChange> ConnectionStatusChanged;
|
||||||
|
|
||||||
|
public void OnTcpRpcConnectionChanged(object sender, ConnectionStateChange args)
|
||||||
|
{
|
||||||
|
EventHandler<ConnectionStatusChange> eventHandler = ConnectionStatusChanged;
|
||||||
|
|
||||||
|
if (eventHandler == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.LastState == ConnectionState.Initializing && args.NewState == ConnectionState.Active)
|
||||||
|
{
|
||||||
|
eventHandler(this, ConnectionStatusChange.Connected);
|
||||||
|
}
|
||||||
|
if (args.LastState == ConnectionState.Active && args.NewState == ConnectionState.Down)
|
||||||
|
{
|
||||||
|
eventHandler(this, ConnectionStatusChange.ConnectionLoss);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Members
|
#region Members
|
||||||
@ -36,17 +58,11 @@ namespace FabAccessAPI
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _APIConnection != null && _APIConnection.RpcClient.State == ConnectionState.Active;
|
return _TcpRpcClient != null && _TcpRpcClient.State == ConnectionState.Active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Session Session
|
public Session Session { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -55,20 +71,33 @@ namespace FabAccessAPI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="AuthenticationException"></exception>
|
/// <exception cref="AuthenticationException"></exception>
|
||||||
/// <exception cref="ConnectingFailedException"></exception>
|
/// <exception cref="ConnectingFailedException"></exception>
|
||||||
public async Task Connect(ConnectionData connectionData)
|
public async Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null)
|
||||||
{
|
{
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
await Disconnect();
|
await Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpRpcClient rpcClient = await _ConnectAsync(connectionData).ConfigureAwait(false);
|
if(tcpRpcClient == null)
|
||||||
|
{
|
||||||
_APIConnection = new Connection(rpcClient);
|
_TcpRpcClient = new TcpRpcClient();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_TcpRpcClient = tcpRpcClient;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _Authenticate(connectionData).ConfigureAwait(false);
|
_TcpRpcClient.ConnectionStateChanged += OnTcpRpcConnectionChanged;
|
||||||
|
|
||||||
|
await _ConnectAsync(_TcpRpcClient, connectionData).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_Bootstrap = _TcpRpcClient.GetMain<IBootstrap>();
|
||||||
|
ConnectionInfo = await _GetConnectionInfo(_Bootstrap);
|
||||||
|
|
||||||
|
Session = await _Authenticate(connectionData).ConfigureAwait(false);
|
||||||
|
ConnectionData = connectionData;
|
||||||
}
|
}
|
||||||
catch(System.Exception)
|
catch(System.Exception)
|
||||||
{
|
{
|
||||||
@ -81,45 +110,68 @@ namespace FabAccessAPI
|
|||||||
{
|
{
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
_APIConnection.RpcClient?.Dispose();
|
_TcpRpcClient.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
_APIConnection = null;
|
_Bootstrap = null;
|
||||||
|
Session = null;
|
||||||
|
_TcpRpcClient = null;
|
||||||
ConnectionData = null;
|
ConnectionData = null;
|
||||||
ConnectionInfo = null;
|
ConnectionInfo = null;
|
||||||
|
|
||||||
|
EventHandler<ConnectionStatusChange> eventHandler = ConnectionStatusChanged;
|
||||||
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
eventHandler(this, ConnectionStatusChange.Disconnected);
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Reconnect()
|
public async Task Reconnect()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (ConnectionData != null)
|
||||||
|
{
|
||||||
|
await Connect(ConnectionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ConnectionInfo> TestConnection(ConnectionData connectionData)
|
EventHandler<ConnectionStatusChange> eventHandler = ConnectionStatusChanged;
|
||||||
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
eventHandler(this, ConnectionStatusChange.Reconnected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TcpRpcClient rpcClient = await _ConnectAsync(connectionData).ConfigureAwait(false);
|
if (tcpRpcClient == null)
|
||||||
Connection testConnection = new Connection(rpcClient);
|
|
||||||
|
|
||||||
rpcClient.Dispose();
|
|
||||||
|
|
||||||
ConnectionInfo connectionInfo = new ConnectionInfo()
|
|
||||||
{
|
{
|
||||||
APIVersion = testConnection.
|
tcpRpcClient = new TcpRpcClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
await _ConnectAsync(tcpRpcClient, connectionData).ConfigureAwait(false);
|
||||||
|
IBootstrap testBootstrap = tcpRpcClient.GetMain<IBootstrap>();
|
||||||
|
|
||||||
|
ConnectionInfo connectionInfo = await _GetConnectionInfo(testBootstrap).ConfigureAwait(false);
|
||||||
|
|
||||||
|
tcpRpcClient.Dispose();
|
||||||
|
|
||||||
|
return connectionInfo;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return null;
|
throw new ConnectingFailedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
/// <summary>
|
||||||
|
/// Validate Certificate
|
||||||
|
/// TODO: Do some validation
|
||||||
|
/// </summary>
|
||||||
private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||||
{
|
{
|
||||||
// TODO Cert Check
|
// TODO Cert Check
|
||||||
@ -132,9 +184,8 @@ namespace FabAccessAPI
|
|||||||
/// <exception cref="AuthenticationException">TLS Error</exception>
|
/// <exception cref="AuthenticationException">TLS Error</exception>
|
||||||
/// <exception cref="ConnectingFailedException">Based on RPC Exception</exception>
|
/// <exception cref="ConnectingFailedException">Based on RPC Exception</exception>
|
||||||
///
|
///
|
||||||
private async Task<TcpRpcClient> _ConnectAsync(ConnectionData connectionData)
|
private async Task _ConnectAsync(TcpRpcClient rpcClient, ConnectionData connectionData)
|
||||||
{
|
{
|
||||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
|
||||||
rpcClient.InjectMidlayer((tcpstream) =>
|
rpcClient.InjectMidlayer((tcpstream) =>
|
||||||
{
|
{
|
||||||
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
||||||
@ -154,8 +205,6 @@ namespace FabAccessAPI
|
|||||||
{
|
{
|
||||||
rpcClient.Connect(connectionData.Host.Host, connectionData.Host.Port);
|
rpcClient.Connect(connectionData.Host.Host, connectionData.Host.Port);
|
||||||
await rpcClient.WhenConnected.ConfigureAwait(false);
|
await rpcClient.WhenConnected.ConfigureAwait(false);
|
||||||
|
|
||||||
return rpcClient;
|
|
||||||
}
|
}
|
||||||
catch (RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
|
catch (RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
@ -163,13 +212,29 @@ namespace FabAccessAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create ConnectionInfo from Bootstrap
|
||||||
|
/// </summary>
|
||||||
|
private async Task<ConnectionInfo> _GetConnectionInfo(IBootstrap bootstrap)
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = new ConnectionInfo()
|
||||||
|
{
|
||||||
|
APIVersion = await bootstrap.GetAPIVersion().ConfigureAwait(false),
|
||||||
|
Mechanisms = new List<string>(await bootstrap.Mechanisms().ConfigureAwait(false)),
|
||||||
|
ServerName = (await bootstrap.GetServerRelease().ConfigureAwait(false)).Item1,
|
||||||
|
ServerRelease = (await bootstrap.GetServerRelease().ConfigureAwait(false)).Item2,
|
||||||
|
};
|
||||||
|
|
||||||
|
return connectionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Authenticate connection with ConnectionData
|
/// Authenticate connection with ConnectionData
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="UnsupportedMechanismException"></exception>
|
/// <exception cref="UnsupportedMechanismException"></exception>
|
||||||
/// <exception cref="InvalidCredentialsException"></exception>
|
/// <exception cref="InvalidCredentialsException"></exception>
|
||||||
/// <exception cref="AuthenticationFailedException"></exception>
|
/// <exception cref="AuthenticationFailedException"></exception>
|
||||||
private async Task _Authenticate(ConnectionData connectionData)
|
private async Task<Session> _Authenticate(ConnectionData connectionData)
|
||||||
{
|
{
|
||||||
Dictionary<string, object> joinedProperties = new Dictionary<string, object>();
|
Dictionary<string, object> joinedProperties = new Dictionary<string, object>();
|
||||||
foreach(KeyValuePair<string, object> keyValuePair in connectionData.Properties)
|
foreach(KeyValuePair<string, object> keyValuePair in connectionData.Properties)
|
||||||
@ -181,7 +246,72 @@ namespace FabAccessAPI
|
|||||||
joinedProperties.Add(keyValuePair.Key, keyValuePair.Value);
|
joinedProperties.Add(keyValuePair.Key, keyValuePair.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _APIConnection.Auth(MechanismString.ToString(connectionData.Mechanism), joinedProperties).ConfigureAwait(false);
|
IAuthentication? authentication = await _Bootstrap.CreateSession(MechanismString.ToString(connectionData.Mechanism)).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return await _SASLAuthenticate(authentication, MechanismString.ToString(connectionData.Mechanism), joinedProperties).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Authenticate Connection to get Session
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="BadMechanismException"></exception>
|
||||||
|
/// <exception cref="InvalidCredentialsException"></exception>
|
||||||
|
/// <exception cref="AuthenticationFailedException"></exception>
|
||||||
|
public async Task<Session> _SASLAuthenticate(IAuthentication authentication, string mech, Dictionary<string, object> properties)
|
||||||
|
{
|
||||||
|
SaslMechanism? saslMechanism = SaslFactory.Create(mech);
|
||||||
|
foreach (KeyValuePair<string, object> entry in properties)
|
||||||
|
{
|
||||||
|
saslMechanism.Properties.Add(entry.Key, entry.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[0];
|
||||||
|
|
||||||
|
if (saslMechanism.HasInitial)
|
||||||
|
{
|
||||||
|
data = saslMechanism.GetResponse(new byte[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response? response = await authentication.Step(data);
|
||||||
|
while (!saslMechanism.IsCompleted)
|
||||||
|
{
|
||||||
|
if(response.Failed != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(response.Challenge != null)
|
||||||
|
{
|
||||||
|
byte[]? additional = saslMechanism.GetResponse(response.Challenge.ToArray());
|
||||||
|
response = await authentication.Step(additional);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AuthenticationFailedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Successful != null)
|
||||||
|
{
|
||||||
|
return response.Successful.Session;
|
||||||
|
}
|
||||||
|
else if (response.Failed != null)
|
||||||
|
{
|
||||||
|
switch (response.Failed.Code)
|
||||||
|
{
|
||||||
|
case Response.Error.badMechanism:
|
||||||
|
throw new BadMechanismException();
|
||||||
|
case Response.Error.invalidCredentials:
|
||||||
|
throw new InvalidCredentialsException();
|
||||||
|
case Response.Error.aborted:
|
||||||
|
case Response.Error.failed:
|
||||||
|
default:
|
||||||
|
throw new AuthenticationFailedException(response.Failed.AdditionalData.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AuthenticationFailedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
using FabAccessAPI.Schema;
|
|
||||||
using S22.Sasl;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using FabAccessAPI.Exceptions;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace FabAccessAPI
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Authenticate with SASL
|
|
||||||
/// </summary>
|
|
||||||
public class Auth
|
|
||||||
{
|
|
||||||
#region Private Fields
|
|
||||||
private readonly IAuthentication _AuthCap;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
public Auth(IAuthentication authCap)
|
|
||||||
{
|
|
||||||
_AuthCap = authCap;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
/// <summary>
|
|
||||||
/// Authenticate Connection to get Session
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="BadMechanismException"></exception>
|
|
||||||
/// <exception cref="InvalidCredentialsException"></exception>
|
|
||||||
/// <exception cref="AuthenticationFailedException"></exception>
|
|
||||||
public async Task<Session> Authenticate(string mech, Dictionary<string, object> properties)
|
|
||||||
{
|
|
||||||
SaslMechanism? saslMechanism = SaslFactory.Create(mech);
|
|
||||||
foreach (KeyValuePair<string, object> entry in properties)
|
|
||||||
{
|
|
||||||
saslMechanism.Properties.Add(entry.Key, entry.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] data = new byte[0];
|
|
||||||
|
|
||||||
if (saslMechanism.HasInitial)
|
|
||||||
{
|
|
||||||
data = saslMechanism.GetResponse(new byte[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Response? response = await _AuthCap.Step(data);
|
|
||||||
while (!saslMechanism.IsCompleted)
|
|
||||||
{
|
|
||||||
if(response.Failed != null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(response.Challenge != null)
|
|
||||||
{
|
|
||||||
byte[]? additional = saslMechanism.GetResponse(response.Challenge.ToArray());
|
|
||||||
response = await _AuthCap.Step(additional);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AuthenticationFailedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.Successful != null)
|
|
||||||
{
|
|
||||||
return response.Successful.Session;
|
|
||||||
}
|
|
||||||
else if (response.Failed != null)
|
|
||||||
{
|
|
||||||
switch (response.Failed.Code)
|
|
||||||
{
|
|
||||||
case Response.Error.badMechanism:
|
|
||||||
throw new BadMechanismException();
|
|
||||||
case Response.Error.invalidCredentials:
|
|
||||||
throw new InvalidCredentialsException();
|
|
||||||
case Response.Error.aborted:
|
|
||||||
case Response.Error.failed:
|
|
||||||
default:
|
|
||||||
throw new AuthenticationFailedException(response.Failed.AdditionalData.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AuthenticationFailedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
using Capnp.Rpc;
|
|
||||||
using FabAccessAPI.Exceptions;
|
|
||||||
using FabAccessAPI.Schema;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace FabAccessAPI
|
|
||||||
{
|
|
||||||
public class Connection
|
|
||||||
{
|
|
||||||
#region Private Fields
|
|
||||||
private readonly IBootstrap? _BootstrapCap = null;
|
|
||||||
private Auth? _Auth = null;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="rpcClient">Should be an already configured and connected TcpRpcClient</param>
|
|
||||||
public Connection(TcpRpcClient rpcClient)
|
|
||||||
{
|
|
||||||
RpcClient = rpcClient;
|
|
||||||
_BootstrapCap = RpcClient.GetMain<IBootstrap>();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Fields
|
|
||||||
public TcpRpcClient? RpcClient { get; } = null;
|
|
||||||
|
|
||||||
public Session? Session { get; private set; } = null;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
/// <summary>
|
|
||||||
/// Authenticate this connection.
|
|
||||||
/// Calling this more then once is UB
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mech">The desired authentication mechanism</param>
|
|
||||||
/// <param name="kvs">Key-Value data specific to the mechanism</param>
|
|
||||||
/// <exception cref="UnsupportedMechanismException"></exception>
|
|
||||||
/// <exception cref="InvalidCredentialsException"></exception>
|
|
||||||
/// <exception cref="AuthenticationFailedException"></exception>
|
|
||||||
public async Task Auth(string mech, Dictionary<string, object> kvs, CancellationToken cancellationToken_ = default)
|
|
||||||
{
|
|
||||||
IReadOnlyList<string>? mechs = await _BootstrapCap.Mechanisms();
|
|
||||||
if (!mechs.Contains(mech))
|
|
||||||
{
|
|
||||||
throw new UnsupportedMechanismException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_Auth == null)
|
|
||||||
{
|
|
||||||
IAuthentication? authCap = await _BootstrapCap.CreateSession(mech, cancellationToken_).ConfigureAwait(false);
|
|
||||||
_Auth = new Auth(authCap);
|
|
||||||
}
|
|
||||||
|
|
||||||
Session = await _Auth.Authenticate(mech, kvs);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ namespace FabAccessAPI
|
|||||||
{
|
{
|
||||||
public class ConnectionInfo
|
public class ConnectionInfo
|
||||||
{
|
{
|
||||||
public Version APIVersion;
|
public Schema.Version APIVersion;
|
||||||
public string ServerName;
|
public string ServerName;
|
||||||
public string ServerRelease;
|
public string ServerRelease;
|
||||||
public List<string> Mechanisms;
|
public List<string> Mechanisms;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FabAccessAPI.Schema;
|
using Capnp.Rpc;
|
||||||
|
using FabAccessAPI.Schema;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ namespace FabAccessAPI
|
|||||||
/// Connect to BFFH Server
|
/// Connect to BFFH Server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionData"></param>
|
/// <param name="connectionData"></param>
|
||||||
Task Connect(ConnectionData connectionData);
|
Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect from BFFH Server
|
/// Disconnect from BFFH Server
|
||||||
@ -52,6 +53,6 @@ namespace FabAccessAPI
|
|||||||
/// Connect to Server and get ConnectionInfo.
|
/// Connect to Server and get ConnectionInfo.
|
||||||
/// The Connection is not maintained.
|
/// The Connection is not maintained.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ConnectionInfo TestConnection(ConnectionData connectionData);
|
Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,17 @@
|
|||||||
|
|
||||||
|
using Capnp.Rpc;
|
||||||
using FabAccessAPI;
|
using FabAccessAPI;
|
||||||
using FabAccessAPI.Exceptions;
|
using FabAccessAPI.Exceptions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FabAccessAPI_Test
|
namespace FabAccessAPI_Test
|
||||||
{
|
{
|
||||||
public class API_Test
|
public class API_Test
|
||||||
{
|
{
|
||||||
[TestCase("Admin1")]
|
|
||||||
public async Task ConnectDisconnect(string username)
|
|
||||||
{
|
|
||||||
API api = new API();
|
|
||||||
|
|
||||||
ConnectionData connectionData = new ConnectionData()
|
|
||||||
{
|
|
||||||
Host = new UriBuilder(TestEnv.SCHEMA, TestEnv.TESTSERVER, TestEnv.TESTSERVER_PORT).Uri,
|
|
||||||
Mechanism = Mechanism.PLAIN,
|
|
||||||
Username = username,
|
|
||||||
Properties = new Dictionary<string, object>()
|
|
||||||
{
|
|
||||||
{ "Username", username }
|
|
||||||
},
|
|
||||||
SecretProperties = new Dictionary<string, object>()
|
|
||||||
{
|
|
||||||
{ "Password", TestEnv.PASSWORD }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await api.Connect(connectionData);
|
|
||||||
await api.Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Connect_HostUnreachable()
|
public async Task Connect_HostUnreachable()
|
||||||
{
|
{
|
||||||
@ -41,12 +19,12 @@ namespace FabAccessAPI_Test
|
|||||||
|
|
||||||
ConnectionData connectionData = new ConnectionData()
|
ConnectionData connectionData = new ConnectionData()
|
||||||
{
|
{
|
||||||
Host = new UriBuilder(TestEnv.SCHEMA, "NotReachable." + TestEnv.TESTSERVER, TestEnv.TESTSERVER_PORT).Uri,
|
Host = new UriBuilder(TestEnv.SCHEMA, "UnkownHost" + TestEnv.TESTSERVER, TestEnv.TESTSERVER_PORT).Uri,
|
||||||
Mechanism = Mechanism.PLAIN,
|
Mechanism = Mechanism.PLAIN,
|
||||||
Username = "UnknownUser",
|
Username = "UnkownUser",
|
||||||
Properties = new Dictionary<string, object>()
|
Properties = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
{ "Username", "UnknownUser" }
|
{ "Username", "UnkownUser" }
|
||||||
},
|
},
|
||||||
SecretProperties = new Dictionary<string, object>()
|
SecretProperties = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
@ -70,20 +48,7 @@ namespace FabAccessAPI_Test
|
|||||||
{
|
{
|
||||||
API api = new API();
|
API api = new API();
|
||||||
|
|
||||||
ConnectionData connectionData = new ConnectionData()
|
ConnectionData connectionData = TestEnv.CreateConnetionData("UnkownUser");
|
||||||
{
|
|
||||||
Host = new UriBuilder(TestEnv.SCHEMA, TestEnv.TESTSERVER, TestEnv.TESTSERVER_PORT).Uri,
|
|
||||||
Mechanism = Mechanism.PLAIN,
|
|
||||||
Username = "UnknownUser",
|
|
||||||
Properties = new Dictionary<string, object>()
|
|
||||||
{
|
|
||||||
{ "Username", "UnknownUser" }
|
|
||||||
},
|
|
||||||
SecretProperties = new Dictionary<string, object>()
|
|
||||||
{
|
|
||||||
{ "Password", TestEnv.PASSWORD }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -95,5 +60,124 @@ namespace FabAccessAPI_Test
|
|||||||
}
|
}
|
||||||
Assert.Fail();
|
Assert.Fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1")]
|
||||||
|
public async Task ConnectDisconnect(string username)
|
||||||
|
{
|
||||||
|
API api = new API();
|
||||||
|
|
||||||
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
|
||||||
|
bool event_Connected = false;
|
||||||
|
bool event_Disconnected = false;
|
||||||
|
api.ConnectionStatusChanged += (sender, eventArgs) =>
|
||||||
|
{
|
||||||
|
if (eventArgs == ConnectionStatusChange.Connected)
|
||||||
|
{
|
||||||
|
event_Connected = true;
|
||||||
|
}
|
||||||
|
if(eventArgs == ConnectionStatusChange.Disconnected)
|
||||||
|
{
|
||||||
|
event_Disconnected = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
|
bool HasSesion = api.Session != null;
|
||||||
|
bool HasConnectionData = api.ConnectionData != null;
|
||||||
|
bool HasConnectionInfo = api.ConnectionInfo != null;
|
||||||
|
bool IsConnected = api.IsConnected;
|
||||||
|
|
||||||
|
await api.Disconnect();
|
||||||
|
|
||||||
|
Thread.Sleep(3000);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.IsTrue(event_Connected, "event_Connected");
|
||||||
|
Assert.IsTrue(event_Disconnected, "event_Disconnected");
|
||||||
|
|
||||||
|
Assert.IsTrue(HasSesion, "HasSesion");
|
||||||
|
Assert.IsTrue(HasConnectionData, "HasConnectionData");
|
||||||
|
Assert.IsTrue(HasConnectionInfo, "HasConnectionInfo");
|
||||||
|
Assert.IsTrue(IsConnected, "IsConnected");
|
||||||
|
|
||||||
|
Assert.IsFalse(api.IsConnected, "api.IsConnected");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1")]
|
||||||
|
public async Task TestConnectíon(string username)
|
||||||
|
{
|
||||||
|
API api = new API();
|
||||||
|
|
||||||
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
|
||||||
|
ConnectionInfo connectionInfo = await api.TestConnection(connectionData);
|
||||||
|
|
||||||
|
Assert.IsNotNull(connectionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1"), Explicit]
|
||||||
|
public async Task Reconnect(string username)
|
||||||
|
{
|
||||||
|
API api = new API();
|
||||||
|
|
||||||
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
|
||||||
|
bool event_Connected = false;
|
||||||
|
bool event_ConnectionLoss = false;
|
||||||
|
bool event_Reconnect = false;
|
||||||
|
bool event_Disconnected = false;
|
||||||
|
|
||||||
|
api.ConnectionStatusChanged += (sender, eventArgs) =>
|
||||||
|
{
|
||||||
|
if (eventArgs == ConnectionStatusChange.Connected)
|
||||||
|
{
|
||||||
|
event_Connected = true;
|
||||||
|
}
|
||||||
|
if (eventArgs == ConnectionStatusChange.ConnectionLoss)
|
||||||
|
{
|
||||||
|
event_ConnectionLoss = true;
|
||||||
|
}
|
||||||
|
if (eventArgs == ConnectionStatusChange.Reconnected)
|
||||||
|
{
|
||||||
|
event_Reconnect = true;
|
||||||
|
}
|
||||||
|
if (eventArgs == ConnectionStatusChange.Disconnected)
|
||||||
|
{
|
||||||
|
event_Disconnected = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
||||||
|
await api.Connect(connectionData, tcpRpcClient);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Stop here and cut internet connection
|
||||||
|
await api.Session.MachineSystem.Info.GetMachineList().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Thread.Sleep(3000);
|
||||||
|
|
||||||
|
// Stop here and connect with internet again
|
||||||
|
await api.Reconnect();
|
||||||
|
await api.Disconnect();
|
||||||
|
|
||||||
|
Thread.Sleep(3000);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.IsTrue(event_Connected, "event_Connected");
|
||||||
|
Assert.IsTrue(event_ConnectionLoss, "event_ConnectionLoss");
|
||||||
|
Assert.IsTrue(event_Reconnect, "event_Reconnect");
|
||||||
|
Assert.IsTrue(event_Disconnected, "event_Disconnected");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,50 +12,6 @@ using static FabAccessAPI.Schema.Machine;
|
|||||||
|
|
||||||
namespace FabAccessAPI_Test
|
namespace FabAccessAPI_Test
|
||||||
{
|
{
|
||||||
public static class API_TestEnv_Test
|
|
||||||
{
|
|
||||||
public const string TESTSERVER = "bffh.lab.bln.kjknet.de";
|
|
||||||
public const int TESTSERVER_PORT = 59666;
|
|
||||||
public const string PASSWORD = "secret";
|
|
||||||
|
|
||||||
public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<Connection> Connect(string username)
|
|
||||||
{
|
|
||||||
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
|
||||||
tcpRpcClient.InjectMidlayer((tcpstream) =>
|
|
||||||
{
|
|
||||||
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sslStream.AuthenticateAsClient("bffhd");
|
|
||||||
return sslStream;
|
|
||||||
}
|
|
||||||
catch (AuthenticationException)
|
|
||||||
{
|
|
||||||
sslStream.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tcpRpcClient.Connect(TESTSERVER, TESTSERVER_PORT);
|
|
||||||
await tcpRpcClient.WhenConnected;
|
|
||||||
|
|
||||||
Connection connection = new Connection(tcpRpcClient);
|
|
||||||
await connection.Auth("PLAIN", new Dictionary<string, object>(StringComparer.Ordinal) { { "Username", username }, { "Password", PASSWORD } });
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Disconnect(Connection connection)
|
|
||||||
{
|
|
||||||
connection.RpcClient.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestFixture, Parallelizable(ParallelScope.Children)]
|
[TestFixture, Parallelizable(ParallelScope.Children)]
|
||||||
[Order(1)]
|
[Order(1)]
|
||||||
public class MachineSystem_Test
|
public class MachineSystem_Test
|
||||||
@ -92,10 +48,11 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(2)]
|
[Order(2)]
|
||||||
public async Task AccessMachineSystem_Info(string username, bool expectAllow)
|
public async Task AccessMachineSystem_Info(string username, bool expectAllow)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Assert.AreEqual(expectAllow, !((MachineSystem.InfoInterface_Proxy)session.MachineSystem.Info).IsNull);
|
Assert.AreEqual(expectAllow, !((MachineSystem.InfoInterface_Proxy)api.Session.MachineSystem.Info).IsNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("Admin1", 15)]
|
[TestCase("Admin1", 15)]
|
||||||
@ -117,14 +74,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(3)]
|
[Order(3)]
|
||||||
public async Task ListMachines(string username, int expectedMachineCount)
|
public async Task ListMachines(string username, int expectedMachineCount)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
IReadOnlyList<Machine> machine_list = await session.MachineSystem.Info.GetMachineList().ConfigureAwait(false);
|
IReadOnlyList<Machine> machine_list = await api.Session.MachineSystem.Info.GetMachineList().ConfigureAwait(false);
|
||||||
|
|
||||||
int result = machine_list.Count;
|
int result = machine_list.Count;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectedMachineCount, result);
|
Assert.AreEqual(expectedMachineCount, result);
|
||||||
}
|
}
|
||||||
@ -156,14 +114,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4)]
|
[Order(4)]
|
||||||
public async Task GetMachineByName(string username, string machineName, bool expectedAllow)
|
public async Task GetMachineByName(string username, string machineName, bool expectedAllow)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Optional<Machine> optional = await session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false);
|
Optional<Machine> optional = await api.Session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false);
|
||||||
|
|
||||||
bool result = optional.Just != null;
|
bool result = optional.Just != null;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectedAllow, result);
|
Assert.AreEqual(expectedAllow, result);
|
||||||
}
|
}
|
||||||
@ -173,12 +132,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(5)]
|
[Order(5)]
|
||||||
public async Task GetMachineByName_WrongName(string username, string machineName)
|
public async Task GetMachineByName_WrongName(string username, string machineName)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Optional<Machine> optional = await session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false);
|
Optional<Machine> optional = await api.Session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.IsNull(optional.Just);
|
Assert.IsNull(optional.Just);
|
||||||
}
|
}
|
||||||
@ -211,13 +171,14 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(6)]
|
[Order(6)]
|
||||||
public async Task GetMachineByURN(string username, string urn, bool expectedAllow)
|
public async Task GetMachineByURN(string username, string urn, bool expectedAllow)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Optional<Machine> optional = await session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false);
|
Optional<Machine> optional = await api.Session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false);
|
||||||
bool result = optional.Just != null;
|
bool result = optional.Just != null;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectedAllow, result);
|
Assert.AreEqual(expectedAllow, result);
|
||||||
}
|
}
|
||||||
@ -228,12 +189,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(7)]
|
[Order(7)]
|
||||||
public async Task GetMachineByURN_WrongURN(string username, string urn)
|
public async Task GetMachineByURN_WrongURN(string username, string urn)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Optional<Machine> optional = await session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false);
|
Optional<Machine> optional = await api.Session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.IsNull(optional.Just);
|
Assert.IsNull(optional.Just);
|
||||||
}
|
}
|
||||||
@ -264,14 +226,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(1)]
|
[Order(1)]
|
||||||
public async Task InfoInterface(string username, string machineID, bool expectInterface)
|
public async Task InfoInterface(string username, string machineID, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
bool result = !((Machine.InfoInterface_Proxy)machine.Info).IsNull;
|
bool result = !((Machine.InfoInterface_Proxy)machine.Info).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -297,14 +260,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(2)]
|
[Order(2)]
|
||||||
public async Task ManageInterface(string username, string machineID, bool expectInterface)
|
public async Task ManageInterface(string username, string machineID, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
bool result = !((ManageInterface_Proxy)machine.Manage).IsNull;
|
bool result = !((ManageInterface_Proxy)machine.Manage).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -330,14 +294,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(3), Ignore("Not Implemented")]
|
[Order(3), Ignore("Not Implemented")]
|
||||||
public async Task AdminInterface(string username, string machineID, bool expectInterface)
|
public async Task AdminInterface(string username, string machineID, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
bool result = !((AdminInterface_Proxy)machine.Admin).IsNull;
|
bool result = !((AdminInterface_Proxy)machine.Admin).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -348,12 +313,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4)]
|
[Order(4)]
|
||||||
public async Task ReadMachineData(string username, string machineID, string description, string wiki, string category)
|
public async Task ReadMachineData(string username, string machineID, string description, string wiki, string category)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
@ -373,10 +339,11 @@ namespace FabAccessAPI_Test
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public async Task SetUp()
|
public async Task SetUp()
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect("Admin1");
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData("Admin1");
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
IReadOnlyList<Machine> machine_list = await session.MachineSystem.Info.GetMachineList().ConfigureAwait(false);
|
IReadOnlyList<Machine> machine_list = await api.Session.MachineSystem.Info.GetMachineList().ConfigureAwait(false);
|
||||||
|
|
||||||
List<Task> tasks = new List<Task>();
|
List<Task> tasks = new List<Task>();
|
||||||
foreach(Machine m in machine_list)
|
foreach(Machine m in machine_list)
|
||||||
@ -394,26 +361,27 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(1)]
|
[Order(1)]
|
||||||
public async Task UseGiveBack(string username, string machineID)
|
public async Task UseGiveBack(string username, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine.State != MachineState.free)
|
if (machine.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine.Use.Use().ConfigureAwait(false);
|
await machine.Use.Use().ConfigureAwait(false);
|
||||||
|
|
||||||
machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine.Inuse.GiveBack().ConfigureAwait(false);
|
await machine.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(MachineState.free, machine.State);
|
Assert.AreEqual(MachineState.free, machine.State);
|
||||||
}
|
}
|
||||||
@ -424,36 +392,38 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(2), Ignore("Not Implemented")]
|
[Order(2), Ignore("Not Implemented")]
|
||||||
public async Task TransferMachine(string username1, string username2, string machineID)
|
public async Task TransferMachine(string username1, string username2, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection1 = await API_TestEnv_Test.Connect(username1);
|
API api1 = new API();
|
||||||
Session session1 = connection1.Session;
|
ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1);
|
||||||
|
await api1.Connect(connectionData1);
|
||||||
|
|
||||||
Connection connection2 = await API_TestEnv_Test.Connect(username2);
|
API api2 = new API();
|
||||||
Session session2 = connection1.Session;
|
ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2);
|
||||||
|
await api2.Connect(connectionData2);
|
||||||
|
|
||||||
Machine machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine1.State != MachineState.free)
|
if (machine1.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine1.Use.Use().ConfigureAwait(false);
|
await machine1.Use.Use().ConfigureAwait(false);
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.Releasefortakeover().ConfigureAwait(false);
|
await machine1.Inuse.Releasefortakeover().ConfigureAwait(false);
|
||||||
|
|
||||||
Machine machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Takeover.Accept().ConfigureAwait(false);
|
await machine2.Takeover.Accept().ConfigureAwait(false);
|
||||||
|
|
||||||
machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Inuse.GiveBack().ConfigureAwait(false);
|
await machine2.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(MachineState.free, machine1.State);
|
Assert.AreEqual(MachineState.free, machine1.State);
|
||||||
}
|
}
|
||||||
@ -464,36 +434,38 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(3), Ignore("Not Implemented")]
|
[Order(3), Ignore("Not Implemented")]
|
||||||
public async Task TransferMachine_Reject(string username1, string username2, string machineID)
|
public async Task TransferMachine_Reject(string username1, string username2, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection1 = await API_TestEnv_Test.Connect(username1);
|
API api1 = new API();
|
||||||
Session session1 = connection1.Session;
|
ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1);
|
||||||
|
await api1.Connect(connectionData1);
|
||||||
|
|
||||||
Connection connection2 = await API_TestEnv_Test.Connect(username2);
|
API api2 = new API();
|
||||||
Session session2 = connection1.Session;
|
ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2);
|
||||||
|
await api2.Connect(connectionData2);
|
||||||
|
|
||||||
Machine machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine1.State != MachineState.free)
|
if (machine1.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine1.Use.Use().ConfigureAwait(false);
|
await machine1.Use.Use().ConfigureAwait(false);
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.Releasefortakeover().ConfigureAwait(false);
|
await machine1.Inuse.Releasefortakeover().ConfigureAwait(false);
|
||||||
|
|
||||||
Machine machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Takeover.Reject().ConfigureAwait(false);
|
await machine2.Takeover.Reject().ConfigureAwait(false);
|
||||||
|
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
machine2 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine2 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(MachineState.free, machine2.State);
|
Assert.AreEqual(MachineState.free, machine2.State);
|
||||||
}
|
}
|
||||||
@ -504,33 +476,35 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4), Ignore("Not Implemented")]
|
[Order(4), Ignore("Not Implemented")]
|
||||||
public async Task CheckMachine(string username1, string username2, string machineID)
|
public async Task CheckMachine(string username1, string username2, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection1 = await API_TestEnv_Test.Connect(username1);
|
API api1 = new API();
|
||||||
Session session1 = connection1.Session;
|
ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1);
|
||||||
|
await api1.Connect(connectionData1);
|
||||||
|
|
||||||
Connection connection2 = await API_TestEnv_Test.Connect(username2);
|
API api2 = new API();
|
||||||
Session session2 = connection1.Session;
|
ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2);
|
||||||
|
await api2.Connect(connectionData2);
|
||||||
|
|
||||||
Machine machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine1.State != MachineState.free)
|
if (machine1.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine1.Use.Use().ConfigureAwait(false);
|
await machine1.Use.Use().ConfigureAwait(false);
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
Machine machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Check.Check().ConfigureAwait(false);
|
await machine2.Check.Check().ConfigureAwait(false);
|
||||||
|
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(MachineState.free, machine1.State);
|
Assert.AreEqual(MachineState.free, machine1.State);
|
||||||
}
|
}
|
||||||
@ -541,40 +515,42 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(5), Ignore("Not Implemented")]
|
[Order(5), Ignore("Not Implemented")]
|
||||||
public async Task CheckMachine_Reject(string username1, string username2, string machineID)
|
public async Task CheckMachine_Reject(string username1, string username2, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection1 = await API_TestEnv_Test.Connect(username1);
|
API api1 = new API();
|
||||||
Session session1 = connection1.Session;
|
ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1);
|
||||||
|
await api1.Connect(connectionData1);
|
||||||
|
|
||||||
Connection connection2 = await API_TestEnv_Test.Connect(username2);
|
API api2 = new API();
|
||||||
Session session2 = connection1.Session;
|
ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2);
|
||||||
|
await api2.Connect(connectionData2);
|
||||||
|
|
||||||
|
|
||||||
Machine machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine1.State != MachineState.free)
|
if (machine1.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine1.Use.Use().ConfigureAwait(false);
|
await machine1.Use.Use().ConfigureAwait(false);
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
Machine machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Check.Reject().ConfigureAwait(false);
|
await machine2.Check.Reject().ConfigureAwait(false);
|
||||||
|
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine2.Check.Check().ConfigureAwait(false);
|
await machine2.Check.Check().ConfigureAwait(false);
|
||||||
|
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(MachineState.free, machine1.State);
|
Assert.AreEqual(MachineState.free, machine1.State);
|
||||||
}
|
}
|
||||||
@ -583,37 +559,42 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4), Ignore("Not Implemented")]
|
[Order(4), Ignore("Not Implemented")]
|
||||||
public async Task CheckMachine_NoPermission(string username1, string username2, string username3, string machineID)
|
public async Task CheckMachine_NoPermission(string username1, string username2, string username3, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection1 = await API_TestEnv_Test.Connect(username1);
|
API api1 = new API();
|
||||||
Session session1 = connection1.Session;
|
ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1);
|
||||||
|
await api1.Connect(connectionData1);
|
||||||
|
|
||||||
Connection connection2 = await API_TestEnv_Test.Connect(username2);
|
API api2 = new API();
|
||||||
Session session2 = connection1.Session;
|
ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2);
|
||||||
|
await api2.Connect(connectionData2);
|
||||||
|
|
||||||
Connection connection3 = await API_TestEnv_Test.Connect(username3);
|
API api3 = new API();
|
||||||
Session session3 = connection3.Session;
|
ConnectionData connectionData3 = TestEnv.CreateConnetionData(username3);
|
||||||
|
await api3.Connect(connectionData3);
|
||||||
|
|
||||||
Machine machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine1.State != MachineState.free)
|
if (machine1.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
await api3.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
await machine1.Use.Use().ConfigureAwait(false);
|
await machine1.Use.Use().ConfigureAwait(false);
|
||||||
machine1 = (await session1.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
await machine1.Inuse.GiveBack().ConfigureAwait(false);
|
||||||
|
|
||||||
Machine machine2 = (await session2.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
bool result = ((CheckInterface_Proxy)machine2.Check).IsNull;
|
bool result = ((CheckInterface_Proxy)machine2.Check).IsNull;
|
||||||
|
|
||||||
Machine machine3 = (await session3.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine3 = (await api3.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
await machine3.Check.Check().ConfigureAwait(false);
|
await machine3.Check.Check().ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection1);
|
await api1.Disconnect();
|
||||||
API_TestEnv_Test.Disconnect(connection2);
|
await api2.Disconnect();
|
||||||
|
await api3.Disconnect();
|
||||||
|
|
||||||
Assert.IsTrue(result);
|
Assert.IsTrue(result);
|
||||||
}
|
}
|
||||||
@ -622,21 +603,22 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(5)]
|
[Order(5)]
|
||||||
public async Task CurrentUser(string username, string machineID)
|
public async Task CurrentUser(string username, string machineID)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
Machine machine = (await session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just;
|
||||||
|
|
||||||
// Check State before run Test
|
// Check State before run Test
|
||||||
if (machine.State != MachineState.free)
|
if (machine.State != MachineState.free)
|
||||||
{
|
{
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
Assert.Inconclusive("State is not 'free'");
|
Assert.Inconclusive("State is not 'free'");
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineInfoExtended machineInfoExtended = await machine.Manage.GetMachineInfoExtended().ConfigureAwait(false);
|
MachineInfoExtended machineInfoExtended = await machine.Manage.GetMachineInfoExtended().ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.IsNull(machineInfoExtended.CurrentUser.Just);
|
Assert.IsNull(machineInfoExtended.CurrentUser.Just);
|
||||||
}
|
}
|
||||||
@ -653,12 +635,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(1)]
|
[Order(1)]
|
||||||
public async Task AccessPermissionSystem(string username, bool expectInterface)
|
public async Task AccessPermissionSystem(string username, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
bool result = session.PermissionSystem != null;
|
bool result = api.Session.PermissionSystem != null;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -689,12 +672,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(3), Ignore("Not Implemented")]
|
[Order(3), Ignore("Not Implemented")]
|
||||||
public async Task ListRoles(string username, int expectRolesCount)
|
public async Task ListRoles(string username, int expectRolesCount)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
IReadOnlyList<Role> roles_list = await session.PermissionSystem.Info.GetRoleList().ConfigureAwait(false);
|
IReadOnlyList<Role> roles_list = await api.Session.PermissionSystem.Info.GetRoleList().ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectRolesCount, roles_list.Count);
|
Assert.AreEqual(expectRolesCount, roles_list.Count);
|
||||||
}
|
}
|
||||||
@ -749,12 +733,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4)]
|
[Order(4)]
|
||||||
public async Task GetUserSelf(string username)
|
public async Task GetUserSelf(string username)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.IsNotNull(user);
|
Assert.IsNotNull(user);
|
||||||
}
|
}
|
||||||
@ -771,14 +756,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(1)]
|
[Order(1)]
|
||||||
public async Task InfoInterface(string username, bool expectInterface)
|
public async Task InfoInterface(string username, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
bool result = !((User.InfoInterface_Proxy)user.Info).IsNull;
|
bool result = !((User.InfoInterface_Proxy)user.Info).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -790,14 +776,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(2), Ignore("Not Implemented")]
|
[Order(2), Ignore("Not Implemented")]
|
||||||
public async Task ManageInterface(string username, bool expectInterface)
|
public async Task ManageInterface(string username, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
bool result = !((User.ManageInterface_Proxy)user.Manage).IsNull;
|
bool result = !((User.ManageInterface_Proxy)user.Manage).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -809,14 +796,15 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(3), Ignore("Not Implemented")]
|
[Order(3), Ignore("Not Implemented")]
|
||||||
public async Task AdminInterface(string username, bool expectInterface)
|
public async Task AdminInterface(string username, bool expectInterface)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
bool result = !((User.AdminInterface_Proxy)user.Admin).IsNull;
|
bool result = !((User.AdminInterface_Proxy)user.Admin).IsNull;
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
@ -828,12 +816,13 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(4)]
|
[Order(4)]
|
||||||
public async Task ReadUserData(string username)
|
public async Task ReadUserData(string username)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
@ -848,15 +837,16 @@ namespace FabAccessAPI_Test
|
|||||||
[Order(5), Ignore("Not Implemented")]
|
[Order(5), Ignore("Not Implemented")]
|
||||||
public async Task ListUserRoles(string username, params string[] expect_roles)
|
public async Task ListUserRoles(string username, params string[] expect_roles)
|
||||||
{
|
{
|
||||||
Connection connection = await API_TestEnv_Test.Connect(username);
|
API api = new API();
|
||||||
Session session = connection.Session;
|
ConnectionData connectionData = TestEnv.CreateConnetionData(username);
|
||||||
|
await api.Connect(connectionData);
|
||||||
|
|
||||||
User user = await session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false);
|
||||||
|
|
||||||
List<Role> roles_user = new List<Role>(await user.Info.ListRoles().ConfigureAwait(false));
|
List<Role> roles_user = new List<Role>(await user.Info.ListRoles().ConfigureAwait(false));
|
||||||
List<string> expect_roles_list = new List<string>(expect_roles);
|
List<string> expect_roles_list = new List<string>(expect_roles);
|
||||||
|
|
||||||
API_TestEnv_Test.Disconnect(connection);
|
await api.Disconnect();
|
||||||
|
|
||||||
if (roles_user.Count != expect_roles_list.Count)
|
if (roles_user.Count != expect_roles_list.Count)
|
||||||
{
|
{
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
using Capnp.Rpc;
|
|
||||||
using FabAccessAPI;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Security;
|
|
||||||
using System.Security.Authentication;
|
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace FabAccessAPI_Test
|
|
||||||
{
|
|
||||||
[TestFixture, Order(0)]
|
|
||||||
public class Connection_Test
|
|
||||||
{
|
|
||||||
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)]
|
|
||||||
public async Task Connect(string host, int port)
|
|
||||||
{
|
|
||||||
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
|
||||||
tcpRpcClient.InjectMidlayer((tcpstream) =>
|
|
||||||
{
|
|
||||||
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sslStream.AuthenticateAsClient("bffhd");
|
|
||||||
return sslStream;
|
|
||||||
}
|
|
||||||
catch (AuthenticationException)
|
|
||||||
{
|
|
||||||
sslStream.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
tcpRpcClient.Connect(host, port);
|
|
||||||
await tcpRpcClient.WhenConnected;
|
|
||||||
|
|
||||||
Connection connection = new Connection(tcpRpcClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase(TESTSERVER, TESTSERVER_PORT, "Admin1", "secret")]
|
|
||||||
public async Task Authenticate_PLAIN(string host, int port, string username, string password)
|
|
||||||
{
|
|
||||||
TcpRpcClient tcpRpcClient = new TcpRpcClient();
|
|
||||||
tcpRpcClient.InjectMidlayer((tcpstream) =>
|
|
||||||
{
|
|
||||||
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sslStream.AuthenticateAsClient("bffhd");
|
|
||||||
return sslStream;
|
|
||||||
}
|
|
||||||
catch (AuthenticationException)
|
|
||||||
{
|
|
||||||
sslStream.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,8 @@
|
|||||||
namespace FabAccessAPI_Test
|
using FabAccessAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace FabAccessAPI_Test
|
||||||
{
|
{
|
||||||
public static class TestEnv
|
public static class TestEnv
|
||||||
{
|
{
|
||||||
@ -6,5 +10,25 @@
|
|||||||
public const string TESTSERVER = "bffh.lab.bln.kjknet.de";
|
public const string TESTSERVER = "bffh.lab.bln.kjknet.de";
|
||||||
public const int TESTSERVER_PORT = 59666;
|
public const int TESTSERVER_PORT = 59666;
|
||||||
public const string PASSWORD = "secret";
|
public const string PASSWORD = "secret";
|
||||||
|
|
||||||
|
public static ConnectionData CreateConnetionData(string username)
|
||||||
|
{
|
||||||
|
ConnectionData connectionData = new ConnectionData()
|
||||||
|
{
|
||||||
|
Host = new UriBuilder(TestEnv.SCHEMA, TestEnv.TESTSERVER, TestEnv.TESTSERVER_PORT).Uri,
|
||||||
|
Mechanism = Mechanism.PLAIN,
|
||||||
|
Username = username,
|
||||||
|
Properties = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "Username", username }
|
||||||
|
},
|
||||||
|
SecretProperties = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "Password", TestEnv.PASSWORD }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return connectionData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user