frameworks-capybara 0.2.30 → 0.2.31

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.31
2
+ Added Firefox profile certificate handling via the FIREFOX_CERT_PATH and FIREFOX_CERT_PREFIX variables.
3
+
1
4
  0.2.30
2
5
  Fixed rake profiles listings to work with Ruby 1.9+
3
6
 
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ platforms :jruby do
4
4
  gem "jruby-openssl"
5
5
  end
6
6
 
7
- gem "rspec-mocks"
7
+ gem "rspec-mocks", "<2.14.0"
8
8
 
9
9
  gemspec
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frameworks-capybara (0.2.30)
4
+ frameworks-capybara (0.2.31)
5
5
  capybara (~> 1.1.2)
6
6
  capybara-celerity
7
7
  capybara-mechanize (>= 0.3.0)
8
8
  cucumber (>= 0.10.5)
9
9
  headless
10
10
  json
11
+ mime-types (~> 1.25)
11
12
  nokogiri (~> 1.5.10)
12
13
  rubyzip (~> 0.9.9)
13
14
  w3c_validators
@@ -32,16 +33,16 @@ GEM
32
33
  celerity (0.9.2)
33
34
  childprocess (0.3.9)
34
35
  ffi (~> 1.0, >= 1.0.11)
35
- cucumber (1.3.8)
36
+ cucumber (1.3.10)
36
37
  builder (>= 2.1.2)
37
38
  diff-lcs (>= 1.1.3)
38
- gherkin (~> 2.12.1)
39
+ gherkin (~> 2.12)
39
40
  multi_json (>= 1.7.5, < 2.0)
40
41
  multi_test (>= 0.0.2)
41
42
  diff-lcs (1.1.3)
42
- domain_name (0.5.14)
43
+ domain_name (0.5.15)
43
44
  unf (>= 0.0.5, < 1.0.0)
44
- ffi (1.9.0)
45
+ ffi (1.9.3)
45
46
  gherkin (2.12.2)
46
47
  multi_json (~> 1.3)
47
48
  headless (1.0.1)
@@ -82,7 +83,7 @@ GEM
82
83
  multi_json (~> 1.0)
83
84
  rubyzip (< 1.0.0)
84
85
  websocket (~> 1.0.4)
85
- unf (0.1.2)
86
+ unf (0.1.3)
86
87
  unf_ext
87
88
  unf_ext (0.0.6)
88
89
  w3c_validators (1.2)
@@ -101,4 +102,4 @@ DEPENDENCIES
101
102
  jruby-openssl
102
103
  rake
103
104
  rspec (>= 1.0.0)
104
- rspec-mocks
105
+ rspec-mocks (< 2.14.0)
@@ -37,6 +37,8 @@ The following environment variables can be set to configure your tests:
37
37
  REMOTE_URL - URL of remote Selenium-Webdriver server e.g. http://yourremotehost:4444/wd/hub
38
38
  FIREFOX_PROFILE - specify a firefox profile to use when running in-browser tests (local or remote)
39
39
  FIREFOX_PREFS - specify a json string of additional preferences e.g. FIREFOX_PREFS='{"javascript.enabled": false}'
40
+ FIREFOX_CERT_PATH - specify optional directory containing Firefox profile certificate (.db) files
41
+ FIREFOX_CERT_PREFIX - specify optional prefix for locating Firefox profile certificate files (e.g. <prefix>-<file>.db)
40
42
  CREATE_NEW_FF_PROFILE - create a new Firefox profile with name provided by FIREFOX_PROFILE
41
43
  CELERITY_JS_ENABLED (string - 'true', 'false') - determines whether Celerity (HTMLUnit) attempts to execute javascript
42
44
  XVFB - (string - 'true', 'false') - determines whether XVFB is used to run browser (i.e. headless Firefox on *nix platform)
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
 
23
+ s.add_runtime_dependency("mime-types", ["~>1.25"])
23
24
  s.add_runtime_dependency("nokogiri", ["~>1.5.10"])
24
25
  s.add_runtime_dependency("rubyzip", ["~>0.9.9"])
25
26
  s.add_runtime_dependency("capybara", ["~>1.1.2"])
@@ -32,10 +32,14 @@ class CapybaraSetup
32
32
  selenium_remote_opts = {:platform => ENV['PLATFORM'],
33
33
  :browser_name => ENV['REMOTE_BROWSER'],
34
34
  :version => ENV['REMOTE_BROWSER_VERSION'],
35
- :url => ENV['REMOTE_URL']}
35
+ :url => ENV['REMOTE_URL']
36
+ }
36
37
 
