namespace JdeScoping.Infrastructure.Tests.Helpers;
///
/// Helper class for mock LDAP test data.
/// Provides test user scenarios for LDAP integration tests.
///
///
/// 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.
///
public static class MockLdapServer
{
///
/// Test user with valid credentials who is a member of the required security group.
/// Expected result: Authentication succeeds with user info.
///
public static TestLdapUser ValidGroupMemberUser { get; } = new(
Username: "testuser",
Password: "validPassword123",
FirstName: "Test",
LastName: "User",
Email: "testuser@example.com",
Title: "Software Engineer",
IsInRequiredGroup: true);
///
/// 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".
///
public static TestLdapUser ValidNotInGroupUser { get; } = new(
Username: "nogroupuser",
Password: "validPassword456",
FirstName: "NoGroup",
LastName: "User",
Email: "nogroupuser@example.com",
Title: "External Contractor",
IsInRequiredGroup: false);
///
/// Test user with invalid credentials.
/// Expected result: Authentication fails with "Incorrect username or password".
///
public static TestLdapUser InvalidCredentialsUser { get; } = new(
Username: "invaliduser",
Password: "wrongPassword",
FirstName: null,
LastName: null,
Email: null,
Title: null,
IsInRequiredGroup: false);
///
/// Expected error message when user is not in the required security group.
///
public const string GroupMembershipErrorMessage = "User is not a member of the required security group";
///
/// Expected error message when credentials are invalid.
///
public const string InvalidCredentialsErrorMessage = "Incorrect username or password";
///
/// Expected error message when all LDAP servers are unreachable.
///
public const string ConnectionErrorMessage = "Unable to connect to directory server";
///
/// Expected error message when username or password is empty.
///
public const string RequiredFieldsErrorMessage = "Username and password are required";
///
/// Sample fake LDAP server URLs for testing connection failures.
/// These are intentionally invalid/unreachable hostnames.
///
public static string[] FakeServerUrls { get; } =
[
"ldap.fake-server-1.invalid",
"ldap.fake-server-2.invalid",
"ldap.fake-server-3.invalid"
];
///
/// Sample group DN for testing.
///
public const string TestGroupDn = "CN=ScopingTool-Users,OU=Groups,DC=corp,DC=example,DC=com";
///
/// Sample search base for testing.
///
public const string TestSearchBase = "DC=corp,DC=example,DC=com";
}
///
/// Represents test data for an LDAP user scenario.
///
/// The user's sAMAccountName
/// The user's password
/// The user's first name (givenName attribute)
/// The user's last name (sn attribute)
/// The user's email address (mail attribute)
/// The user's job title (title attribute)
/// Whether the user is a member of the required security group
public record TestLdapUser(
string Username,
string Password,
string? FirstName,
string? LastName,
string? Email,
string? Title,
bool IsInRequiredGroup);