Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
<packageSources>
<add key="Octopus Dependencies" value="https://f.feedz.io/octopus-deploy/dependencies/nuget" />
<add key="NuGet.org v3" value="https://api.nuget.org/v3/index.json" />
<add key="ASPNET Code MyGet" value="https://dotnet.myget.org/F/dotnet-core/" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ActiveDirectoryMembershipTests
[TestCase("EXAMPLE\\joe", "joe", "EXAMPLE")]
public void CredentialsAreNormalized(string rawUsername, string usedUsername, string usedDomain)
{
var log = Substitute.For<ILog>();
var log = Substitute.For<ISystemLog>();
var credentialNormalizer = new DirectoryServicesObjectNameNormalizer(log);
var domainUser = credentialNormalizer.NormalizeName(rawUsername);
Assert.AreEqual(usedUsername, domainUser.NormalizedName);
Expand Down
2 changes: 1 addition & 1 deletion source/DirectoryServices.Tests/CredentialValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void SetUp()

directoryServicesService = Substitute.For<IDirectoryServicesService>();

var log = Substitute.For<ILog>();
var log = Substitute.For<ISystemLog>();

identityCreator = new IdentityCreator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class DirectoryServicesExternalSecurityGroupLocatorTests

DirectoryServicesExternalSecurityGroupLocator locator;
IUserPrincipalFinder userPrincipalFinder;
InMemoryLog log;
ISystemLog log;

[SetUp]
public void SetUp()
{
log = new InMemoryLog();
log = Substitute.For<ISystemLog>();
var configurationStore = Substitute.For<IDirectoryServicesConfigurationStore>();

var contextProvider = Substitute.For<IDirectoryServicesContextProvider>();
Expand All @@ -33,48 +33,50 @@ public void SetUp()
var directoryServicesObjectNameNormalizer = Substitute.For<IDirectoryServicesObjectNameNormalizer>();
directoryServicesObjectNameNormalizer.NormalizeName(Arg.Any<string>())
.Returns(x => new DomainUser(null, ((string)x.Args()[0])));

locator = new DirectoryServicesExternalSecurityGroupLocator(
log,
contextProvider,
directoryServicesObjectNameNormalizer,
configurationStore,
userPrincipalFinder
);

configurationStore.GetAreSecurityGroupsEnabled().Returns(true);
contextProvider.GetContext(null).ReturnsForAnyArgs(new PrincipalContext(ContextType.Machine));

}

[Test]
public void GetGroupIdsForUser_NotFound()
{
userPrincipalFinder.FindByIdentity(null, null).ReturnsForAnyArgs((IUserPrincipalWrapper) null);

var result = locator.GetGroupIdsForUser("Bob", CancellationToken.None);
result.WasAbleToRetrieveGroups.ShouldBeFalse();
log.Logs.ShouldContain((LogCategory.Trace, null, $"While loading security groups, a principal identifiable by 'Bob' was not found in '{Environment.MachineName}'"));

log.Received().Trace($"While loading security groups, a principal identifiable by 'Bob' was not found in '{Environment.MachineName}'");
}

[Test]
public void GetGroupIdsForUser_ErrorGettingAuthorizationGroups()
{

var userPrincipal = Substitute.For<IUserPrincipalWrapper>();
userPrincipalFinder.FindByIdentity(null, null).ReturnsForAnyArgs(userPrincipal);

var authGroupsException = new Exception("AuthorizationGroups Exception");
userPrincipal.GetAuthorizationGroups(CancellationToken.None).ThrowsForAnyArgs(authGroupsException);
userPrincipal.GetGroups(CancellationToken.None).Returns(new[] {new FakeGroupPrincipal(groupSid)});

var result = locator.GetGroupIdsForUser("Bob", CancellationToken.None);
result.WasAbleToRetrieveGroups.ShouldBeTrue();
result.GroupsIds.ShouldBe(new[] { groupSid});

log.Logs.ShouldContain(l => l.category == LogCategory.Verbose && l.exception == authGroupsException);
log.Logs.ShouldNotContain(l => l.category == LogCategory.Error || l.category == LogCategory.Fatal);

log.Received().Verbose(authGroupsException);
log.DidNotReceive().Error(Arg.Any<string>());
log.DidNotReceive().Error(Arg.Any<Exception>());
log.DidNotReceive().Fatal(Arg.Any<string>());
log.DidNotReceive().Fatal(Arg.Any<Exception>());
}

[Test]
Expand All @@ -85,34 +87,37 @@ public void GetGroupIdsForUser_ErrorGettingAnyGroups()

var authGroupsException = new Exception("AuthorizationGroups Exception");
userPrincipal.GetAuthorizationGroups(CancellationToken.None).ThrowsForAnyArgs(authGroupsException);

var groupsException = new Exception("Groups Exception");
userPrincipal.GetGroups(CancellationToken.None).ThrowsForAnyArgs(groupsException);

var result = locator.GetGroupIdsForUser("Bob", CancellationToken.None);

result.WasAbleToRetrieveGroups.ShouldBeFalse();
result.GroupsIds.ShouldBeNull();
log.Logs.ShouldContain(l => l.category == LogCategory.Verbose && l.exception == authGroupsException);
log.Logs.ShouldContain(l => l.category == LogCategory.Error && l.exception == groupsException);

log.Received().Verbose(authGroupsException);
log.Received().ErrorFormat(groupsException, "Active Directory search for {0} failed.", "Bob");
}