37
38
  custom_opts = {:job_name => ENV['SAUCE_JOB_NAME'],
38
- :max_duration => ENV['SAUCE_MAX_DURATION']}
39
+ :max_duration => ENV['SAUCE_MAX_DURATION'],
40
+ :firefox_cert_path => ENV['FIREFOX_CERT_PATH'],
41
+ :firefox_cert_prefix => ENV['FIREFOX_CERT_PREFIX']
42
+ }
39
43
 
40
44
  validate_env_vars(capybara_opts.merge(selenium_remote_opts)) #validate environment variables set using cucumber.yml or passed via command line
41
45
 
@@ -80,11 +84,39 @@ class CapybaraSetup
80
84
  end
81
85
  end
82
86
 
87
+ # WARNING: This modifies the Firefox profile passed in the parameters
88
+ def update_firefox_profile_with_certificates(profile, certificate_path, certificate_prefix = '')
89
+ profile_path = profile.layout_on_disk
90
+
91
+ # Create links to the certificate files in the profile directory
92
+ ['cert8.db', 'key3.db', 'secmod.db'].each do |cert_file|
93
+ source_file = "#{certificate_prefix}#{cert_file}"
94
+ source_path = "#{certificate_path}" + File::SEPARATOR + source_file
95
+ dest_path = profile_path + File::SEPARATOR + cert_file
96
+ if(! File.exist?(source_path))
97
+ raise "Firefox cert db file #{source_path} does not exist."
98
+ end
99
+ FileUtils.cp(source_path, dest_path)
100
+ end
101
+
102
+ # Force the certificates to get pulled into the profile
103
+ profile = Selenium::WebDriver::Firefox::Profile.new(profile_path)
104
+
105
+ # Avoid Firefox certificate alerts
106
+ profile["security.default_personal_cert"] = 'Select Automatically'
107
+
108
+ return profile
109
+ end
110
+
83
111
  def register_selenium_driver(opts,remote_opts,custom_opts)
84
112
  Capybara.register_driver :selenium do |app|
85
113
 
86
114
  if opts[:firefox_prefs] || opts[:profile]
87
115
  opts[:profile] = create_profile(opts[:profile], opts[:firefox_prefs])
116
+
117
+ if custom_opts[:firefox_cert_path]
118
+ opts[:profile] = update_firefox_profile_with_certificates(opts[:profile], custom_opts[:firefox_cert_path], custom_opts[:firefox_cert_prefix])
119
+ end
88
120
  end
89
121
 
90
122
  opts[:switches] = [opts.delete(:chrome_switches)] if(opts[:chrome_switches])
@@ -1,3 +1,3 @@
1
1
  module FrameworksCapybara
2
- VERSION = '0.2.30'
2
+ VERSION = '0.2.31'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'securerandom'
2
3
  ##
3
4
  #Monkey Patch
4
5
  #This is required because Capybara has module methods (singletons) which create
@@ -448,6 +449,138 @@ describe CapybaraSetup do
448
449
  end
449
450
  end
450
451
 
