Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.
Draft
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ TestResult.xml
!packages.config
.idea
**/launchSettings.json

.terraform/
terraform.tfstate*
.terraform*
4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"Compile",
"CopyToLocalPackages",
"Default",
"Integration",
"Integration2",
"Pack",
"Restore",
"Test"
Expand All @@ -105,6 +107,8 @@
"Compile",
"CopyToLocalPackages",
"Default",
"Integration",
"Integration2",
"Pack",
"Restore",
"Test"
Expand Down
117 changes: 117 additions & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nuke.Common;
using Nuke.Common.CI.TeamCity;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.OctoVersion;
using Nuke.Common.Utilities.Collections;
Expand Down Expand Up @@ -122,6 +129,116 @@ class Build : NukeBuild
});
});


Target Integration2 => _ => _
.Executes(() =>
{
var composeDirectory = SourceDirectory / "Ldap.Integration.Tests/scripts/OpenLdap/";
Environment.SetEnvironmentVariable("OCTOPUS_LDAP_OPENLDAP_PORT", "3777");

using (var process = ProcessTasks.StartProcess("pwsh", "./New-OpenLdapIntegrationTestEnvironment.ps1", composeDirectory))
{
process.AssertZeroExitCode();
}

try
{
DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetFilter("AuthProvider=OpenLDAP")
.SetProcessArgumentConfigurator(arguments => arguments
.Add("--logger trx")
.Add("--logger console;verbosity=normal")
.Add(TeamCity.Instance is not null ? "--logger teamcity" : string.Empty)
));
}
finally
{
using var process = ProcessTasks.StartProcess("pwsh", "./Remove-OpenLdapIntegrationTestEnvironment.ps1", composeDirectory);
process.AssertZeroExitCode();
}


/*DockerTasks.Docker($"compose -f docker-compose.yml --project-name {CONTAINER_PROJECT} up -d",
composeDirectory);

DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetFilter("AuthProvider=OpenLDAP")
.SetNoBuild(true)
.EnableNoRestore());

var x = ProcessTasks.StartShell("New-OpenLdapIntegrationTestEnvironment.ps1", composeDirectory);
x.WaitForExit();

DockerTasks.Docker($"compose -f docker-compose.yml --project-name {CONTAINER_PROJECT} down",
composeDirectory);*/
});

Target Integration => _ => _
.Executes(() =>
{
var composeDirectory = SourceDirectory / "Ldap.Integration.Tests/scripts/ActiveDirectory/Azure/";

string public_ip_addr, admin_password;


using (var process = ProcessTasks.StartProcess("pwsh", "./New-ActiveDirectoryIntegrationTestEnvironment.ps1", composeDirectory))
{
process.AssertZeroExitCode();
}

using (var process = ProcessTasks.StartProcess("terraform", "output -json", composeDirectory))
{
process.AssertZeroExitCode();
var rawJson = process.Output.Where(d => d.Type == OutputType.Std)
.Select(d => d.Text)
.Aggregate(string.Empty, (a, b) => $"{a}{Environment.NewLine}{b}");
var raw = JsonConvert.DeserializeObject<JObject>(rawJson);

public_ip_addr = raw["public_ip_addr"].Value<string>("value");
admin_password = raw["admin_password"].Value<string>("value");
}

try
{
DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetFilter("AuthProvider=ActiveDirectory")
.SetProcessEnvironmentVariable("OCTOPUS_LDAP_AD_SERVER", public_ip_addr)
.SetProcessEnvironmentVariable("OCTOPUS_LDAP_AD_PASSWORD", admin_password)
.SetProcessArgumentConfigurator(arguments => arguments
.Add("--logger trx")
.Add("--logger console;verbosity=normal")
));
}
finally
{
using var process = ProcessTasks.StartProcess("pwsh", "./Remove-ActiveDirectoryIntegrationTestEnvironment.ps1", composeDirectory);
process.AssertZeroExitCode();
}


/*DockerTasks.Docker($"compose -f docker-compose.yml --project-name {CONTAINER_PROJECT} up -d",
composeDirectory);

DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetFilter("AuthProvider=OpenLDAP")
.SetNoBuild(true)
.EnableNoRestore());

var x = ProcessTasks.StartShell("New-OpenLdapIntegrationTestEnvironment.ps1", composeDirectory);
x.WaitForExit();

DockerTasks.Docker($"compose -f docker-compose.yml --project-name {CONTAINER_PROJECT} down",
composeDirectory);*/
});

