Last active
August 29, 2015 14:04
-
-
Save zmajstor/63ac950717226ddd3559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payload | |
def general_payload | |
payload = Hash.new | |
payload['PayloadVersion'] = 1 | |
payload['PayloadUUID'] = rand(10) | |
payload['PayloadOrganization'] = organization | |
payload | |
end | |
end | |
class WebclipPayload < Payload | |
attr_accessor :url, :identifier, :display_name, :description, :icon, :label, :organization | |
def initialize(profile) | |
@profile = profile | |
end | |
def payload | |
content_payload = general_payload | |
content_payload['PayloadIdentifier'] = @profile.identifier + ".webclip.intranet" | |
content_payload['PayloadType'] = "com.apple.webClip.managed" | |
content_payload | |
end | |
end | |
class Profile < Payload | |
attr_accessor :identifier, :display_name, :description, :organization | |
def initialize(args = nil) | |
@organization = "ProMDM" | |
@identifier = "net.promdm" | |
@payloads = [] | |
end | |
def add_webclip | |
webclip = WebclipPayload.new(self) | |
webclip.identifier = identifier | |
webclip.organization = organization | |
webclip.display_name = "iOS Enrolled Webclip" | |
@payloads << webclip | |
return self | |
end | |
def add_other_payload | |
# add some other payload | |
# ... | |
end | |
def content | |
payload = general_payload | |
payload['PayloadType'] = "Configuration" # do not modify | |
payload['PayloadIdentifier'] = identifier + ".encrypted-profile-service" | |
payload['PayloadContent'] = @payloads.map(&:payload) | |
payload | |
end | |
end | |
# dump: | |
p Profile.new.add_webclip.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GeneralPayloadHelper | |
def general_payload | |
payload = Hash.new | |
payload['PayloadVersion'] = 1 | |
payload['PayloadUUID'] = rand(100 | |
payload['PayloadOrganization'] = organization | |
payload['PayloadDisplayName'] = display_name | |
payload['PayloadDescription'] = description | |
payload | |
end | |
end | |
class WebclipPayload | |
attr_accessor :url, :identifier, :display_name, :description, :icon, :label, :organization | |
include GeneralPayloadHelper | |
def initialize(profile) | |
@profile = profile | |
end | |
def payload | |
content_payload = general_payload | |
content_payload['PayloadIdentifier'] = @profile.identifier + ".webclip.intranet" | |
content_payload['PayloadType'] = "com.apple.webClip.managed" | |
content_payload | |
end | |
end | |
class Profile | |
attr_accessor :identifier, :display_name, :description, :organization | |
include GeneralPayloadHelper | |
def initialize(args = nil) | |
@organization = "ProMDM" | |
@identifier = "net.promdm" | |
@payloads = [] | |
end | |
def add_webclip | |
webclip = WebclipPayload.new(self) | |
webclip.identifier = identifier | |
webclip.organization = organization | |
webclip.display_name = "iOS Enrolled Webclip" | |
@payloads << webclip | |
return self | |
end | |
def add_other_payload | |
# add some other payload | |
# ... | |
end | |
def content | |
payload = general_payload | |
payload['PayloadType'] = "Configuration" # do not modify | |
payload['PayloadIdentifier'] = identifier + ".encrypted-profile-service" | |
payload['PayloadContent'] = @payloads.map(&:payload) | |
payload | |
end | |
end | |
p Profile.new.add_webclip.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe GeneralPayloadHelper do | |
before(:each) do | |
@dummy_class = Struct.new(:organization, :display_name, :description).include(GeneralPayloadHelper).new | |
@dummy_class.organization = "dummy" | |
end | |
it "returns general payload hash" do | |
gp = @dummy_class.general_payload | |
expect(gp).to be_kind_of(Hash) | |
expect(gp["PayloadVersion"]).to eq(1) | |
expect(gp["PayloadOrganization"]).to eq("dummy") | |
# etc ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment