Skip to content
Open
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
10 changes: 10 additions & 0 deletions Sources/XKit/Model/Entitlements/EntitlementTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extension EntitlementContainer {
WiFiAwareEntitlement.self,
HomeKitEntitlement.self,
HealthKitEntitlement.self,
HealthKitBackgroundDeliveryEntitlement.self,
AppleSignInEntitlement.self,
]
}
Expand Down Expand Up @@ -200,3 +201,12 @@ public struct HealthKitEntitlement: Entitlement, RawRepresentable {
public var rawValue: Bool
public init(rawValue: Bool) { self.rawValue = rawValue }
}

/// Not a capability of its own: it only needs to be present on the signed binary,
/// so unlike `HealthKitEntitlement` it has no `DeveloperServicesCapability`.
public struct HealthKitBackgroundDeliveryEntitlement: Entitlement, RawRepresentable {
public static let identifier = "com.apple.developer.healthkit.background-delivery"

public var rawValue: Bool
public init(rawValue: Bool) { self.rawValue = rawValue }
}
46 changes: 46 additions & 0 deletions Tests/XToolTests/HealthKitEntitlementTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Foundation
import Testing
@testable import XKit

private let healthKitPlist = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.background-delivery</key>
<true/>
</dict>
</plist>
"""

@Test func healthKitBackgroundDeliverySurvivesFreeTeamFiltering() throws {
let entitlements = try PropertyListDecoder().decode(
Entitlements.self,
from: Data(healthKitPlist.utf8)
)

// the same filter DeveloperServicesAddAppOperation applies on free teams
let filtered = try entitlements.entitlements().filter { $0.anyCapability?.isFree != false }
let encoded = try PropertyListEncoder().encode(Entitlements(entitlements: filtered))
let dictionary = try #require(
PropertyListSerialization.propertyList(from: encoded, format: nil) as? [String: Any]
)

#expect(dictionary["com.apple.developer.healthkit"] as? Bool == true)
#expect(dictionary["com.apple.developer.healthkit.background-delivery"] as? Bool == true)
}

@Test func healthKitBackgroundDeliveryIsNotRegisteredAsACapability() throws {
let entitlements = try PropertyListDecoder().decode(
Entitlements.self,
from: Data(healthKitPlist.utf8)
)
let backgroundDelivery = try #require(
entitlements.entitlements().compactMap { $0 as? HealthKitBackgroundDeliveryEntitlement }.first
)

#expect(backgroundDelivery.rawValue)
#expect(backgroundDelivery.anyCapability == nil)
}