sauce-connect 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/sauce/connect.rb +69 -1
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2YxMTk3ZjhiYmUyMTlhNDcwMmQ5MDNhMDdmYWMyNjkxOTZhYWVlZQ==
4
+ MzQ1YTExNjUwNTc3ZTg0MWE0NWQzYjU1YmE2YmM2YTAzNzQ4ODA5Yw==
5
5
  data.tar.gz: !binary |-
6
- ZTdhOGNmNjg3ZDQxYTU2M2E2OGQ0NjU2MzVkNDM3Y2E1MzFjMGEyMQ==
6
+ MDk1ZmNkYzA0YTllMTM1YTA4NDQ3N2NmOWM2Y2M3MzY3MmI2MDk3NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjcxNWI5NTEwYmRmNGNiZmFlNmEyOTljZTI0MTExMGVmMmE5ZWFmODFiMjg2
10
- OTc5ZTQ0ODM1M2I0MGNjNzZkZDFkNzA2NjYwYTI1YmUxNzBiNjljYzFhMjhk
11
- ZTY4ZTVhMjNmMGE3NzEyZjE2YWVjOGEyYzNhNDczNWYzNzU0MTE=
9
+ ZTYxNTY0MDk3NDZhNjZjYWM0YTY4MDBkNmUzMjY5YWRiMWE4MDI5ODgxNzA5
10
+ ZjZmYjQyNDY4YWRlZGRkM2JmZTFhZDAyN2M1ZmYwZTU3YWI4ZTEyMjY4NDFh
11
+ NDUzMTczYTNiNjdlZGQ3NTQxZDcxMjYxNDZmNzNhM2QwMmI0MzY=
12
12
  data.tar.gz: !binary |-
13
- NDc3OTAxMjk5MzQxY2VjZjdmZjdiMWIzMDViNjI1NTU1ZTRkOTY5NGI2YTQz
14
- MTI2ZGMyNjZhN2VmODUxM2M3ZWI2OGE1ZDEzZWFkOTAyODU0ZDE5Y2FjNTY1
15
- MGVlNTVlNmNlM2VmZTY2YTFkNTc5OGY0Zjg5NTFiYzRhZTIwZmE=
13
+ YWIwNmIyMDkzNzdjZDEyNjRmMGQ3YzMyMTM4OGZlOTRkNzc0Zjc3MTk2MzMw
14
+ MmZiMGNlMjk1MDM4ODg2MjM2Zjg3ZDE4Y2QzNDZiMmYzYWQ2MGVkYzU1MjAz
15
+ ZDc1MjYwYjgzZDE3M2MyYzM2MjhkMGM4ZTI3MzNkMDdhODQ4Mzk=
data/lib/sauce/connect.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'sauce/config'
2
+ require 'net/http'
3
+ require 'socket'
2
4
 
3
5
  module Sauce
4
6
  class Connect
7
+ class TunnelNotPossibleException < StandardError
8
+ end
9
+
5
10
  TIMEOUT = 90
6
11
 
7
12
  attr_reader :status, :error
@@ -13,6 +18,7 @@ module Sauce
13
18
  @quiet = options[:quiet]
14
19
  @timeout = options.fetch(:timeout) { TIMEOUT }
15
20
  @config = Sauce::Config.new(options)
21
+ @skip_connection_test = @config[:skip_connection_test]
16
22
 
17
23
  if @config.username.nil?
18
24
  raise ArgumentError, "Username required to launch Sauce Connect. Please set the environment variable $SAUCE_USERNAME"
@@ -23,7 +29,37 @@ module Sauce
23
29
  end
24
30
  end
25
31
 
32
+ def ensure_connection_is_possible
33
+ $stderr.puts "[Checking REST API is contactable...]" unless @quiet
34
+ uri = URI("http://saucelabs.com/rest/v1/#{@config[:username]}/tunnels")
35
+
36
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
37
+ request = Net::HTTP::Get.new uri.request_uri
38
+ request.basic_auth(@config[:username], @config[:access_key])
39
+ response = http.request request
40
+ end
41
+
42
+ unless response.kind_of? Net::HTTPOK
43
+ $stderr.puts Sauce::Connect.cant_access_rest_api_message
44
+ raise TunnelNotPossibleException "Couldn't access REST API"
45
+ end
46
+
47
+ begin
48
+ $stderr.puts "[Checking port 443 is open...]" unless @quiet
49
+ socket = TCPSocket.new 'saucelabs.com', 443
50
+ rescue SystemCallError => e
51
+ raise e unless e.class.name.start_with? 'Errno::'
52
+ $stderr.puts Sauce::Connect.port_not_open_message
53
+ raise TunnelNotPossibleException, "Couldn't use port 443"
54
+ end
55
+
56
+ end
57
+
26
58
  def connect
59
+ unless @skip_connection_test
60
+ ensure_connection_is_possible
61
+ end
62
+
27
63
  puts "[Connecting to Sauce Labs...]"
28
64
 
29
65
  formatted_cli_options = array_of_formatted_cli_options_from_hash(cli_options)
@@ -129,5 +165,37 @@ module Sauce
129
165
  "--#{opt_name}=#{value}"
130
166
  end
131
167
  end
168
+
169
+ def self.port_not_open_message
170
+ <<-ENDLINE
171
+ Unable to connect to port 443 on saucelabs.com, which may interfere with
172
+ Sauce Connect.
173
+
174
+ This might be caused by a HTTP mocking framework like WebMock or
175
+ FakeWeb. Check out
176
+ (https://github.com/saucelabs/sauce_ruby#network-mocking)
177
+ if you're using one. Sauce Connect needs access to *.saucelabs.com,
178
+ port 80 and port 443.
179
+
180
+ You can disable network tests by setting :skip_connection_test to true in
181
+ your Sauce.config block.
182
+ ENDLINE
183
+ end
184
+
185
+ def self.cant_access_rest_api_message
186
+ <<-ENDLINE
187
+ Unable to connect to the Sauce REST API, which may interfere with
188
+ Sauce Connect.
189
+
190
+ This might be caused by a HTTP mocking framework like WebMock or
191
+ FakeWeb. Check out
192
+ (https://github.com/saucelabs/sauce_ruby#network-mocking)
193
+ if you're using one. Sauce Connect needs access to *.saucelabs.com,
194
+ port 80 and port 443.
195
+
196
+ You can disable network tests by setting :skip_connection_test to true in
197
+ your Sauce.config block.
198
+ ENDLINE
199
+ end
132
200
  end
133
- end
201
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sauce-connect
3
3
  version: !ruby/object:Gem::Version
4
4
  version: !binary |-
5
- My4zLjA=
5
+ My4zLjE=
6
6
  platform: ruby
7
7
  authors:
8
8
  - R. Tyler Croy
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-02-05 00:00:00.000000000 Z
15
+ date: 2014-02-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: sauce
@@ -64,3 +64,4 @@ signing_key:
64
64
  specification_version: 4
65
65
  summary: ''
66
66
  test_files: []
67
+ has_rdoc: