airborne 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5f2674eef0b9d537ac538d0b0c5610adca03e5a63ad3a5755d409afab9641fe7
4
- data.tar.gz: 36d18e03c11ef4e9ae2d41e88d75bc8719899b541eec5572be393f426a3fd933
2
+ SHA1:
3
+ metadata.gz: 4d361645e26853ce3f56827cc2bd1dbf0742f58d
4
+ data.tar.gz: ce83f9aa0ab23bcda5917e179e1c0b8525f805fb
5
5
  SHA512:
6
- metadata.gz: fcc9fe452b86c3fb2938dedd21dbbb51e05b64a8eb5721114246458134684a01dbf89ef864c27b0cba602e3158c8cd4aa1efeea0446bc59ed41a32ae3dfc4121
7
- data.tar.gz: 9d7d2316ca24842d9190b5e6850c3813384af3708917f5c92d7b5a72f2f613a392d8d849e8b85de7c480a51a8dbb1c5ba74ac4bc56bbdd89efc0543e4b8908be
6
+ metadata.gz: 41aaab8803c8750dd2cc8d16043cc76d15b75d0cd3bd6df791f05703d42c8816a0d7fcc525bf699ec03e013ef6f17d5ae3dd9a87eedf0f59103da53f916e82a1
7
+ data.tar.gz: b99f18a689e857aa156de77471e7908b1859ac5e3afa83735c0154b17ffa416ad7c64642dc07204b7ba116f2c54070dfd444f091ff3ef915af1cc6fa4c47bce8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Airborne
1
+ # Airborne
2
2
 
