Skip to content

Commit

Permalink
[release/8.0.1xx-xcode15.1] [msbuild] Process custom entitlements as …
Browse files Browse the repository at this point in the history
…if they came from an Entitlements.plist file. (#19955)

We need to process custom entitlements just like if they came from an
Entitlements.plist file - which means replacing terms such as
`$(AppIdentifierPrefix)` and `$(TeamIdentifierPrefix)` with their correct value
depending on the provisioning profile.

Partial fix for #19903.

Backport of #19942
  • Loading branch information
vs-mobiletools-engineering-service2 committed Jan 30, 2024
1 parent dae5688 commit 7075fa1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision? profi
return result;
}

void AddCustomEntitlements (PDictionary dict)
void AddCustomEntitlements (PDictionary dict, MobileProvision? profile)
{
if (CustomEntitlements is null)
return;
Expand Down Expand Up @@ -280,7 +280,7 @@ void AddCustomEntitlements (PDictionary dict)
dict [entitlement] = new PBoolean (booleanValue);
break;
case "string":
dict [entitlement] = new PString (value ?? string.Empty);
dict [entitlement] = MergeEntitlementString (new PString (value), profile, entitlement == ApplicationIdentifierKey);
break;
case "stringarray":
var arraySeparator = item.GetMetadata ("ArraySeparator");
Expand All @@ -289,7 +289,7 @@ void AddCustomEntitlements (PDictionary dict)
var arrayContent = value.Split (new string [] { arraySeparator }, StringSplitOptions.None);
var parray = new PArray ();
foreach (var element in arrayContent)
parray.Add (new PString (element));
parray.Add (MergeEntitlementString (new PString (element), profile, entitlement == ApplicationIdentifierKey));
dict [entitlement] = parray;
break;
default:
Expand Down Expand Up @@ -407,7 +407,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision? profile,
break;
}

AddCustomEntitlements (entitlements);
AddCustomEntitlements (entitlements, profile);

return entitlements;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,19 @@ CustomCompileEntitlements CreateEntitlementsTask (out string compiledEntitlement
compiledEntitlements = task.CompiledEntitlements.ItemSpec;
archivedEntitlements = Path.Combine (AppBundlePath, "archived-expanded-entitlements.xcent");

DeleteDirectory (Path.Combine (MonoTouchProjectPath, "bin"));
DeleteDirectory (Path.Combine (MonoTouchProjectPath, "obj"));

return task;
}

void DeleteDirectory (string directory)
{
if (!Directory.Exists (directory))
return;
Directory.Delete (directory, true);
}

[Test (Description = "Xambug #46298")]
public void ValidateEntitlement ()
{
Expand Down Expand Up @@ -207,5 +217,46 @@ public void AllowJit_None ()
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
}

[Test]
public void AppIdentifierPrefix ()
{
var customEntitlements = new TaskItem [] {
new TaskItem ("keychain-access-group", new Dictionary<string, string> { { "Type", "String" }, { "Value", "$(AppIdentifierPrefix)org.xamarin" } }),
};
var task = CreateEntitlementsTask (out var compiledEntitlements, out var archivedEntitlements);
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=ios";
task.CustomEntitlements = customEntitlements;
ExecuteTask (task);
var compiled = PDictionary.FromFile (compiledEntitlements);
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
var kag = ((PString) compiled ["keychain-access-group"]).Value;
Assert.That (kag, Is.EqualTo ("32UV7A8CDE.org.xamarin"), "value 1");

var archived = PDictionary.FromFile (archivedEntitlements);
Assert.IsTrue (archived.ContainsKey ("keychain-access-group"), "archived");
var archivedKag = ((PString) archived ["keychain-access-group"]).Value;
Assert.That (archivedKag, Is.EqualTo ("32UV7A8CDE.org.xamarin"), "archived value 1");
}

[Test]
public void TeamIdentifierPrefix ()
{
var customEntitlements = new TaskItem [] {
new TaskItem ("keychain-access-group", new Dictionary<string, string> { { "Type", "String" }, { "Value", "$(TeamIdentifierPrefix)org.xamarin" } }),
};
var task = CreateEntitlementsTask (out var compiledEntitlements, out var archivedEntitlements);
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=ios";
task.CustomEntitlements = customEntitlements;
ExecuteTask (task);
var compiled = PDictionary.FromFile (compiledEntitlements);
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
var kag = ((PString) compiled ["keychain-access-group"]).Value;
Assert.That (kag, Is.EqualTo ("Z8CSQKJE7R.org.xamarin"), "value 1");

var archived = PDictionary.FromFile (archivedEntitlements);
Assert.IsTrue (archived.ContainsKey ("keychain-access-group"), "archived");
var archivedKag = ((PString) archived ["keychain-access-group"]).Value;
Assert.That (archivedKag, Is.EqualTo ("Z8CSQKJE7R.org.xamarin"), "archived value 1");
}
}
}

4 comments on commit 7075fa1

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ API diff for current PR / commit

NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

.NET (No breaking changes)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 7075fa1d8ac197a68f84a4f6b60e4b563189aa4d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

0 tests crashed, 3 tests failed, 92 tests passed.

Failures

❌ linker tests

1 tests failed, 39 tests passed.
  • trimmode copy/tvOS - simulator/Debug [dotnet]: Crashed

Html Report (VSDrops) Download

❌ monotouch tests

2 tests failed, 27 tests passed.
  • monotouch-test/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2776 Passed: 2629 Inconclusive: 4 Failed: 1 Ignored: 146)
  • monotouch-test/iOS Unified 64-bits - simulator/Debug [dotnet]: Crashed

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ framework: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 4 tests passed. Html Report (VSDrops) Download
⚠️ install_source: No tests selected. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
⚠️ mac_binding_project: No tests selected. Html Report (VSDrops) Download
⚠️ mmp: No tests selected. Html Report (VSDrops) Download
⚠️ mononative: No tests selected. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ mtouch: No tests selected. Html Report (VSDrops) Download
⚠️ xammac: No tests selected. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7075fa1d8ac197a68f84a4f6b60e4b563189aa4d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

0 tests crashed, 1 tests failed, 94 tests passed.

Failures

❌ monotouch tests [attempt 2]

1 tests failed, 28 tests passed.
  • monotouch-test/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2892 Passed: 2769 Inconclusive: 10 Failed: 1 Ignored: 122)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ framework: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 4 tests passed. Html Report (VSDrops) Download
⚠️ install_source: No tests selected. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 40 tests passed. [attempt 2] Html Report (VSDrops) Download
⚠️ mac_binding_project: No tests selected. Html Report (VSDrops) Download
⚠️ mmp: No tests selected. Html Report (VSDrops) Download
⚠️ mononative: No tests selected. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ mtouch: No tests selected. Html Report (VSDrops) Download
⚠️ xammac: No tests selected. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7075fa1d8ac197a68f84a4f6b60e4b563189aa4d [CI build]

Please sign in to comment.