Target Default => _ => _
.DependsOn(Pack);

Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "5.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
2 changes: 2 additions & 0 deletions source/Ldap.Integration.Tests/ICanMatchExternalUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public TheMatchMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void MatchesAUserFromActiveDirectory()
{
var userName = "developer1";
Expand All @@ -37,6 +38,7 @@ internal void MatchesAUserFromActiveDirectory()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void MatchesAUserFromOpenLDAP()
{
var userName = "developer1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public TheSearchMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void FindsGroupsFromActiveDirectory()
{
var partialName = "Devel";
Expand Down Expand Up @@ -56,6 +57,7 @@ internal void FindsGroupsFromActiveDirectoryWithSpecialCharacters()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void FindsGroupsFromOpenLDAP()
{
var partialName = "Devel";
Expand All @@ -74,6 +76,7 @@ internal void FindsGroupsFromOpenLDAP()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void FindsGroupsFromOpenLDAPWithSpecialCharacters()
{
var partialName = "Special";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public TheSearchMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void FindsUsersFromActiveDirectory()
{
var partialName = "devel";
Expand All @@ -35,6 +36,7 @@ internal void FindsUsersFromActiveDirectory()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void FindsUsersFromOpenLDAP()
{
var partialName = "devel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public TheValidateCredentialsMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void ValidatesAUserFromActiveDirectory()
{
// Arrange
Expand All @@ -45,6 +46,7 @@ internal void ValidatesAUserFromActiveDirectory()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void ValidatesAUserFromOpenLDAP()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public TheReadMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void ReadsGroupsForAUserFromActiveDirectory()
{
// Arrange
Expand Down Expand Up @@ -48,6 +49,7 @@ internal void ReadsGroupsForAUserFromActiveDirectory()
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void ReadsGroupsForAUserFromActiveDirectoryWithSpecialCharacters()
{
// Arrange
Expand Down Expand Up @@ -77,6 +79,7 @@ internal void ReadsGroupsForAUserFromActiveDirectoryWithSpecialCharacters()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void ReadsGroupsForAUserFromOpenLDAP()
{
// Arrange
Expand Down Expand Up @@ -107,6 +110,7 @@ internal void ReadsGroupsForAUserFromOpenLDAP()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void ReadsGroupsForAUserFromOpenLDAPWithSpecialCharacters()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public TheGetOrCreateUserMethod(ITestOutputHelper testLogger)
}

[Fact]
[Trait("AuthProvider","ActiveDirectory")]
internal void CreatesAUserFromActiveDirectory()
{
// Arrange
Expand All @@ -44,6 +45,7 @@ internal void CreatesAUserFromActiveDirectory()
}

[Fact]
[Trait("AuthProvider","OpenLDAP")]
internal void CreatesAUserFromOpenLDAP()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.36" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
41 changes: 18 additions & 23 deletions source/Ldap.Integration.Tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ A docker-compose stack is defined that spins up an openldap server bootstrapped

Environment variables can be used to configure the integration test settings.

| Env Var | Required | Default Value |
| --- | --- | --- |
| `OCTOPUS_LDAP_OPENLDAP_SERVER` | No | localhost |
| `OCTOPUS_LDAP_OPENLDAP_PORT` | No | 389 |
| Env Var | Required | Default Value |
| --- | --- |------------------------------|
| `OCTOPUS_LDAP_OPENLDAP_SERVER` | No | localhost |
| `OCTOPUS_LDAP_OPENLDAP_PORT` | No | 389 |
| `OCTOPUS_LDAP_OPENLDAP_USER` | No | cn=admin,dc=domain1,dc=local |
| `OCTOPUS_LDAP_OPENLDAP_PASSWORD` | Yes | |
| `OCTOPUS_LDAP_OPENLDAP_PASSWORD` | Yes | Pass |

### Running Integration Tests

Expand All @@ -34,34 +34,29 @@ Powershell scripts are located [here](scripts/OpenLdap) to create/tear down the
```

## Active Directory

As it is not possible to containerize Microsoft AD, these need to be run against a VM hosted instance somewhere that gets populated with known test data.

[This Azure Template](https://github.com/maxskunkworks/TLG/tree/master/tlg-base-config_3-vm) is one relatively straight forward option to create an AD environment. Firewall settings will generally need to applied manually to enable inbound connections.

### Configuration

Environment variables can be used to configure the integration test settings.

| Env Var | Required | Default Value |
| --- | --- | --- |
| `OCTOPUS_LDAP_AD_SERVER` | Yes | |
| `OCTOPUS_LDAP_AD_PORT` | No | 389 |
| `OCTOPUS_LDAP_AD_USER` | Yes | |
| Env Var | Required | Default Value |
| --- | --- |---------------------------|
| `OCTOPUS_LDAP_AD_SERVER` | Yes | |
| `OCTOPUS_LDAP_AD_PORT` | No | 389 |
| `OCTOPUS_LDAP_AD_USER` | Yes | adminuser@mycompany.local |
| `OCTOPUS_LDAP_AD_PASSWORD` | Yes | |

### Running Integration Tests
A terraform script has been provided [here](scripts/ActiveDirectory/Azure) that will provision an AD instance in Azure along with relevant test data.

Powershell scripts are located [here](scripts/ActiveDirectory) to populate an existing ActiveDirectory instance with the required test data. Due to cross platform and other limmitations, they currently are simple scripts that must be run from a machine connected to the test domain using an account with appropriate permissions.

- Populate the integration test data
- Create the integration test stack
```
./Update-ActiveDirectoryIntegrationTestData.ps1
./New-ActiveDirectoryIntegrationTestEnvironment.ps1
```

- Run the ActiveDirectory integration tests

- Cleanup the integration test data
- Update your environment variables with the generated server IP and password.
- Run the OpenLdap integration tests
- Tear down the integration test stack
```
./Remove-ActiveDirectoryIntegrationTestEnvironment.ps1
```
./Remove-ActiveDirectoryIntegrationTestData.ps1
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ internal static class ConfigurationHelper

public static LdapConfiguration GetActiveDirectoryConfiguration()
{
var server = Environment.GetEnvironmentVariable(ENVVAR_AD_SERVER);
var server = Environment.GetEnvironmentVariable(ENVVAR_AD_SERVER) ?? "20.231.14.150";
var port = Convert.ToInt32(Environment.GetEnvironmentVariable(ENVVAR_AD_PORT) ?? "389");
var user = Environment.GetEnvironmentVariable(ENVVAR_AD_USER);
var password = Environment.GetEnvironmentVariable(ENVVAR_AD_PASSWORD);
var user = Environment.GetEnvironmentVariable(ENVVAR_AD_USER) ?? "adminuser@mycompany.local";
var password = Environment.GetEnvironmentVariable(ENVVAR_AD_PASSWORD) ?? "Z@qDBHRXQmwoXBTs";

return new LdapConfiguration()
.Enabled()
Expand Down Expand Up @@ -51,7 +51,7 @@ public static LdapConfiguration GetOpenLdapConfiguration()
var server = Environment.GetEnvironmentVariable(ENVVAR_OPENLDAP_SERVER) ?? "localhost";
var port = Convert.ToInt32(Environment.GetEnvironmentVariable(ENVVAR_OPENLDAP_PORT) ?? "389");
var user = Environment.GetEnvironmentVariable(ENVVAR_OPENLDAP_USER) ?? "cn=admin,dc=domain1,dc=local";
var password = Environment.GetEnvironmentVariable(ENVVAR_OPENLDAP_PASSWORD);
var password = Environment.GetEnvironmentVariable(ENVVAR_OPENLDAP_PASSWORD) ?? "Pass";

return new LdapConfiguration()
.Enabled()
Expand Down
Loading