improved tests and error handling

This commit is contained in:
Kai Jan Kriegel
2020-12-21 13:44:29 +01:00
parent 1e84827c13
commit 7bb1d8d8a5
4 changed files with 45 additions and 18 deletions

View File

@ -98,6 +98,7 @@ namespace FabAccessAPI {
}
public class UnauthorizedException : Exception{}
public class UnsupportedMechanismException : Exception{}
/// <summary>
/// THIS IS VERY INCOMPLETE!

View File

@ -2,6 +2,7 @@
using FabAccessAPI.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FabAccessAPI {
@ -14,6 +15,8 @@ namespace FabAccessAPI {
private Machines? _machines = null;
#endregion
public TcpRpcClient? RpcClient => _rpcClient;
#region Log
private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
@ -40,9 +43,11 @@ namespace FabAccessAPI {
var authCap = await _bootstrapCap.Auth();
_auth = new Auth(authCap);
var mechs = await _auth.GetMechanisms().ConfigureAwait(false);
_Log.Debug($"The Server supports the following auth mechs: {mechs}");
_Log.Debug($"The Server supports the following auth mechs: {string.Join(", ", mechs)}");
// TODO: Check that the requested auth mech is actually available.
if (!mechs.Contains(mech)) {
throw new UnsupportedMechanismException();
}
await _auth.Authenticate(mech, kvs).ConfigureAwait(false);
}

View File

@ -5,6 +5,9 @@ using System.Linq;
using System.Threading.Tasks;
namespace FabAccessAPI {
public class MachineException : Exception { }
/// <summary>
/// Wraps a capability for accessing the Machines subsystem of BFFH
/// </summary>
@ -43,7 +46,7 @@ namespace FabAccessAPI {
var mach = (await _machinesCap.GetMachine(name).ConfigureAwait(false)).Item1;
if (mach == null) {
//TODO: Throw a more specific exception!
throw new Exception();
throw new MachineException();
}
return new Machine(mach);
}