calabash-android 0.4.9 → 0.4.10.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ab10641f1654a9184460287b3acd39c18a7e554
4
- data.tar.gz: c53ea565299a3b2cb84c0c0b4d2a5202e05a06b6
3
+ metadata.gz: 1d3a23228157e56e511aa96bdbdb7947d65d4ca5
4
+ data.tar.gz: 19d05bb6a38811caeb1dba9faadbe259cf64f681
5
5
  SHA512:
6
- metadata.gz: 0d8aeabcb184cea1d57ad76088c9f35b9dfa195343433ba434cf229dcbd956d19aa59b52ddb54805858ee8ab341260d5d7f15b7a8d466daaf842ca27c4a05e85
7
- data.tar.gz: 6990b2abc8e1fe6239d9427cf3d073431900a0c2f8db5c6a15b8ea9fd800d6db87a310e4fd6a49a25a6ee203e9bb49f5497ff8432cc91b9a15701e60455e0c92
6
+ metadata.gz: 50c4753229d9d7ad0ca8341289c084af3557d772acc9c7d6b3558c271bfd9029ffddcc010578550668e37e82324f69c7a8add8fd56e89e31a47505afcde65866
7
+ data.tar.gz: 5b0b9a43deb710ab276af9db66a52437022d6bf49d295b9012eea65f5cf0f07166c7447bd0243402c928fac72878cc8191d54ad0ec3db3a20349c42e171c83dc
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in calabash-android.gemspec
4
4
  gemspec
