diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs index 1fcc711df97a..d04652a3b2d3 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs @@ -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; @@ -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"); @@ -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: @@ -407,7 +407,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision? profile, break; } - AddCustomEntitlements (entitlements); + AddCustomEntitlements (entitlements, profile); return entitlements; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs index 5eaec127c4cf..8fdec1cf7a0e 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs @@ -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 () { @@ -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 { { "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 { { "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"); + } } }