Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robe/calamari legacy #1322

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
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
51 changes: 44 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public Build()
Lazy<string> NugetVersion { get; }

Target CheckForbiddenWords =>
_ => _.Executes(() =>
_ => _
.OnlyWhenStatic(() => !IsLocalBuild)
.Executes(() =>
{
Log.Information("Checking codebase for forbidden words");

Expand Down Expand Up @@ -169,6 +171,18 @@ public Build()
{
Log.Information("Compiling Calamari v{CalamariVersion}", NugetVersion.Value);

DotNetBuild(_ => _.SetProjectFile(SourceDirectory / "Calamari.FullFrameworkTools"/ "Calamari.FullFrameworkTools.csproj")
.SetConfiguration(Configuration)
.DisableNoRestore()
.SetVersion(NugetVersion.Value)
.SetInformationalVersion(GitVersionInfo?.InformationalVersion));

DotNetBuild(_ => _.SetProjectFile(SourceDirectory / "Calamari.FullFrameworkTools.Tests"/ "Calamari.FullFrameworkTools.Tests.csproj")
.SetConfiguration(Configuration)
.DisableNoRestore()
.SetVersion(NugetVersion.Value)
.SetInformationalVersion(GitVersionInfo?.InformationalVersion));

DotNetBuild(_ => _.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetNoRestore(true)
Expand Down Expand Up @@ -219,11 +233,32 @@ public Build()
nugetVersion,
FixedRuntimes.Cloud);

// Create the self-contained Calamari packages for each runtime ID defined in Calamari.csproj
foreach (var rid in GetRuntimeIdentifiers(Solution.GetProject(RootProjectName)!)!)
DoPublish(RootProjectName, Frameworks.Net60, nugetVersion, rid);
});
if (OperatingSystem.IsWindows())
{
var path = SourceDirectory / "Calamari.FullFrameworkTools" / "bin" / Configuration / Frameworks.Net462 ;
CopyDirectoryRecursively(path, (PublishDirectory / "Calamari" / Frameworks.Net462 / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
CopyDirectoryRecursively(path, (PublishDirectory / "Calamari" / Frameworks.Net60 / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
}

// Create the self-contained Calamari packages for each runtime ID defined in Calamari.csproj
foreach (var rid in GetRuntimeIdentifiers(Solution.GetProject(RootProjectName)!)!)
{
var publishPath = DoPublish(RootProjectName, Frameworks.Net60, nugetVersion, rid);

if (rid == FixedRuntimes.Windows && OperatingSystem.IsWindows())
{
CopyFullFrameworkFiles(publishPath);
}
}
});


void CopyFullFrameworkFiles(AbsolutePath targetPath)
{
var path = SourceDirectory / "Calamari.FullFrameworkTools" / "bin" / Configuration / Frameworks.Net462;
CopyDirectoryRecursively(path, (targetPath / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
}

Target PublishCalamariFlavourProjects =>
_ => _
.DependsOn(Compile)
Expand Down Expand Up @@ -329,7 +364,7 @@ void PublishPackage(CalamariPackageMetadata calamariPackageMetadata)
File.Copy(RootDirectory / "global.json", outputDirectory / "global.json");

}

static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPublish) {

if (!OperatingSystem.IsWindows())
Expand All @@ -340,7 +375,7 @@ static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPu
}

packagesToPublish
//We only need to bundle executable (not tests or libraries) full framework projects
//We only need to bundle executable (not tests or libraries) full framework projects
.Where(d => d.Framework == Frameworks.Net462 && d.Project.GetOutputType() == "Exe")
.ForEach(calamariPackageMetadata =>
{
Expand Down Expand Up @@ -434,6 +469,8 @@ void CompressCalamariProject(Project project)
var defaultTarget = OperatingSystem.IsWindows() ? Frameworks.Net462 : Frameworks.Net60;
AbsolutePath binFolder = SourceDirectory / "Calamari.Tests" / "bin" / Configuration / defaultTarget;
Directory.Exists(binFolder);

CopyFullFrameworkFiles(binFolder);
var actions = new List<Action>
{
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Calamari.Common.FeatureToggles
public static class OctopusFeatureToggles
{
public static readonly OctopusFeatureToggle NonPrimaryGitDependencySupportFeatureToggle = new OctopusFeatureToggle("non-primary-git-dependency-support");
public static readonly OctopusFeatureToggle FullFrameworkTasksExternalProcess = new OctopusFeatureToggle("full-framework-tasks-external-process");

public class OctopusFeatureToggle
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Calamari.FullFrameworkTools.Tests</AssemblyName>
<PackageId>Calamari.FullFrameworkTools.Tests</PackageId>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<OutputType>Library</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
<NoWarn>NU1603</NoWarn>
<ApplicationIcon />
<StartupObject />
<TargetFramework>net462</TargetFramework>
<RootNamespace>Calamari.FullFrameworkTools.Tests</RootNamespace>

</PropertyGroup>
<!--<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
<DefineConstants>$(DefineConstants);NETFX;AWS;IIS_SUPPORT;USE_NUGET_V2_LIBS;USE_OCTODIFF_EXE;WINDOWS_CERTIFICATE_STORE_SUPPORT;WINDOWS_USER_ACCOUNT_SUPPORT;WINDOWS_REGISTRY_SUPPORT</DefineConstants>
</PropertyGroup>-->
<ItemGroup>
<PackageReference Include="XPath2" Version="1.0.12" />
<!--<ProjectReference Include="..\Calamari.Testing\Calamari.Testing.csproj" />
<ProjectReference Include="..\Calamari\Calamari.csproj" />-->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Assent" Version="1.6.1" />
<PackageReference Include="Polly" Version="8.3.1" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<!--<ProjectReference Include="..\Calamari.Aws\Calamari.Aws.csproj" />
<ProjectReference Include="..\Calamari.Azure\Calamari.Azure.csproj" />-->
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System" />
<Reference Include="System.Security" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Calamari.FullFrameworkTools\Calamari.FullFrameworkTools.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.IO;
using Calamari.FullFrameworkTools.Command;
using Calamari.FullFrameworkTools.Utils;
using Calamari.FullFrameworkTools.WindowsCertStore;
using FluentAssertions;
using Newtonsoft.Json;
using NSubstitute;
using NUnit.Framework;

namespace Calamari.FullFrameworkTools.Tests.Command
{
[TestFixture]
public class CommandRequestInvokerTests
{
readonly IRequestTypeLocator requestTypeLocator = Substitute.For<IRequestTypeLocator>();
readonly ICommandHandler commandHandler = Substitute.For<ICommandHandler>();

[Test]
public void Foo()
{
var invoker = new CommandRequestInvoker(requestTypeLocator, commandHandler);
requestTypeLocator.FindType(nameof(MockRequest)).Returns(typeof(MockRequest));
var requestObject = new MockRequest(4, 5);
var jsonRequestObj = JsonConvert.SerializeObject(requestObject);
commandHandler.Handle(Arg.Is<MockRequest>(d => d.NumberOne == requestObject.NumberOne && d.NumberTwo == requestObject.NumberTwo))
.Returns(77);

var result = invoker.Run(nameof(MockRequest), jsonRequestObj);

result.Should().BeEquivalentTo(77);
}

[Test]
public void SimpleHandlerEncrypted()
{
var invoker = new CommandRequestInvoker(requestTypeLocator, commandHandler);
requestTypeLocator.FindType(nameof(MockRequest)).Returns(typeof(MockRequest));
var requestObject = new MockRequest(4, 5);
var jsonRequestObj = JsonConvert.SerializeObject(requestObject);

var password = "pass23HJka";
var enc = new AesEncryption(password);
var encRequestObj = enc.Encrypt(jsonRequestObj);

using (var temp = new TempFile(encRequestObj))
{
var result = invoker.Run(nameof(MockRequest), password, temp.FilePath);

result.Should().BeEquivalentTo(77);
}
}

}


public class TempFile : IDisposable
{
public TempFile(byte[] content)
{
FilePath = Path.GetTempFileName();
File.WriteAllBytes(FilePath, content);
}

public string FilePath { get; }

public void Dispose()
{
try
{
File.Delete(FilePath);
}
catch
{
// ignored
}
}
}
public class MockRequest : IRequest
{
public MockRequest(int numberOne, int numberTwo)
{
NumberOne = numberOne;
NumberTwo = numberTwo;
}

public int NumberOne { get; }
public int NumberTwo { get; }
}
}
66 changes: 66 additions & 0 deletions source/Calamari.FullFrameworkTools.Tests/Iis/IisFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using Calamari.FullFrameworkTools.Iis;
using NUnit.Framework;

namespace Calamari.FullFrameworkTools.Tests.Iis
{
/// <summary>
/// Note. This test is a direct clone of <see cref="Calamari.Tests.Fixtures.Iis.IisFixture"/>.
/// While we extract IIS functionality out of Calamari, we will have the relevant functionality in both places for a short period.
/// Ensure any changes to make to this test are reflected in the clone test.
/// </summary>
[TestFixture]
public class IisFixture
{
readonly WebServerSupport webServer = WebServerSupport.AutoDetect();
string siteName;

[SetUp]
public void SetUp()
{
siteName = "Test-" + Guid.NewGuid();
webServer.CreateWebSiteOrVirtualDirectory(siteName, "/", "C:\\InetPub\\wwwroot", 1081);
webServer.CreateWebSiteOrVirtualDirectory(siteName, "/Foo", "C:\\InetPub\\wwwroot", 1081);
webServer.CreateWebSiteOrVirtualDirectory(siteName, "/Foo/Bar/Baz", "C:\\InetPub\\wwwroot", 1081);
}

[Test]
public void CanUpdateIisSite()
{
var server = new InternetInformationServer();
var success = server.OverwriteHomeDirectory(siteName, "C:\\Windows\\system32", false);
Assert.IsTrue(success, "Home directory was not overwritten");

var path = webServer.GetHomeDirectory(siteName, "/");
Assert.AreEqual("C:\\Windows\\system32", path);
}

[Test]
public void CanUpdateIisSiteWithVirtualDirectory()
{
var server = new InternetInformationServer();
var success = server.OverwriteHomeDirectory(siteName + "/Foo", "C:\\Windows\\Microsoft.NET", false);
Assert.IsTrue(success, "Home directory was not overwritten");

var path = webServer.GetHomeDirectory(siteName, "/Foo");
Assert.AreEqual("C:\\Windows\\Microsoft.NET", path);
}

[Test]
public void CanUpdateIisSiteWithNestedVirtualDirectory()
{
var server = new InternetInformationServer();
var success = server.OverwriteHomeDirectory(siteName + "/Foo/Bar/Baz", "C:\\Windows\\Microsoft.NET\\Framework", false);
Assert.IsTrue(success, "Home directory was not overwritten");

var path = webServer.GetHomeDirectory(siteName, "/Foo/Bar/Baz");
Assert.AreEqual("C:\\Windows\\Microsoft.NET\\Framework", path);
}

[TearDown]
public void TearDown()
{
webServer.DeleteWebSite(siteName);
}
}
}
41 changes: 41 additions & 0 deletions source/Calamari.FullFrameworkTools.Tests/IisCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Calamari.FullFrameworkTools.Iis;
using NSubstitute;
using NUnit.Framework;

namespace Calamari.FullFrameworkTools.Tests
{
[TestFixture]
public class IisCommandTests
{
[Test]
public void GivenTwoParameters_ThenParametersPassedToOverwriteHomeDirectory()
{
var iisServer = Substitute.For<IInternetInformationServer>();
var cmd = new IisCommand(iisServer);

var websiteName = "WEBSITENAME";
var path = "PATH";
cmd.Execute(new[] { websiteName, path });
iisServer.Received().OverwriteHomeDirectory(websiteName, path, false);
}

[Test]
public void GivenOneParameter_ThenException()
{
var iisServer = Substitute.For<IInternetInformationServer>();
var cmd = new IisCommand(iisServer);

Assert.Throws<CommandException>(() => cmd.Execute(new string[] { Guid.NewGuid().ToString()}));
}

[Test]
public void GivenNoParameter_ThenException()
{
var iisServer = Substitute.For<IInternetInformationServer>();
var cmd = new IisCommand(iisServer);

Assert.Throws<CommandException>(() => cmd.Execute(Array.Empty<string>()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.InteropServices;

[assembly: Guid("EC26DBFD-A364-4AF9-BFEF-F8ABCA2656FA")]
18 changes: 18 additions & 0 deletions source/Calamari.FullFrameworkTools.Tests/SerializedLogTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Calamari.FullFrameworkTools.Command;
using NUnit.Framework;

namespace Calamari.FullFrameworkTools.Tests
{
[TestFixture]
public class SerializedLogTest
{

[Test]
public void Foo()
{
var log = new SerializedLog();

log.Error("CAKE");
}
}
}
Loading