Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtaining codesigning information about App and Ipa #388

Merged
merged 5 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/run_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'run_loop/core'
require 'run_loop/version'
require 'run_loop/plist_buddy'
require "run_loop/codesign"
require 'run_loop/app'
require 'run_loop/ipa'
require 'run_loop/sim_control'
Expand Down
15 changes: 15 additions & 0 deletions lib/run_loop/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ def calabash_server_version
version
end

# @!visibility private
def codesign_info
RunLoop::Codesign.info(path)
end

# @!visibility private
def developer_signed?
RunLoop::Codesign.developer?(path)
end

# @!visibility private
def distribution_signed?
RunLoop::Codesign.distribution?(path)
end

# @!visibility private
# Collects the paths to executables in the bundle.
def executables
Expand Down
4 changes: 4 additions & 0 deletions lib/run_loop/cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'run_loop/cli/instruments'
require 'run_loop/cli/simctl'
require "run_loop/cli/locale"
require "run_loop/cli/codesign"

trap 'SIGINT' do
puts 'Trapped SIGINT - exiting'
Expand Down Expand Up @@ -35,6 +36,9 @@ def version
desc "locale", "Tools for interacting with locales"
subcommand "locale", RunLoop::CLI::Locale

desc "codesign", "Tools for interacting with codesign"
subcommand "codesign", RunLoop::CLI::Codesign

end
end
end
24 changes: 24 additions & 0 deletions lib/run_loop/cli/codesign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "thor"
require "run_loop"
require "run_loop/cli/errors"

module RunLoop
module CLI
class Codesign < Thor

desc "info ARTIFACT", "Print codesign information about ARTIFACT (ipa, app, or library)"

def info(app_or_ipa)
extension = File.extname(app_or_ipa)

if extension == ".app"
puts RunLoop::App.new(app_or_ipa).codesign_info
elsif extension == ".ipa"
puts RunLoop::Ipa.new(app_or_ipa).codesign_info
else
puts RunLoop::Codesign.info(app_or_ipa)
end
end
end
end
end
76 changes: 76 additions & 0 deletions lib/run_loop/codesign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module RunLoop
# @!visibility private
# A wrapper around codesign command line tool
class Codesign

# @!visibility private
DEV_REGEX = /Authority=iPhone Developer:/

# @!visibility private
APP_STORE_REGEX = /Authority=Apple iPhone OS Application Signing/

# @!visibility private
DISTR_REGEX = /Authority=iPhone Distribution:/

# @!visibility private
NOT_SIGNED_REGEX = /code object is not signed at all/

# @!visibility private
def self.info(path)
self.expect_path_exists(path)
self.exec(["--display", "--verbose=4", path])
end

# @!visibility private
#
# True if the asset is signed.
def self.signed?(path)
info = self.info(path)
info[NOT_SIGNED_REGEX, 0] == nil
end

# @!visibility private
#
# True if the asset is signed with anything other than a dev cert.
def self.distribution?(path)
info = self.info(path)

info[NOT_SIGNED_REGEX, 0] == nil &&
info[DEV_REGEX, 0] == nil
end

# @!visibility private
#
# True if the asset is signed with a dev cert
def self.developer?(path)
info = self.info(path)
info[DEV_REGEX, 0] != nil
end

private

def self.expect_path_exists(path)
if !File.exist?(path)
raise ArgumentError,
%Q{There is no file or directory at path:

#{path}
}
end
end

def self.exec(args)
if !args.is_a?(Array)
raise ArgumentError, "Expected args: '#{args}' to be an Array"
end

xcrun = RunLoop::Xcrun.new
cmd = ["codesign"] + args
options = {:log_cmd => true}
hash = xcrun.exec(cmd, options)

hash[:out]
end
end
end

15 changes: 15 additions & 0 deletions lib/run_loop/ipa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ def calabash_server_version
app.calabash_server_version
end

# @!visibility private
def codesign_info
app.codesign_info
end

# @!visibility private
def developer_signed?
app.developer_signed?
end

# @!visibility private
def distribution_signed?
app.distribution_signed?
end

private

# @!visibility private
Expand Down
6 changes: 4 additions & 2 deletions scripts/ci/jenkins/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ $RBENV_EXEC bundle exec rspec \
spec/integration/xcode_spec.rb \
spec/integration/otool_spec.rb \
spec/integration/strings_spec.rb \
spec/integration/app_spec.rb
spec/integration/app_spec.rb \
spec/integration/codesign_spec.rb

# CLI tests

Expand All @@ -42,5 +43,6 @@ execute "$RBENV_EXEC bundle exec run-loop version"
execute "$RBENV_EXEC bundle exec run-loop help"
execute "$RBENV_EXEC bundle exec run-loop instruments help"
execute "$RBENV_EXEC bundle exec run-loop simctl help"

execute "$RBENV_EXEC bundle exec run-loop codesign help"
execute "$RBENV_EXEC bundle exec run-loop codesign info spec/resources/CalSmoke.ipa"

41 changes: 41 additions & 0 deletions spec/integration/codesign_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

describe RunLoop::Codesign do
let(:distribution) { Resources.shared.wetap_bundle }
let(:developer) do
ipa = RunLoop::Ipa.new(Resources.shared.ipa_path)
ipa.send(:app).send(:path)
end
let(:unsigned) { Resources.shared.app_bundle_path }

describe ".distribution?" do
it "true" do
expect(RunLoop::Codesign.distribution?(distribution)).to be_truthy
end

it "false" do
expect(RunLoop::Codesign.distribution?(developer)).to be_falsey
end
end

describe ".developer?" do
it "true" do
expect(RunLoop::Codesign.developer?(developer)).to be_truthy
end

it "false" do
expect(RunLoop::Codesign.developer?(distribution)).to be_falsey
end
end

describe ".signed?" do
it "true" do
expect(RunLoop::Codesign.signed?(developer)).to be_truthy
expect(RunLoop::Codesign.signed?(distribution)).to be_truthy
end

it "false" do
expect(RunLoop::Codesign.signed?(unsigned)).to be_falsey
end
end
end

20 changes: 20 additions & 0 deletions spec/lib/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@
end
end

describe "codesign" do
it "#codesign_info" do
expect(RunLoop::Codesign).to receive(:info).with(app.path).and_return(:info)

expect(app.codesign_info).to be == :info
end

it "#developer_signed?" do
expect(RunLoop::Codesign).to receive(:developer?).with(app.path).and_return(:value)

expect(app.developer_signed?).to be == :value
end

it "#distribution_signed?" do
expect(RunLoop::Codesign).to receive(:distribution?).with(app.path).and_return(:value)

expect(app.distribution_signed?).to be == :value
end
end

it '#sha1' do
expect(RunLoop::Directory).to receive(:directory_digest).with(app.path).and_return 'sha1'

Expand Down
Loading