- `TestBuilder`-Klasse erstellt, um die Einrichtung der Abhängigkeitsinjektion für Unit-Tests zu vereinfachen. - `TestBuilder` so konfiguriert, dass Dienstregistrierungen und Datenbankkontext enthalten sind. - `TestBuilder` in das Test-Framework integriert, um eine einfache Bereitstellung von Diensten und Controllern zu ermöglichen.
103 lines
3.5 KiB
C#
103 lines
3.5 KiB
C#
using DAL._Shared.SharedModels;
|
|
using DAL._Shared.SharedRepositories;
|
|
using HRD.LDAPService;
|
|
using HRD.LDAPService.JWT;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using StaffDBServer.SharedControllers;
|
|
using Xunit;
|
|
using XUnitWebApi.SharedConfig;
|
|
using XUnitWebApi.Test;
|
|
|
|
namespace XUnitWebApi.SharedLDAP
|
|
{
|
|
public class Shared_Test_LDAP : TestBuilder
|
|
{
|
|
[Theory]
|
|
[InlineData("user", "pwd")]
|
|
[InlineData("user2", "pwd")]
|
|
public async System.Threading.Tasks.Task Validate_Credentials_WebAppUser(string login, string passwort)
|
|
{
|
|
Shared_Test_Config.Init_Webapi_Context();
|
|
|
|
try
|
|
{
|
|
WebAppUser userFromClient = new WebAppUser(
|
|
login,
|
|
login,
|
|
"User",
|
|
login);
|
|
userFromClient.Password = passwort;
|
|
|
|
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository = Provider.GetRequiredService<WebAppEmployeeInfoRepository>();
|
|
WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == userFromClient.LoginName);
|
|
Assert.NotNull(webAppEmployeeInfo);
|
|
|
|
WebAppUserHelper webAppUserHelper = Provider.GetRequiredService<WebAppUserHelper>();
|
|
LdapUser ldapUserFromClient = new LdapUser(userFromClient.LoginName, webAppEmployeeInfo.EmployeeId, userFromClient.Password, webAppEmployeeInfo.DepartmentId, webAppEmployeeInfo.ExtendedDepartmentIdList);
|
|
Assert.NotNull(ldapUserFromClient);
|
|
|
|
var jwtManager = Provider.GetRequiredService<JwtManager>();
|
|
bool ldapUserOk = jwtManager.GenerateLdapUserWithJwtToken(ldapUserFromClient);
|
|
Assert.True(ldapUserOk);
|
|
|
|
WebAppUser newUser = await webAppUserHelper.CheckLoginWithNameAndPasswordAsync(userFromClient);
|
|
|
|
Assert.NotNull(newUser);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
[Theory]
|
|
[InlineData("visitoripad", "pwd")]
|
|
public void Validate_Credentials_with_password(string login, string passwort)
|
|
{
|
|
try
|
|
{
|
|
LdapUser ldapUser = new LdapUser(login, 0, passwort);
|
|
var ldapAuthenticationService = Provider.GetRequiredService<LdapAuthenticationService>();
|
|
var result = ldapAuthenticationService.CheckAndUpdateIdentityWithPassword(ldapUser);
|
|
|
|
Assert.True(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(GetLdapUsers))]
|
|
public void Validate_Credentials_with_password_Version2(LdapUser ldapUser)
|
|
{
|
|
try
|
|
{
|
|
var ldapAuthenticationService = Provider.GetRequiredService<LdapAuthenticationService>();
|
|
var result = ldapAuthenticationService.CheckAndUpdateIdentityWithPassword(ldapUser);
|
|
|
|
Assert.True(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<object[]> GetLdapUsers()
|
|
{
|
|
LdapUser ldapUser = new LdapUser("user1", 0, "pwd");
|
|
LdapUser ldapUser2 = new LdapUser("Error", 0, "pwd");
|
|
|
|
var allData = new List<object[]>
|
|
{
|
|
new object[] { ldapUser },
|
|
new object[] { ldapUser2 }
|
|
};
|
|
|
|
return allData;
|
|
}
|
|
}
|
|
} |