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
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
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,3 +1,4 @@
using Microsoft.Maui.IntegrationTests.Apple;

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

[Test]
[TestCase("maui-blazor", "Debug", DotNetCurrent)]
[TestCase("maui-blazor", "Release", DotNetCurrent)]
public void CheckEntitlementsForMauiBlazorOnMacCatalyst(string id, string config, string framework)
{
if(TestEnvironment.IsWindows)
Assert.Ignore("Running MacCatalyst templates is only supported on Mac.");

string projectDir = TestDirectory;
string projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");
// Note: Debug app is stored in the maccatalyst-x64 folder, while the Release is in parent directory
string appLocation = config == "Release" ?
Path.Combine(projectDir, "bin", config, $"{framework}-maccatalyst", $"{Path.GetFileName(projectDir)}.app") :
Path.Combine(projectDir, "bin", config, $"{framework}-maccatalyst", "maccatalyst-x64", $"{Path.GetFileName(projectDir)}.app");
string entitlementsPath = Path.Combine(projectDir, "x.xml");

List<string> buildWithCodeSignProps = new List<string>(BuildProps)
{
"EnableCodeSigning=true"
};

Assert.IsTrue(DotnetInternal.New(id, projectDir, framework), $"Unable to create template {id}. Check test output for errors.");
Assert.IsTrue(DotnetInternal.Build(projectFile, config, framework: $"{framework}-maccatalyst", properties: buildWithCodeSignProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");

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 = Codesign.SearchForExpectedEntitlements(entitlementsPath, appLocation, expectedEntitlements);

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

void EnableTizen(string projectFile)
{
FileUtilities.ReplaceInFile(projectFile, new Dictionary<string, string>()
Expand Down
Loading