Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Adding check whether an unsupported entitlement is used, that we can …
Browse files Browse the repository at this point in the history
…not add on the API.

- We check this before checking if App ID exist and is valid as as far we know,
these needed to be added in the provisioning profile generation phase.
So even if the user creates App ID manually, the step can not generate the correct profiles.
The extra entitlements require Apple approval, which we can not test,
so choose to fail early and make the user use the Certificates Installer Step.
  • Loading branch information
lpusok committed Dec 7, 2020
1 parent 938c31f commit 8394b5a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
12 changes: 12 additions & 0 deletions appstoreconnect/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ var ServiceTypeByKey = map[string]CapabilityType{
"com.apple.developer.ubiquity-container-identifiers": Ignored,
}

// UnsupportedEntitlements contains entitlements not supported via the API and this step,
// profile needs to be manually generated on Apple Developer Portal
var UnsupportedEntitlements = []string{
"com.apple.developer.contacts.notes",
"com.apple.developer.carplay-audio",
"com.apple.developer.carplay-communication",
"com.apple.developer.carplay-charging",
"com.apple.developer.carplay-maps",
"com.apple.developer.carplay-parking",
"com.apple.developer.carplay-quick-ordering",
}

// CapabilitySettingAllowedInstances ...
type CapabilitySettingAllowedInstances string

Expand Down
13 changes: 13 additions & 0 deletions autoprovision/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ func dataProtectionEquals(entVal string, cap appstoreconnect.BundleIDCapability)
return true, nil
}

// ContainsUnsupportedEntitlement returns an error if an entitlement is used that we can not generate using the API
func ContainsUnsupportedEntitlement(entitlementsByBundleID map[string]serialized.Object, unsupportedEntitlements []string) error {
for id, entitlements := range entitlementsByBundleID {
for entitlement := range entitlements {
if sliceutil.IsStringInSlice(entitlement, unsupportedEntitlements) {
return fmt.Errorf("unsupported entitlement (%s) set for bundle ID %s", entitlement, id)
}
}
}

return nil
}

// AppearsOnDeveloperPortal reports whether the given (project) Entitlement needs to be registered on Apple Developer Portal or not.
// List of services, to be registered: https://developer.apple.com/documentation/appstoreconnectapi/capabilitytype.
func (e Entitlement) AppearsOnDeveloperPortal() bool {
Expand Down
59 changes: 59 additions & 0 deletions autoprovision/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package autoprovision_test
import (
"testing"

"github.com/bitrise-io/xcode-project/serialized"
"github.com/bitrise-steplib/steps-ios-auto-provision-appstoreconnect/autoprovision"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -100,3 +101,61 @@ func TestICloudContainers(t *testing.T) {
})
}
}

func TestContainsUnsupportedEntitlement(t *testing.T) {
tests := []struct {
name string
entitlementsByBundleID map[string]serialized.Object
unsupportedEntitlements []string
wantErr bool
}{
{
name: "no entitlements",
entitlementsByBundleID: map[string]serialized.Object{
"com.bundleid": map[string]interface{}{},
},
unsupportedEntitlements: []string{"com.entitlements-unsupported"},
},
{
name: "contains unsupported entitlement",
entitlementsByBundleID: map[string]serialized.Object{
"com.bundleid": map[string]interface{}{
"com.entitlement-supported": true,
"com.entitlement-unsupported": true,
},
},
unsupportedEntitlements: []string{"com.entitlement-unsupported"},
wantErr: true,
},
{
name: "contains unsupported entitlement, multiple bundle IDs",
entitlementsByBundleID: map[string]serialized.Object{
"com.bundleID1": map[string]interface{}{
"com.entitlement-supported": true,
},
"com.bundleid": map[string]interface{}{
"com.entitlement-supported": true,
"com.entitlement-unsupported": true,
},
},
unsupportedEntitlements: []string{"com.entitlement-unsupported"},
wantErr: true,
},
{
name: "all entitlements supported",
entitlementsByBundleID: map[string]serialized.Object{
"com.bundleid": map[string]interface{}{
"com.entitlement-supported": true,
},
},
unsupportedEntitlements: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := autoprovision.ContainsUnsupportedEntitlement(tt.entitlementsByBundleID, tt.unsupportedEntitlements); (err != nil) != tt.wantErr {
t.Errorf("ContainsUnsupportedEntitlement() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func main() {
log.Printf("- %s", id)
}

if err := autoprovision.ContainsUnsupportedEntitlement(entitlementsByBundleID, appstoreconnect.UnsupportedEntitlements); err != nil {
failf("Error: %v. Generate provisioning profile manually on Apple Developer Portal and use the Certificate and profile installer Step.", err)
}

platform, err := projHelper.Platform(config)
if err != nil {
failf("Failed to read project platform: %s", err)
Expand Down

0 comments on commit 8394b5a

Please sign in to comment.