-
Notifications
You must be signed in to change notification settings - Fork 20
/
Rakefile
90 lines (79 loc) · 3.58 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'bundler/gem_tasks'
require 'motion-provisioning'
# Rake::Task[:build].enhance [:build_export_private_key] # make sure export_private_key is compiled prior to Bundler's "build" task so that it can be included in the gem package
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
t.rspec_opts = "--tag #{task_args[:tag]}"
end
rescue LoadError
end
desc "Generate the certificates needed by the test suite."
task :generate_certificates do
FileUtils.mkdir_p('spec/fixtures')
Dir.chdir('spec/fixtures') do
# Create the root certs
`openssl genrsa -out rootCA.p12 2048`
`openssl req -x509 -new -nodes -key rootCA.p12 -sha256 -days 1024 -out rootCA.pem -subj "/C=US/ST=California/L=San Francisco/O=Apple Inc./OU=IT Department/CN=MotionProvisioning ROOT"`
puts "Adding certificate to Keychain (sudo privileges required)"
`sudo security add-trusted-cert -d -k "#{Dir.home}/Library/Keychains/login.keychain" rootCA.pem`
`security import rootCA.pem`
[:ios, :mac].each do |platform|
[:development, :distribution].each do |type|
generate_certificate(platform, type)
end
end
end
end
# Generates a certificate for the specified platform and type
def generate_certificate(platform, type)
`openssl genrsa -out #{platform}_#{type}_private_key.p12 2048`
`openssl req -new -key #{platform}_#{type}_private_key.p12 -out #{platform}_#{type}.csr -subj "/C=US/ST=California/L=San Francisco/CN=#{platform} #{type}: MotionProvisioning/O=MotionProvisioning/OU=IT Department"`
`openssl x509 -req -extfile openssl.conf -extensions 'my server exts' -in #{platform}_#{type}.csr -CA rootCA.pem -CAkey rootCA.p12 -CAcreateserial -outform der -out #{platform}_#{type}_certificate.cer -days 500 -sha256`
end
task :build_export_private_key do
Dir.chdir('export_private_key') do
system('clang -framework Security -framework CoreFoundation export_private_key.c -o export_private_key')
FileUtils.mv('export_private_key', '../bin/')
end
end
# Run this from time to time to ensure everything is running in the Real World
# like expected.
desc "Create all types of certificates and profiles using a real developer account."
task :production_test do
require "bundler/setup"
require "motion-provisioning"
require "fileutils"
MotionProvisioning.client
num = rand(9999)
ios_app_id = "com.hipbyte.iostest#{num}"
ios_app = MotionProvisioning::Application.find_or_create(bundle_id: ios_app_id, name: "My iOS Test App")
[:ios, :tvos].each do |platform|
[:distribution, :adhoc, :development, :development_free].each do |type|
free = type == :development_free
type = :development if type == :development_free
cert_type = type == :development ? :development : :distribution
MotionProvisioning.certificate(type: cert_type, platform: :ios, free: free)
MotionProvisioning.profile(bundle_identifier: ios_app_id,
platform: platform,
app_name: "My iOS Test App",
type: type,
free: free)
FileUtils.rm(Dir.glob('provisioning/*.cer'))
end
end
ios_app.delete!
num = rand(9999)
mac_app_id = "com.hipbyte.mactest#{num}"
mac_app = MotionProvisioning::Application.find_or_create(bundle_id: mac_app_id, name: "My macOS Test App", mac: true)
platform = :mac
[:distribution, :development].each do |type|
MotionProvisioning.certificate(type: type, platform: :mac)
MotionProvisioning.profile(bundle_identifier: mac_app_id,
platform: platform,
app_name: "My macOS Test App",
type: type)
FileUtils.rm(Dir.glob('provisioning/*.cer'))
end
mac_app.delete!
end