Skip to content

Commit 5cdeb51

Browse files
Created new Codesign class and moved SearchForExpectedEntitlements to it.
1 parent bcf962c commit 5cdeb51

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Diagnostics;
2+
3+
namespace Microsoft.Maui.IntegrationTests.Apple
4+
{
5+
public static class Codesign
6+
{
7+
public static List<string> SearchForExpectedEntitlements(
8+
string entitlementsPath,
9+
string appLocation,
10+
List<string> expectedEntitlements)
11+
{
12+
List<string> foundEntitlements = new();
13+
string procOutput = ToolRunner.Run(new ProcessStartInfo()
14+
{
15+
FileName = "/usr/bin/codesign",
16+
Arguments = $"-d --entitlements {entitlementsPath} --xml {appLocation}"
17+
}, out int errorCode);
18+
19+
Assert.AreEqual(errorCode, 0, procOutput);
20+
Assert.IsTrue(File.Exists(entitlementsPath));
21+
22+
string fileContent = File.ReadAllText(entitlementsPath);
23+
foreach (string entitlement in expectedEntitlements)
24+
{
25+
if (fileContent.Contains(entitlement, StringComparison.OrdinalIgnoreCase))
26+
foundEntitlements.Add(entitlement);
27+
}
28+
29+
return foundEntitlements;
30+
}
31+
}
32+
}
33+

src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using Microsoft.Maui.IntegrationTests.Apple;
22

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

185-
List<string> SearchForExpectedEntitlements(string entitlementsPath, string appLocation, List<string> expectedEntitlements)
186-
{
187-
List<string> foundEntitlements = new();
188-
string procOutput = ToolRunner.Run(new ProcessStartInfo()
189-
{
190-
FileName = "/usr/bin/codesign",
191-
Arguments = $"-d --entitlements {entitlementsPath} --xml {appLocation}"
192-
}, out int errorCode);
193-
194-
Assert.AreEqual(errorCode, 0, procOutput);
195-
Assert.IsTrue(File.Exists(entitlementsPath));
196-
197-
string fileContent = File.ReadAllText(entitlementsPath);
198-
foreach (string entitlement in expectedEntitlements)
199-
{
200-
if (fileContent.Contains(entitlement, StringComparison.OrdinalIgnoreCase))
201-
foundEntitlements.Add(entitlement);
202-
}
203-
204-
return foundEntitlements;
205-
}
206-
207185
[Test]
208186
[TestCase("maui-blazor", "Debug", "net8.0")]
209187
[TestCase("maui-blazor", "Release", "net8.0")]
@@ -229,7 +207,7 @@ public void CheckEntitlementsForMauiBlazorOnMacCatalyst(string id, string config
229207
List<string> expectedEntitlements = config == "Release" ?
230208
new() { "com.apple.security.app-sandbox", "com.apple.security.network.client" } :
231209
new() { "com.apple.security.get-task-allow" };
232-
List<string> foundEntitlements = SearchForExpectedEntitlements(entitlementsPath, appLocation, expectedEntitlements);
210+
List<string> foundEntitlements = Codesign.SearchForExpectedEntitlements(entitlementsPath, appLocation, expectedEntitlements);
233211

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

0 commit comments

Comments
 (0)