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

Added integration test for maui blazor maccatalyst codesign verification. #17331

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Created new Codesign class and moved SearchForExpectedEntitlements to…
… it.
dustin-wojciechowski committed Sep 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5cdeb51f2d884792d1ec3312b9e8c046a75f9329
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics;

namespace Microsoft.Maui.IntegrationTests.Apple
{
public static class Codesign
{
public static List<string> SearchForExpectedEntitlements(
string entitlementsPath,
string appLocation,
List<string> expectedEntitlements)
{
List<string> foundEntitlements = new();
string procOutput = ToolRunner.Run(new ProcessStartInfo()
{
FileName = "/usr/bin/codesign",
Arguments = $"-d --entitlements {entitlementsPath} --xml {appLocation}"
}, out int errorCode);

Assert.AreEqual(errorCode, 0, procOutput);
Assert.IsTrue(File.Exists(entitlementsPath));

string fileContent = File.ReadAllText(entitlementsPath);
foreach (string entitlement in expectedEntitlements)
{
if (fileContent.Contains(entitlement, StringComparison.OrdinalIgnoreCase))
foundEntitlements.Add(entitlement);
}

return foundEntitlements;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using Microsoft.Maui.IntegrationTests.Apple;

namespace Microsoft.Maui.IntegrationTests
{
@@ -182,28 +182,6 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

List<string> SearchForExpectedEntitlements(string entitlementsPath, string appLocation, List<string> expectedEntitlements)
{
List<string> foundEntitlements = new();
string procOutput = ToolRunner.Run(new ProcessStartInfo()
{
FileName = "/usr/bin/codesign",
Arguments = $"-d --entitlements {entitlementsPath} --xml {appLocation}"
}, out int errorCode);

Assert.AreEqual(errorCode, 0, procOutput);
Assert.IsTrue(File.Exists(entitlementsPath));

string fileContent = File.ReadAllText(entitlementsPath);
foreach (string entitlement in expectedEntitlements)
{
if (fileContent.Contains(entitlement, StringComparison.OrdinalIgnoreCase))
foundEntitlements.Add(entitlement);
}

return foundEntitlements;
}

[Test]
[TestCase("maui-blazor", "Debug", "net8.0")]
[TestCase("maui-blazor", "Release", "net8.0")]
@@ -229,7 +207,7 @@ public void CheckEntitlementsForMauiBlazorOnMacCatalyst(string id, string config
List<string> expectedEntitlements = config == "Release" ?
new() { "com.apple.security.app-sandbox", "com.apple.security.network.client" } :
new() { "com.apple.security.get-task-allow" };
List<string> foundEntitlements = SearchForExpectedEntitlements(entitlementsPath, appLocation, expectedEntitlements);
List<string> foundEntitlements = Codesign.SearchForExpectedEntitlements(entitlementsPath, appLocation, expectedEntitlements);

CollectionAssert.AreEqual(expectedEntitlements, foundEntitlements, "Entitlements missing from executable.");
}