26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
114 lines
4.3 KiB
C#
114 lines
4.3 KiB
C#
namespace JdeScoping.Infrastructure.Tests.Helpers;
|
|
|
|
/// <summary>
|
|
/// Helper class for mock LDAP test data.
|
|
/// Provides test user scenarios for LDAP integration tests.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is not an actual LDAP server mock, but provides test data structures
|
|
/// that document the expected behavior of LDAP authentication.
|
|
/// For real LDAP server mocking, consider using a containerized LDAP server
|
|
/// (e.g., OpenLDAP in Docker) or a protocol-level mock.
|
|
/// </remarks>
|
|
public static class MockLdapServer
|
|
{
|
|
/// <summary>
|
|
/// Test user with valid credentials who is a member of the required security group.
|
|
/// Expected result: Authentication succeeds with user info.
|
|
/// </summary>
|
|
public static TestLdapUser ValidGroupMemberUser { get; } = new(
|
|
Username: "testuser",
|
|
Password: "validPassword123",
|
|
FirstName: "Test",
|
|
LastName: "User",
|
|
Email: "testuser@example.com",
|
|
Title: "Software Engineer",
|
|
IsInRequiredGroup: true);
|
|
|
|
/// <summary>
|
|
/// Test user with valid credentials who is NOT a member of the required security group.
|
|
/// Expected result: Authentication fails with "User is not a member of the required security group".
|
|
/// </summary>
|
|
public static TestLdapUser ValidNotInGroupUser { get; } = new(
|
|
Username: "nogroupuser",
|
|
Password: "validPassword456",
|
|
FirstName: "NoGroup",
|
|
LastName: "User",
|
|
Email: "nogroupuser@example.com",
|
|
Title: "External Contractor",
|
|
IsInRequiredGroup: false);
|
|
|
|
/// <summary>
|
|
/// Test user with invalid credentials.
|
|
/// Expected result: Authentication fails with "Incorrect username or password".
|
|
/// </summary>
|
|
public static TestLdapUser InvalidCredentialsUser { get; } = new(
|
|
Username: "invaliduser",
|
|
Password: "wrongPassword",
|
|
FirstName: null,
|
|
LastName: null,
|
|
Email: null,
|
|
Title: null,
|
|
IsInRequiredGroup: false);
|
|
|
|
/// <summary>
|
|
/// Expected error message when user is not in the required security group.
|
|
/// </summary>
|
|
public const string GroupMembershipErrorMessage = "User is not a member of the required security group";
|
|
|
|
/// <summary>
|
|
/// Expected error message when credentials are invalid.
|
|
/// </summary>
|
|
public const string InvalidCredentialsErrorMessage = "Incorrect username or password";
|
|
|
|
/// <summary>
|
|
/// Expected error message when all LDAP servers are unreachable.
|
|
/// </summary>
|
|
public const string ConnectionErrorMessage = "Unable to connect to directory server";
|
|
|
|
/// <summary>
|
|
/// Expected error message when username or password is empty.
|
|
/// </summary>
|
|
public const string RequiredFieldsErrorMessage = "Username and password are required";
|
|
|
|
/// <summary>
|
|
/// Sample fake LDAP server URLs for testing connection failures.
|
|
/// These are intentionally invalid/unreachable hostnames.
|
|
/// </summary>
|
|
public static string[] FakeServerUrls { get; } =
|
|
[
|
|
"ldap.fake-server-1.invalid",
|
|
"ldap.fake-server-2.invalid",
|
|
"ldap.fake-server-3.invalid"
|
|
];
|
|
|
|
/// <summary>
|
|
/// Sample group DN for testing.
|
|
/// </summary>
|
|
public const string TestGroupDn = "CN=ScopingTool-Users,OU=Groups,DC=corp,DC=example,DC=com";
|
|
|
|
/// <summary>
|
|
/// Sample search base for testing.
|
|
/// </summary>
|
|
public const string TestSearchBase = "DC=corp,DC=example,DC=com";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents test data for an LDAP user scenario.
|
|
/// </summary>
|
|
/// <param name="Username">The user's sAMAccountName</param>
|
|
/// <param name="Password">The user's password</param>
|
|
/// <param name="FirstName">The user's first name (givenName attribute)</param>
|
|
/// <param name="LastName">The user's last name (sn attribute)</param>
|
|
/// <param name="Email">The user's email address (mail attribute)</param>
|
|
/// <param name="Title">The user's job title (title attribute)</param>
|
|
/// <param name="IsInRequiredGroup">Whether the user is a member of the required security group</param>
|
|
public record TestLdapUser(
|
|
string Username,
|
|
string Password,
|
|
string? FirstName,
|
|
string? LastName,
|
|
string? Email,
|
|
string? Title,
|
|
bool IsInRequiredGroup);
|