Skip to content

Commit

Permalink
Add test Cases for signed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
saintentropy committed Dec 12, 2019
1 parent e4ec678 commit 182399a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/Libraries/PackageManagerTests/PackageLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Dynamo.PackageManager.Tests
class PackageLoaderTests : DynamoModelTestBase
{
public string PackagesDirectory { get { return Path.Combine(TestDirectory, "pkgs"); } }
public string PackagesDirectorySigned { get { return Path.Combine(TestDirectory, "pkgs_signed"); } }

protected override void GetLibrariesToPreload(List<string> libraries)
{
Expand Down Expand Up @@ -503,6 +504,63 @@ public void PackageLoadExceptionTest()
Assert.IsFalse(EngineController.DisableRun);
}

[Test]
public void ScanPackageDirectoryWithCheckingCertificatesEnabledWillNotLoadPackageWithoutValidCertificate()
{
var loader = new PackageLoader(new [] {PackagesDirectory}, new [] {PackagesDirectorySigned});
var libraryLoader = new ExtensionLibraryLoader(CurrentDynamoModel);

loader.PackagesLoaded += libraryLoader.LoadPackages;
loader.RequestLoadNodeLibrary += libraryLoader.LoadNodeLibrary;

var pkgDir = Path.Combine(PackagesDirectorySigned, "Unsigned Package");
var pkg = loader.ScanPackageDirectory(pkgDir, true);

// Assert that ScanPackageDirectory returns no packages
Assert.IsNull(pkg);
}

[Test]
public void ScanPackageDirectoryWithCheckingCertificatesEnabledWillNotLoadPackageWithAlteredCertificate()
{
var loader = new PackageLoader(new[] { PackagesDirectory }, new[] { PackagesDirectorySigned });
var libraryLoader = new ExtensionLibraryLoader(CurrentDynamoModel);

loader.PackagesLoaded += libraryLoader.LoadPackages;
loader.RequestLoadNodeLibrary += libraryLoader.LoadNodeLibrary;

var pkgDir = Path.Combine(PackagesDirectorySigned, "Modfied Signed Package");
var pkg = loader.ScanPackageDirectory(pkgDir, true);

// Assert that ScanPackageDirectory returns no packages
Assert.IsNull(pkg);
}

[Test]
public void ScanPackageDirectoryWithCheckingCertificatesEnabledWillLoadPackageWithValidCertificate()
{
var loader = new PackageLoader(new[] { PackagesDirectory }, new[] { PackagesDirectorySigned });
var libraryLoader = new ExtensionLibraryLoader(CurrentDynamoModel);

loader.PackagesLoaded += libraryLoader.LoadPackages;
loader.RequestLoadNodeLibrary += libraryLoader.LoadNodeLibrary;

var pkgDir = Path.Combine(PackagesDirectorySigned, "Signed Package");
var pkg = loader.ScanPackageDirectory(pkgDir, true);

// Assert that ScanPackageDirectory returns a package
Assert.IsNotNull(pkg);
loader.LoadPackages(new List<Package> { pkg });

// Verify that package resolved successfully
var libs = CurrentDynamoModel.LibraryServices.ImportedLibraries.ToList();
Assert.IsTrue(libs.Contains(Path.Combine(PackagesDirectorySigned, "Signed Package", "bin", "Package.dll")));

// Verify that the package are imported successfully
var entries = CurrentDynamoModel.SearchModel.SearchEntries.ToList();
Assert.IsTrue(entries.Any(x => x.FullName == "Package.Package.Package.Hello"));
}

[Test]
public void IsUnderPackageControlIsCorrectForValidFunctionDefinition()
{
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions test/pkgs_signed/Modfied Signed Package/pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"license":"","file_hash":null,"name":"Package","version":"1.0.0","description":"original package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]}
Binary file added test/pkgs_signed/Signed Package/bin/Package.dll
Binary file not shown.
1 change: 1 addition & 0 deletions test/pkgs_signed/Signed Package/pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"license":"","file_hash":null,"name":"Package","version":"1.0.0","description":"original package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]}
Binary file not shown.
1 change: 1 addition & 0 deletions test/pkgs_signed/Unsigned Package/pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"license":"","file_hash":null,"name":"Package","version":"1.0.0","description":"original package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]}

0 comments on commit 182399a

Please sign in to comment.