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(); WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == userFromClient.LoginName); Assert.NotNull(webAppEmployeeInfo); WebAppUserHelper webAppUserHelper = Provider.GetRequiredService(); LdapUser ldapUserFromClient = new LdapUser(userFromClient.LoginName, webAppEmployeeInfo.EmployeeId, userFromClient.Password, webAppEmployeeInfo.DepartmentId, webAppEmployeeInfo.ExtendedDepartmentIdList); Assert.NotNull(ldapUserFromClient); var jwtManager = Provider.GetRequiredService(); 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(); 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(); var result = ldapAuthenticationService.CheckAndUpdateIdentityWithPassword(ldapUser); Assert.True(result); } catch (Exception) { throw; } } public static IEnumerable GetLdapUsers() { LdapUser ldapUser = new LdapUser("user1", 0, "pwd"); LdapUser ldapUser2 = new LdapUser("Error", 0, "pwd"); var allData = new List { new object[] { ldapUser }, new object[] { ldapUser2 } }; return allData; } } }