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

[msbuild] Process custom entitlements as if they came from an Entitlements.plist file. #19942

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
Expand Up @@ -247,7 +247,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 @@ -286,7 +286,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 @@ -295,7 +295,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 @@ -413,7 +413,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");
}
}
}
Loading