module Chook::Randomizers

A namespace for holding methods and constants used for creating random data for Test Events and Test Subjects.

Constants

COMPUTER_SERIAL_CHARACTER_SETS
MOBILE_SERIAL_CHARACTER_SETS
NAMES
PATCH_SOFTWARE_TITLES

A full list of supported titles is unfortunately not available via the API :(

PUSH_COMMANDS

Keeping this set of PUSH_COMMANDS in here just in case JAMF decides to make the Push webhooks more useful… PUSH_COMMANDS = [

'Settings',
'DeviceLock',
'EraseDevice',
'ClearPasscode',
'UnmanageDevice',
'UpdateInventory',
'ClearRestrictionsPassword',
'SettingsEnableDataRoaming',
'SettingsDisableDataRoaming',
'SettingsEnableVoiceRoaming',
'SettingsDisableVoiceRoaming',
'SettingsEnableAppAnalytics',
'SettingsDisableAppAnalytics',
'SettingsEnableDiagnosticSubmission',
'SettingsDisableDiagnosticSubmission',
'BlankPush',
'Wallpaper', # supervised only
'DeviceName', # supervised only
'ShutDownDevice', # supervised only
'RestartDevice', # supervised only
'PasscodeLockGracePeriod' # shared iPad only

].freeze

REST_OPS
SAMPLE_COMPUTER_MODELS
SAMPLE_MOBILE_MODELS
WORDS

Public Class Methods

bool() click to toggle source

Random Boolean

@return [Boolean] True or False

# File lib/chook/subject/randomizers.rb, line 434
def self.bool
  rand(0..1).zero?
end
computer_model() click to toggle source

Computer Model (wrapper)

@return [String] Randomly selected Computer model

# File lib/chook/subject/randomizers.rb, line 381
def self.computer_model
  model
end
computer_os_version() click to toggle source

Computer OS Version (wrapper)

@return [String] Operating System Version from a Computer in the JSS

# File lib/chook/subject/randomizers.rb, line 418
def self.computer_os_version
  os_version
end
computer_serial_number() click to toggle source

Computer Serial Number

@return [String] Valid Computer Serial Number

# File lib/chook/subject/randomizers.rb, line 271
def self.computer_serial_number
  serial_number_from COMPUTER_SERIAL_CHARACTER_SETS
end
computer_udid() click to toggle source

Computer UUID (wrapper)

@return [String] Randomly generated computer UUID formatted String

# File lib/chook/subject/randomizers.rb, line 312
def self.computer_udid
  udid
end
email_address() click to toggle source

Random Email

@return [String] Randomly generated email address formatted String e.g. FirstNameLastName@randomword.com

# File lib/chook/subject/randomizers.rb, line 241
def self.email_address
  name.gsub(' ','.') + '@' + word + '.com'
end
host() click to toggle source

Random hostname-formatted String

@return [String] A random hostname-formatted String

# File lib/chook/subject/randomizers.rb, line 500
def self.host
  "#{word}.#{word}.com"
end
iccid() click to toggle source

Random ICCID

@return [String] Randomly generated ICCID formatted number String

# File lib/chook/subject/randomizers.rb, line 352
def self.iccid
  int(20).to_s.scan(/.{4}/).join(' ')
end
imei() click to toggle source

Random IMEI

@return [String] Randomly generated IMEI formatted number String

# File lib/chook/subject/randomizers.rb, line 341
def self.imei
  indexes = [2, 9, 16]
  imei = int(15).to_s
  indexes.each { |idx| imei.insert(idx, ' ') }
  imei
end
int(x = 1) click to toggle source

Random Int

@param [Integer] Optionally choose the length of the returned random Integer @return [Integer] Randomized number of an optionally specified length

# File lib/chook/subject/randomizers.rb, line 250
def self.int(x = 1)
  startpoint = 10**(x - 1)
  endpoint = (10**x) - 1
  rand(startpoint..endpoint)
end
mac_address() click to toggle source

Random MAC Address

@return [String] Randomly generated MAC address formatted String

# File lib/chook/subject/randomizers.rb, line 333
def self.mac_address
  SecureRandom.hex(6).upcase.scan(/.{2}/).join(':')
end
mobile_model() click to toggle source

Mobile Model (wrapper)

@return [String] Randomly selected MobileDevice model

# File lib/chook/subject/randomizers.rb, line 373
def self.mobile_model
  model(true)
end
mobile_os_version() click to toggle source

Mobile OS Version (wrapper)

@return [String] Operating System Version from a MobileDevice in the JSS

# File lib/chook/subject/randomizers.rb, line 410
def self.mobile_os_version
  os_version(true)
end
mobile_serial_number() click to toggle source

Mobile Serial Number (wrapper)

@return [String] Valid Mobile Device Serial Number

# File lib/chook/subject/randomizers.rb, line 279
def self.mobile_serial_number
  serial_number_from MOBILE_SERIAL_CHARACTER_SETS
end
mobile_udid() click to toggle source

Mobile UDID (wrapper)

@return [String] Randomly generated mobile UDID formatted String

# File lib/chook/subject/randomizers.rb, line 320
def self.mobile_udid
  udid(true)
end
model(mobile = false) click to toggle source

Random Model

@param [Boolean] mobile Returns a valid Computer model by default, mobile: true returns a valid Mobile Device model @return [String] Randomly selected Computer or MobileDevice model

# File lib/chook/subject/randomizers.rb, line 361
def self.model(mobile = false)
  if mobile
    SAMPLE_MOBILE_MODELS.sample
  else
    SAMPLE_COMPUTER_MODELS.sample
  end
end
name() click to toggle source

Random Name

@return [String] Randomly generated US English formatted “FirstName LastName”.

# File lib/chook/subject/randomizers.rb, line 233
def self.name
  NAMES.read.lines.sample.chomp + ' ' + NAMES.read.lines.sample.chomp
end
os_build() click to toggle source

Random OS Build

@return [String] Randomized OS build string

# File lib/chook/subject/randomizers.rb, line 426
def self.os_build
  SecureRandom.hex(3).upcase
end
os_version(mobile = false) click to toggle source

Random OS Version

@param [Boolean] mobile Returns a randomized Computer OS version by default, mobile: true returns a randomized Mobile Device OS version @return [Type] String

# File lib/chook/subject/randomizers.rb, line 398
def self.os_version(mobile = false)
  if mobile
    [rand(4..11), int, int].join('.')
  else
    [10, rand(6..15), int].join('.')
  end
end
patch() click to toggle source

Random Patch Software Title

@return [String] Random Patch Software Title

# File lib/chook/subject/randomizers.rb, line 476
def self.patch
  PATCH_SOFTWARE_TITLES.sample
end
phone() click to toggle source

Random Phone Number

@return [String] Random US-formatted Phone Number

# File lib/chook/subject/randomizers.rb, line 450
def self.phone
  raw_phone = int(10).to_s.split(//)
  [3, 7].each { |index| raw_phone.insert(index, '-') }
  raw_phone.join('')
end
product() click to toggle source

Product is null in the sample JSONs… And there isn't anything labeled “product” in JSS::API.get_rsrc(“mobiledevices/id/#{id}”)

# File lib/chook/subject/randomizers.rb, line 325
def self.product
  nil
end
push() click to toggle source

Random Push Command

@return [String] Random Push Command from PUSH_COMMANDS

# File lib/chook/subject/randomizers.rb, line 468
def self.push
  PUSH_COMMANDS.sample
end
rest_operation() click to toggle source

Random REST Operation

@return [String] Random GET, POST, PUT, or DELETE

# File lib/chook/subject/randomizers.rb, line 442
def self.rest_operation
  REST_OPS.sample
end
room() click to toggle source

Random Room Number

@return [String] Random Room Number

# File lib/chook/subject/randomizers.rb, line 460
def self.room
  int((1..4).to_a.sample).to_s
end
serial_number_from(dataset) click to toggle source

Random Serial Number

@param [Array<Array>] A dataset for generating a serial number @return [String] Valid Computer or Mobile Device Serial Number

# File lib/chook/subject/randomizers.rb, line 261
def self.serial_number_from(dataset)
  serial = ''
  dataset.each { |pos| serial << pos.sample }
  serial
end
time() click to toggle source

Random Time (for lastUpdate in Patch Software Update subject)

@return [Time] A random date and time

# File lib/chook/subject/randomizers.rb, line 484
def self.time
  Time.at(rand * Time.now.to_i)
end
udid(mobile = false) click to toggle source

Random U*ID MobileDevice UDID and Mac UUID are poorly distingusished in Jamf Pro. In a Jamf Pro Computer record, the “UDID” in the web interface corresponds to the Hardware UUID. On a Jamf Pro MobileDevice record, the UDID is actually a UDID. Since these are actually different things, they are generated differently.

@return [String] Randomly generated UUID/UDID formatted String

# File lib/chook/subject/randomizers.rb, line 291
def self.udid(mobile = false)
  if mobile
    # UDID = SHA1(serial + IMEI + wifiMac + bluetoothMac)
    Digest::SHA1.hexdigest(serial_number(mobile: true) + int(15).to_s + mac_address + mac_address)
  else
    # UUID
    # In its canonical textual representation, the sixteen octets of a UUID are represented as 32 hexadecimal (base 16) digits
    # displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens).
    # For example:
    # 123e4567-e89b-12d3-a456-426655440000
    indexes = [8, 13, 18, 23]
    uuid = SecureRandom.hex(16).upcase
    indexes.each { |idx| uuid.insert(idx, '-') }
    uuid.upcase
  end
end
url() click to toggle source

Random URL-formatted String

@return [String] A random URL-formatted String

# File lib/chook/subject/randomizers.rb, line 492
def self.url
  "http://www.#{word}.com:#{int}"
end
version() click to toggle source

Version

@return [String] Carrier Settings Version formatted String

# File lib/chook/subject/randomizers.rb, line 389
def self.version
  [int(2), int].join('.')
end
word() click to toggle source

Random Word Use this to generate device or username Strings

@return [String] Randomly generated US English word to stand in for a username, device name, etc.

# File lib/chook/subject/randomizers.rb, line 225
def self.word
  WORDS.read.lines.sample.chomp
end