Skip to content

Commit

Permalink
Created new Codesign class and moved SearchForExpectedEntitlements to…
Browse files Browse the repository at this point in the history
… it.
  • Loading branch information
dustin-wojciechowski committed Sep 12, 2023
1 parent bcf962c commit 5cdeb51
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
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;
}
}
}

26 changes: 2 additions & 24 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
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
{
Expand Down Expand Up @@ -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")]
Expand All @@ -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.");
}
Expand Down

0 comments on commit 5cdeb51

Please sign in to comment.