refactor: LdapTest von HRD.LdapService.Text nach XUnitWebApi.Test verschoben und Abhängigkeiten refaktoriert
- `LdapTest`-Klasse vom Namespace `HRD.LdapService.Text` in den Namespace `XUnitWebApi.Test` verschoben. - `LdapTest`-Klasse aktualisiert, um von `TestBuilder` zu erben, um die erforderlichen Abhängigkeiten per Dependency Injection (DI) bereitzustellen. - Direkte Instanziierung von Diensten (`JwtManager`, `LdapAuthenticationService`, `LdapManager`) entfernt und durch DI-basierte Abrufmethoden (`Provider.GetRequiredService`) ersetzt. - Das veraltete Projekt `HRD.LdapService` gelöscht, da dessen Code nun in `XUnitWebApi.Test` integriert ist.
This commit is contained in:
parent
41900e8e06
commit
cfd163a7a7
@ -1,25 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp7.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="xunit" Version="2.8.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HRD.LDAPService\HRD.LDAPService.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -12,8 +12,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HRD.AppLogger", "HRD.AppLog
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HRD.LDAPService", "HRD.LDAPService\HRD.LDAPService.csproj", "{B90CF1F9-9AB5-4415-8211-2644D75AA276}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HRD.LdapService.Test", "HRD.LdapService.Test\HRD.LdapService.Test.csproj", "{9E719C7C-B48C-4071-9412-886B41D7D442}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HRD.WebApi", "HRD.WebApi\HRD.WebApi.csproj", "{B886F61C-1555-477B-9804-319686FAF2C9}"
|
||||
EndProject
|
||||
Global
|
||||
@ -42,10 +40,6 @@ Global
|
||||
{B90CF1F9-9AB5-4415-8211-2644D75AA276}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B90CF1F9-9AB5-4415-8211-2644D75AA276}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B90CF1F9-9AB5-4415-8211-2644D75AA276}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9E719C7C-B48C-4071-9412-886B41D7D442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9E719C7C-B48C-4071-9412-886B41D7D442}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9E719C7C-B48C-4071-9412-886B41D7D442}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9E719C7C-B48C-4071-9412-886B41D7D442}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B886F61C-1555-477B-9804-319686FAF2C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B886F61C-1555-477B-9804-319686FAF2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B886F61C-1555-477B-9804-319686FAF2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -55,8 +49,8 @@ Global
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F02FC958-650A-495C-B4BA-13C2AFE9AB72}
|
||||
SolutionGuid = {C7A45DA6-C1A5-4BE3-8A00-F3C3ABF566BA}
|
||||
SolutionGuid = {3336A9F1-24F5-40E2-B3FB-42340B3E74A7}
|
||||
SolutionGuid = {C7A45DA6-C1A5-4BE3-8A00-F3C3ABF566BA}
|
||||
SolutionGuid = {F02FC958-650A-495C-B4BA-13C2AFE9AB72}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
using HRD.LDAPService;
|
||||
using HRD.LDAPService.JWT;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace HRD.LdapService.Text
|
||||
namespace XUnitWebApi.Test
|
||||
{
|
||||
public class LdapTest
|
||||
public class LdapTest : TestBuilder
|
||||
{
|
||||
|
||||
private static void InitJWTConfig(bool deaktivateLDAP = false)
|
||||
@ -43,6 +41,7 @@ namespace HRD.LdapService.Text
|
||||
var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ2LmJvamFyc2tpIiwibmFtZWlkIjoiMCIsImVtYWlsIjoiVi5Cb2phcnNraUBoZW5zZWwtcmVjeWNsaW5nLmNvbSIsImRlcGFydG1lbnRpZCI6IjAiLCJleHRlbmRldGRlcGFydG1lbnRpZGxpc3QiOiIiLCJFeHRlbmRlZEF0dHJpYnV0ZXNfUmVnaW9uIjoiMTAsMjAiLCJFeHRlbmRlZEF0dHJpYnV0ZXNfQXR0cmlidXQjMSI6IkFCQ0BBQkMuREUsREVGQEFCQy5ERSxHRUhAQUJDLkRFIiwibmJmIjoxNjU4NzU4NDE0LCJleHAiOjE2NTkxMTg0MTQsImlhdCI6MTY1ODc1ODQxNH0.KUODwRBRn-xc3-0RaVKJ0uzwsXZ7RgORRAZUzTfxfNk";
|
||||
var loginName = "v.bojarski";
|
||||
|
||||
var JwtManager = Provider.GetRequiredService<JwtManager>();
|
||||
LdapUser renewLdapUser = JwtManager.RenewLdapUserWithJwtToken(token);
|
||||
|
||||
Assert.Same(renewLdapUser.LoginName, loginName);
|
||||
@ -73,6 +72,7 @@ namespace HRD.LdapService.Text
|
||||
|
||||
|
||||
ldapUser.ExtendedAttributesList = extendedAttributesList;
|
||||
var JwtManager = Provider.GetRequiredService<JwtManager>();
|
||||
var isOk = JwtManager.GenerateLdapUserWithJwtToken(ldapUser);
|
||||
LdapUser ldapUserWithJWT = new LdapUser(ldapUser.LoginName);
|
||||
ldapUserWithJWT.Token = ldapUser.Token;
|
||||
@ -80,7 +80,8 @@ namespace HRD.LdapService.Text
|
||||
extendedAttributesList = new List<KeyValuePair<string, string>>();
|
||||
extendedAttributesList.Add(new KeyValuePair<string, string>("Attribut#1", "ABC@ABC.DE,DEF@ABC.DE,GEH@ABC.DE"));
|
||||
ldapUser.ExtendedAttributesList = extendedAttributesList;
|
||||
var renewLdapUserWithJWT = LdapAuthenticationService.RenewIdentity( ldapUserWithJWT);
|
||||
var LdapAuthenticationService = Provider.GetRequiredService<LdapAuthenticationService>();
|
||||
var renewLdapUserWithJWT = LdapAuthenticationService.RenewIdentity(ldapUserWithJWT);
|
||||
|
||||
Assert.True(renewLdapUserWithJWT.IsValid());
|
||||
}
|
||||
@ -101,11 +102,13 @@ namespace HRD.LdapService.Text
|
||||
|
||||
ldapUser.AddExtendedAttribute("Attribut#1", "ABC@ABC.DE,DEF@ABC.DE,GEH@ABC.DE");
|
||||
ldapUser.AddExtendedAttribute("VendorId", "100210");
|
||||
var JwtManager = Provider.GetRequiredService<JwtManager>();
|
||||
var isOk = JwtManager.GenerateLdapUserWithJwtToken(ldapUser);
|
||||
LdapUser ldapUserWithJWT = new LdapUser(ldapUser.LoginName);
|
||||
ldapUserWithJWT.Token = ldapUser.Token;
|
||||
ldapUserWithJWT.PasswordHash = ldapUser.PasswordHash;
|
||||
|
||||
var LdapAuthenticationService = Provider.GetRequiredService<LdapAuthenticationService>();
|
||||
var renewLdapUserWithJWT = LdapAuthenticationService.RenewIdentity(ldapUserWithJWT);
|
||||
|
||||
LdapUser ldapUser2 = new LdapUser(LoginName);
|
||||
@ -115,7 +118,7 @@ namespace HRD.LdapService.Text
|
||||
|
||||
Assert.Equal(ldapUser.PasswordHashShort, ldapUserWithJWT.PasswordHashShort);
|
||||
Assert.True(renewLdapUserWithJWT.IsValid());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -125,10 +128,8 @@ namespace HRD.LdapService.Text
|
||||
var loginName = "v.bojarski";
|
||||
var groupName = "GG_WebApp__Test_Apps_User";
|
||||
|
||||
var LdapManager = Provider.GetRequiredService<LdapManager>();
|
||||
Assert.True(LdapManager.AD_AddUserloginToGroup(loginName, groupName));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user