3
3
  [![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master&style=flat-square)](https://travis-ci.org/brooklynDev/airborne)
4
4
  [![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master)
@@ -156,6 +156,57 @@ For requests that require Query params you can pass a params hash into headers.
156
156
  post 'http://example.com/api/v1/my_api', { }, { 'params' => {'param_key' => 'param_value' } }
157
157
  ```
158
158
 
159
+ ### (Not) Verifying SSL Certificates
160
+
161
+ SSL certificate verification is enabled by default (specifically, `OpenSSL::SSL::VERIFY_PEER`).
162
+
163
+ Carefully consider how you use this. It's not a solution for getting around a failed SSL cert verification; rather, it's intended for testing systems that don't have a legitimate SSL cert, such as a development or test environment.
164
+
165
+ You can override this behavior per request:
166
+
167
+ ```ruby
168
+ verify_ssl = false
169
+ post 'http://example.com/api/v1/my_api', "Hello there!", { content_type: 'text/plain' }, verify_ssl
170
+ ```
171
+
172
+ or with a global Airborne configuration:
173
+
174
+ ```ruby
175
+ Airborne.configure do |config|
176
+ config.verify_ssl = false # equivalent to OpenSSL::SSL::VERIFY_NONE
177
+ end
178
+ ```
179
+
180
+ Note the per-request option always overrides the Airborne configuration:
181
+
182
+ ```ruby
183
+ before do
184
+ Airborne.configuration.verify_ssl = false
185
+ end
186
+
187
+ it 'will still verify the SSL certificate' do
188
+ verify_ssl = true
189
+ post 'http://example.com/api/v1/my_api', "Hello there!", { content_type: 'text/plain' }, verify_ssl
190
+ end
191
+ ```
192
+
193
+ You can use the `verify_ssl` setting to override your global defaults in test blocks like this:
194
+
195
+ ```ruby
196
+ describe 'test something', verify_ssl: false do
197
+ end
198
+ ```
199
+
200
+ OR
201
+
202
+ ```ruby
203
+ describe 'test something' do
204
+ Airborne.configuration.verify_ssl = false
205
+ end
206
+ ```
207
+
208
+ This feature currently isn't supported when testing loaded Rack applications (see "Testing Rack Applications" below). If you need to set `verify_ssl: false`, then we recommend starting your Rack app server and sending the `airborne` HTTP requests as you would when testing any other service.
209
+
159
210
  ## Testing Rack Applications
160
211
 
161
212
  If you have an existing Rack application like `sinatra` or `grape` you can run Airborne against your application and test without actually having a server running. To do that, just specify your rack application in your Airborne configuration:
@@ -238,7 +289,7 @@ it 'should allow nested paths' do
238
289
  end
239
290
  ```
240
291
 
241
- Alternativley, if we only want to test `coordinates` we can dot into just the `coordinates`:
292
+ Alternatively, if we only want to test `coordinates` we can dot into just the `coordinates`:
242
293
 
243
294
  ```ruby
244
295
  it 'should allow nested paths' do
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'airborne'
5
- s.version = '0.3.2'
5
+ s.version = '0.3.3'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'RSpec driven API testing framework'
8
8
  s.authors = ['Alex Friedman', 'Seth Pollack']
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.add_runtime_dependency 'rack-test', '< 2.0', '>= 1.1.0'
16
16
  s.add_runtime_dependency 'rack'
17
17
  s.add_runtime_dependency 'activesupport'
18
- s.add_development_dependency 'webmock', '~> 0'
18
+ s.add_development_dependency 'webmock', '~> 3'
19
19
  end
@@ -15,11 +15,14 @@ RSpec.configure do |config|
15
15
  config.add_setting :rack_app
16
16
  config.add_setting :requester_type
17
17
  config.add_setting :requester_module
18
+ config.add_setting :verify_ssl, default: true
18
19
  config.before do |example|
19
20
  config.match_expected = example.metadata[:match_expected].nil? ?
20
21
  Airborne.configuration.match_expected_default? : example.metadata[:match_expected]
21
22
  config.match_actual = example.metadata[:match_actual].nil? ?
22
23
  Airborne.configuration.match_actual_default? : example.metadata[:match_actual]
24
+ config.verify_ssl = example.metadata[:verify_ssl].nil? ?
25
+ Airborne.configuration.verify_ssl? : example.metadata[:verify_ssl]
23
26
  end
24
27
 
25
28
  # Include last since it depends on the configuration already being added
@@ -29,24 +29,24 @@ module Airborne
29
29
  RSpec.configuration
30
30
  end
31
31
 
32
- def get(url, headers = nil)
33
- @response = make_request(:get, url, headers: headers)
32
+ def get(url, headers = nil, verify_ssl = base_verify_ssl)
33
+ @response = make_request(:get, url, headers: headers, verify_ssl: verify_ssl)
34
34
  end
35
35
 
36
- def post(url, post_body = nil, headers = nil)
37
- @response = make_request(:post, url, body: post_body, headers: headers)
36
+ def post(url, post_body = nil, headers = nil, verify_ssl = base_verify_ssl)
37
+ @response = make_request(:post, url, body: post_body, headers: headers, verify_ssl: verify_ssl)
38
38
  end
39
39
 
40
- def patch(url, patch_body = nil, headers = nil)
41
- @response = make_request(:patch, url, body: patch_body, headers: headers)
40
+ def patch(url, patch_body = nil, headers = nil, verify_ssl = base_verify_ssl)
41
+ @response = make_request(:patch, url, body: patch_body, headers: headers, verify_ssl: verify_ssl)
42
42
  end
43
43
 
44
- def put(url, put_body = nil, headers = nil)
45
- @response = make_request(:put, url, body: put_body, headers: headers)
44
+ def put(url, put_body = nil, headers = nil, verify_ssl = base_verify_ssl)
45
+ @response = make_request(:put, url, body: put_body, headers: headers, verify_ssl: verify_ssl)
46
46
  end
47
47
 
48
- def delete(url, delete_body = nil, headers = nil)
49
- @response = make_request(:delete, url, body: delete_body, headers: headers)
48
+ def delete(url, delete_body = nil, headers = nil, verify_ssl = base_verify_ssl)
49
+ @response = make_request(:delete, url, body: delete_body, headers: headers, verify_ssl: verify_ssl)
50
50
  end
51
51
 
52
52
  def head(url, headers = nil)
@@ -79,4 +79,8 @@ module Airborne
79
79
  base = Airborne.configuration.base_url || ''
80
80
  base + url
81
81
  end
82
+
83
+ def base_verify_ssl
84
+ Airborne.configuration.verify_ssl || false
85
+ end
82
86
  end
@@ -4,17 +4,29 @@ module Airborne
4
4
  module RestClientRequester
5
5
  def make_request(method, url, options = {})
6
6
  headers = base_headers.merge(options[:headers] || {})
7
+ verify_ssl = options.fetch(:verify_ssl, true)
7
8
  res = if method == :post || method == :patch || method == :put
8
9
  begin
9
10
  request_body = options[:body].nil? ? '' : options[:body]
10
11
  request_body = request_body.to_json if is_json_request(headers)
11
- RestClient.send(method, get_url(url), request_body, headers){|response, request, result| response }
12
+ RestClient::Request.execute(
13
+ method: method,
14
+ url: get_url(url),
15
+ payload: request_body,
16
+ headers: headers,
17
+ verify_ssl: verify_ssl
18
+ ) { |response, request, result| response }
12
19
  rescue RestClient::Exception => e
13
20
  e.response
14
21
  end
15
22
  else
16
23
  begin
17
- RestClient.send(method, get_url(url), headers){|response, request, result| response }
24
+ RestClient::Request.execute(
25
+ method: method,
26
+ url: get_url(url),
27
+ headers: headers,
28
+ verify_ssl: verify_ssl
29
+ ) { |response, request, result| response }
18
30
  rescue RestClient::Exception => e
19
31
  e.response
20
32
  end
@@ -2,27 +2,36 @@ require 'spec_helper'
2
2
 
3
3
  describe 'client requester' do
4
4
  before do
5
- allow(RestClient).to receive(:send)
5
+ allow(RestClient::Request).to receive(:execute)
6
6
  RSpec::Mocks.space.proxy_for(self).remove_stub_if_present(:get)
7
7
  end
8
8
 
9
9
  after do
10
- allow(RestClient).to receive(:send).and_call_original
11
- Airborne.configure { |config| config.headers = {} }
10
+ allow(RestClient::Request).to receive(:execute).and_call_original
11
+ Airborne.configure { |config| config.headers = {} }
12
+ Airborne.configure { |config| config.verify_ssl = true }
12
13
  end
13
14
 
14
15
  it 'should set :content_type to :json by default' do
15
16
  get '/foo'
16
17
 
17
- expect(RestClient).to have_received(:send)
18
- .with(:get, 'http://www.example.com/foo', { content_type: :json })
18
+ expect(RestClient::Request).to have_received(:execute).with(
19
+ method: :get,
20
+ url: 'http://www.example.com/foo',
21
+ headers: { content_type: :json },
22
+ verify_ssl: true
23
+ )
19
24
  end
20
25
 
21
26
  it 'should override headers with option[:headers]' do
22
27
  get '/foo', { content_type: 'application/x-www-form-urlencoded' }
23
28
 
24
- expect(RestClient).to have_received(:send)
25
- .with(:get, 'http://www.example.com/foo', { content_type: 'application/x-www-form-urlencoded' })
29
+ expect(RestClient::Request).to have_received(:execute).with(
30
+ method: :get,
31
+ url: 'http://www.example.com/foo',
32
+ headers: { content_type: 'application/x-www-form-urlencoded' },
33
+ verify_ssl: true
34
+ )
26
35
  end
27
36
 
28
37
  it 'should override headers with airborne config headers' do
@@ -30,28 +39,147 @@ describe 'client requester' do
30
39
 
31
40
  get '/foo'
32
41
 
33
- expect(RestClient).to have_received(:send)
34
- .with(:get, 'http://www.example.com/foo', { content_type: 'text/plain' })
42
+ expect(RestClient::Request).to have_received(:execute).with(
43
+ method: :get,
44
+ url: 'http://www.example.com/foo',
45
+ headers: { content_type: 'text/plain' },
46
+ verify_ssl: true
47
+ )
35
48
  end
36
49
 
37
50
  it 'should serialize body to json when :content_type is (default) :json' do
38
51
  post '/foo', { test: 'serialized' }
39
52
 
40
- expect(RestClient).to have_received(:send)
41
- .with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: :json })
53
+ expect(RestClient::Request).to have_received(:execute).with(
54
+ method: :post,
55
+ url: 'http://www.example.com/foo',
56
+ payload: { test: 'serialized' }.to_json,
57
+ headers: { content_type: :json },
58
+ verify_ssl: true
59
+ )
42
60
  end
43
61
 
44
62
  it 'should serialize body to json when :content_type is any enhanced JSON content type' do
45
63
  post '/foo', { test: 'serialized' }, { content_type: 'application/vnd.airborne.2+json' }
46
64
 
47
- expect(RestClient).to have_received(:send)
48
- .with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: 'application/vnd.airborne.2+json' })
65
+ expect(RestClient::Request).to have_received(:execute).with(
66
+ method: :post,
67
+ url: 'http://www.example.com/foo',
68
+ payload: { test: 'serialized' }.to_json,
69
+ headers: { content_type: 'application/vnd.airborne.2+json' },
70
+ verify_ssl: true
71
+ )
49
72
  end
50
73
 
51
74
  it 'should not serialize body to json when :content_type does not match JSON' do
52
75
  post '/foo', { test: 'not serialized' }, { content_type: 'text/plain' }
53
76
 
54
- expect(RestClient).to have_received(:send)
55
- .with(:post, 'http://www.example.com/foo', { test: 'not serialized' }, { content_type: 'text/plain' })
77
+ expect(RestClient::Request).to have_received(:execute).with(
78
+ method: :post,
79
+ url: 'http://www.example.com/foo',
80
+ payload: { test: 'not serialized' },
81
+ headers: { content_type: 'text/plain' },
82
+ verify_ssl: true
83
+ )
84
+ end
85
+
86
+ context 'verify_ssl' do
87
+ it 'should be true by default' do
88
+ get '/foo'
89
+
90
+ expect(RestClient::Request).to have_received(:execute).with(
91
+ method: :get,
92
+ url: 'http://www.example.com/foo',
93
+ headers: { content_type: :json },
94
+ verify_ssl: true
95
+ )
96
+ end
97
+
98
+ it 'should be set by airborne config' do
99
+ Airborne.configure { |config| config.verify_ssl = false }
100
+
101
+ get '/foo'
102
+
103
+ expect(RestClient::Request).to have_received(:execute).with(
104
+ method: :get,
105
+ url: 'http://www.example.com/foo',
106
+ headers: { content_type: :json },
107
+ verify_ssl: false
108
+ )
109
+ end
110
+
111
+ it 'should be overriden with options[:verify_ssl]' do
112
+ get '/foo', nil, false
113
+
114
+ expect(RestClient::Request).to have_received(:execute).with(
115
+ method: :get,
116
+ url: 'http://www.example.com/foo',
117
+ headers: { content_type: :json },
118
+ verify_ssl: false
119
+ )
120
+ end
121
+
122
+ it 'should override airborne config with options[:verify_ssl]' do
123
+ Airborne.configure { |config| config.verify_ssl = false }
124
+
125
+ get '/foo', nil, true
126
+
127
+ expect(RestClient::Request).to have_received(:execute).with(
128
+ method: :get,
129
+ url: 'http://www.example.com/foo',
130
+ headers: { content_type: :json },
131
+ verify_ssl: true
132
+ )
133
+ end
134
+
135
+ it 'should interpret airborne "config.verify_ssl = nil" as false' do
136
+ Airborne.configure { |config| config.verify_ssl = nil }
137
+
138
+ get '/foo'
139
+
140
+ expect(RestClient::Request).to have_received(:execute).with(
141
+ method: :get,
142
+ url: 'http://www.example.com/foo',
143
+ headers: { content_type: :json },
144
+ verify_ssl: false
145
+ )
146
+ end
147
+
148
+ context 'rspec metadata', verify_ssl: false do
149
+ it 'should override the base airborne config with the rspec metadata' do
150
+ get '/foo'
151
+
152
+ expect(RestClient::Request).to have_received(:execute).with(
153
+ method: :get,
154
+ url: 'http://www.example.com/foo',
155
+ headers: { content_type: :json },
156
+ verify_ssl: false
157
+ )
158
+ end
159
+
160
+ it 'should be overriden with options[:verify_ssl]' do
161
+ get '/foo', nil, true
162
+
163
+ expect(RestClient::Request).to have_received(:execute).with(
164
+ method: :get,
165
+ url: 'http://www.example.com/foo',
166
+ headers: { content_type: :json },
167
+ verify_ssl: true
168
+ )
169
+ end
170
+
171
+ it 'should be overriden by supplied airborne config' do
172
+ Airborne.configure { |config| config.verify_ssl = true }
173
+
174
+ get '/foo'
175
+
176
+ expect(RestClient::Request).to have_received(:execute).with(
177
+ method: :get,
178
+ url: 'http://www.example.com/foo',
179
+ headers: { content_type: :json },
180
+ verify_ssl: true
181
+ )
182
+ end
183
+ end
56
184
  end
57
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airborne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Friedman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-25 00:00:00.000000000 Z
12
+ date: 2019-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -29,42 +29,42 @@ dependencies:
29
29
  name: rest-client
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 2.0.2
35
32
  - - "<"
36
33
  - !ruby/object:Gem::Version
37
34
  version: '3.0'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: 2.0.2
45
42
  - - "<"
46
43
  - !ruby/object:Gem::Version
47
44
  version: '3.0'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.2
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rack-test
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.1.0
55
52
  - - "<"
56
53
  - !ruby/object:Gem::Version
57
54
  version: '2.0'
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.1.0
58
58
  type: :runtime
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.1.0
65
62
  - - "<"
66
63
  - !ruby/object:Gem::Version
67
64
  version: '2.0'
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.1.0
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: rack
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +99,14 @@ dependencies:
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: '3'
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: '3'
110
110
  description:
111
111
  email:
112
112
  - a.friedman07@gmail.com
@@ -200,7 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 3.0.3
203
+ rubyforge_project:
204
+ rubygems_version: 2.6.11
204
205
  signing_key:
205
206
  specification_version: 4
206
207
  summary: RSpec driven API testing framework