consolidate the tests locations
This commit is contained in:
@@ -17,8 +17,6 @@ using StellaOps.Authority.Plugin.Ldap.Credentials;
|
||||
using StellaOps.Authority.Plugin.Ldap.Monitoring;
|
||||
using StellaOps.Authority.Plugin.Ldap.Tests.Fakes;
|
||||
using StellaOps.Authority.Plugin.Ldap.Tests.TestHelpers;
|
||||
using StellaOps.Authority.Storage.Documents;
|
||||
using StellaOps.Authority.Storage.InMemory.Stores;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -228,7 +226,7 @@ public sealed class LdapConnectorResilienceTests
|
||||
var store = CreateStore(options, new FakeLdapConnectionFactory(connection));
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
Func<Task> act = async () => await store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await act.Should().ThrowAsync<TimeoutException>();
|
||||
@@ -250,7 +248,7 @@ public sealed class LdapConnectorResilienceTests
|
||||
var store = CreateStore(options, new FakeLdapConnectionFactory(connection));
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
Func<Task> act = async () => await store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await act.Should().ThrowAsync<InvalidOperationException>();
|
||||
@@ -277,7 +275,7 @@ public sealed class LdapConnectorResilienceTests
|
||||
cts.Cancel(); // Pre-cancel
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => store.VerifyPasswordAsync("user", "Password1!", cts.Token);
|
||||
Func<Task> act = async () => await store.VerifyPasswordAsync("user", "Password1!", cts.Token);
|
||||
|
||||
// Assert
|
||||
await act.Should().ThrowAsync<OperationCanceledException>();
|
||||
@@ -375,20 +373,34 @@ public sealed class LdapConnectorResilienceTests
|
||||
private LdapCredentialStore CreateStore(LdapPluginOptions options, ILdapConnectionFactory connectionFactory)
|
||||
{
|
||||
var monitor = new StaticOptionsMonitor(options);
|
||||
var userStore = new InMemoryUserStore(_timeProvider);
|
||||
var sessionStore = new InMemorySessionStore(_timeProvider);
|
||||
var claimsCache = new FakeLdapClaimsCache();
|
||||
|
||||
return new LdapCredentialStore(
|
||||
"corp-ldap",
|
||||
monitor,
|
||||
connectionFactory,
|
||||
userStore,
|
||||
sessionStore,
|
||||
NullLogger<LdapCredentialStore>.Instance,
|
||||
new LdapMetrics("corp-ldap"),
|
||||
_auditStore,
|
||||
claimsCache,
|
||||
_timeProvider,
|
||||
NullLoggerFactory.Instance);
|
||||
_timeProvider);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test Helper Classes
|
||||
|
||||
private sealed class StaticOptionsMonitor : IOptionsMonitor<LdapPluginOptions>
|
||||
{
|
||||
private readonly LdapPluginOptions value;
|
||||
|
||||
public StaticOptionsMonitor(LdapPluginOptions options)
|
||||
{
|
||||
value = options ?? throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
public LdapPluginOptions CurrentValue => value;
|
||||
|
||||
public LdapPluginOptions Get(string? name) => value;
|
||||
|
||||
public IDisposable? OnChange(Action<LdapPluginOptions, string?> listener) => null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -11,11 +11,12 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StellaOps.Authority.Plugin.Ldap.Connections;
|
||||
using StellaOps.Authority.Plugin.Ldap.Credentials;
|
||||
using StellaOps.Authority.Plugin.Ldap.Monitoring;
|
||||
using StellaOps.Authority.Plugin.Ldap.Tests.Fakes;
|
||||
using StellaOps.Authority.Plugin.Ldap.Tests.TestHelpers;
|
||||
using StellaOps.Authority.Storage.InMemory.Stores;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -169,7 +170,7 @@ public sealed class LdapConnectorSecurityTests
|
||||
var store = CreateStore(options, new FakeLdapConnectionFactory(connection));
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
Func<Task> act = async () => await store.VerifyPasswordAsync("user", "Password1!", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await act.Should().ThrowAsync<InvalidOperationException>();
|
||||
@@ -226,8 +227,8 @@ public sealed class LdapConnectorSecurityTests
|
||||
Host = "ldap://ldap.internal", // Non-secure
|
||||
BindDn = "cn=service,dc=example,dc=internal",
|
||||
BindPasswordSecret = "secret",
|
||||
UserDnFormat = "uid={username},ou=people,dc=example,dc=internal",
|
||||
TrustStore = new LdapTrustStoreOptions { Mode = LdapTrustStoreMode.None }
|
||||
UserDnFormat = "uid={username},ou=people,dc=example,dc=internal"
|
||||
// Note: Using default TrustStore settings - LdapTrustStoreMode only supports System or Bundle
|
||||
}
|
||||
};
|
||||
|
||||
@@ -355,20 +356,34 @@ public sealed class LdapConnectorSecurityTests
|
||||
private LdapCredentialStore CreateStore(LdapPluginOptions options, ILdapConnectionFactory connectionFactory)
|
||||
{
|
||||
var monitor = new StaticOptionsMonitor(options);
|
||||
var userStore = new InMemoryUserStore(_timeProvider);
|
||||
var sessionStore = new InMemorySessionStore(_timeProvider);
|
||||
var claimsCache = new FakeLdapClaimsCache();
|
||||
|
||||
return new LdapCredentialStore(
|
||||
"corp-ldap",
|
||||
monitor,
|
||||
connectionFactory,
|
||||
userStore,
|
||||
sessionStore,
|
||||
NullLogger<LdapCredentialStore>.Instance,
|
||||
new LdapMetrics("corp-ldap"),
|
||||
_auditStore,
|
||||
claimsCache,
|
||||
_timeProvider,
|
||||
NullLoggerFactory.Instance);
|
||||
_timeProvider);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test Helper Classes
|
||||
|
||||
private sealed class StaticOptionsMonitor : IOptionsMonitor<LdapPluginOptions>
|
||||
{
|
||||
private readonly LdapPluginOptions value;
|
||||
|
||||
public StaticOptionsMonitor(LdapPluginOptions options)
|
||||
{
|
||||
value = options ?? throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
public LdapPluginOptions CurrentValue => value;
|
||||
|
||||
public LdapPluginOptions Get(string? name) => value;
|
||||
|
||||
public IDisposable? OnChange(Action<LdapPluginOptions, string?> listener) => null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user