[Test]
public void GetGroupIdsForUser_Success()
{

var userPrincipal = Substitute.For<IUserPrincipalWrapper>();
userPrincipalFinder.FindByIdentity(null, null).ReturnsForAnyArgs(userPrincipal);

userPrincipal.GetAuthorizationGroups(CancellationToken.None).ReturnsForAnyArgs(new[] {new FakeGroupPrincipal(groupSid)});

var result = locator.GetGroupIdsForUser("Bob", CancellationToken.None);

result.WasAbleToRetrieveGroups.ShouldBeTrue();
result.GroupsIds.ShouldBe(new[] { groupSid});
log.Logs.ShouldNotContain(l => l.category == LogCategory.Error || l.category == LogCategory.Fatal);

log.DidNotReceive().Error(Arg.Any<string>());
log.DidNotReceive().Error(Arg.Any<Exception>());
log.DidNotReceive().Fatal(Arg.Any<string>());
log.DidNotReceive().Fatal(Arg.Any<Exception>());
}

class FakeGroupPrincipal : IPrincipalWrapper
Expand Down
62 changes: 0 additions & 62 deletions source/DirectoryServices.Tests/InMemoryLog.cs

This file was deleted.

4 changes: 2 additions & 2 deletions source/Server/Configuration/DatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Configur
{
class DatabaseInitializer : ExecuteWhenDatabaseInitializes
{
readonly ILog log;
readonly ISystemLog log;
readonly IConfigurationStore configurationStore;
readonly IWritableKeyValueStore settings;

bool cleanupRequired = false;

public DatabaseInitializer(ILog log, IConfigurationStore configurationStore, IWritableKeyValueStore settings)
public DatabaseInitializer(ISystemLog log, IConfigurationStore configurationStore, IWritableKeyValueStore settings)
{
this.log = log;
this.configurationStore = configurationStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Configur
{
class DirectoryServicesConfigureCommands : IContributeToConfigureCommand
{
readonly ILog log;
readonly ISystemLog log;
readonly Lazy<IDirectoryServicesConfigurationStore> activeDirectoryConfiguration;

public DirectoryServicesConfigureCommands(
ILog log,
ISystemLog log,
Lazy<IDirectoryServicesConfigurationStore> activeDirectoryConfiguration)
{
this.log = log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Director
{
class DirectoryServicesCredentialValidator : IDirectoryServicesCredentialValidator
{
readonly ILog log;
readonly ISystemLog log;
readonly IDirectoryServicesObjectNameNormalizer objectNameNormalizer;
readonly IUpdateableUserStore userStore;
readonly IDirectoryServicesConfigurationStore configurationStore;
Expand All @@ -24,7 +24,7 @@ class DirectoryServicesCredentialValidator : IDirectoryServicesCredentialValidat
internal static string EnvironmentUserDomainName = Environment.UserDomainName;

public DirectoryServicesCredentialValidator(
ILog log,
ISystemLog log,
IDirectoryServicesObjectNameNormalizer objectNameNormalizer,
IUpdateableUserStore userStore,
IDirectoryServicesConfigurationStore configurationStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Director
{
class DirectoryServicesExternalSecurityGroupLocator : IDirectoryServicesExternalSecurityGroupLocator
{
readonly ILog log;
readonly ISystemLog log;
readonly IDirectoryServicesContextProvider contextProvider;
readonly IDirectoryServicesObjectNameNormalizer objectNameNormalizer;
readonly IDirectoryServicesConfigurationStore configurationStore;
readonly IUserPrincipalFinder userPrincipalFinder;

public DirectoryServicesExternalSecurityGroupLocator(
ILog log,
ISystemLog log,
IDirectoryServicesContextProvider contextProvider,
IDirectoryServicesObjectNameNormalizer objectNameNormalizer,
IDirectoryServicesConfigurationStore configurationStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Director
{
class DirectoryServicesObjectNameNormalizer : IDirectoryServicesObjectNameNormalizer
{
readonly ILog log;
readonly ISystemLog log;
const string NTAccountUsernamePrefix = "nt:";

public DirectoryServicesObjectNameNormalizer(ILog log)
public DirectoryServicesObjectNameNormalizer(ISystemLog log)
{
this.log = log;
}
Expand Down
4 changes: 2 additions & 2 deletions source/Server/DirectoryServices/DirectoryServicesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Director
{
class DirectoryServicesService : IDirectoryServicesService
{
readonly ILog log;
readonly ISystemLog log;
readonly IDirectoryServicesObjectNameNormalizer objectNameNormalizer;
readonly IDirectoryServicesContextProvider contextProvider;

Expand All @@ -27,7 +27,7 @@ class DirectoryServicesService : IDirectoryServicesService
/// </summary>
const int LOGON32_PROVIDER_DEFAULT = 0;

public DirectoryServicesService(ILog log,
public DirectoryServicesService(ISystemLog log,
IDirectoryServicesObjectNameNormalizer objectNameNormalizer,
IDirectoryServicesContextProvider contextProvider)
{
Expand Down
4 changes: 2 additions & 2 deletions source/Server/DirectoryServices/GroupRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace Octopus.Server.Extensibility.Authentication.DirectoryServices.Director
{
class GroupRetriever : IExternalGroupRetriever
{
readonly ILog log;
readonly ISystemLog log;
readonly IDirectoryServicesConfigurationStore configurationStore;
readonly IDirectoryServicesExternalSecurityGroupLocator groupLocator;

public GroupRetriever(
ILog log,
ISystemLog log,
IDirectoryServicesConfigurationStore configurationStore,
IDirectoryServicesExternalSecurityGroupLocator groupLocator)
{
Expand Down
Loading