dayglojesus / managedmac

Comprehensive Puppet module for OS X.
http://dayglojesus.github.io/managedmac/
Apache License 2.0
62 stars 21 forks source link

mobileconfig: Error: undefined method `[]' for nil:NilClass #60

Closed dayglojesus closed 9 years ago

dayglojesus commented 9 years ago

Mobileconfig type/provider is not managing individual Payloads properly.

The :content property in the Mobileconfig type accepts an array of Payload hashes each with its own PayloadType and PayloadIdentifier key.

This makes creating compound profiles (configs which span multiple PayloadTypes) simple and straightforward. However, after adding one of these unique Payloads to a Mobileconfig resource successfully, attempts to remove a Payload will fail.

Example: Each of these parameters establishes settings in a different PayloadType...

# This corresponds to PayloadType "com.apple.screensaver" key "askForPassword"
managedmac::security::ask_for_password: true
# This corresponds to PayloadType "com.apple.systempolicy.control" key "EnableAssessment"
managedmac::security::gatekeeper_enable_assessment: true

When these params are passed to the managedmac::security class, TWO distinct Payloads are created.

The bug manifests itself when you attempt to remove one of these params/PayloadTypes by dropping one of the parameters...

# This corresponds to PayloadType "com.apple.screensaver" key "askForPassword"
managedmac::security::ask_for_password: true

You can successfully remove the entire resource, but excising 1 or more individual Payloads produces an error:

Error: undefined method `[]' for nil:NilClass`
dayglojesus commented 9 years ago

This is a bug in the Mobileconfig type, here: https://github.com/dayglojesus/managedmac/blob/master/lib/puppet/type/mobileconfig.rb#L136

It's an out-of-bounds error on the array. This was introduced when we began using PayloadUUIDs as MD5 sums.

Easy fix. We perform an early return if the "is" and "should" arrays are not of equal length.