Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed May 24, 2022
1 parent 9c43917 commit cccc170
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 58 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ A fork of the original Rhino.Licensing software licensing framework used for [Ch
## Building the Project

Visual Studio or VS Code can be used to build the solution.
Note that the `Rhino.Licensing.AdminTool*` projects are not currently part of the solution or presently being maintained.

A full build, test, and pack run can be started using the `build.ps1` PowerShell script.

## Testing

Running the `build.ps1` will run unit tests for the project.
Running `build.ps1 -Target Test` will run unit tests for the project.

## Acknowledgements

Expand Down
133 changes: 133 additions & 0 deletions RhinoBuilding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#requires -runasadministrator
$baseDir = Resolve-Path "$PSScriptRoot/.."
$ErrorActionPreference = 'Stop'

Write-Warning "BE AWARE THAT THIS SCRIPT IS CURRENTLY VERY SPECIFIC TO THE VERSIONS IT'S TARGETTING."
Write-Warning "IF YOU ARE TARGETING NEWER CHOCOLATEY COMPONENTS IT LIKELY NEEDS TO BE MODIFIED"
Write-Warning "PLEASE CANCEL WITH CTRL+C IF YOU DO NOT KNOW WHAT THIS WARNING MEANS"
Pause

$reposMissing = @(
'choco'
'choco-licensed'
'licensing-services'
'chocolatey-pro-server-simple'
'choco-licensed-management-ui'
'choco-licensed-services'
'ChocolateyGUI'
'chocolateygui-licensed'
) | Where-Object { -not (Test-Path -Path "$baseDir/$_" -PathType Container) }

if ($reposMissing.Count -gt 0) {
throw "Missing repositories: $reposMissing"
}

function check {
if ($LASTEXITCODE -ne 0) {
throw "Something didn't work building $args"
}
}

function copyNupkg {
param(
$Package,
[switch]
$CakeBuild,
$Base = $baseDir
)
$splat = @{
Path = if ($CakeBuild) {
"$Base/$Package/code_drop/Packages/Chocolatey/*.nupkg"
} else {
"$Base/$Package/code_drop/nuget/*.nupkg"
}
Destination = "C:\CodeDrops"
}
New-Item $splat.Destination -ErrorAction Ignore -ItemType Directory
Copy-Item @splat
}

$RhinoLicensingSource = "$baseDir/rhino-licensing"
$RhinoLicensingFiles = "$RhinoLicensingSource/code_drop/temp/_PublishedLibs/Rhino.Licensing"
$RhinoLicensingPackage = "$RhinoLicensingSource/code_drop/Packages/NuGet"
$ChocolateyFiles = "$baseDir/choco/code_drop/chocolatey/lib"
$ChocolateyLicensedFiles = "$baseDir/choco-licensed/code_drop/chocolateypro"
$ChocolateyGUIFiles = "$baseDir/ChocolateyGUI/code_drop/temp/_PublishedLibs"



try {
Push-Location $RhinoLicensingSource
./build.ps1
check Rhino.Licensing

Write-Host Chocolatey
Set-Location $baseDir/choco
Copy-Item "$RhinoLicensingFiles/net40/Rhino.Licensing.dll" "$baseDir/choco/lib/Rhino.Licensing.1.4.1/lib/net40/Rhino.Licensing.dll"
./build.bat
check Chocolatey CLI
copyNupkg -Package choco

Write-Host Chocolatey Licensed Extension
Set-Location $baseDir/choco-licensed
nuget restore src/chocolateypro.sln
Copy-Item "$RhinoLicensingFiles/net40/Rhino.Licensing.dll" "$baseDir/choco-licensed/lib/Rhino.Licensing.1.4.1/lib/net40/Rhino.Licensing.dll"
Copy-Item $ChocolateyFiles/chocolatey.dll "$baseDir/choco-licensed/src/packages/chocolatey.lib.1.0.0/lib/chocolatey.dll"
./build.bat
check Chocolatey Licensed Extension
copyNupkg -Package choco-licensed

Write-Host Licensing Services
Set-Location $baseDir/licensing-services
dotnet add source/LicensingServices.Core package Rhino.Licensing -v 1.6.0-cleanup -s $RhinoLicensingPackage
./build.ps1
check Licensing Services
copyNupkg -Package licensing-services -CakeBuild

Write-Host Simple Server Pro
Set-Location $baseDir/chocolatey-pro-server-simple
nuget restore src
Copy-Item $RhinoLicensingFiles "$baseDir/chocolatey-pro-server-simple/src/packages/Rhino.Licensing.1.5.0/lib" -Recurse -Force
./build.ps1
check Simple Server Pro
copyNupkg -Package chocolatey-pro-server-simple -CakeBuild

Write-Host Chocolatey Central Management
Set-Location $baseDir/choco-licensed-management-ui
dotnet restore ChocolateySoftware.ChocolateyManagement.sln
Copy-Item $RhinoLicensingFiles "$baseDir/choco-licensed-management-ui/src/packages/rhino.licensing/1.4.0/lib/" -Recurse -Force
./build.ps1
check Chocolatey Central Management
copyNupkg -Package .\choco-licensed-management-ui -CakeBuild

Write-Host Chocolatey Agent
Set-Location $baseDir/choco-licensed-services
nuget restore src
Copy-Item $ChocolateyFiles/chocolatey.dll "$baseDir/choco-licensed-services/src/packages/chocolatey.lib.1.0.0/lib/chocolatey.dll" -Recurse -Force
Copy-Item $ChocolateyLicensedFiles/chocolatey.licensed.dll "$baseDir/choco-licensed-services/src/packages/chocolatey-licensed.lib.4.0.0/lib/chocolatey.licensed.dll" -Recurse -Force
./build.bat
check Chocolatey Agent
copyNupkg -Package choco-licensed-services

Write-Host Chocolatey GUI
Set-Location $baseDir/ChocolateyGUI
nuget restore Source
Copy-Item $ChocolateyFiles/chocolatey.dll "$baseDir/ChocolateyGUI/Source/packages/chocolatey.lib.1.0.0/lib/chocolatey.dll" -Recurse -Force
./build.ps1
check Chocolatey GUI
copyNupkg -Package ChocolateyGUI -CakeBuild

Write-Host Chocolatey GUI - Licensed Extension
Set-Location $baseDir/chocolateygui-licensed
nuget restore Source
Copy-Item $ChocolateyFiles/chocolatey.dll "$baseDir/chocolateygui-licensed/Source/packages/chocolatey.lib.1.0.0/lib/chocolatey.dll" -Recurse -Force
Copy-Item $ChocolateyGUIFiles/ChocolateyGui.Common/ChocolateyGui.Common.dll "$baseDir/chocolateygui-licensed/Source/packages/ChocolateyGui.Common.1.0.0/lib/net48"
Copy-Item $ChocolateyGUIFiles/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.dll "$baseDir/chocolateygui-licensed/Source/packages/ChocolateyGui.Common.Windows.1.0.0/lib/net48"
./build.ps1
check Chocolatey GUI - Licensed Extension
copyNupkg -Package chocolateygui-licensed -CakeBuild

}
finally {
Pop-Location
}
3 changes: 2 additions & 1 deletion recipe.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.13.3
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.14.0


///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -35,6 +35,7 @@ BuildParameters.SetParameters(
shouldAuthenticodeSignOutputAssemblies: false,
shouldStrongNameSignDependentAssemblies: false,
shouldRunInspectCode: false,
shouldGenerateSolutionVersionCSharpFile: false,
treatWarningsAsErrors: false,
testDirectoryPath: "./test",
shouldRunDotNetPack: true,
Expand Down
81 changes: 44 additions & 37 deletions test/Rhino.Licensing.Tests/BaseLicenseTest.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
using System.IO;

namespace Rhino.Licensing.Tests
{
public class BaseLicenseTest
{
public readonly static string public_and_private;
public readonly static string public_only;
public readonly static string floating_private;
public readonly static string floating_public;

static BaseLicenseTest()
{
public_and_private = new StreamReader(typeof (Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream(
"Rhino.Licensing.Tests.public_and_private.xml"))
.ReadToEnd();

public_only = new StreamReader(typeof (Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream("Rhino.Licensing.Tests.public_only.xml"))
.ReadToEnd();


floating_private = new StreamReader(typeof(Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream("Rhino.Licensing.Tests.floating_private.xml"))
.ReadToEnd();

floating_public = new StreamReader(typeof(Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream("Rhino.Licensing.Tests.floating_public.xml"))
.ReadToEnd();
}

}
using System;
using System.Collections.Generic;
using System.IO;

namespace Rhino.Licensing.Tests
{
public class BaseLicenseTest
{
public readonly static string public_and_private;
public readonly static string public_only;

static BaseLicenseTest()
{
public_and_private = new StreamReader(typeof(Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream(
"Rhino.Licensing.Tests.public_and_private.xml"))
.ReadToEnd();

public_only = new StreamReader(typeof(Can_generate_and_validate_key)
.Assembly
.GetManifestResourceStream("Rhino.Licensing.Tests.public_only.xml"))
.ReadToEnd();
}

public static IEnumerable<object[]> GetAllLicenseTypes()
{
foreach (var licenseType in Enum.GetValues(typeof(LicenseType)))
{
yield return new object[] { licenseType };
}
}

public static IEnumerable<object[]> GetAllLicenseTypesWithSigningAlgorithms()
{
foreach (var licenseType in Enum.GetValues(typeof(LicenseType)))
{
foreach (var signingAlgorithm in Enum.GetValues(typeof(SigningAlgorithm)))
{
yield return new object[] { licenseType, signingAlgorithm };
}
}
}
}
}
45 changes: 34 additions & 11 deletions test/Rhino.Licensing.Tests/Can_generate_and_validate_key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ namespace Rhino.Licensing.Tests
{
public class Can_generate_and_validate_key : BaseLicenseTest
{
[Fact]
public void Gen_and_validate()
[Theory]
[MemberData(nameof(GetAllLicenseTypes))]
public void Gen_and_validate(LicenseType licenseType)
{
var guid = Guid.NewGuid();
var generator = new LicenseGenerator(public_and_private);
var expiration = DateTime.Now.AddDays(30);
var key = generator.Generate("Oren Eini", guid, expiration, LicenseType.Trial);
var key = generator.Generate("Oren Eini", guid, expiration, licenseType);

var path = Path.GetTempFileName();
File.WriteAllText(path, key);
Expand All @@ -24,11 +25,12 @@ public void Gen_and_validate()
Assert.Equal(guid, validator.UserId);
Assert.Equal(expiration, validator.ExpirationDate);
Assert.Equal("Oren Eini", validator.Name);
Assert.Equal(LicenseType.Trial, validator.LicenseType);
Assert.Equal(licenseType, validator.LicenseType);
}

[Fact]
public void Gen_and_validate_with_attributes()
[Theory]
[MemberData(nameof(GetAllLicenseTypes))]
public void Gen_and_validate_with_attributes(LicenseType licenseType)
{
var guid = Guid.NewGuid();
var generator = new LicenseGenerator(public_and_private);
Expand All @@ -38,7 +40,7 @@ public void Gen_and_validate_with_attributes()
{
{"prof", "llb"},
{"reporting", "on"}
}, LicenseType.Trial);
}, licenseType);

var path = Path.GetTempFileName();
File.WriteAllText(path, key);
Expand All @@ -49,11 +51,12 @@ public void Gen_and_validate_with_attributes()
Assert.Equal(guid, validator.UserId);
Assert.Equal(expiration, validator.ExpirationDate);
Assert.Equal("Oren Eini", validator.Name);
Assert.Equal(LicenseType.Trial, validator.LicenseType);
Assert.Equal(licenseType, validator.LicenseType);
}

[Fact]
public void Throws_date_exception_when_license_is_expired()
[Theory]
[MemberData(nameof(GetAllLicenseTypes))]
public void Throws_date_exception_when_license_is_expired(LicenseType licenseType)
{
var guid = Guid.NewGuid();
var generator = new LicenseGenerator(public_and_private);
Expand All @@ -63,7 +66,7 @@ public void Throws_date_exception_when_license_is_expired()
{
{"prof", "llb"},
{"reporting", "on"}
}, LicenseType.Trial);
}, licenseType);

var path = Path.GetTempFileName();
File.WriteAllText(path, key);
Expand All @@ -72,6 +75,26 @@ public void Throws_date_exception_when_license_is_expired()
Assert.Throws<LicenseExpiredException>(() => validator.AssertValidLicense());
}

[Theory]
[MemberData(nameof(GetAllLicenseTypesWithSigningAlgorithms))]
public void Gen_and_validate_signing_algorithm(LicenseType licenseType, SigningAlgorithm signingAlgorithm)
{
var guid = Guid.NewGuid();
var generator = new LicenseGenerator(public_and_private);
var expiration = DateTime.Now.AddDays(30);
var key = generator.Generate("Oren Eini", guid, expiration, licenseType, signingAlgorithm);

var path = Path.GetTempFileName();
File.WriteAllText(path, key);

var validator = new LicenseValidator(public_only, path);
validator.AssertValidLicense();

Assert.Equal(guid, validator.UserId);
Assert.Equal(expiration, validator.ExpirationDate);
Assert.Equal("Oren Eini", validator.Name);
}

[Fact]
public void Cannot_validate_hacked_license()
{
Expand Down
5 changes: 0 additions & 5 deletions test/Rhino.Licensing.Tests/Rhino.Licensing.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@
<ProjectReference Include="..\..\src\Rhino.Licensing\Rhino.Licensing.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="floating_private.xml" />
<EmbeddedResource Include="floating_public.xml" />
</ItemGroup>

<!--<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>-->
Expand Down
1 change: 0 additions & 1 deletion test/Rhino.Licensing.Tests/floating_private.xml

This file was deleted.

1 change: 0 additions & 1 deletion test/Rhino.Licensing.Tests/floating_public.xml

This file was deleted.

0 comments on commit cccc170

Please sign in to comment.