mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
Added: User and Permission Test
This commit is contained in:
parent
8d7957f0f9
commit
8170f93d59
@ -342,45 +342,45 @@ namespace FabAccessAPI_Test
|
|||||||
Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[TestCase("Admin1", "MachineA1", true)]
|
[TestCase("Admin1", "MachineA1", true)]
|
||||||
//[TestCase("Admin1", "MachineB1", true)]
|
[TestCase("Admin1", "MachineB1", true)]
|
||||||
//[TestCase("Admin1", "MachineC1", true)]
|
[TestCase("Admin1", "MachineC1", true)]
|
||||||
//[TestCase("ManagerA1", "MachineA1", false)]
|
[TestCase("ManagerA1", "MachineA1", false)]
|
||||||
//[TestCase("ManagerA1", "MachineB1", false)]
|
[TestCase("ManagerA1", "MachineB1", false)]
|
||||||
//[TestCase("ManagerA1", "MachineC1", false)]
|
[TestCase("ManagerA1", "MachineC1", false)]
|
||||||
//[TestCase("ManagerB1", "MachineA1", false)]
|
[TestCase("ManagerB1", "MachineA1", false)]
|
||||||
//[TestCase("ManagerB1", "MachineB1", false)]
|
[TestCase("ManagerB1", "MachineB1", false)]
|
||||||
//[TestCase("ManagerB1", "MachineC1", false)]
|
[TestCase("ManagerB1", "MachineC1", false)]
|
||||||
//[TestCase("ManagerC1", "MachineA1", false)]
|
[TestCase("ManagerC1", "MachineA1", false)]
|
||||||
//[TestCase("ManagerC1", "MachineB1", false)]
|
[TestCase("ManagerC1", "MachineB1", false)]
|
||||||
//[TestCase("ManagerC1", "MachineC1", false)]
|
[TestCase("ManagerC1", "MachineC1", false)]
|
||||||
//[TestCase("ManagerABC1", "MachineA1", false)]
|
[TestCase("ManagerABC1", "MachineA1", false)]
|
||||||
//[TestCase("ManagerABC1", "MachineB1", false)]
|
[TestCase("ManagerABC1", "MachineB1", false)]
|
||||||
//[TestCase("ManagerABC1", "MachineC1", false)]
|
[TestCase("ManagerABC1", "MachineC1", false)]
|
||||||
//[TestCase("MakerA1", "MachineA1", false)]
|
[TestCase("MakerA1", "MachineA1", false)]
|
||||||
//[TestCase("MakerB1", "MachineB1", false)]
|
[TestCase("MakerB1", "MachineB1", false)]
|
||||||
//[TestCase("MakerC1", "MachineC1", false)]
|
[TestCase("MakerC1", "MachineC1", false)]
|
||||||
//[TestCase("GuestA1", "MachineA1", false)]
|
[TestCase("GuestA1", "MachineA1", false)]
|
||||||
//[TestCase("GuestB1", "MachineB1", false)]
|
[TestCase("GuestB1", "MachineB1", false)]
|
||||||
//[TestCase("GuestC1", "MachineC1", false)]
|
[TestCase("GuestC1", "MachineC1", false)]
|
||||||
//[TestCase("MakerQRA", "MachineA1", false)]
|
[TestCase("MakerQRA", "MachineA1", false)]
|
||||||
//[TestCase("MakerQRB", "MachineB1", false)]
|
[TestCase("MakerQRB", "MachineB1", false)]
|
||||||
//[TestCase("MakerQRC", "MachineC1", false)]
|
[TestCase("MakerQRC", "MachineC1", false)]
|
||||||
//[Order(3)]
|
[Order(3)]
|
||||||
//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);
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
// Session session = connection.Session;
|
Session session = connection.Session;
|
||||||
|
|
||||||
// MachineSystem.IInfoInterface infoInterface = await session.MachineSystem.Info().ConfigureAwait(false);
|
MachineSystem.IInfoInterface infoInterface = await session.MachineSystem.Info().ConfigureAwait(false);
|
||||||
// Machine machine = await infoInterface.GetMachine(machineID).ConfigureAwait(false);
|
Machine machine = await infoInterface.GetMachine(machineID).ConfigureAwait(false);
|
||||||
|
|
||||||
// bool result = !((AdminInterface_Proxy)machine.Admin).IsNull;
|
bool result = !((AdminInterface_Proxy)machine.Admin).IsNull;
|
||||||
|
|
||||||
// API_TestEnv_Test.Disconnect(connection);
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
// Assert.AreEqual(expectInterface, result);
|
Assert.AreEqual(expectInterface, result);
|
||||||
//}
|
}
|
||||||
|
|
||||||
[TestCase("Admin1", "MachineA1", "Description of MachineA1", @"https://fab-access.readthedocs.io", "CategoryA")]
|
[TestCase("Admin1", "MachineA1", "Description of MachineA1", @"https://fab-access.readthedocs.io", "CategoryA")]
|
||||||
[TestCase("Admin1", "MachineB2", "Description of MachineB2", @"https://fab-access.readthedocs.io", "CategoryB")]
|
[TestCase("Admin1", "MachineB2", "Description of MachineB2", @"https://fab-access.readthedocs.io", "CategoryB")]
|
||||||
@ -520,4 +520,267 @@ namespace FabAccessAPI_Test
|
|||||||
Assert.AreEqual(MachineState.free, machine.State);
|
Assert.AreEqual(MachineState.free, machine.State);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestFixture, Parallelizable(ParallelScope.Children)]
|
||||||
|
[Order(4)]
|
||||||
|
public class PermissionSystem_Test
|
||||||
|
{
|
||||||
|
[TestCase("Admin1", true)]
|
||||||
|
[TestCase("ManagerA1", true)]
|
||||||
|
[TestCase("MakerA1", true)]
|
||||||
|
[TestCase("GuestA1", true)]
|
||||||
|
[Order(1)]
|
||||||
|
public async Task AccessPermissionSystem(string username, bool expectInterface)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
bool result = !((PermissionSystem_Proxy)session.PermissionSystem).IsNull;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectInterface, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//[TestCase("Admin1", true)]
|
||||||
|
//[TestCase("ManagerA1", true)]
|
||||||
|
//[TestCase("MakerA1", true)]
|
||||||
|
//[TestCase("GuestA1", true)]
|
||||||
|
//[Order(2)]
|
||||||
|
//public async Task InfoInterface(string username, bool expectInterface)
|
||||||
|
//{
|
||||||
|
// Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
// Session session = connection.Session;
|
||||||
|
|
||||||
|
// MachineSystem.IInfoInterface infoInterface = await session.PermissionSystem.Info().ConfigureAwait(false);
|
||||||
|
|
||||||
|
// bool result = !((Machine.InfoInterface_Proxy)machine.Info).IsNull;
|
||||||
|
|
||||||
|
// API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
// Assert.AreEqual(expectInterface, result);
|
||||||
|
//}
|
||||||
|
|
||||||
|
[TestCase("Admin1", 13)]
|
||||||
|
[TestCase("ManagerA1", 13)]
|
||||||
|
[TestCase("MakerA1", 13)]
|
||||||
|
[TestCase("GuestA1", 13)]
|
||||||
|
[Order(3)]
|
||||||
|
public async Task ListRoles(string username, int expectRolesCount)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
PermissionSystem.IInfoInterface infoInterface = await session.PermissionSystem.Info().ConfigureAwait(false);
|
||||||
|
IReadOnlyList<Role> roles_list = await infoInterface.GetRoleList().ConfigureAwait(false);
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectRolesCount, roles_list.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestFixture, Parallelizable(ParallelScope.Children)]
|
||||||
|
[Order(5)]
|
||||||
|
public class UserSystem_Test
|
||||||
|
{
|
||||||
|
[TestCase("Admin1", true)]
|
||||||
|
[TestCase("ManagerA1", true)]
|
||||||
|
[TestCase("MakerA1", true)]
|
||||||
|
[TestCase("GuestA1", true)]
|
||||||
|
[Order(1)]
|
||||||
|
public async Task AccessUserSystem(string username, bool expectInterface)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
bool result = !((UserSystem_Proxy)session.UserSystem).IsNull;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectInterface, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//[TestCase("Admin1", true)]
|
||||||
|
//[TestCase("ManagerA1", true)]
|
||||||
|
//[TestCase("MakerA1", true)]
|
||||||
|
//[TestCase("GuestA1", true)]
|
||||||
|
//[Order(2)]
|
||||||
|
//public async Task InfoInterface(string username, bool expectInterface)
|
||||||
|
//{
|
||||||
|
// Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
// Session session = connection.Session;
|
||||||
|
|
||||||
|
// UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
|
||||||
|
// bool result = !((UserSystem.InfoInterface_Proxy)infoInterface.Info).IsNull;
|
||||||
|
|
||||||
|
// API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
// Assert.AreEqual(expectInterface, result);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//[TestCase("Admin1", true)]
|
||||||
|
//[TestCase("ManagerA1", false)]
|
||||||
|
//[TestCase("MakerA1", false)]
|
||||||
|
//[TestCase("GuestA1", false)]
|
||||||
|
//[Order(3)]
|
||||||
|
//public async Task ManageInterface(string username, bool expectInterface)
|
||||||
|
//{
|
||||||
|
// Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
// Session session = connection.Session;
|
||||||
|
|
||||||
|
// UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
|
||||||
|
// bool result = !((UserSystem.InfoInterface_Proxy)infoInterface.Info).IsNull;
|
||||||
|
|
||||||
|
// API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
// Assert.AreEqual(expectInterface, result);
|
||||||
|
//}
|
||||||
|
|
||||||
|
[TestCase("Admin1")]
|
||||||
|
[TestCase("ManagerA1")]
|
||||||
|
[TestCase("MakerA1")]
|
||||||
|
[TestCase("GuestA1")]
|
||||||
|
[Order(4)]
|
||||||
|
public async Task GetUserSelf(string username)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.IsNotNull(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestFixture, Parallelizable(ParallelScope.Children)]
|
||||||
|
[Order(6)]
|
||||||
|
public class User_Test_Stateless
|
||||||
|
{
|
||||||
|
[TestCase("Admin1", true)]
|
||||||
|
[TestCase("ManagerA1", true)]
|
||||||
|
[TestCase("MakerA1", true)]
|
||||||
|
[TestCase("GuestA1", true)]
|
||||||
|
[Order(1)]
|
||||||
|
public async Task InfoInterface(string username, bool expectInterface)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
bool result = !((User.InfoInterface_Proxy)user.Info).IsNull;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectInterface, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1", true)]
|
||||||
|
[TestCase("ManagerA1", true)]
|
||||||
|
[TestCase("MakerA1", true)]
|
||||||
|
[TestCase("GuestA1", true)]
|
||||||
|
[Order(2)]
|
||||||
|
public async Task ManageInterface(string username, bool expectInterface)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
bool result = !((User.ManageInterface_Proxy)user.Manage).IsNull;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectInterface, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1", true)]
|
||||||
|
[TestCase("ManagerA1", false)]
|
||||||
|
[TestCase("MakerA1", false)]
|
||||||
|
[TestCase("GuestA1", false)]
|
||||||
|
[Order(3)]
|
||||||
|
public async Task AdminInterface(string username, bool expectInterface)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
bool result = !((User.AdminInterface_Proxy)user.Admin).IsNull;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(expectInterface, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1")]
|
||||||
|
[TestCase("ManagerA1")]
|
||||||
|
[TestCase("MakerA1")]
|
||||||
|
[TestCase("GuestA1")]
|
||||||
|
[Order(4)]
|
||||||
|
public async Task ReadUserData(string username)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.AreEqual(username, user.Username);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Admin1", "somerole")]
|
||||||
|
[TestCase("ManagerA1")]
|
||||||
|
[TestCase("MakerA1")]
|
||||||
|
[TestCase("GuestA1")]
|
||||||
|
[Order(5)]
|
||||||
|
public async Task ListUserRoles(string username, params string[] expect_roles)
|
||||||
|
{
|
||||||
|
Connection connection = await API_TestEnv_Test.Connect(username);
|
||||||
|
Session session = connection.Session;
|
||||||
|
|
||||||
|
UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
|
||||||
|
User user = (await infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
|
List<Role> roles_user = new List<Role>(await user.Info.ListRoles().ConfigureAwait(false));
|
||||||
|
List<string> expect_roles_list = new List<string>(expect_roles);
|
||||||
|
|
||||||
|
API_TestEnv_Test.Disconnect(connection);
|
||||||
|
|
||||||
|
if (roles_user.Count != expect_roles_list.Count)
|
||||||
|
{
|
||||||
|
Assert.Fail("Roles Count is different");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Role role_user in roles_user)
|
||||||
|
{
|
||||||
|
if(!expect_roles_list.Exists(x => x == role_user.Name))
|
||||||
|
{
|
||||||
|
Assert.Fail("Roles are different");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
[Order(7)]
|
||||||
|
public class User_Test
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user