452
+ context "integration tests for update_firefox_profile_with_certificates() method" do
453
+ before do
454
+ def write_random_data(file_path)
455
+ file_data = SecureRandom.hex
456
+ File.open(file_path, "w") { |a_file|
457
+ a_file.write(file_data)
458
+ }
459
+ file_data
460
+ end
461
+
462
+ def compare_file_data(profile_path, file_name, expected_data)
463
+ profile_file = profile_path + File::SEPARATOR + file_name
464
+ actual_data = nil
465
+ File.open(profile_file, "r") { |a_file|
466
+ actual_data = a_file.read
467
+ }
468
+ expected_data.should == actual_data
469
+ end
470
+
471
+ ENV['BROWSER'] = 'firefox'
472
+ ENV['ENVIRONMENT'] = 'test'
473
+ ENV['HTTP_PROXY'] = 'http://example.cache.co.uk:80'
474
+ @cert_dir = Dir.mktmpdir
475
+ @cert8_db = @cert_dir + File::SEPARATOR + 'cert8.db'
476
+ @key3_db = @cert_dir + File::SEPARATOR + 'key3.db'
477
+ @secmod_db = @cert_dir + File::SEPARATOR + 'secmod.db'
478
+ end
479
+
480
+ after do
481
+ FileUtils.remove_entry @cert_dir
482
+ end
483
+
484
+ it "should raise an exception if the cert8.db file is missing in the source directory" do
485
+ profile = Selenium::WebDriver::Firefox::Profile.new
486
+
487
+ key3_data = write_random_data(@key3_db)
488
+ secmod_data = write_random_data(@secmod_db)
489
+
490
+ an_exception = nil
491
+ begin
492
+ CapybaraSetup.new.instance_exec(profile, @cert_dir) { |profile, certificate_path|
493
+ update_firefox_profile_with_certificates(profile, certificate_path)
494
+ }
495
+ rescue RuntimeError => e
496
+ an_exception = e
497
+ end
498
+
499
+ an_exception.should_not be_nil
500
+ end
501
+
502
+ it "should raise an exception if the key3.db file is missing in the source directory" do
503
+ profile = Selenium::WebDriver::Firefox::Profile.new
504
+
505
+ cert8_data = write_random_data(@cert8_db)
506
+ secmod_data = write_random_data(@secmod_db)
507
+
508
+ an_exception = nil
509
+ begin
510
+ CapybaraSetup.new.instance_exec(profile, @cert_dir) { |profile, certificate_path|
511
+ update_firefox_profile_with_certificates(profile, certificate_path)
512
+ }
513
+ rescue RuntimeError => e
514
+ an_exception = e
515
+ end
516
+
517
+ an_exception.should_not be_nil
518
+ end
519
+
520
+ it "should raise an exception if the secmod.db file is missing in the source directory" do
521
+ profile = Selenium::WebDriver::Firefox::Profile.new
522
+
523
+ cert8_data = write_random_data(@cert8_db)
524
+ key3_data = write_random_data(@key3_db)
525
+
526
+ an_exception = nil
527
+ begin
528
+ CapybaraSetup.new.instance_exec(profile, @cert_dir) { |profile, certificate_path|
529
+ update_firefox_profile_with_certificates(profile, certificate_path)
530
+ }
531
+ rescue RuntimeError => e
532
+ an_exception = e
533
+ end
534
+
535
+ an_exception.should_not be_nil
536
+ end
537
+
538
+ it "should update a firefox profile with valid references to certificate db files" do
539
+
540
+ profile = Selenium::WebDriver::Firefox::Profile.new
541
+
542
+ cert8_data = write_random_data(@cert8_db)
543
+ key3_data = write_random_data(@key3_db)
544
+ secmod_data = write_random_data(@secmod_db)
545
+
546
+ setup = CapybaraSetup.new
547
+ result = nil
548
+ setup.instance_exec(profile, @cert_dir, result) { |profile, certificate_path, result|
549
+ result = update_firefox_profile_with_certificates(profile, certificate_path)
550
+ }
551
+
552
+ profile_path = result.layout_on_disk
553
+ compare_file_data(profile_path, 'cert8.db', cert8_data)
554
+ compare_file_data(profile_path, 'key3.db', key3_data)
555
+ compare_file_data(profile_path, 'secmod.db', secmod_data)
556
+ end
557
+
558
+ it "should update a firefox profile with references to certificate db files with prefixes" do
559
+
560
+ profile = Selenium::WebDriver::Firefox::Profile.new
561
+ cert_prefix = 'a'
562
+ @cert8_db = @cert_dir + File::SEPARATOR + cert_prefix + 'cert8.db'
563
+ @key3_db = @cert_dir + File::SEPARATOR + cert_prefix + 'key3.db'
564
+ @secmod_db = @cert_dir + File::SEPARATOR + cert_prefix + 'secmod.db'
565
+
566
+ cert8_data = write_random_data(@cert8_db)
567
+ key3_data = write_random_data(@key3_db)
568
+ secmod_data = write_random_data(@secmod_db)
569
+
570
+ setup = CapybaraSetup.new
571
+ result = nil
572
+ setup.instance_exec(profile, @cert_dir, cert_prefix, result) { |profile, certificate_path, certificate_prefix, result|
573
+ result = update_firefox_profile_with_certificates(profile, certificate_path, certificate_prefix)
574
+ }
575
+
576
+ profile_path = result.layout_on_disk
577
+ compare_file_data(profile_path, 'cert8.db', cert8_data)
578
+ compare_file_data(profile_path, 'key3.db', key3_data)
579
+ compare_file_data(profile_path, 'secmod.db', secmod_data)
580
+ end
581
+
582
+ end
583
+
451
584
  end
452
585
 
453
586
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frameworks-capybara
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 30
10
- version: 0.2.30
9
+ - 31
10
+ version: 0.2.31
11
11
  platform: ruby
12
12
  authors:
13
13
  - matt robbins
@@ -15,13 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-10-23 00:00:00 +01:00
18
+ date: 2013-11-19 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 61
30
+ segments:
31
+ - 1
32
+ - 25
33
+ version: "1.25"
34
+ name: mime-types
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
25
40
  none: false
26
41
  requirements:
27
42
  - - ~>
@@ -33,11 +48,11 @@ dependencies:
33
48
  - 10
34
49
  version: 1.5.10
35
50
  name: nokogiri
36
- requirement: *id001
51
+ requirement: *id002
37
52
  - !ruby/object:Gem::Dependency
38
53
  type: :runtime
39
54
  prerelease: false
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
56
  none: false
42
57
  requirements:
43
58
  - - ~>
@@ -49,11 +64,11 @@ dependencies:
49
64
  - 9
50
65
  version: 0.9.9
51
66
  name: rubyzip
52
- requirement: *id002
67
+ requirement: *id003
53
68
  - !ruby/object:Gem::Dependency
54
69
  type: :runtime
55
70
  prerelease: false
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
57
72
  none: false
58
73
  requirements:
59
74
  - - ~>
@@ -65,11 +80,11 @@ dependencies:
65
80
  - 2
66
81
  version: 1.1.2
67
82
  name: capybara
68
- requirement: *id003
83
+ requirement: *id004
69
84
  - !ruby/object:Gem::Dependency
70
85
  type: :runtime
71
86
  prerelease: false
72
- version_requirements: &id004 !ruby/object:Gem::Requirement
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ">="
@@ -81,11 +96,11 @@ dependencies:
81
96
  - 0
82
97
  version: 0.3.0
83
98
  name: capybara-mechanize
84
- requirement: *id004
99
+ requirement: *id005
85
100
  - !ruby/object:Gem::Dependency
86
101
  type: :runtime
87
102
  prerelease: false
88
- version_requirements: &id005 !ruby/object:Gem::Requirement
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
91
106
  - - ">="
@@ -95,11 +110,11 @@ dependencies:
95
110
  - 0
96
111
  version: "0"
97
112
  name: json
98
- requirement: *id005
113
+ requirement: *id006
99
114
  - !ruby/object:Gem::Dependency
100
115
  type: :runtime
101
116
  prerelease: false
102
- version_requirements: &id006 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
103
118
  none: false
104
119
  requirements:
105
120
  - - ">="
@@ -109,11 +124,11 @@ dependencies:
109
124
  - 0
110
125
  version: "0"
111
126
  name: headless
112
- requirement: *id006
127
+ requirement: *id007
113
128
  - !ruby/object:Gem::Dependency
114
129
  type: :runtime
115
130
  prerelease: false
116
- version_requirements: &id007 !ruby/object:Gem::Requirement
131
+ version_requirements: &id008 !ruby/object:Gem::Requirement
117
132
  none: false
118
133
  requirements:
119
134
  - - ">="
@@ -123,11 +138,11 @@ dependencies:
123
138
  - 0
124
139
  version: "0"
125
140
  name: capybara-celerity
126
- requirement: *id007
141
+ requirement: *id008
127
142
  - !ruby/object:Gem::Dependency
128
143
  type: :runtime
129
144
  prerelease: false
130
- version_requirements: &id008 !ruby/object:Gem::Requirement
145
+ version_requirements: &id009 !ruby/object:Gem::Requirement
131
146
  none: false
132
147
  requirements:
133
148
  - - ">="
@@ -137,11 +152,11 @@ dependencies:
137
152
  - 0
138
153
  version: "0"
139
154
  name: w3c_validators
140
- requirement: *id008
155
+ requirement: *id009
141
156
  - !ruby/object:Gem::Dependency
142
157
  type: :runtime
143
158
  prerelease: false
144
- version_requirements: &id009 !ruby/object:Gem::Requirement
159
+ version_requirements: &id010 !ruby/object:Gem::Requirement
145
160
  none: false
146
161
  requirements:
147
162
  - - ">="
@@ -153,11 +168,11 @@ dependencies:
153
168
  - 5
154
169
  version: 0.10.5
155
170
  name: cucumber
156
- requirement: *id009
171
+ requirement: *id010
157
172
  - !ruby/object:Gem::Dependency
158
173
  type: :development
159
174
  prerelease: false
160
- version_requirements: &id010 !ruby/object:Gem::Requirement
175
+ version_requirements: &id011 !ruby/object:Gem::Requirement
161
176
  none: false
162
177
  requirements:
163
178
  - - ">="
@@ -167,11 +182,11 @@ dependencies:
167
182
  - 0
168
183
  version: "0"
169
184
  name: rake
170
- requirement: *id010
185
+ requirement: *id011
171
186
  - !ruby/object:Gem::Dependency
172
187
  type: :development
173
188
  prerelease: false
174
- version_requirements: &id011 !ruby/object:Gem::Requirement
189
+ version_requirements: &id012 !ruby/object:Gem::Requirement
175
190
  none: false
176
191
  requirements:
177
192
  - - ">="
@@ -183,7 +198,7 @@ dependencies:
183
198
  - 0
184
199
  version: 1.0.0
185
200
  name: rspec
186
- requirement: *id011
201
+ requirement: *id012
187
202
  description: Gem to ease the pain of managing capybara driver config and provide a home for common utils and patches
188
203
  email:
189
204
  - mcrobbins@gmail.com