5
+ gem 'rake', '10.1.0'
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ calabash-android (0.4.10.pre1)
5
+ awesome_print
6
+ cucumber
7
+ escape (~> 0.0.4)
8
+ httpclient (~> 2.3.2)
9
+ json
10
+ popen4 (~> 0.1.2)
11
+ retriable
12
+ rubyzip (~> 0.9.9)
13
+ slowhandcuke
14
+ xamarin-test-cloud (>= 0.9.23)
15
+
16
+ GEM
17
+ remote: http://rubygems.org/
18
+ specs:
19
+ Platform (0.4.0)
20
+ awesome_print (1.1.0)
21
+ builder (3.2.2)
22
+ cucumber (1.3.6)
23
+ builder (>= 2.1.2)
24
+ diff-lcs (>= 1.1.3)
25
+ gherkin (~> 2.12.0)
26
+ multi_json (~> 1.7.5)
27
+ multi_test (>= 0.0.2)
28
+ diff-lcs (1.2.4)
29
+ escape (0.0.4)
30
+ gherkin (2.12.1)
31
+ multi_json (~> 1.3)
32
+ httpclient (2.3.4.1)
33
+ json (1.8.0)
34
+ mime-types (1.25)
35
+ multi_json (1.7.9)
36
+ multi_test (0.0.2)
37
+ open4 (1.3.0)
38
+ popen4 (0.1.2)
39
+ Platform (>= 0.4.0)
40
+ open4 (>= 0.4.0)
41
+ rake (10.1.0)
42
+ rest-client (1.6.7)
43
+ mime-types (>= 1.16)
44
+ retriable (1.3.3.1)
45
+ rubyzip (0.9.9)
46
+ slowhandcuke (0.0.3)
47
+ cucumber
48
+ thor (0.18.1)
49
+ xamarin-test-cloud (0.9.23)
50
+ bundler (>= 1.3.0, < 2.0)
51
+ json
52
+ rest-client (~> 1.6.7)
53
+ retriable (~> 1.3.3.1)
54
+ rubyzip (~> 0.9.9)
55
+ thor (>= 0.18.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ calabash-android!
62
+ rake (= 10.1.0)
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler'
2
2
  load 'lib/calabash-android/helpers.rb'
3
+ load 'lib/calabash-android/env.rb'
3
4
 
4
5
  def build
5
6
  test_server_template_dir = File.join(File.dirname(__FILE__), 'test-server')
@@ -9,9 +10,8 @@ def build
9
10
  @test_server_dir = File.join(workspace_dir, 'test-server')
10
11
  FileUtils.cp_r(test_server_template_dir, workspace_dir)
11
12
 
12
- ant_executable = (is_windows? ? "ant.bat" : "ant")
13
13
  args = [
14
- ant_executable,
14
+ Env.ant_path,
15
15
  "clean",
16
16
  "package",
17
17
  "-debug",
@@ -44,9 +44,6 @@ task :build do
44
44
  end
45
45
 
46
46
  build
47
-
48
- Rake::Task["install"].execute
49
-
50
47
  end
51
48
 
52
49
 
@@ -3,6 +3,8 @@
3
3
  require 'fileutils'
4
4
  require 'rbconfig'
5
5
  require 'calabash-android/helpers'
6
+ require 'calabash-android/java_keystore'
7
+ require 'calabash-android/env'
6
8
 
7
9
  # for ruby 1.9.1 and earlier
8
10
  unless defined? RbConfig.ruby
@@ -1,11 +1,26 @@
1
1
  def calabash_build(app)
2
- keystore = read_keystore_info()
3
- if fingerprint_from_keystore != fingerprint_from_apk(app)
4
- puts "#{app} is not signed with the configured keystore '#{keystore["keystore_location"]}' Aborting!"
5
- exit 1
6
- end
2
+ apk_fingerprint = fingerprint_from_apk(app)
3
+ log "#{app} was signed with a certificate with fingerprint #{apk_fingerprint}"
7
4
 
5
+ keystores = JavaKeystore.get_keystores
6
+ keystore = keystores.find { |k| k.fingerprint == apk_fingerprint}
7
+
8
+ unless keystore
9
+ puts "#{app} is not signed with any of the available keystores."
10
+ puts "Tried the following keystores:"
11
+ keystores.each do |k|
12
+ puts k.location
13
+ end
14
+ puts ""
15
+ puts "You can resign the app with #{keystores.first.location} by running:
16
+ calabash-android resign #{app}"
8
17
 
18
+ puts ""
19
+ puts "Notice that resigning an app might break some functionality."
20
+ puts "Getting a copy of the certificate used when the app was build will in general be more reliable."
21
+
22
+ exit 1
23
+ end
9
24
 
10
25
  test_server_file_name = test_server_path(app)
11
26
  FileUtils.mkdir_p File.dirname(test_server_file_name) unless File.exist? File.dirname(test_server_file_name)
@@ -36,7 +51,7 @@ def calabash_build(app)
36
51
  zip_file.add("AndroidManifest.xml", "customAndroidManifest.xml")
37
52
  end
38
53
  end
39
- sign_apk("#{workspace_dir}/TestServer.apk", test_server_file_name)
54
+ keystore.sign_apk("#{workspace_dir}/TestServer.apk", test_server_file_name)
40
55
  begin
41
56
 
42
57
  rescue Exception => e
@@ -13,7 +13,7 @@ def calabash_setup
13
13
  ask_for_setting(:keystore_password, "Please enter the password for the keystore")
14
14
  ask_for_setting(:keystore_alias, "Please enter the alias")
15
15
 
16
- open('.calabash_settings', 'w') do |f|
16
+ open('calabash_settings', 'w') do |f|
17
17
  f.puts @settings.to_json
18
18
  end
19
19
  puts "Saved your settings to .calabash_settings. You can edit the settings manually or run this setup script again"
@@ -23,4 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency( "awesome_print" )
24
24
  s.add_dependency( 'httpclient', '~> 2.3.2')
25
25
  s.add_dependency( 'xamarin-test-cloud', '>= 0.9.23')
26
+ s.add_dependency( 'popen4', '~> 0.1.2')
27
+ s.add_dependency( 'escape', '~> 0.0.4')
26
28
  end
@@ -0,0 +1,27 @@
1
+
2
+ class Env
3
+
4
+ def self.keytool_path
5
+ if is_windows?
6
+ "\"#{ENV["JAVA_HOME"]}/bin/keytool.exe\""
7
+ else
8
+ "keytool"
9
+ end
10
+ end
11
+
12
+ def self.jarsigner_path
13
+ if is_windows?
14
+ "\"#{ENV["JAVA_HOME"]}/bin/jarsigner.exe\""
15
+ else
16
+ "jarsigner"
17
+ end
18
+ end
19
+
20
+ def self.ant_path
21
+ is_windows? ? "ant.bat" : "ant"
22
+ end
23
+
24
+ def self.is_windows?
25
+ (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
26
+ end
27
+ end
@@ -1,7 +1,12 @@
1
+ require "stringio"
1
2
  require 'rexml/document'
2
3
  require 'rexml/xpath'
3
4
  require 'zip/zip'
4
5
  require 'tempfile'
6
+ require 'popen4'
7
+ require 'escape'
8
+ require 'rbconfig'
9
+ require 'calabash-android/java_keystore'
5
10
 
6
11
  include REXML
7
12
 
@@ -81,20 +86,8 @@ def resign_apk(app_path)
81
86
  end
82
87
 
83
88
  def sign_apk(app_path, dest_path)
84
- keystore = read_keystore_info()
85
-
86
- if is_windows?
87
- jarsigner_path = "\"#{ENV["JAVA_HOME"]}/bin/jarsigner.exe\""
88
- else
89
- jarsigner_path = "jarsigner"
90
- end
91
-
92
- cmd = "#{jarsigner_path} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass #{keystore["keystore_password"]} -keystore #{keystore["keystore_location"]} \"#{app_path}\" #{keystore["keystore_alias"]}"
93
- log cmd
94
- unless system(cmd)
95
- puts "jarsigner command: #{cmd}"
96
- raise "Could not sign app (#{app_path}"
97
- end
89
+ java_keystore = JavaKeystore.get_keystores.first
90
+ java_keystore.sign_apk(app_path, dest_path)
98
91
  end
99
92
 
100
93
  def tools_dir
@@ -107,60 +100,8 @@ def android_home_path
107
100
  ENV["ANDROID_HOME"].gsub("\\", "/")
108
101
  end
109
102
 
110
- def read_keystore_info
111
- keystore = default_keystore
112
-
113
- if File.exist? ".calabash_settings"
114
- keystore = JSON.parse(IO.read(".calabash_settings"))
115
- fail_if_key_missing(keystore, "keystore_location")
116
- fail_if_key_missing(keystore, "keystore_password")
117
- fail_if_key_missing(keystore, "keystore_alias")
118
- keystore["keystore_location"] = File.expand_path(keystore["keystore_location"])
119
- end
120
- keystore["keystore_location"] = put_in_quotes(remove_quotes(keystore["keystore_location"]))
121
- keystore
122
- end
123
-
124
- def default_keystore
125
- {
126
- "keystore_location" => File.expand_path(File.join(ENV["HOME"], "/.android/debug.keystore")),
127
- "keystore_password" => "android",
128
- "keystore_alias" => "androiddebugkey",
129
- }
130
- end
131
-
132
- def fail_if_key_missing(map, key)
133
- raise "Found .calabash_settings but no #{key} defined." unless map[key]
134
- end
135
-
136
- def remove_quotes(s)
137
- s.gsub(/"/, "")
138
- end
139
-
140
- def put_in_quotes(s)
141
- %Q{"#{s}"}
142
- end
143
-
144
- def keytool_path
145
- if is_windows?
146
- "\"#{ENV["JAVA_HOME"]}/bin/keytool.exe\""
147
- else
148
- "keytool"
149
- end
150
- end
151
-
152
- def fingerprint_from_keystore
153
- keystore_info = read_keystore_info
154
- cmd = "#{keytool_path} -v -list -alias #{keystore_info["keystore_alias"]} -keystore #{keystore_info["keystore_location"]} -storepass #{keystore_info["keystore_password"]}"
155
-
156
- log cmd
157
- fingerprints = `#{cmd}`
158
- md5_fingerprint = extract_md5_fingerprint(fingerprints)
159
- log "MD5 fingerprint for keystore (#{keystore_info["keystore_location"]}): #{md5_fingerprint}"
160
- md5_fingerprint
161
- end
162
-
163
103
  def fingerprint_from_apk(app_path)
104
+ app_path = File.expand_path(app_path)
164
105
  Dir.mktmpdir do |tmp_dir|
165
106
  Dir.chdir(tmp_dir) do
166
107
  FileUtils.cp(app_path, "app.apk")
@@ -169,10 +110,11 @@ def fingerprint_from_apk(app_path)
169
110
  z.extract if /^META-INF\/\w+.(RSA|rsa)/ =~ z.name
170
111
  end
171
112
  rsa_files = Dir["#{tmp_dir}/META-INF/*"]
113
+
172
114
  raise "No RSA file found in META-INF. Cannot proceed." if rsa_files.empty?
173
115
  raise "More than one RSA file found in META-INF. Cannot proceed." if rsa_files.length > 1
174
116
 
175
- cmd = "#{keytool_path} -v -printcert -file \"#{rsa_files.first}\""
117
+ cmd = "#{Env.keytool_path} -v -printcert -file \"#{rsa_files.first}\""
176
118
  log cmd
177
119
  fingerprints = `#{cmd}`
178
120
  md5_fingerprint = extract_md5_fingerprint(fingerprints)
@@ -183,18 +125,11 @@ def fingerprint_from_apk(app_path)
183
125
  end
184
126
 
185
127
  def extract_md5_fingerprint(fingerprints)
186
- log fingerprints
187
-
188
128
  m = fingerprints.scan(/MD5.*((?:[a-fA-F\d]{2}:){15}[a-fA-F\d]{2})/).flatten
189
129
  raise "No MD5 fingerprint found:\n #{fingerprints}" if m.empty?
190
130
  m.first
191
131
  end
192
132
 
193
- def is_windows?
194
- require 'rbconfig'
195
- (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
196
- end
197
-
198
133
  def log(message, error = false)
199
134
  $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (error or ARGV.include? "-v" or ARGV.include? "--verbose")
200
135
  end
@@ -0,0 +1,91 @@
1
+ class JavaKeystore
2
+ attr_reader :errors, :location, :keystore_alias, :password, :fingerprint
3
+ def initialize(location, keystore_alias, password)
4
+ raise "No such file #{location}" unless File.exists?(File.expand_path(location))
5
+
6
+ keystore_data = system_with_stdout_on_success(Env.keytool_path, '-list', '-v', '-alias', keystore_alias, '-keystore', location, '-storepass', password)
7
+ unless keystore_data
8
+ error = "Could not list certificates in keystore. Probably because the password was incorrect."
9
+ @errors = [message: error]
10
+ log error
11
+ #TODO: Handle the case where password is correct but the alias is missing.
12
+ end
13
+ @location = location
14
+ @keystore_alias = keystore_alias
15
+ @password = password
16
+ @fingerprint = extract_md5_fingerprint(keystore_data)
17
+ end
18
+
19
+ def sign_apk(apk_path, dest_path)
20
+ raise "Cannot sign with a miss configured keystore" if errors
21
+ raise "No such file: #{apk_path}" unless File.exists?(apk_path)
22
+
23
+ unless system_with_stdout_on_success(Env.jarsigner_path, '-sigalg', 'MD5withRSA', '-digestalg', 'SHA1', '-signedjar', dest_path, '-storepass', password, '-keystore', location, apk_path, keystore_alias)
24
+ raise "Could not sign app: #{apk_path}"
25
+ end
26
+ end
27
+
28
+ def system_with_stdout_on_success(cmd, *args)
29
+ args = args.clone.unshift cmd
30
+
31
+ out, err = nil, nil
32
+ cmd = Escape.shell_command(args)
33
+ log "Command: #{cmd}"
34
+ status = POpen4::popen4(cmd) do |stdout, stderr, stdin, pid|
35
+ out = stdout.read
36
+ err = stderr.read
37
+ end
38
+ if status.exitstatus == 0
39
+ out
40
+ else
41
+ nil
42
+ end
43
+ end
44
+
45
+ def self.read_keystore_with_default_password_and_alias(path)
46
+ path = File.expand_path path
47
+
48
+ if File.exists? path
49
+ keystore = JavaKeystore.new(path, 'androiddebugkey', 'android')
50
+ if keystore.errors
51
+ log "Trying to "
52
+ nil
53
+ else
54
+ log "Unlocked keystore at #{path} - fingerprint: #{keystore.fingerprint}"
55
+ keystore
56
+ end
57
+ else
58
+ log "Trying to read keystore from: #{path} - no such file"
59
+ nil
60
+ end
61
+ end
62
+
63
+ def self.get_keystores
64
+ if keystore = keystore_from_settings
65
+ keystore
66
+ else
67
+ [
68
+ read_keystore_with_default_password_and_alias(File.join(ENV["HOME"], "/.android/debug.keystore")),
69
+ read_keystore_with_default_password_and_alias("debug.keystore"),
70
+ read_keystore_with_default_password_and_alias(File.join(ENV["HOME"], ".local/share/Xamarin/Mono\ for\ Android/debug.keystore")),
71
+ read_keystore_with_default_password_and_alias(File.join(ENV["HOME"], "AppData/Local/Xamarin/Mono for Android/debug.keystore")),
72
+ ].compact
73
+ end
74
+ end
75
+
76
+ def self.keystore_from_settings
77
+ keystore = JSON.parse(IO.read(".calabash_settings")) if File.exist? ".calabash_settings"
78
+ keystore = JSON.parse(IO.read("calabash_settings")) if File.exist? "calabash_settings"
79
+ return unless keystore
80
+ fail_if_key_missing(keystore, "keystore_location")
81
+ fail_if_key_missing(keystore, "keystore_password")
82
+ fail_if_key_missing(keystore, "keystore_alias")
83
+ keystore["keystore_location"] = File.expand_path(keystore["keystore_location"])
84
+ JavaKeystore.new(keystore["keystore_location"], keystore["keystore_alias"], keystore["keystore_password"])
85
+ end
86
+
87
+ def fail_if_key_missing(map, key)
88
+ raise "Found .calabash_settings but no #{key} defined." unless map[key]
89
+ end
90
+
91
+ end
@@ -10,6 +10,7 @@ require 'calabash-android/helpers'
10
10
  require 'calabash-android/wait_helpers'
11
11
  require 'calabash-android/touch_helpers'
12
12
  require 'calabash-android/version'
13
+ require 'calabash-android/env'
13
14
  require 'retriable'
14
15
  require 'cucumber'
15
16
 
@@ -405,7 +406,7 @@ module Operations
405
406
  end
406
407
 
407
408
  def adb
408
- if is_windows?
409
+ if Env.is_windows?
409
410
  %Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe")
410
411
  else
411
412
  %Q("#{ENV["ANDROID_HOME"]}/platform-tools/adb")
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.4.9"
3
+ VERSION = "0.4.10.pre1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Maturana Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.9.23
125
+ - !ruby/object:Gem::Dependency
126
+ name: popen4
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.1.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.1.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: escape
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 0.0.4
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 0.0.4
125
153
  description: 'calabash-android drives tests for native and hybrid Android apps. '
126
154
  email:
127
155
  - jonas@lesspainful.com
@@ -133,6 +161,7 @@ files:
133
161
  - .calabash_settings
134
162
  - CHANGES.txt
135
163
  - Gemfile
164
+ - Gemfile.lock
136
165
  - LICENSE
137
166
  - Rakefile
138
167
  - bin/calabash-android
@@ -158,7 +187,9 @@ files:
158
187
  - lib/calabash-android/canned_steps.md
159
188
  - lib/calabash-android/color_helper.rb
160
189
  - lib/calabash-android/cucumber.rb
190
+ - lib/calabash-android/env.rb
161
191
  - lib/calabash-android/helpers.rb
192
+ - lib/calabash-android/java_keystore.rb
162
193
  - lib/calabash-android/lib/AXMLPrinter2.jar
163
194
  - lib/calabash-android/lib/apktool-cli-1.5.3-SNAPSHOT.jar
164
195
  - lib/calabash-android/lib/manifest_extractor.jar
@@ -874,14 +905,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
874
905
  version: '0'
875
906
  required_rubygems_version: !ruby/object:Gem::Requirement
876
907
  requirements:
877
- - - '>='
908
+ - - '>'
878
909
  - !ruby/object:Gem::Version
879
- version: '0'
910
+ version: 1.3.1
880
911
  requirements: []
881
912
  rubyforge_project:
882
- rubygems_version: 2.0.2
913
+ rubygems_version: 2.0.5
883
914
  signing_key:
884
915
  specification_version: 4
885
916
  summary: Client for calabash-android for automated functional testing on Android
886
917
  test_files: []
887
- has_rdoc: